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

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

Closed
michaelgwelch opened this issue Apr 30, 2022 · 4 comments · Fixed by #86 or metasys-server/openapi-snippet#1

Comments

@michaelgwelch
Copy link
Contributor

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 michaelgwelch changed the title Seems to not work when examples is used instead of example for parameters Seems to not generate good parameter value in a snippet when examples is used instead of example Apr 30, 2022
@michaelgwelch
Copy link
Contributor Author

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

@michaelgwelch
Copy link
Contributor Author

michaelgwelch commented Apr 30, 2022

No, looks like we can address the issue right in this repo:

if (typeof param.example !== 'undefined') {
// only if the schema has an example value
fullPath = fullPath.replace('{' + param.name + '}', param.example);

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
Copy link
Contributor Author

Also need to fix up this method:

const getParameterValues = function (param, values) {
let value =
'SOME_' + (param.type || param.schema.type).toUpperCase() + '_VALUE';
if (values && typeof values[param.name] !== 'undefined') {
value =
values[param.name] + ''; /* adding a empty string to convert to string */
} else if (typeof param.default !== 'undefined') {
value = param.default + '';
} else if (
typeof param.schema !== 'undefined' &&
typeof param.schema.example !== 'undefined'
) {
value = param.schema.example + '';
} else if (typeof param.example !== 'undefined') {
value = param.example + '';
}
return {
name: param.name,
value: value,
};
};

michaelgwelch added a commit to michaelgwelch/openapi-snippet that referenced this issue Apr 30, 2022
If `example` isn't set for a parameter, then go ahead
and check for `examples`. If that is present, then use the
value from the first entry as the parameter value.

Fix ErikWittern#81
@michaelgwelch
Copy link
Contributor Author

michaelgwelch commented Apr 30, 2022

Please consider #86 as a potential solution

michaelgwelch added a commit to michaelgwelch/openapi-snippet that referenced this issue Apr 30, 2022
If `example` isn't set for a parameter, then go ahead
and check for `examples`. If that is present, then use the
value from the first entry as the parameter value.

Note: The value of the fist entry must have type `string`.
If no suitable value is found, then the code snippet
will not have a value.

Fix ErikWittern#81
michaelgwelch added a commit to michaelgwelch/openapi-snippet that referenced this issue Apr 30, 2022
If `example` isn't set for a parameter, then go ahead
and check for `examples`. If that is present, then use the
value from the first entry as the parameter value.

Note: The value of the fist entry must have type `string`.
If no suitable value is found, then the code snippet
will not have a value.

Fix ErikWittern#81
michaelgwelch added a commit to michaelgwelch/openapi-snippet that referenced this issue Apr 30, 2022
If `example` isn't set for a parameter, then go ahead
and check for `examples`. If that is present, then use the
value from the first entry as the parameter value.

Note: The value of the fist entry must have type `string`.
If no suitable value is found, then the code snippet
will not have a value.

Fix ErikWittern#81
michaelgwelch added a commit to michaelgwelch/openapi-snippet that referenced this issue Apr 30, 2022
If `example` isn't set for a parameter, then go ahead
and check for `examples`. If that is present, then use the
value from the first entry as the parameter value.

Note: The value of the fist entry must have type `string`.
If no suitable value is found, then the code snippet
will not have a value.

Fix ErikWittern#81
michaelgwelch added a commit to michaelgwelch/openapi-snippet that referenced this issue May 6, 2022
This commit does several related things.

* consider examples for parameter values

  If `example` isn't set for a parameter, then go ahead
  and check for `examples`. If that is present, then use the
  value from the first entry as the parameter value.

  Fix ErikWittern#81

* implement support for explode for array and object
  (for simple and form styles only and only for query,
  path and header parameters)

  Fix ErikWittern#83

* Fix 3 test scenarios that showed unexploded form
  parameters when explode should have default to true

  This was documented in ErikWittern#83

* Resolve $ref nodes for header parameters

  Fix ErikWittern#84

* Add a full suite of tests for parameters. Only
  form and simple style were tested as the library
  seems to have no current support for other styles.
michaelgwelch added a commit to michaelgwelch/openapi-snippet that referenced this issue May 6, 2022
This commit does several related things.

* consider examples for parameter values

  If `example` isn't set for a parameter, then go ahead
  and check for `examples`. If that is present, then use the
  value from the first entry as the parameter value.

  Fix ErikWittern#81

* implement support for explode for array and object
  (for simple and form styles only and only for query,
  path and header parameters)

  Fix ErikWittern#83

* Fix 3 test scenarios that showed unexploded form
  parameters when explode should have default to true

  This was documented in ErikWittern#83

* Resolve $ref nodes for header parameters

  Fix ErikWittern#84

* Add a full suite of tests for parameters. Only
  form and simple style were tested as the library
  seems to have no current support for other styles.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment