Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allOf + enum is resulting in a enum array merge when it should be an intersection #2472

Open
frankkilcommins opened this issue Feb 22, 2022 · 2 comments

Comments

@frankkilcommins
Copy link

frankkilcommins commented Feb 22, 2022

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

allOf-enum-composition-bug

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

@frankkilcommins frankkilcommins changed the title allOf + enum is resulting in a enum array merge when it should actually be an intersection allOf + enum is resulting in a enum array merge when it should be an intersection Feb 23, 2022
@antoine-chopin
Copy link

antoine-chopin commented Sep 21, 2022

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?

@simonaslaurinavicius
Copy link

Any updates on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants