Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Combining multiple files into one keeps references to some api files #87

Open
apoza opened this issue Mar 2, 2023 · 1 comment
Open

Comments

@apoza
Copy link

apoza commented Mar 2, 2023

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'
 [...]
@MateusFrFreitas
Copy link

MateusFrFreitas commented Mar 29, 2023

+1

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

No branches or pull requests

2 participants