Skip to content

Instantly share code, notes, and snippets.

@johanste
Last active October 5, 2020 22:28
Show Gist options
  • Save johanste/b443aaa42ff203828c0571583a71f0ee to your computer and use it in GitHub Desktop.
Save johanste/b443aaa42ff203828c0571583a71f0ee to your computer and use it in GitHub Desktop.
Polymorphic swagger
{
"swagger": "2.0",
"info": {
"title": "Example of polymorphic models, hypothetical document recognition style",
"version": "1.0"
},
"consumes": ["application/json"],
"produces": ["application/json"],
"paths": {
"/analyze": {
"post": {
"operationId": "analyze",
"parameters": [
{
"name": "fakeForm",
"in": "body",
"schema": {
"$ref": "#/definitions/AnalyzedForm"
}
}
],
"responses": {
"200": {
"description": "Successfully identied the type and contents of the document",
"schema": {
"$ref": "#/definitions/AnalyzedForm"
}
}
}
}
}
},
"definitions": {
"AnalyzedForm": {
"description": "Base model for arbitrary forms. Has an untyped set of fields that can be discovered",
"type": "object",
"required": [
"docType",
"fields"
],
"discriminator": "docType",
"properties": {
"docType": {
"type": "string"
},
"fields": {
"$ref": "#/definitions/FormFields"
}
}
},
"FormFields": {
"description": "Base model for collectoin of form fields. Has no known field names",
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/FormField"
}
},
"FormField": {
"type": "object",
"discriminator": "propertyType",
"required": [
"propertyType"
],
"properties": {
"value": {
},
"precision": {
"type": "number",
"minimum": 0,
"maximum": 1
}
}
},
"StringFormField": {
"x-ms-discriminator-value": "string",
"allOf": [
{
"$ref": "#/definitions/FormField"
}
],
"type": "object",
"properties": {
"value": {
"type": "string"
}
}
},
"NumberFormField": {
"x-ms-discriminator-value": "number",
"allOf": [
{
"$ref": "#/definitions/FormField"
}
],
"type": "object",
"properties": {
"value": {
"type": "number"
}
}
},
"DateFormField": {
"x-ms-discriminator-value": "date",
"allOf": [
{
"$ref": "#/definitions/FormField"
}
],
"type": "object",
"properties": {
"value": {
"type": "string",
"format": "date"
}
}
},
"AnalyzedPassport": {
"x-ms-discriminator-value": "passport",
"allOf": [
{
"$ref": "#/definitions/AnalyzedForm"
}
],
"properties": {
"fields": {
"$ref": "#/definitions/AnalyzedPassportFormFields"
}
}
},
"AnalyzedPassportFormFields": {
"allOf": [
{
"$ref": "#/definitions/FormFields"
}
],
"properties": {
"issuingCountry": {
"$ref": "#/definitions/StringFormField"
},
"firstName": {
"$ref": "#/definitions/StringFormField"
}
}
},
"AnalyzedBusinessCard": {
"x-ms-discriminator-value": "form:businesscard",
"allOf": [
{
"$ref": "#/definitions/AnalyzedForm"
}
],
"properties": {
"fields": {
"$ref": "#/definitions/AnalyzedBusinessCardFields"
}
}
},
"AnalyzedBusinessCardFields": {
"properties": {
"companyName": {
"$ref": "#/definitions/StringFormField"
},
"phoneNumber": {
"$ref": "#/definitions/StringFormField"
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment