Skip to content

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

Merged
glowcloud merged 12 commits intomasterfrom
issue-9158
Jul 3, 2025
Merged

fix(oas3): reset request body values in try it out#9717
glowcloud merged 12 commits intomasterfrom
issue-9158

Conversation

@glowcloud
Copy link
Copy Markdown
Contributor

Refs #9158
Supersedes #9346

@glowcloud
Copy link
Copy Markdown
Contributor Author

glowcloud commented Mar 19, 2024

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:

const useInitialValFromSchemaSamples = prop.has("default")

and when resetting:
export const getDefaultRequestBodyValue = (requestBody, mediaType, activeExamplesKey, fn) => {

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

const hasExceededMaxProperties = () => schema
&& schema.maxProperties !== null && schema.maxProperties !== undefined
&& propertyAddedCounter >= schema.maxProperties

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: "jsmith@business.com"
      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

@char0n
Copy link
Copy Markdown
Contributor

char0n commented May 8, 2024

One test is not passing.

@glowcloud glowcloud mentioned this pull request May 10, 2024
17 tasks
@glowcloud glowcloud merged commit 32dd3af into master Jul 3, 2025
8 checks passed
swagger-bot pushed a commit that referenced this pull request Jul 7, 2025
## [5.26.1](v5.26.0...v5.26.1) (2025-07-07)

### Bug Fixes

* **oas3:** reset request body values in try it out ([#9717](#9717)) ([32dd3af](32dd3af))
@swagger-bot
Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 5.26.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

delendik-testops pushed a commit to ModiusOpenData/swagger-ui that referenced this pull request Mar 3, 2026
delendik-testops pushed a commit to ModiusOpenData/swagger-ui that referenced this pull request Mar 3, 2026
## [5.26.1](swagger-api/swagger-ui@v5.26.0...v5.26.1) (2025-07-07)

### Bug Fixes

* **oas3:** reset request body values in try it out ([swagger-api#9717](swagger-api#9717)) ([32dd3af](swagger-api@32dd3af))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants