FeathersJS and the Swagger!

I remember once dancing to a tune by the american rapper T.I titled “swagger like Us”, Well to the fans of that song I’m sorry, I only want to steal your time a little and make you benefit from another swagger, this time, FeathersJS swagger.

What Is Swagger?

Swagger is a set of open-source tools built around the OpenAPI Specification that can help you design, build, document and consume REST APIs.

The major Swagger tools include:

  • Swagger Editor : Browser-based editor where you can write OpenAPI specs.
  • Swagger UI: Renders OpenAPI specs as interactive API documentation.
  • Swagger Codegen: Generates server stubs and client libraries from an OpenAPI spec.

visit copy this link https://swagger.io/docs/specification/about and paste on your browser address tab; to learn more about swagger

FeathesJs swagger let you add documentation to your services and service them to swaggerU.I, the latest version of FeathersJS swagger works with Swagger UI 3.x and let you create documentation more easily.

To install FeathersJs swagger run npm install feathers-swagger --save

Basic example

Here’s an example of a Feathers server that uses feathers-swagger.

const feathers = require('feathers');
const rest = require('feathers-rest');
const memory = require('feathers-memory');
const bodyParser = require('body-parser');
const swagger = require('feathers-swagger');
const messageService = memory();
// swagger spec for this service, see http://swagger.io/specification/
messageService.docs = {
description: 'A service to send and receive messages',
definitions: {
messages: {
"type": "object",
"required": [
"text"
],
"properties": {
"text": {
"type": "string",
"description": "The message text"
},
"useId": {
"type": "string",
"description": "The id of the user that sent the message"
}
}
}
}
};
const app = feathers()
  .use(bodyParser.json())
.use(bodyParser.urlencoded({ extended: true }))
.configure(rest())
.configure(swagger({
docsPath: '/docs',
info: {
title: 'A test',
description: 'A description'
}
}))
.use('/messages', messageService);
app.listen(3030);

Please note that code example is copied from the documentation at https://github.com/feathersjs-ecosystem/feathers-swagger and I’m not taking claims in the code example at all but to show you an example of FeathersJs swagger and to learn more about Feathers Swagger, please visit the above link.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.