-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Request validator plugin respects existing properties and generates required ones #3283
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
Conversation
| }); | ||
| }); | ||
|
|
||
| describe('generateRequestValidatorPlugin()', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| for (const routePath of Object.keys(api.paths)) { | ||
| const pathItem: OA3PathItem = api.paths[routePath]; | ||
|
|
||
| // TODO: Add path plugins to route |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Completed and comment removed in a subsequent PR
cf2627c to
2d7025a
Compare
| }); | ||
| }); | ||
|
|
||
| it('should throw error if no operation request body content defined', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure what the effect is here.
Consider 200 operations and a request-validator defined.
- 100 POST ones expecting a body (and having it defined)
- 100 GET ones not expecting a body (and hence not defined in the OAS)
Then this would throw errors on the 100 GETs, right? In that case a user cannot specify the root level plugin config, but needs to add 100 specific ones for the POST ones. That will become painful...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha, should it silently continue if it can't find the appropriate properties? This is me writing a test for existing behaviour but can certainly change it if it's wrong
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes. I think that makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in e41e047 (#3283). I also updated the behavior of parameters_schema generation to not throw errors.
e798e73 to
e535aa5
Compare
e535aa5 to
e41e047
Compare
037c6ad to
d3e6d59
Compare

The request-validator plugin has several options to be send under the
configobject. These parameters are:parameter_schemabody_schemaallowed_content_typesverbose_responseOut of these four, the first three can be generated or be user-defined, and the fourth must be user defined.
In an OpenAPI spec, the user may specify an object with none or some of the config parameters. If a user defines a config parameter, then that config parameter will be used and not generated. If a parameter that can be generated is not defined, then O2K will attempt to generate.
Here is an example spec with the plugin defined on each operation. This is not an exhaustive example, but should server as a good base to begin testing from.
If O2K is unable to generate the
body_schema(from the operation request JSON body) orparameter_schema(from the operation parameters), then a default "pass-all" config should be applied, where thebody_schemais set to'{}'.See the unit tests added, which checks of these rules. Also see FTI-2252. This doesn't address all of the requirements outlined in the FTI, there is a subsequent PR to support plugins (request validator or otherwise) at other levels of the spec (root, server, path, operation).
Fixes INS-457, closes #2867