swagger-parser
swagger-parser copied to clipboard
Question: OpenAPI `AllOf` schema validity for same property fields with different data types
Hi Team,
I'm using OpenAPIV3Parser to get openAPI specifications for the parser version 2.1.13. I am wondering if it is possible to validate the AllOf schema in a way that allows the same field to have different data types for each given object. Currently, the AllOf schema does not allow this, which can sometimes mislead the tooling supports we have implemented.
Please find this sample YAML file for AllOf reference to the main issue detectedCatalogColumn schema https://gist.github.com/lnash94/13473a548f9306b88e1270a77b465abd
example code [1]:
components:
schemas:
User:
type: object
properties:
id:
type: integer
name:
type: string
email:
type: string
AdminUser:
type: object
allOf:
- $ref: '#/components/schemas/User'
- properties:
role:
type: string
enum: ['admin', 'moderator']
name:
type: integer
The schema we have provided has name property in the AdminUser schema is of type integer, while the name property in the User schema is of type string. This means that an AdminUser object cannot have both a string name and an integer name.
At the same time I would be grateful if you can provide some insight whether this schema is valid written one [2], because this AllOf schema contains links field with different Object schema type
example [2]
components:
schemas:
DetectedCatalogColumn:
allOf:
- $ref: '#/components/schemas/CatalogColumn'
- required:
- links
type: object
properties:
links:
$ref: '#/components/schemas/DetectedCatalogColumnLinks'
description: The catalog column detected during the first parsing step
CatalogColumn:
required:
- catalogColumnName
- configuration
- id
- links
- userColumName
type: object
properties:
ignored:
type: boolean
default: false
duplicateProductValueConfiguration:
type: string
id:
type: integer
links:
$ref: '#/components/schemas/CatalogColumnLinks'
description: The catalog column configuration
CatalogColumnLinks:
type: object
properties:
rename:
$ref: '#/components/schemas/Links.Catalog_ChangeCatalogColumnUserNameLink'
Links.Catalog_ChangeCatalogColumnUserNameLink:
allOf:
- $ref: '#/components/schemas/BeezUP_Common_Link3'
BeezUP_Common_Link3:
required:
- href
type: object
properties:
label:
type: string
description: >-
The label corresponding to the link. This label is automatically
translated based on the Accept-Language http header.
example: The translated label
docUrl:
type: string
description:
type: string
description: The description of the link
example: This is a description link
urlTemplated:
type: boolean
description: indicates whether the href is templated or not
allRequiredParamsProvided:
type: boolean
description: indicates whether all required params have been provided
allOptionalParamsProvided:
type: boolean
DetectedCatalogColumnLinks:
type: object
properties:
configure:
type: string
ignore:
type: integer
reattend:
type: boolean
Reference tool: https://github.com/ballerina-platform/openapi-tools https://ballerina.io/learn/openapi-tool/