dzieciou
dzieciou

Reputation: 4514

Swagger Editor fails to parse definition with enum type parameters

I use Swagger Editor to render API documentation and generate Python client.

I've imported Swagger JSON Definition for one of public APIs that get's transformed by the editor into YAML.

However, for parameters of enum type I am getting the following error:

Structural error at paths./aggregates/metadata.get.parameters.0.type
should be equal to one of the allowed values
allowedValues: string, number, boolean, integer, array
Jump to line 23

Is it a bug in Swagger Editor, a bug in the definition I picked up or some version incompatibility?

Here's a related Swagger definition in YAML:

swagger: '2.0'
info:
  version: v1
  title: BDL API
  termsOfService: ''
basePath: /api/v1
paths:
  /aggregates/metadata:
    get:
      tags:
        - Aggregates
      summary: Metadane / Metadata
      operationId: AggregatesMetadataGet
      consumes: []
      produces:
        - application/json
        - application/xml
      parameters:
        - name: lang
          in: query
          description: ''
          required: false
          type: enum
          enum:
            - pl
            - en

Upvotes: 0

Views: 688

Answers (1)

Helen
Helen

Reputation: 97540

Replace type: enum with type: string. This is a syntax error in the API definition and not a Swagger Editor issue.


Another issue in that definition is the redundant Accept parameter in operations:

  /aggregates/metadata:
    get:
      ...
      produces:
        - application/json
        - application/xml
      parameters:
        - ...
        - name: Accept    # <-----
          in: header
          description: ...
          required: false
          type: string
          enum:
            - application/json
            - application/xml

The Accept header is controlled by the produces keyword, there's no need to define it as a parameter. This is technically not an error, but might cause issues with tooling.

Upvotes: 1

Related Questions