【发布时间】:2019-02-05 15:47:25
【问题描述】:
我有许多 swagger 文件,使用相同的定义。我想将此定义移动到单独的文件并引用它们。
主要的招摇文件看起来像:
swagger: '2.0'
info:
version: 1.0.0
basePath: /api
tags:
- name: MyClient
schemes:
- http
consumes:
- application/json
produces:
- application/json
paths:
/v1/myrequest:
post:
tags:
- PassportCheck
summary: Проверить паспорт ФЛ
operationId: passportCheck
produces:
- application/json
parameters:
- name: Body
in: body
required: true
description: ''
schema:
$ref: '#/definitions/MyRequest'
responses:
'200':
description: OK
schema:
$ref: '#/definitions/MyResponse'
'400':
description: Bad request
schema:
$ref: '#/definitions/Errors'
definitions:
MyRequest:
type: object
properties:
some properties
我尝试导入的文件保存到 exceptions.yaml(并保存到同一位置),如下所示:
swagger: '2.0'
info:
version: 1.0.0
title: Exception API
tags:
- name: ExceptionAPI
definitions:
Errors:
required:
- errors
properties:
errors:
type: array
items:
data declarations go here
我已阅读 $ref https://swagger.io/docs/specification/using-ref/,但找不到如何导入定义而不是 API
我正在尝试通过以下更改导入它:
'400':
description: Bad request
schema:
$ref: 'exceptions.yaml#/definitions/Errors'
[ERROR] /C:/Data/MyService/target/generated-sources/src/main/java/myservice/rest/v1/api/V1Api.java:[55,70] cannot find symbol
symbol: class ExceptionsYamldefinitionsErrors
或者在不同的变体中使用相对路径
'400':
description: Bad request
schema:
$ref: '..exceptions.yaml#/definitions/Errors'
[ERROR] Failed to execute goal io.swagger:swagger-codegen-maven-plugin:2.3.1:generate (correqts-adapter) on project individual-client-service: Execution correqts-adapter of goal io.swagger:swagger-codegen-maven-plugin:2.3.1:generate fail
ed: Unable to load RELATIVE ref: ..exceptions.yaml: Could not find ..exceptions.yaml on the classpath ->
或在现有声明下插入 $ref:
definitions:
$ref: 'exceptions.yaml'
完全被忽略了
有没有人解决过类似的问题?
【问题讨论】:
标签: swagger swagger-2.0 swagger-codegen