[英]Swagger to call differents node.js rest API's
I have a problem developing a swagger project.我在开发 swagger 项目时遇到问题。
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.我在 Node.js 上开发了四个 restAPI,现在我只想创建一个 Swagger 项目来调用四个 restAPI 的所有端点。 So my endpoints are in differents projects.
所以我的端点在不同的项目中。 I am executing the following sentences in order to develop the swagger project.
我正在执行以下句子以开发 swagger 项目。
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))在此之后,我打开 web 编辑器,该编辑器显示以下代码:(我只粘贴了定义端点(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.谢谢艾玛。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.