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

Cannot pass definitions field when using openapi configuration #691

Open
2 tasks done
imjuni opened this issue Nov 13, 2022 · 0 comments
Open
2 tasks done

Cannot pass definitions field when using openapi configuration #691

imjuni opened this issue Nov 13, 2022 · 0 comments

Comments

@imjuni
Copy link
Contributor

imjuni commented Nov 13, 2022

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.9.2

Plugin version

8.1.0

Node.js version

14.20.1

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

Ubuntu 20.04.3 LTS

Description

Issue

Cannot found $ref schema when custom SchemaController apply on fastify server instance. @fastify/swagger display error message like that,

{
  "statusCode": 500,
  "error": "Internal Server Error",
  "message": "Cannot read property 'type' of undefined"
}

Custom SchemaController

ajv schema store split from fastify server instance because schema store use other case. eg. redis, rabbitmq pub/sub or file upload etc(share $ref schema).

Analysis

  1. I believe the following code is a bug.
// as-is
if (schema.querystring) resolveCommonParams('query', parameters, schema.querystring, ref, openapiObject.definitions, securityIgnores.query)
if (schema.body) {
  openapiMethod.requestBody = { content: {} }
  resolveBodyParams(openapiMethod.requestBody, schema.body, schema.consumes, ref)
}
if (schema.params) resolveCommonParams('path', parameters, schema.params, ref, openapiObject.definitions)
if (schema.headers) resolveCommonParams('header', parameters, schema.headers, ref, openapiObject.definitions, securityIgnores.header)
// TODO: need to documentation, we treat it same as the querystring
// fastify do not support cookies schema in first place
if (schema.cookies) resolveCommonParams('cookie', parameters, schema.cookies, ref, openapiObject.definitions, securityIgnores.cookie)
// to-be
if (schema.querystring) resolveCommonParams('query', parameters, schema.querystring, ref, openapiObject.components.schemas, securityIgnores.query)
if (schema.body) {
  openapiMethod.requestBody = { content: {} }
  resolveBodyParams(openapiMethod.requestBody, schema.body, schema.consumes, ref)
}
if (schema.params) resolveCommonParams('path', parameters, schema.params, ref, openapiObject.components.schemas)
if (schema.headers) resolveCommonParams('header', parameters, schema.headers, ref, openapiObject.components.schemas, securityIgnores.header)
// TODO: need to documentation, we treat it same as the querystring
// fastify do not support cookies schema in first place
if (schema.cookies) resolveCommonParams('cookie', parameters, schema.cookies, ref, openapiObject.components.schemas, securityIgnores.cookie)

2. resolveLocalRef function not search root scope.
* fastify document explain to $ref as a root reference
* but resolveLocalRef function don't search root scope. Only search inline scope.

Steps to Reproduce

Reproducable Repo.

Use this repo.

  1. git clone [email protected]:imjuni/maeum.git
  2. cd maeum
  3. npm install
  4. npm run dev

Expected Behavior

Works with custom schemaController.

@imjuni imjuni changed the title Cannot found $ref schema when using custom schema controller Cannot pass definitions field when using openapi configuration Nov 16, 2022
imjuni added a commit to imjuni/fastify-swagger that referenced this issue Nov 16, 2022
* fix cannot pass externalSchemas when using openapi configuration
imjuni added a commit to imjuni/fastify-swagger that referenced this issue Nov 16, 2022
* fix cannot pass externalSchemas when using openapi configuration
imjuni added a commit to imjuni/fastify-swagger that referenced this issue Nov 17, 2022
* fix cannot pass externalSchemas when using openapi configuration
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

1 participant