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).
definitions field remove from the option so that change openapiObject.definitions to openapiObject.components.schemas
definitions is always undefined so no way to pass externalSchemas
// 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)
Prerequisites
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,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
definitions
field remove from the option so that changeopenapiObject.definitions
toopenapiObject.components.schemas
definitions
is alwaysundefined
so no way to pass externalSchemas~~2. resolveLocalRef function not search root scope.
$ref as a root reference
resolveLocalRef
function don't search root scope. Only search inline scope.~~Steps to Reproduce
Reproducable Repo.
Use this repo.
git clone git@github.com:imjuni/maeum.git
cd maeum
npm install
npm run dev
Expected Behavior
Works with custom schemaController.