Skip to content

OpenAPI v2 converter: referenced parameter produces a validation error #1146

@jmini

Description

@jmini

With this OpenAPI v2 spec:

swagger: "2.0"
info:
  description: "Test"
  version: "1.0.0"
  title: "Swagger v2 example"
  termsOfService: "http://swagger.io/terms/"
  contact:
    email: "apiteam@swagger.io"
  license:
    name: "Apache 2.0"
    url: "http://www.apache.org/licenses/LICENSE-2.0.html"
host: "petstore.swagger.io"
basePath: "/v2"
schemes:
- "https"
- "http"
paths:
  /brands/{brand-id}/stations:
    get:
      tags:
        - Brand
      summary: Returns a list of the brand's stations
      operationId: getBrandStations
      parameters:
        - $ref: "#/parameters/brand-id"
        - in: query
          name: available-to-client-only
          required: true
          type: boolean
      responses:
        200:
          description: OK
parameters:
  brand-id:
    in: path
    description: this is a test
    name: brand-id
    required: true
    type: string

When I parse it like this:

OpenAPIParser openApiParser = new OpenAPIParser();
ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setFlatten(true);

SwaggerParseResult parseResult = openApiParser.readLocation(inputSpec, null, options);
for (String string : parseResult.getMessages()) {
    System.err.println(string);
}

I get this error:

attribute paths.'/brands/{brand-id}/stations'. Declared path parameter brand-id needs to be defined as a path parameter in path or operation level

This is wrong, because the parameter is defined.

Swagger-UI is interpreting the spec correctly:

Screenshot 2019-07-08 at 20 07 06


As comparison the corresponding OpenAPI v3 spec is working fine:

openapi: 3.0.1
info:
  title: Example ref param
  version: '1.0'
servers:
  - url: 'http://localhost:9999/'
paths:
  /brands/{brand-id}/stations:
    get:
      tags:
        - Brand
      summary: Returns a list of the brand's stations
      operationId: getBrandStations
      parameters:
        - $ref: "#/components/parameters/brand-id"
        - in: query
          name: available-to-client-only
          required: true
          schema:
            type: boolean
      responses:
        200:
          description: OK
components:
  parameters:
    brand-id:
      in: path
      required: true
      name: brand-id
      schema:
        type: string

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions