Skip to content

[BUG] Parameter with enum is not correctly generated for OAS 3.0 and 3.1 #717

Open
@diei

Description

@diei

Describe the bug

With OAS 2.0 generated JSON of rswag a select box is rendered of enum values for URL parameters. Since I updated to OAS 3 the enum values are not properly processed and no select box is rendered, only an input field. The JSON is generated not as OAS 3 expects it.

Steps to Test or Reproduce

An API with a parameter like described in the following snipped generates a JSON like shown below.

test.rswag_spec.rb:

path '/tests' do
  get 'fetch tests' do
    parameter name: :test_type, in: :query, type: :string, required: false, enum: ['type1', 'type2']

    [...]  
  end
end

Generates:

...
"parameters": [
  {
    "name": "test_type",
    "in": "query",
    "required": false,
    "enum": [
      "type1",
      "type2"
    ],
    "schema": {
      "type": "string"
    }
  }
]
...

Expected behavior

The generated JSON should look like:

...
"parameters": [
  {
    "name": "test_type",
    "in": "query",
    "required": false,
    "schema": {
      "type": "string",
      "enum": [
        "type1",
        "type2"
      ]
    }
  }
]
...

The enum should be in the schema attribute. Then the select box is rendered on the UI page.

Dependency versions

The version of are you using for:

  • Rswag: 2.13.0
  • RSpec-core: 3.12.2
  • Rails: 7.0.8
  • Ruby: 3.2.2

Relates to which version of OAS (OpenAPI Specification)

  • OAS2
  • OAS3
  • OAS3.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions