swagger-js
swagger-js copied to clipboard
allOf + enum is resulting in a enum array merge when it should be an intersection
Q&A (please complete the following information)
- OS: [Windows 11]
- Environment: [Chrome 98.0.4758.102]
- Method of installation: []
- Swagger-Client version: []
- Swagger/OpenAPI version: [OpenAPI 3.0.3]
Content & configuration
Paste the yaml below into https://editor.swagger.io/
Swagger/OpenAPI definition:
openapi: 3.0.3
info:
title: Sample API
description: Sample API for inheritance
version: 0.0.1
paths: {}
components:
schemas:
Policy:
type: object
properties:
policyNumber:
description: The insurance policy number
type: string
example: IXP12345678
startAt:
type: string
format: date-time
pattern: '^[0-9]{4}-[0-9]{2}-[0-9]{2}T[012][0-9]:[0-5][0-9]:[0-5][0-9]Z$'
description: The date-time from which this policy becomes active
endAt:
type: string
format: date-time
pattern: '^[0-9]{4}-[0-9]{2}-[0-9]{2}T[012][0-9]:[0-5][0-9]:[0-5][0-9]Z$'
description: The date-time from which this policy ceases
policyType:
type: string
description: The type of insurance policy (base set)
enum: [CAR, HOME, HEALTH]
CarPolicy:
allOf:
- $ref: "#/components/schemas/Policy"
- type: object
properties:
make:
description: The make of care
type: string
example: Nissan
range:
description: car model range
type: string
example: hatchback
model:
description: car model
type: string
example: micra
registrationNumber:
description: the registration number of the vehicle
type: string
example: 00G1011
value:
type: number
format: double
description: The value of the vehicle
example: 2000.0
policyType:
type: string
description: specialized policy type
enum: [CAR, CAR-COMPREHENSIVE]
Describe the bug you're encountering
allOf + enum is resulting in a enum array merge when it should actually be an intersection as any instance must validate against all subschemas.
In the example above, the expected result in the composed model would be to have the policyType with enum: [CAR] as CAR is the only enum value existing in both schemas. However a merge of the two enum arrays occurs resulting in enum: [CAR, HOME, HEALTH, CAR, CAR-COMPREHENSIVE] (even duplicates).
To reproduce...
Steps to reproduce the behavior: Paste the YAML into swagger editor
Expected behavior
allOf + enum is resulting in a enum array merge when it should actually be an intersection as any instance must validate against all subschemas.
Screenshots

Additional context or thoughts
Enums will have to be fixed directly in all-off plugin, before the deepmerge is executed. See this PR for related discussion
I've got this issue as well, do you know if there's anything planned to fix it or at least if it's considered a bug by maintainers?
Any updates on this?