swagger-cli icon indicating copy to clipboard operation
swagger-cli copied to clipboard

Combining multiple files into one keeps references to some api files

Open apoza opened this issue 2 years ago • 1 comments

Problem

I have an API splitted in several files and I have used swagger-cli to combine those files into one (to use that file in API consumer services/applications) When any API file is referenced using $ref that file is exported (included) in the new API file as component (that's good). But those files that are referenced without using $ref are exported (included in the bundled file) keeping the reference to the file.

Example

Let's suppose that we have OpenApi.yaml that has this endpoint deffinition

 [...]
 /offering:
    post:
      [...]
      requestBody:
        description: This is an offering
        required: true
        content:
          application/json:
            schema:
              $ref: ./Offering.yaml
 [...]

This is Offering.yaml

title: Offering
description: Interface of offering requests
oneOf:
  - $ref: ./LocalOffering.yaml
  - $ref: ./InternationalOffering.yaml
discriminator:
  propertyName: type
  mapping:
    local: ./LocalOffering.yaml
    international: ./InternationalOffering.yaml

When I combine the API files (executing: swagger-cli bundle OpenApi.yaml --outfile CombinedApi.yaml --type yaml) this is the outcome (CombinedApi.yaml):

 [...]
Offering:
      title: Offering
      description: Interface of offering requests
      oneOf:
        - $ref: '#/components/schemas/LocalOffering'
        - $ref: '#/components/schemas/InternationalOffering'
      discriminator:
        propertyName: type
        mapping:
          local: ./LocalOffering.yaml
          international: ./InternationalOffering.yaml
 [...]

As we can see the discriminator.mapping.local and discriminator.mapping.international keeps files references. That means that we need those files so the combination in one file is not valid

Expected behavior

I would expect than those files referenced without using $ref would be exported in a way (maybe the same way that $ref ones) that doesn't keep the reference to the files.

Expected outcome:

 [...]
Offering:
      title: Offering
      description: Interface of offering requests
      oneOf:
        - $ref: '#/components/schemas/LocalOffering'
        - $ref: '#/components/schemas/InternationalOffering'
      discriminator:
        propertyName: type
        mapping:
          local: '#/components/schemas/LocalOffering'
          international: '#/components/schemas/InternationalOffering'
 [...]

apoza avatar Mar 02 '23 12:03 apoza

+1

MateusFrFreitas avatar Mar 29 '23 18:03 MateusFrFreitas