Skip to content

An error occurs when a parameter schema contains a non-string const #1098

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
frozenbonito opened this issue Apr 27, 2025 · 0 comments
Open

Comments

@frozenbonito
Copy link

frozenbonito commented Apr 27, 2025

An error occurs when a parameter schema contains a const value that is not a string, as shown below:

openapi: 3.1.0
info:
  title: Example API
  version: 1.0.0
paths:
  /hello-world:
    post:
      tags:
        - Example
      parameters:
        - name: Protocol-Version
          in: header
          required: true
          schema:
            $ref: '#/components/schemas/protocol-version'
components:
  schemas:
    protocol-version:
      type: number
      const: 1

The following error occurs:

Uncaught (in promise) TypeError: o.allowedValues.split is not a function
    at de.inputParametersTemplate (api-request.js:520:1)
    at api-request.js:217:1
    at xR.render (callback-template.js:74:1)
    at xR.update (callback-template.js:74:1)
    at xR._$AS (common-utils.js:13:1)
    at re (rapidoc-min.js:2:9848)
    at ne._$AI (rapidoc-min.js:2:10938)
    at se.p (rapidoc-min.js:2:10532)
    at ne.$ (rapidoc-min.js:2:11583)
    at ne._$AI (rapidoc-min.js:2:11079)

Since const can accept any data type, it is necessary to handle non-string types appropriately.
Specifically, when assigning schema.const to allowedValues, it should be processed in advance using getPrintableVal():

// Set Allowed Values
info.allowedValues = schema.const
? schema.const
: Array.isArray(schema.enum)
? schema.enum.map((v) => (getPrintableVal(v))).join('┃')
: '';

info.allowedValues = schema.items.const
? schema.const
: Array.isArray(schema.items?.enum)
? schema.items.enum.map((v) => (getPrintableVal(v))).join('┃')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant