No operations defined in spec! Dynamic mode
See original GitHub issuePrerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
Fastify version
4.3.0
Plugin version
7.4.1
Node.js version
16.16.0
Operating system
Windows
Operating system version (i.e. 20.04, 11.3, 10)
11
Description
My controllers look like below:
export const GroupController = async (fastify: FastifyInstance) => {
fastify.get(
"/",
{
schema: {
description: 'Get all Groups in the database',
summary: 'Get Groups',
response: { 200: GroupsSchema },
},
},
async (_req: FastifyRequest, reply: FastifyReply) => {
const groups = await fastify.orm
.getRepository(Group)
.createQueryBuilder("Group")
.getMany();
return reply.send(groups);
}
);
fastify.post<{ Body: GroupType }>(
"/",
{ schema: { body: GroupSchema, response: { 201: GroupSchema } } },
async (_req, reply) => {
const group = new Group();
group.name = _req.body.name;
const result = await fastify.orm.getRepository(Group).save(group);
return reply.status(201).send(result);
}
);
};
And then my schemas are defined using Typebox as such:
import { Static, Type } from '@sinclair/typebox'
export const GroupSchema = Type.Object({
id: Type.Optional(Type.Number({description: "The id of the group", examples:[1]})),
name: Type.String({description: "Name of the group", examples:["Test1"]})
})
export const GroupsSchema = Type.Array(GroupSchema);
export type GroupType = Static<typeof GroupSchema>
And then the routes are defined here:
import { FastifyInstance } from "fastify";
import { HealthStatusController } from '../controller/health-status-controller';
import { GroupController } from '../controller/group/group-controller';
export const Router = async(fastify: FastifyInstance) => {
fastify.register(HealthStatusController, {prefix: '/api/v1/health-status'});
fastify.register(GroupController, {prefix: '/api/v1/group'});
}
Finally swagger is registered like this:
// swagger registration
server.register(fastifySwagger, {
routePrefix: '/docs',
swagger: {
info: {
title: 'API documentation for IT core Twitter backend',
description: 'Swagger docs for the API',
version: '1.0.0'
},
schemes: ['http']
},
exposeRoute:true
});
But when I open the documentation this is what I see:
No operations defined in spec!
Steps to Reproduce
Create a latest fastify project with latest plugin version in TypeScript. And the routes do not work.
The structure of the project is below - The router and app is in infrastructure folder. Controllers are in controller and the server is at root. Fastify swagger is registered in app.ts
├───controller │ └───group ├───entities ├───infrastrcuture ├───migrations └───schemas
Expected Behavior
Expect the swagger docs to show up.
Issue Analytics
- State:
- Created a year ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
No operations defined in spec! - I get this error even though ...
I am trying to setup swagger on top of my node application using the swagger npm package. I have my end points and...
Read more >No operations defined in spec!---v5.0.0-rc4 #1315 - GitHub
The reason for the error was found. It was caused by the namespace. The same class name in different namespaces would cause the...
Read more >No operations defined in spec - IBM
If you see No operations defined in spec in the Swagger editor, the project is not yet ready for testing. Refresh the Swagger...
Read more >Using OpenAPI and Swagger UI - Quarkus
This guide explains how your Quarkus application can expose its API description through an OpenAPI specification and how you can test it via...
Read more >Paths and Operations - Swagger
Swagger defines a unique operation as a combination of a path and an HTTP method. This means that two GET or two POST...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Please register
@fastify/swaggerbefore any route. It is usingonRoutehooks to get all routes and it means that if the route is added before the registration of this plugin. None of them will be see.Also, you may need to
awaitthis plugin if you want to add route in the same level of context.Thank you! that was it