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

Issue on discriminator mapping #99

Open
Fimeo opened this issue Mar 22, 2024 · 0 comments
Open

Issue on discriminator mapping #99

Fimeo opened this issue Mar 22, 2024 · 0 comments

Comments

@Fimeo
Copy link

Fimeo commented Mar 22, 2024

References in the mapping key of discriminator schema component is not resolved during the openapi-merge with dispute prefix.

References are not renamed properly and the final openapi file is invalid.

For example

The first openapi file openapi1.yml

openapi: 3.0.3
info:
  title: Swagger
  description: description
  version: 1.0.0
servers:
  - url: http://example.com
tags:
  - name: pet
    description: Everything about your Pets
    externalDocs:
      description: Find out more
      url: http://swagger.io
paths:
  /pet:
    post:
      tags:
        - pet
      summary: Add a new pet to the store
      description: Add a new pet to the store
      operationId: addPet
      requestBody:
        description: Create a new pet in the store
        content:
          application/json:
            schema:
              oneOf:
                - $ref: '#/components/schemas/Pet'
                - $ref: '#/components/schemas/Pet2'
              discriminator:
                propertyName: name
                mapping:
                  pet: '#/components/schemas/Pet'
                  pet2: '#/components/schemas/Pet2'
        required: true
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Pet'
components:
  schemas:
    Pet:
      required:
        - id
        - name
      type: object
      properties:
        id:
          type: integer
          format: int64
          example: 10
        name:
          type: string
          example: doggie
    Pet2:
      required:
        - id
        - name
        - lastName
      type: object
      properties:
        id:
          type: integer
          format: int64
          example: 10
        name:
          type: string
          example: doggie
        lastName:
          type: string
          example: doogle
  requestBodies:
    Pet:
      description: Pet object that needs to be added to the store
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Pet'

The second openapifile : openapi2.yml

openapi: 3.0.3
info:
  title: Swagger
  description: description
  version: 1.0.0
servers:
  - url: http://example.com
tags:
  - name: pet
    description: Everything about your Pets
    externalDocs:
      description: Find out more
      url: http://swagger.io
paths:
  /pet2:
    post:
      tags:
        - pet
      summary: Add a new pet to the store
      description: Add a new pet to the store
      operationId: addPet
      requestBody:
        description: Create a new pet in the store
        content:
          application/json:
            schema:
              oneOf:
                - $ref: '#/components/schemas/Pet'
                - $ref: '#/components/schemas/Pet2'
              discriminator:
                propertyName: name
                mapping:
                  pet: '#/components/schemas/Pet'
                  pet2: '#/components/schemas/Pet2'
        required: true
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Pet'
components:
  schemas:
    Pet:
      required:
        - id
        - name
      type: object
      properties:
        id:
          type: integer
          format: int64
          example: 10
        name:
          type: string
          example: doggie
    Pet2:
      required:
        - id
        - name
        - lastName
      type: object
      properties:
        id:
          type: integer
          format: int64
          example: 10
        name:
          type: string
          example: doggie
        lastName:
          type: string
          example: doogle
  requestBodies:
    Pet:
      description: Pet object that needs to be added to the store
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Pet'

And the merge configuration : (according to the openapi-merge-cli package)

{
    "inputs": [
      {
        "inputFile": "./openapi1.yml",
        "dispute": {
            "prefix": "openapi1",
            "alwaysApply": true
        }
      },
      {
        "inputFile": "./openapi2.yml",
        "dispute": {
            "prefix": "openapi2",
            "alwaysApply": true
        }
      }
    ], 
    "output": "./openap3.yml"
  }

The result is :

openapi: 3.0.3
info:
  title: Swagger
  description: description
  version: 1.0.0
servers:
  - url: 'http://example.com'
tags:
  - name: pet
    description: Everything about your Pets
    externalDocs:
      description: Find out more
      url: 'http://swagger.io'
paths:
  /pet:
    post:
      tags:
        - pet
      summary: Add a new pet to the store
      description: Add a new pet to the store
      operationId: addPet
      requestBody:
        description: Create a new pet in the store
        content:
          application/json:
            schema:
              oneOf:
                - $ref: '#/components/schemas/openapi1Pet'
                - $ref: '#/components/schemas/openapi1Pet2'
              discriminator:
                propertyName: name
                mapping:
                  pet: '#/components/schemas/Pet'
                  pet2: '#/components/schemas/Pet2'
        required: true
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/openapi1Pet'
  /pet2:
    post:
      tags:
        - pet
      summary: Add a new pet to the store
      description: Add a new pet to the store
      operationId: openapi2addPet
      requestBody:
        description: Create a new pet in the store
        content:
          application/json:
            schema:
              oneOf:
                - $ref: '#/components/schemas/openapi2Pet'
                - $ref: '#/components/schemas/openapi2Pet2'
              discriminator:
                propertyName: name
                mapping:
                  pet: '#/components/schemas/Pet'
                  pet2: '#/components/schemas/Pet2'
        required: true
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/openapi2Pet'
components:
  schemas:
    openapi1Pet:
      required:
        - id
        - name
      type: object
      properties:
        id:
          type: integer
          format: int64
          example: 10
        name:
          type: string
          example: doggie
    openapi1Pet2:
      required:
        - id
        - name
        - lastName
      type: object
      properties:
        id:
          type: integer
          format: int64
          example: 10
        name:
          type: string
          example: doggie
        lastName:
          type: string
          example: doogle
    openapi2Pet:
      required:
        - id
        - name
      type: object
      properties:
        id:
          type: integer
          format: int64
          example: 10
        name:
          type: string
          example: doggie
    openapi2Pet2:
      required:
        - id
        - name
        - lastName
      type: object
      properties:
        id:
          type: integer
          format: int64
          example: 10
        name:
          type: string
          example: doggie
        lastName:
          type: string
          example: doogle
  requestBodies:
    openapi1Pet:
      description: Pet object that needs to be added to the store
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/openapi1Pet'
    openapi2Pet:
      description: Pet object that needs to be added to the store
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/openapi2Pet'

Where the following content is invalid :

          application/json:
            schema:
              oneOf:
                - $ref: '#/components/schemas/openapi1Pet'
                - $ref: '#/components/schemas/openapi1Pet2'
              discriminator:
                propertyName: name
                mapping:
                  pet: '#/components/schemas/Pet'
                  pet2: '#/components/schemas/Pet2'

Reference of components are well renamed in the oneOf property but not in the mapping discriminator.

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

1 participant