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

fix: default missing type to any type #90

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

michaelgwelch
Copy link
Contributor

@michaelgwelch michaelgwelch commented Jul 25, 2022

Primarily this is to fix the TypeError that is thrown if a parameter
is missing any type information. Such an error makes it hard to debug
your spec:

/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)

Per the spec if no type is given then the type defaults 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 parameter 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 #89

Note While I cannot find an explicit statement about Any Type in
the OpenApi spec, any openapi validators I used (like SwaggerHub)
act as if the type is Any Type and does not act as if the type is
"object". This is likely because in the absence of a constraint
in OpenAPI spec, no constraint is assumed.

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
@michaelgwelch michaelgwelch force-pushed the fixErrorOnMissingParameterSchema branch from e325f02 to 1c00d91 Compare July 26, 2022 13:34
@michaelgwelch
Copy link
Contributor Author

@ErikWittern are you still supporting this project?

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 this pull request may close these issues.

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