Skip to content
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

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

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
Member

char0n commented May 8, 2024

One test is not passing.

@glowcloud glowcloud mentioned this pull request May 10, 2024
17 tasks
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.

3 participants