swagger-api / swagger-api/swagger-ui
Error on swagger-ui: Cannot read property 'toString' of undefined
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 29k
- Forks
- 9.3k
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 25
Description
Q&A (please complete the following information)
- OS: macOS
- Browser: chrome
- Version: 89.0.4389.114
- Method of installation: npm
- Swagger-UI version: 3.46.0
- Swagger/OpenAPI version: OpenAPI 3.0
Content & configuration
Example Swagger/OpenAPI definition:
openapi: 3.0.1
info:
title: OpenAPI definition
version: v0
servers:
- url: 'http://localhost:8080'
description: Generated server url
paths:
/hello:
get:
tags:
- hello
operationId: hello
parameters:
- name: user
in: query
required: true
schema:
$ref: '#/components/schemas/User'
- name: someEnums
in: query
description: SomeEum decs
content:
'*/*':
schema:
type: array
items:
type: string
enum:
- FIRST
- SECOND
- name: textSet
in: query
description: First decs
content:
'*/*':
schema:
type: array
items:
type: string
- name: someText
in: query
description: Second decs
content:
'*/*':
schema:
type: string
responses:
'200':
description: OK
content:
'*/*':
schema:
type: string
components:
schemas:
User:
type: object
properties:
someText:
type: string
textSet:
uniqueItems: true
type: array
items:
type: string
someEnums:
uniqueItems: true
type: array
items:
type: string
enum:
- FIRST
- SECOND
Swagger-UI configuration options: Default swagger-ui configuration
url=http://localhost:8080/v3/api-docs
Describe the bug you're encountering
Swagger UI fails to execute request when one of query parameters is not filled out using the yaml sample.
It works only when you fill out all the query parameters (then you can remove any of the filled out parameters and no error would occur).
To reproduce...
Steps to reproduce the behavior:
- Go to the swagger-ui'
- Click on 'Try it'
- Click on 'Execute'
- See error on the browser console:
TypeError: Cannot read property 'toString' of undefined
at Xn (content-serializer.js:18)
at er (parameter-builders.js:43)
at index.js:241
at Array.forEach (<anonymous>)
at Object.dr [as buildRequest] (index.js:196)
at actions.js:452
at utils.js:177
at bindActionCreators.js:3
at wrap-actions.js:33
at Object.r (system.js:174)
(anonymous) @ system.js:464
Expected behavior
Requests executed as expected.
Screenshots

Additional context or thoughts
As a workaround, when the OpenAPI definition doesn't contain content: element, but only schema: referenced directly, it works.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure with the provided OpenAPI 3.0 YAML and Swagger UI configuration, leaving one query parameter empty. Start at content-serializer.js:18 and parameter-builders.js:43, then trace the buildRequest entry point in index.js. Done means the sample request executes successfully with an unfilled query parameter, without the toString error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, openapi
- Domain
- api, frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100