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

4.3.x Custom resolvers are incompatible with options.apiSpec set to path. #426

Closed
aviskase opened this issue Oct 27, 2020 · 5 comments
Closed

Comments

@aviskase
Copy link
Contributor

aviskase commented Oct 27, 2020

Related to #416

Describe the bug
After upgrading to 4.3.x custom resolvers are incompatible with options.apiSpec set to path.

In 4.2.3 custom resolver was working with:

resolver: (basePath: string, route) => {
 const functionName = route.schema['operationId'];
 ...

In 4.3.x custom resolver had to be change to different approach because there is no longer .schema property in the route:

resolver: (basePath: string, route, apiDoc) => {
  const pathKey = route.openApiRoute.substring(route.basePath.length);
  const schema = apiDoc.paths[pathKey][route.method.toLowerCase()];
  const functionName = schema['operationId'];
  ...

But it relies on installOperationHandlers to send apiDoc always as an object, whereas per line

router[method.toLowerCase()](path, resolver(basePath, route, this.options.apiSpec));
it sends whatever was defined in options (in my case, path to API description doc).

@aviskase
Copy link
Contributor Author

I found that apiDoc argument was introduced in #366 in version 3.17.x , so I think the are two problems here:

  • for some reason, route.schema is now undefined
  • apiDoc is better to be loaded into object before passing into resolver (for uniformity)

@cdimascio
Copy link
Owner

cdimascio commented Oct 27, 2020

thanks @aviskase
router[method.toLowerCase()](path, resolver(basePath, route, this.options.apiSpec)); should be
router[method.toLowerCase()](path, resolver(basePath, route, context.apiDoc));
feel free to create a PR with the change, and i'll get it merged. if not, i'll get it done tonight

@aviskase
Copy link
Contributor Author

yup, will do

@cdimascio
Copy link
Owner

cdimascio commented Oct 27, 2020

i'll revisit schema. i removed it as part of the readOnly/required work. not something i wanted to do, but felt was necessary to ensure solid performance.
background:
in order to handle the schema for readOnly vs writeOnly using ajv, i need to manipulate the schema's required property based on the case (readOnly vs writeOnly). the validator manipulates the required prop once on schema load (as opposed to per api request) for efficiency. though efficient, it has a downside, in that two very similar variants of the apiDoc exist. i want to explore other mechanisms before exposing this (not so ideal) implementation detail to the user through an API.

aviskase added a commit to aviskase/express-openapi-validator that referenced this issue Oct 27, 2020
@cdimascio
Copy link
Owner

fixed in v4.3.5. thanks @aviskase !

ex1st pushed a commit to ex1st/express-openapi-validator that referenced this issue Dec 9, 2020
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

No branches or pull requests

2 participants