postmanlabs / openapi-to-postman

Plugin for converting OpenAPI 3.0 specs to the Postman Collection (v2) format
Apache License 2.0
915 stars 196 forks source link

Option to disable faking of response values? #240

Open schneivo77 opened 4 years ago

schneivo77 commented 4 years ago

Hi,

I've just noticed, that in the current version (v1.2.0) the example values which are unknown are replaced by random latin strings. Is it possible to disable this behaviour? So that the example values which are known are still used for the responses but for the unknown the data-type is used as in previous versions?

Because I prefer it, if there is written for example "timestamp": "dateTime" instead of "timestamp": "dolor sit reprehenderit" in the response example.

VShingala commented 4 years ago

@schneivo77 We have changed behaviour of how values are resolved for example option. Where if schema defined example is invalid or not available then instead generating string placeholders like "<integer>" actual faked value is generated to make sure faked value is adhering to schema.

You can apply following two option to keep using schema type as resolution for values instead faked example.

requestParametersResolution: 'Schema',
exampleParametersResolution: 'Schema'

For more details on what this options does you can follow description here.

schneivo77 commented 4 years ago

@VShingala Thanks for your answer. Yes, I've noticed this behaviour.

I'd still like to use the option exampleParametersResolution: 'Example' but without the generated Lorem ipsum strings for unknown or invalid values. So for these values I'd like to have placedholders (\<integer>, \<string>, \<dateTime> etc.), like in previous versions.

I think a 'Mixed' option like this would be nice:

known values:  use example

unknown/invalid values: use placedholder
anikitin commented 1 year ago

Sounds like a useful improvement. This is what Swagger UI does. Not all string fields are actually names/descriptions where "lorem ipsum" is applicable. And not always good examples are provided unfortunately.

tidharm commented 1 year ago

I'm wondering where is this standing? I completely agree with @schneivo77, the current Lorem Ipsum placeholders make it impossible to automate collection creation (especially in requests, not just responses).

For example, I use automation that generates a new collection of our API every time our Swagger updates, and as part of that automation, I do some find&replace to utilize either specified variables or placeholders that make more sense in our collection's context.

The problem is that not only the current setting uses the Lorem Ipsum placeholders, but each response uses a random part of that text, so I could never find and replace it.

@VShingala Is it possible to at least allow specifying particular strings? Or at least prevent it from populating strings at random?

VShingala commented 1 year ago

@tidharm Your use case makes sense. We'll revisit this internally again and evaluate what we can do here and inform here.

cc @akshaydeo

tidharm commented 1 year ago

Thanks @VShingala. For now, I worked around this (in my own fork, see commit e228656) by updating the var LIPSUM_WORDS in assets/json-schema-faker.js to only include one word, so now that word is always the one that's populated as a placeholder so I know exactly what to find&replace.

VShingala commented 1 year ago

@tidharm Thanks for the reference, It makes sense! Although there is more such random data that can be there i.e. integers, booleans etc. Also, some fields can control the behavior of generated data, i.e. maxLength, minLength, pattern etc.

We'll need to look at all such cases and ensure it's working as expected.

tidharm commented 1 year ago

@VShingala Interesting (about maxLength, minLength, pattern), can you point me in the right direction, where in the documentation does this appear? I didn't see it under Options.

As for integers and booleans, I'm guessing that when the schema has one of these under-defined variables, it would populate default values (false for boolean, 0 for integers), isn't that so? I don't think it would populate a string instead, would it?