Skip to content

Commit 1c87d45

Browse files
Revise parameter handling for snippets (ErikWittern#86)
* Revise example swagger to match test There are three test cases dealing with array value query parameters in test/parameter_example_swagger.json. The assertion for each of these is wrong as it assumes the array should not be exploded. However, two of these parameters are explicitly form style. The third is implicitly form style because that is the default for query parameters. None of them specify a value for explode, so this defaults to true. Therefore the assertions are wrong. See https://spec.openapis.org/oas/v3.0.3#fixed-fields-9 This commit does not fix the logic in the code, rather (for now) it just updates the spec that is being used for the test to set explode equal to false. * create function createHarParameterObjects This function takes an OpenAPI parameter and a sample value and creates a HAR "parameter" object which is just a {name: "", value: ""} object. The function handles all of the variatons outlined in the spec and this commit adds all the test cases that are presented here: https://swagger.io/docs/specification/serialization This function will be used in future commits to handle every type of parrameter while generating snippets. * refactor getParameterValues in terms of createHarParameterObjects This doesn't change the functionality yet. This is just in preparation for providing full support for all variations of parameters. This commit breaks no tests but prepares us for more test cases. * Add support for exploded values in query parameters * Add support for simple style exploded values in path * Add tests to demonstrate working label style path params * Add tests to demonstrate working matrix style path params * Add support for pipe and space delimited path params * Add tests to demonstrate working object and array values in headers * Re-order checks for candidate example param values Per the swagger guide: https://swagger.io/docs/specification/describing-parameters/ "Using default to specify a sample value. This is not intended use of default and can lead to unexpected behavior in some Swagger tools. Use the example or examples keyword for this purpose instead." Per this I think `default` should be the sample value of last resort instead favoring `example` and `examples` first. * Add support for samples in examples key This works for header, path, and query parameter which will now be discovered if the sample is in the examles key. The snippet will choose the first example in examples. * refactor getQueryStrings in terms of reusable method getQueryStrings was doing something special that getFullPath and getHeadersArray are not doing: considering both path and operation level defined parameters. By parameterizing this method on `in` we can later use it for `path`, `header` and `cookie` parameters as well. * Refactor getFullPath and getHeadersArray These functions are now written in terms of getParameterCollectionIn which does the following correctly * Considers path and operation parameters and overrides appropriately * Resolves parameter references * Resolves schema references * Looks at example, examples, schema.example and default keys looking for sample value So now getFullPath and getHeadersArray benefit from all of this logic. Each had one or more short comings. * Add support for cookie parameters * Resolve examples objects as needed
1 parent 2e6c2c9 commit 1c87d45

File tree

4 files changed

+2118
-67
lines changed

4 files changed

+2118
-67
lines changed

0 commit comments

Comments
 (0)