【发布时间】:2016-03-17 10:09:33
【问题描述】:
我正在使用 swagger 0.7.5 并尝试将 swagger.yaml 文件拆分为多个。我使用swagger project create sample-api 命令创建项目。选择的框架是express。执行这些命令创建了一个带有 ExpressJS 设置和默认 swagger.yaml 文件的 nodejs 项目。由于我的目标是大型应用程序,因此我想将 yaml 文件拆分为多个。根据文档,我已经开始将响应模型外部化到外部文件,这就是它的外观
swagger.yaml
swagger: "2.0"
info:
version: "0.0.1"
title: Hello Service
host: localhost:10010
basePath: /
... #skipping code for brevity
paths:
/hello:
x-swagger-router-controller: user
get:
description: Say hello
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/HelloResponse"
default:
description: Error
schema:
$ref: "#/definitions/ErrorResponse"
/swagger:
x-swagger-pipe: swagger_raw
definitions:
HelloResponse:
$ref : models/response/hello_response.yaml
ErrorResponse:
required:
- message
properties:
message:
type: string
models/response/hello_response.yaml
type: string
properties:
message:
type: string
在项目目录的根目录执行swagger project start命令后,服务启动,并在浏览器中显示文档。问题是,swagger doc 不显示外部化 yaml 文件的结构并显示以下错误消息。
项目的目录结构如下所示
- api
-- swagger
--- swagger.yaml
- config
-- config.yaml
- models
-- response
--- hello_response.yaml
- app.js
注意:我尝试在swagger.yaml 级别复制models 目录,但也没有用。
【问题讨论】:
标签: yaml swagger swagger-ui swagger-2.0