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

Bundle with examples used several times #209

Open
gigaga opened this issue Mar 21, 2022 · 0 comments
Open

Bundle with examples used several times #209

gigaga opened this issue Mar 21, 2022 · 0 comments

Comments

@gigaga
Copy link

gigaga commented Mar 21, 2022

Hi,

By using swagger-parser v10.0.3, I tried to bundle my file that contains several external references from $ref into one by using bundle function.

My spec file is


info:
  version: 1.0.0-SNAPSHOT
  title: petstore-several

paths:
  /pets:
    get:
      tags:
        - pets
      responses:
        '200':
          description: Pet
          content:
            application/json:    
              schema:
                $ref: "#/components/schemas/Pet"
              examples:
                $ref: ./examples.yaml#/test
    delete:
      tags:
        - pets
      responses:
        '200':
          description: Pet
          content:
            application/json:    
              schema:
                $ref: "#/components/schemas/Pet"
              examples:
                $ref: ./examples.yaml#/test
    
components:
  schemas:
    Pet:
        type: object
        required:
        - pet_type
        properties:
          pet_type:
            type: string

And my js code is :

import SwaggerParser from 'swagger-parser';

async function run() {
    let api = await SwaggerParser.bundle("./examples/specs/petstore/petstore-several-files/petstore-several-files.yaml");
    console.log(JSON.stringify(api, null, 2));
}

run();

The execution sdtout is :

{
  "openapi": "3.0.0",
  "info": {
    "version": "1.0.0-SNAPSHOT",
    "title": "petstore-several"
  },
  "paths": {
    "/pets": {
      "get": {
        "tags": [
          "pets"
        ],
        "responses": {
          "200": {
            "description": "Pet",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Pet"
                },
                "examples": {
                  "jedi": {
                    "value": {
                      "pet_type": "tata"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "pets"
        ],
        "responses": {
          "200": {
            "description": "Pet",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Pet"
                },
                "examples": {
                  "$ref": "#/paths/~1pets/get/responses/200/content/application~1json/examples"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Pet": {
        "type": "object",
        "required": [
          "pet_type"
        ],
        "properties": {
          "pet_type": {
            "type": "string"
          }
        }
      }
    }
  }
}

The ref of the second example still is present in bundled spec :(. Redoc, swagger-ui and openapi-generator are not able to manage correctly this second example :(.
As workaround, we have to duplicate examples.yaml file (even if it is exactly the same content) but it is very dirty :(

Thanks.

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