Comments (16)
Oh, you'll need the exposeRoute: true
option.
from fastify-swagger.
Great, working now!
One little thing: On the Usage section on README.md - there is a extra {}
fastify.register(require('fastify-swagger'), {
swagger: {
info: {
title: 'Test swagger',
description: 'testing the fastify swagger api',
version: '0.1.0'
},
routePrefix: '/documentation',
host: 'localhost',
schemes: ['http'],
consumes: ['application/json'],
produces: ['application/json'],
securityDefinitions: {
apiKey: {
type: 'apiKey',
name: 'apiKey',
in: 'header'
}
}
}
})
This doesn't work!
Here is my version:
fastify.register(require('fastify-swagger'), {
swagger: {
info: {
title: 'EDS Cognitive',
description: 'Testing the fastify swagger api',
version: '0.1.0'
},
},
exposeRoute: true,
routePrefix: '/documentation'
})
Not sure why but....
Thanks a lot.
We will start to use fastify on a big enterprise project, you'll see me a lot here...lol
cya
from fastify-swagger.
I'm a bit lost. What do you mean? Can you make a full example?
from fastify-swagger.
I'm trying to add fastify-swagger on my project. The project was created with fastify-cli!
This is my app.js:
module.exports = function (fastify, opts, next) {
fastify.register(require('@now-ims/fastify-firestore'), {
projectId: 'nomikos-544df',
keyFilename: './nomikos-78ff516da5d8.json'
})
fastify.register(require('fastify-swagger'), {
swagger: {
info: {
title: 'Test swagger',
description: 'testing the fastify swagger api',
version: '0.1.0'
},
routePrefix: '/documentation',
host: 'localhost',
schemes: ['http'],
consumes: ['application/json'],
produces: ['application/json'],
securityDefinitions: {
apiKey: {
type: 'apiKey',
name: 'apiKey',
in: 'header'
}
}
}
})
// This loads all plugins defined in plugins
// those should be support plugins that are reused
// through your application
fastify.register(AutoLoad, {
dir: path.join(__dirname, 'plugins')
})
// This loads all plugins defined in services
// define your routes in one of these
fastify.register(AutoLoad, {
dir: path.join(__dirname, 'services')
})
// Make sure to call next when done
next()
}
In the documentation i saw that it's necessary to add the command below but I'm not sure where to put it, as the server is initialised by fastify start command.
fastify.swagger()
from fastify-swagger.
fastify.swagger()
will just return the swagger definition. You do not have to do much, just navigate to /documentation
and your swagger-ui should appear.
Is it working?
from fastify-swagger.
But where to add the fastify.swagger()
? On the route?
My root.js
'use strict'
module.exports = function (fastify, opts, next) {
const options = {
schema: {
response: {
200: {
type: 'object',
properties: {
root: { type: 'boolean' }
}
}
}
}
}
fastify.get('/', options, function (request, reply) {
reply.send({ root: true })
})
next()
}
// 20180611161700
// http://localhost:3000/documentation
{
"statusCode": 404,
"error": "Not Found",
"message": "Not Found"
}
from fastify-swagger.
@lgertel would you like to send a PR to update the README?
I'm glad you picked fastify!
from fastify-swagger.
@mcollina yeah! sure!
I'll work on this and send news asap.
Who knows, maybe sometime I'll be able to work on the core too :)
from fastify-swagger.
Doesnt work for me, with current CLI create and having multiple folders in services folder. swagger docs is only shown for routes defined in app.js, root where are registrations
from fastify-swagger.
Can you please paste your app.js?
from fastify-swagger.
"use strict";
const PORT = process.env.PORT || 3000;
const path = require("path");
const AutoLoad = require("fastify-autoload");
const fastify = require("fastify")({
logger: true
});
// Require external modules
const mongoose = require("mongoose");
// Connect to DB
mongoose
.connect("mongodb://localhost:27017/navrush")
.then(() => console.log("MongoDB connected…"))
.catch(err => console.log(err));
// Place here your custom code!
// Do not touch the following lines
// This loads all plugins defined in plugins
// those should be support plugins that are reused
// through your application
fastify.register(AutoLoad, {
dir: path.join(__dirname, "plugins")
});
// This loads all plugins defined in services
// define your routes in one of these
fastify.register(AutoLoad, {
dir: path.join(__dirname, "services")
});
// Register Swagger
fastify.register(require('fastify-swagger'), {
swagger: {
info: {
title: 'EDS Cognitive',
description: 'Testing the fastify swagger api',
version: '0.1.0'
},
},
exposeRoute: true,
routePrefix: '/documentation'
})
fastify.listen(PORT, err => {
if (err) throw err;
console.log(`server listening on ${fastify.server.address().port}`);
});
fastify.ready(err => {
if (err) throw err;
fastify.swagger();
});
from fastify-swagger.
from fastify-swagger.
If I add any schema definition to services/auth/index,js there are not part of swagger generated docs
from fastify-swagger.
that needs to be loaded before the autoload calls. There is a comment at the top where to add your plugins.
from fastify-swagger.
Thank you, works. Please try to add this to main example, as this is what you will get if you follow guides :D
from fastify-swagger.
This also worked for me,
I was trying to install @fastify/swagger-ui but was getting an error.
-> AssertionError [ERR_ASSERTION]: The dependency '@fastify/swagger' of plugin '@fastify/swagger-ui' is not registered
I tried just registering fastify-swagger, via "autoload" but adding a file for swagger. but that did not work. But i did not have the exposeRoute: true option.
/app.js
// ... fastify.register(require("@fastify/swagger"), { swagger: { info: { title: "Armani Machines", description: "Api documentation test using Swagger/Swaggerui", version: "0.1.0", }, }, exposeRoute: true, routePrefix: "/documentation", uiConfig: { docExpansion: "full", deepLinking: false, }, }); // ...
This code worked for me
from fastify-swagger.
Related Issues (20)
- Endpoint-specific schema transform HOT 12
- Automatically generate path params definition HOT 13
- Error: .swagger() must be called after .ready() HOT 14
- Generate json without swagger-ui HOT 1
- Custom "examples" names and summaries for request body, params, etc HOT 4
- Example values for individual request body fields are not compliant with OpenAPI specification HOT 4
- Wildcard paths fails Swagger validation HOT 4
- referencing #/components/schema when they don't exist
- Support for different content with the same http code. HOT 1
- Bad request for querystring when using explode is false HOT 1
- Included types break usage of config object HOT 1
- No valid examples and migration guide does not work out of the box HOT 1
- 👋 I'm Giovanni and I would like to work on this HOT 1
- Update README with OpenAPI v3 instead of Swagger example HOT 6
- Shared JSON schema: Cannot create property 'in' on string 'object' HOT 6
- Support (responses) components with OpenAPI v3 HOT 8
- Using custom AJV keywords results in openAPI error
- Missing description when using $ref HOT 1
- Allow adding additional static routes in addition to dynamic mode HOT 1
- Zod schema references ($ref) breaking fastify route querystrings HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastify-swagger.