swagger-ui
swagger-ui copied to clipboard
fix(oas3): reset request body values in try it out
Refs #9158 Supersedes #9346
There's an issue with getting different default values on loading try it out and on resetting it. After clicking on try it out:
After clicking on reset:
It seems like it's because we have a different logic for getting these values. For the first case, starting here: https://github.com/swagger-api/swagger-ui/blob/6bb810a64ff68b06688fa3d207033a5bb0086418/src/core/plugins/oas3/components/request-body.jsx#L165 and when resetting: https://github.com/swagger-api/swagger-ui/blob/6bb810a64ff68b06688fa3d207033a5bb0086418/src/core/plugins/oas3/components/request-body.jsx#L8 The first case doesn't get us examples for the parameters that don't have them in schema, while the second one gets them (as, for example, "string" for string type parameters).
This looks like a separate issue to me and we should decide which way of getting values should be the correct one, and apply a fix for it in a separate PR.
Because we're using the second method for resetting, and because it uses getSampleSchema
, in particular this check in some places
https://github.com/swagger-api/swagger-ui/blob/6bb810a64ff68b06688fa3d207033a5bb0086418/src/core/plugins/json-schema-5-samples/fn/index.js#L251-L253
If we have a specification with maxProperties
like this:
openapi: 3.0.3
info:
title: Test API
version: 1.0.0
paths:
/users:
post:
summary: Create a user
description: Create a user, one of various ways
requestBody:
content:
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/UserSource'
responses:
'204':
description: Successfully opened document
'400':
description: Invalid request
content:
application/json:
schema:
properties:
output:
type: string
example: "Invalid request"
components:
schemas:
UserSource:
type: object
properties:
name:
description: Full name
type: string
example: "John Smith"
badgeid:
description: Badge number
type: integer
format: uint32
example: 959310
email:
description: E-mail
type: string
example: "[email protected]"
minProperties: 1
maxProperties: 1
and we use reset, only the maxProperties
number of parameters will be reset, for example here only the name:
One test is not passing.