You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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.
The text was updated successfully, but these errors were encountered:
@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.
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:
When importing to Postman:
Using the app:
Using the SDK:
MultipleRequestAndResponseExamplesUrlEncodedRequest.json
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. TheschemaUtils.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.
The text was updated successfully, but these errors were encountered: