У меня есть простое приложение Flask с Open API 3. Я определил файл yml таким образом, используя oneOf для разных 200 ответов
paths:
/document:
post:
operationId: document.classify
tags:
- document
summary: Classify a document and return the belonging cluster
description: Assign a class to the input document
requestBody:
content:
application/json:
schema:
...
description: Document to classify
required: true
responses:
'200':
description: OK
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/Output'
- $ref: '#/components/schemas/Fault'
components:
schemas:
Output:
type: object
properties:
dID:
type: string
ClassificationConcepts:
type: array
items:
properties:
Concept:
type: array
description: Comma separated classification tags
items:
type: string
Fault:
type: object
properties:
faultCode:
type: string
description: Fault code number
faultMessage:
type: string
description: Fault code message
Но шаг проверки не пропускает вывод, с ошибкой "Не удалось проверить 'oneOf' в схеме" В экземпляре: {'ClassificationConcepts': [{'Concept': ['Test']}], 'dID': 'test'}.
'oneOf': [{
'properties': {
'ClassificationConcepts': {
'items': {
'properties': {
'Concept': {
'description': 'Comma '
'separated '
'classification '
'tags',
'items': {
'type': 'string'
},
'type': 'array'
}
}
},
'type': 'array'
},
'dID': {
'type': 'string'
}
},
'type': 'object',
'x-scope': ['']
}
...
]
}
Вот мой код Python:
dID = body.get("dID")
try:
class_predicted = classifier.classification_doc(document_text)
result = {"dID": dID,
"ClassificationConcepts": [
{"Concept": class_predicted}
]
}
response = jsonify(result)
response.headers.set("Content-Type", "application/json")
return response
except ValueError as e:
result = {"faultCode": 1, "faultMessage": e.__cause__ }
return make_response(
jsonify(result)
)