Skip to content

const parameter value is not displayed #1307

@2is10

Description

@2is10

Describe the bug

When a request parameter’s schema uses const to define its only acceptable value, the plugin doesn’t show that value where the parameter is described.

Also, in the request form, a free-form text input is shown for the parameter value, with no guidance about the only allowed value.

Expected behavior

The plugin should show the parameter’s constant value where the parameter is described. In the request form, the constant value should be offered as a choice for the parameter value.

Current behavior

The plugin doesn’t show the only allowed value for a parameter that uses const anywhere. No guidance is provided for the parameter input in the Request form.

Possible solution

In the parameter description area, the plugin could show the const value labeled with “Constant value:” like it already does when const is used in an object schema (#1143).

In the request form, the plugin could handle a parameter with a const value the same way it handles a parameter whose schema is an enum with only one value—by offering a dropdown with two options: 1) no value, 2) the only acceptable value.

Steps to reproduce

  1. Use the plugin to view network-snapshots.yaml.
  2. Notice that on the page for the “Export a Snapshot” operation, the plugin doesn’t mention the only acceptable value ("CONFIG") for the parameter named "only". We have written a description for it that mentions this value.

The relevant portion of network-snapshots.yaml is:

      parameters:
        - name: "snapshotId"
          in: "path"
          required: true
          schema:
            type: "string"
        - name: "only"
          in: "query"
          description: "Use `?only=CONFIG` to include only device configuration files."
          schema:
            type: "string"
            const: "CONFIG"

Screenshots

Here’s how the plugin currently behaves. See the parameter named “only”.

Image

Here’s how the plugin behaves if we change the parameter’s schema to a single-valued enum (a workaround):

Image Image

Context

We have 6-8 API operations in a large API that use a const parameter for one reason or another. It would be helpful for the documentation that the plugin generates to communicate to users the only acceptable value for these parameters.

A possible workaround is changing our OpenAPI files to use a single-valued enum instead of const for these parameters, but we shouldn’t have to. The const keyword has been part of OpenAPI 3.1 since it was released in Feb 2021 (see the outcomes of OAI/OpenAPI-Specification#1313 and/or OAI/OpenAPI-Specification#1666 to confirm).

Note: This plugin has supported const in object schemas since 4.5.0 (#1143) and in their examples since 4.6.0 (#1260). It would be great to also support const in parameter values, for consistency.

Your Environment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions