fix(oas3): reset request body values in try it out by glowcloud · Pull Request #9717 · swagger-api/swagger-ui · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jul 3, 2025
Merged

Conversation

glowcloud
Copy link
Contributor

Refs #9158
Supersedes #9346

@glowcloud
Copy link
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
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
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.

5 participants

TMZ Celebrity News – Breaking Stories, Videos & Gossip

Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

🎥 Watch TMZ Live

TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.