i use @fastify/swagger and @fastify/swagger-ui, my config
import fastifySwagger from '@fastify/swagger';
import fastifySwaggerUi from '@fastify/swagger-ui';
import { FastifyInstance } from 'fastify';
import fp from 'fastify-plugin';
const swagger = async (fastify: FastifyInstance) => {
await fastify.register(fastifySwagger, {
mode: 'dynamic',
openapi: {
openapi: '3.0.3',
info: {
title: 'openapi',
version: '0.1.0'
}
}
});
await fastify.register(fastifySwaggerUi, {
routePrefix: '/openapi',
uiConfig: {
deepLinking: true
},
uiHooks: {
onRequest: function (request, reply, next) {
next();
},
preHandler: function (request, reply, next) {
next();
}
},
staticCSP: true,
transformStaticCSP: (header) => header,
transformSpecification: (swaggerObject, request, reply) => {
return swaggerObject;
},
transformSpecificationClone: true
});
};
export default fp(swagger);
my routes like this
export const articleRouter = async (fastify: FastifyInstance) => {
fastify.get(
'/list',
{
schema: {
tags: ['article'],
summary: 'getting artilce list',
description: 'description in routes',
params: {
type: 'object',
description: 'some params',
properties: {
limit: {
type: 'number',
description: 'limit articles'
},
sort: {
type: 'string',
description: 'asc or desc'
}
},
required: ['sort']
},
}
},
async (req, resp) => {
const articles = await articleService.findArticles();
resp.send(articles);
}
);
};
swagger screenshot
All works, but field 'limit' is alway required. Why?
Please, help me.
I'm playing with all properties in config and routes but no one helpe me.