Skip to content

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

@frozenbonito

Description

@frozenbonito

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('┃')

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