swagger-api / swagger-api/swagger-client
allOf + enum is resulting in a enum array merge when it should be an intersection
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 2.7k
- Forks
- 765
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 6
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with the supplied OpenAPI YAML in Swagger Editor, then inspect the allOf plugin and the related discussion in PR #2437 before the deepmerge step. Done means the composed policyType enum is the intersection [CAR], without duplicates, and the behavior is covered by an appropriate regression check.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api, backend-api-design
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100