swagger-ui icon indicating copy to clipboard operation
swagger-ui copied to clipboard

fix(oas3): reset request body values in try it out

Open glowcloud opened this issue 11 months ago • 2 comments

Refs #9158 Supersedes #9346

glowcloud avatar Mar 19 '24 15:03 glowcloud

There's an issue with getting different default values on loading try it out and on resetting it. After clicking on try it out:

default

After clicking on reset:

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:

Screenshot 2024-03-19 at 16 04 06

glowcloud avatar Mar 19 '24 15:03 glowcloud

One test is not passing.

char0n avatar May 08 '24 13:05 char0n