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

Swagger spec is not normalized if structure is hidden behind a reference

Open biochimia opened this issue 7 years ago • 3 comments

I tracked down a regression in swagger-ui to an interaction between swagger normalization and subtree resolution introduced in https://github.com/swagger-api/swagger-js/pull/1274.

With that change, normalization happens only before subtree resolution, and this breaks in cases where the structure of the references hides the structure of the swagger file from normalization.

I boiled it down to this this test https://github.com/swagger-api/swagger-js/compare/master...biochimia:regression/normalize-before-resolution

Q&A (please complete the following information)

  • OS: [e.g. macOS] macOS
  • Environment: [e.g. Chrome 59, Node.js v10.0.0] Node.js v10.12.0
  • Method of installation: [e.g. npm, unpkg] npm
  • Swagger-Client version: [e.g. 3.8.0] >3.6.0, <=3.8.21
  • Swagger/OpenAPI version: [e.g. Swagger 2.0, OpenAPI 3.0] OpenAPI 3.0

Content & configuration

Test case: https://github.com/swagger-api/swagger-js/compare/master...biochimia:regression/normalize-before-resolution

Swagger/OpenAPI definition:

paths.yaml:
  root:
    parameters:
      - $ref: '#/parameters.yaml/accept-header'
    get:
      parameters:
        - $ref: '#/parameters.yaml/name'
        - $ref: '#/parameters.yaml/status'
parameters.yaml:
  accept-header:
    name: accept
    in: header
    description: content-type for response
    required: true
    type: string
  name:
    name: name
    in: formData
    description: name of the pet
    required: false
    type: string
  status:
    name: status
    in: formData
    description: status of the pet
    required: false
    type: string
paths:
  /:
    $ref: '#/paths.yaml/root'

Swagger-Client usage:

SwaggerClient({
  // your config options here
})

Describe the bug you're encountering

Because normalizeSwagger() doesn't get to see the structure of the path object before resolution, if doesn't copy path parameters into individual methods. Later when the subtrees are resolved normalization is already disabled and is not performed.

To reproduce...

Steps to reproduce the behavior:

  1. ...

Expected behavior

Screenshots

Additional context or thoughts

biochimia avatar Oct 16 '18 11:10 biochimia

The same bug will be part of normalization that will be introduced for OpenAPI 3.1 in https://github.com/swagger-api/swagger-js/pull/2738.

This issue needs to be processed after introducting OpenAPI 3.1.0 support in swagger-client for both OpenAPI 2.0 - 3.0.x and OpenAPI 3.1.0 normalizations.

char0n avatar Jan 03 '23 08:01 char0n