EmmaDev
EmmaDev

Reputation: 69

Swagger to call differents node.js rest API's

I have a problem developing a swagger project.

SCENARIO:

I have four restAPIs developed on Node.js, and now I want to create just ONE Swagger project to call all the endpoints of the four restAPI's. So my endpoints are in differents projects. I am executing the following sentences in order to develop the swagger project.

npm install -g swagger

swagger project create -f express file-name  //Select express by default

swagger project start

swagger project edit 

After this I open the web editor that shows the following code: (I paste just the part of the code that defines the endpoint (get))

paths:
  /hello:
    # binds a127 app logic to a route
    x-swagger-router-controller: hello_world
get:
  description: Returns 'Hello' to the caller
  # used as the method name of the controller
  operationId: hello
  parameters:
    - name: name
      in: query
      description: The name of the person to whom to say hello
      required: false
      type: string
  responses:
    "200":
      description: Success
      schema:
        # a pointer to a definition
        $ref: "#/definitions/HelloWorldResponse"
    # responses may fall through to errors
    default:
      description: Error
      schema:
        $ref: "#/definitions/ErrorResponse"

Can anybody helpme please?

Thxs Emma.

Upvotes: 0

Views: 49

Answers (1)

vicky
vicky

Reputation: 415

import errors from './components/errors';
import path from 'path';
var swaggerUi = require('swagger-ui-express');
var swaggerDocument = require('./swagger.js');

export default function(app) {
    // Insert routes below
    app.use('/api/announcements', require('./api/announcements'));

    app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument))

}

put this in route file and add swagger file in server

Upvotes: 1

Related Questions