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

There are some issues that can crop up related to missing or "any type" parameter schemas #89

Open
michaelgwelch opened this issue Jul 25, 2022 · 1 comment · May be fixed by #90
Open

Comments

@michaelgwelch
Copy link
Contributor

michaelgwelch commented Jul 25, 2022

I'm working on fixes for the following:

  • If a parameter is missing a type and also missing schema then a TypeError is thrown:

    /openapi-snippet/openapi-to-har.js:441
     'SOME_' + (param.type || param.schema.type).toUpperCase() + '_VALUE';
                                                 ^
    TypeError: Cannot read properties of undefined (reading 'type')
        at getParameterValues (/Users/cwelchmi/emu/metasys-rest-api/node_modules/openapi-snippet/openapi-to-har.js:441:43)
  • the method parseParametersToQuery checks the schema type and if it is undefined then the type is defaulted to object but it should just leave it undefined.

    A schema without a type matches any data type – numbers, strings, objects, and so on. {} is shorthand syntax for an arbitrary-type schema

    Quoted from any type

@michaelgwelch

This comment was marked as resolved.

michaelgwelch added a commit to michaelgwelch/openapi-snippet that referenced this issue Jul 25, 2022
Per the spec if no type is given then the type default to the Any Type:
https://swagger.io/docs/specification/data-models/data-types/#any

This commit removes a check that explicitly sets any undefined
type to object, instead leaving it blank. Then where type checking
is done it adds support not only for missing types, but the explicit
any type expressed as {}.

One existing test was expecting SOME_OBJECT_TYPE because of a missing
type, this test was corrected to look for SOME_ANY_TYPE. Three
additional tests were added to check that no type, {} in param.type, and
{} in param.schema.type were all handled appropriately.

Fixes ErikWittern#89
@michaelgwelch michaelgwelch linked a pull request Jul 25, 2022 that will close this issue
michaelgwelch added a commit to michaelgwelch/openapi-snippet that referenced this issue Jul 26, 2022
Per the spec if no type is given then the type default to the Any Type:
https://swagger.io/docs/specification/data-models/data-types/#any

This commit removes a check that explicitly sets any undefined
type to object, instead leaving it blank. Then where type checking
is done it adds support for missing types.

One existing test was expecting SOME_OBJECT_TYPE because of a missing
type, this test was corrected to look for SOME_ANY_TYPE. An additional
test was added to explicitly state that missing types are to be
considered Any Type.

In addition a fix was made that if the value of a type field is not
a string, then the parmater value SOME_ERROR_TYPE is generated. This
allows the snippet generator to run without error, but presumably
in some workflow the openapi validator will catch the spec error.

Fixes ErikWittern#89
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant