-
Notifications
You must be signed in to change notification settings - Fork 839
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
Open API Generating Collection does not properly generate string request body when using format #9080
Open API Generating Collection does not properly generate string request body when using format #9080
Comments
@mtaylorfsmb You can provide options while generating collection under What this will do is use Eample/Fake value according to your schema and generate an actual value which can be validated correctly further. Try it out, and let me know any issue you might have. |
@VShingala Going that way helps some. Firstly, if the other approach doesn't really work at all except for perhaps basic strings then why even give it as an option? The problems with using the examples is that it impacts all values. So every schema needs an example. But also the parameters in paths, which use variables when you use the other approach, now just use an example value. In my experience parameters in paths use variables and request/response bodies use examples. So either approach requires manually modifying the generated collection. |
@VShingala sorry I was incorrect about path parameters using vars. It doesn't do that, I was just used to doing that. However I tried putting an example on the parameter and it was ignored when it was generated. parameters:
- in: path
name: value
required: true
type: string
example: "{{value}}" It generated a random string value. |
@mtaylorfsmb So the Also you need not to define examples for each schema, For example, Generated value will respect all keywords mentioned in OpenAPI spec. |
OK, yes the "data faker" isn't too great for my purposes. An example is better but it doesn't seem to respect patterns or enums or other formatted values. But this doesn't have to be perfect so I can live with it as I'm going to have to hand edit the collections anyway. |
As for this, the Mentioned example seems incorrect. The below mentioned parameter will achieve what you are trying to do.
|
That was a typo. It doesn't work under the schema for me. It still autogenerates an example value instead. Maybe I'm doing it wrong but I'll look into that later. |
I think I figured out the issue with the example. The type I'm using for this parameter is backed by a schema object. That schema object's example is taking priority over the explicit example given in the parameter. This is not good for my purposes but might make sense for others. In my word "closer" examples should take precedence over schema examples. |
@mtaylorfsmb Just checking in here. Sounds like this issue is now resolved, can you confirm? |
I don't believe it is correct but it is working. Schema examples are taking priority over examples directly in the parameter. So if I define a schema to back a complex string type and put an example on it then that example takes precedence over the example tag that might be placed on the actual parameter. As I mentioned in my last post I believe "closer" examples should take precedence over schema examples. A schema example is demonstrating the type. A parameter example is demonstrating a reasonable value for that parameter. Different parameters, of the same type, may have different examples depending upon the endpoint. |
@CoolDadTx @mtaylorfsmb I think mentioned behaviour by you makes more sense, where the more "closer" (or "outer") example should take precedence. In this case, |
Describe the bug
I have an OpenAPI YAML file that I in Postman that I'm using to generate a collection. Whenever it generates the collection it generates request bodies that have bad values for properties that are string but have a format string. Specifically it always puts in "" or "", etc. But this isn't valid for a formatted string so running the validation option under Test produces an error for each one.
To Reproduce
Steps to reproduce the behavior:
Sample YAML file.
What gets generated for the body is something like this:
Expected behavior
When a property is nullable then ideally it should be set to null (at least for strings and objects) so the collection doesn't generate a potentially bad value.
For enums then ideally it should put in a placeholder with possible values or just leave blank.
For dates or other formatted strings ideally it'll generate a formatted example value or leave blank.
For numbers it should put a numeric 0 in or leave blank.
As it stands now, after auto-generating the collection I would then have to manually clean it all up before I could give it to someone to use as an example. Furthermore using the Validation button on the Test tab flags each of these properties as badly formatted.
Screenshots
If applicable, add screenshots to help explain your problem. Please make sure the screenshot does not contain any sensitive information such as API keys or access tokens.
App information (please complete the following information):
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: