Closed akama-aka closed 1 month ago
You are missing await
before the fastify.ready
You are missing
await
before thefastify.ready
Then I should get the error that it is not async. Which makes sense because the server.js file is not a module.
You are missing
await
before thefastify.ready
Then I should get the error that it is not async. Which makes sense because the server.js file is not a module.
The document shows you should call fastify.swagger
after awaiting the fastify.ready
.
I am only pointing out you are not following the document.
You can use thenable or callback if top level await is not possible.
You are missing
await
before thefastify.ready
Then I should get the error that it is not async. Which makes sense because the server.js file is not a module.
The document shows you should call
fastify.swagger
after awaiting thefastify.ready
. I am only pointing out you are not following the document.You can use thenable or callback if top level await is not possible.
You're not pointing out, reading my description. My JavaScript IS NOT A MODULE. So it is not possible to use await
randomly in the server file. And I already had it in a faatify.listen function but it also did nothing.
The documentation only shows instructions for a Module JavaScript project, mine is not a module it is a CommonJS project.
The documentation only shows instructions for a Module JavaScript project, mine is not a module it is a CommonJS project.
The document show you should await fastify.ready
means it should run after the promise is resolved.
It doesn't matter it is ESM
or CJS
, the await
is there for a reason.
You can change it to thenable or callback, anything that serve the same purpose.
But not just remove it (same as not follow the document).
And I already had it in a faatify.listen function but it also did nothing.
That does not ensure fastify.swagger
is run after the designed timing.
It should place inside the callback if you want to use fastify.listen
.
The documentation only shows instructions for a Module JavaScript project, mine is not a module it is a CommonJS project.
The document show you should
await fastify.ready
means it should run after the promise is resolved. It doesn't matter it isESM
orCJS
, theawait
is there for a reason. You can change it to thenable or callback, anything that serve the same purpose. But not just remove it (same as not follow the document).And I already had it in a faatify.listen function but it also did nothing.
That does not ensure
fastify.swagger
is run after the designed timing. It should place inside the callback if you want to usefastify.listen
.
I've it now like that:
// Set default headers
fastify.listen({ host: process.env.SERVER_HOST, port: process.env.SERVER_PORT }, async (err) => {
await fastify.ready();
fastify.swagger();
if (err) throw err;
},
)
const process = require("node:process");
const swagger = require('@fastify/swagger');
require("dotenv").config();
const fastify = require("fastify")({
logger: true,
});
fastify.register(require("@fastify/postgres"), {
connectionString: process.env.DATABASE_URL,
});
fastify.register(swagger, {
openapi: {
openapi:'3.0.0',
info: {
title:'my title',
description:'a desc',
version:'1.0.0'
},
servers: [
{url:'https://sub.domain.tld',description: 'desc'}
],
tags: [
{name:"tag1",description:"desc1"},
{name:"tag2",description:"desc2"},
{name:'tag3',description: "desc3"}
],
components: {
securitySchemes: {
authorization: {
type:'apiKey',
name: 'authorization',
in:'header'
},
"x-auth-agent-token": {
type:'apiKey',
name:'x-auth-agent-token',
in:'header'
}
}
}
}
})
and it still doesnt create yaml or json file anywhere
it still doesnt create yaml or json file anywhere
This plugin does not write any file.
It returns json
or yaml
through fastify.swagger
So, you can log and see the result. Then, use the return in the way you want.
it still doesnt create yaml or json file anywhere
This plugin does not write any file. It returns
json
oryaml
throughfastify.swagger
So, you can log and see the result. Then, use the return in the way you want.
Ahh okay thanks, but it just returns the default data I've set in the fastify.register function. How can I get the routed Endpoints?
Prerequisites
Fastify version
4.28.0
Plugin version
No response
Node.js version
20.13.1
Operating system
Windows
Operating system version (i.e. 20.04, 11.3, 10)
22631.3880
Description
Hello, I've tried to follow the README.md intruction but sadly there's no sight of life for a normal JavaScript implementation and because of that and the reason that I can't find something related to this error in any Google search I opened this issue. My server.js File looks like that:
As soon as I want to start the server with node server.js I get the in title mentioned error message. And if I change
fastify.swagger()
tofastify.swagger
I get no error but it also doesnt create anything elseI hope the documentations gets updated for both types of nodejs projects.
Link to code that reproduces the bug
No response
Expected Behavior
No response