Skip to content

A requestBody with no content causes console error "TypeError: Cannot read properties of undefined (reading 'entrySeq') #10767

@rfoletta

Description

@rfoletta

Q&A (please complete the following information)

  • OS: [Windows 11]
  • Browser: [chrome]
  • Version: [145.0.7632.160]
  • Method of installation: [I include your dist folder with your swagger ui into my own java applicaiton.]
  • Swagger-UI version: [5.32.0]
  • Swagger/OpenAPI version: [Swagger 2.0 ??, OpenAPI 3.0.1]

Content & configuration

"paths" : {
"/catalog/regions" : {
"description" : "/catalog/regions",
"get" : {
"tags" : [ "General" ],
"summary" : "List all catalog regions",
"description" : "Returns the currently available catalog regions. The value of the name field is used by the regionName field in the Create Service Dealer request Body.",
"requestBody" : {
"description" : "",
"required" : false
},
"responses" : {
"200" : {
"description" : "List of catalog regions returned successfully.",
"content" : {
"application/json" : {
"schema" : {
"type" : "array",
"items" : {
"$ref" : "#/components/schemas/CatalogRegion"
},
"types" : [ "array" ]
},
"examples" : {
"Catalog Regions Response" : {
"description" : "",
"value" : "[ { "regionId": 1, "name": "USA" }, { "regionId": 2, "name": "CANADA" }, { "regionId": 3, "name": "MEXICO" }]",
"valueSetFlag" : true
}
}
}
}
}
},
"security" : [ {
"x-auth-token" : [ ]
}, {
"x-account" : [ ]
} ]
}
}
}

Example Swagger/OpenAPI definition:
I'm using java annotations to build the openAPI spec.
I had an issue where even though my Operation had no RequestBody, I still added a default RequestBody to the Operation with a blank description, required=false and no content.
swagger 5.28.1 had no problem with this but when I upgraded to 5.32.0 I began to see the issue.

Describe the bug you're encountering

I don't know for sure this is a bug but I think it is.
The sample path definition I provided above contains the following requestBody.
"requestBody" : {
"description" : "",
"required" : false
}
Looking at the OpenAPI RequestBody java class I see that the defaults for description is "" and required is false and content is null so this caused me to create the requestBody above without the content field.

When I execute my API call, I found that in the swagger selectors.js getOAS3RequiredRequestBodyContentType() function it creates a default requiredObj and returns it if the requestBody.size < 1.
It then looks at required and then assumes there is a content field so it calls .entrySeq() on the null content.
Here is the code from your selectors.js
export const getOAS3RequiredRequestBodyContentType = (state, pathMethod) => {
let requiredObj = {
requestBody: false,
requestContentType: {}
}
let requestBody = state.getIn(["resolvedSubtrees", "paths", ...pathMethod, "requestBody"], fromJS([]))
if (requestBody.size < 1) {
return requiredObj
}
if (requestBody.getIn(["required"])) {
requiredObj.requestBody = requestBody.getIn(["required"])
}
//==============
// I think this is where the bug is when it calls entrySeq() on a null content
//==============
requestBody.getIn(["content"]).entrySeq().forEach((contentType) => { // e.g application/json
const key = contentType[0]
if (contentType[1].getIn(["schema", "required"])) {
const val = contentType[1].getIn(["schema", "required"]).toJS()
requiredObj.requestContentType[key] = val
}
})
return requiredObj
}

To reproduce...

Steps to reproduce the behavior:
Not sure how you can reproduce. You would have to feed swagger a path definition like I provided above with a requestBody that does not contain a content field.

Expected behavior

The code should check for the presence of the content field before acting on it. Probably return the default requiredObj if there is no content.

Additional context or thoughts

I'm new to swagger and I have gotten around this issue by fixing my code to not add a requestBody when there is no content but though it might be a good idea to let you know about it.
Thanks.

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