ErikWittern / openapi-snippet

Generates code snippets for given Swagger / Open API documents
MIT License
115 stars 66 forks source link

Seems to not generate good parameter value in a snippet when `examples` is used instead of `example` #81

Closed michaelgwelch closed 2 years ago

michaelgwelch commented 2 years ago

We use examples in our parameter definitions. But it appears that opneapi-snippet doesn't inspect these and only considers the example key when generating values for parameters in a code snippet.

I'm not familiar with your code-base but I'll take a look at what it might take to just use examples[0].value when example is missing.

michaelgwelch commented 2 years ago

Ok, after inspecting your code, looks like the issue is likely upstream (in openapi-sampler perhaps?)

michaelgwelch commented 2 years ago

No, looks like we can address the issue right in this repo: https://github.com/ErikWittern/openapi-snippet/blob/2e6c2c91859c56442f134ced22ef609e7b4b36cd/openapi-to-har.js#L350-L352

I'll give it a try. If there is no example, but there is examples then let's just grab the first key in the examples object and get its value.

michaelgwelch commented 2 years ago

Also need to fix up this method:

https://github.com/ErikWittern/openapi-snippet/blob/2e6c2c91859c56442f134ced22ef609e7b4b36cd/openapi-to-har.js#L222-L242

michaelgwelch commented 2 years ago

Please consider #86 as a potential solution