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

Request with multiple application/x-www-form-urlencoded request body and response examples don't get imported properly #791

Open
duykhanh412 opened this issue May 6, 2024 · 1 comment

Comments

@duykhanh412
Copy link

This PR #768 has added the support for multiple examples to be generated as request examples. It works well when the request body type is json and others, however, it doesn't work well when the request body type is application/x-www-form-urlencoded.

Below is the OpenAPI yaml:

openapi: 3.0.1
info:
  title: URLEncoded Request With Multiple Request Body Examples
  version: v1
paths:
  /Foo:
    post:
      summary: Foo
      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              type: object
              properties:
                foo:
                  type: string
                bar:
                  type: string
            examples:
              Example 1:
                value:
                  foo: abc
                  bar: def
              Example 2:
                value:
                  foo: xyz
      responses:
        "200":
          description: Successful
          content:
            application/json:
              examples:
                Example 1:
                  value:
                    first_name: abc
                    last_name: def
                Example 2:
                  value:
                    first_name: xyz

When importing to Postman:

You can see that the request bodies for both examples are exactly the same and values are some random text that get generated automatically.

I've put in a few debugging points and can see that for json request body, the examples section is passed into the schemaUtils.resolveBodyData function and then mapped to the examples in the response, whereas, for urlencoded request body, the requestBody examples section is ignored entirely and only the schema is passed in. The schemaUtils.resolveBodyData tries to then read from the example section within the schema instead, which only supports one example. So even if I've tried to add multiple examples into the example section of the schema instead, it would still not work, Postman would instead try to merge all the request body examples together into one request body to be used by both examples in that case.

Ideally, when multiple examples are provided in the urlencoded request body of a request, it should be generated as response examples just like json request body type.

@VShingala
Copy link
Member

@duykhanh412 Thanks for raising the issue! Yeah, since JSON bodies are the most used schemas, we started with the support for it. We'll work on the same for both URL encoded and FormData in future. I'll update here once we have some update on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants