yaml - 将 Swagger 规范拆分为较小的文件时出错
问题描述
我的文件夹结构如下
/spec
/definitions
index.yaml
User.yaml
/paths
...
spec.yaml
里面的内容index.yaml
是
User:
$ref: ./User.yaml
里面的内容User.yaml
是
type: "object"
properties:
id:
type: "integer"
format: "int64"
first_name:
type: "string"
last_name:
type: "string"
email:
type: "string"
password:
type: "string"
phone:
type: "string"
xml:
name: "User"
example:
first_name: "firstName"
last_name: "lastName"
password: "password"
phone: "phone"
id: 0
email: "email"
在里面spec.yaml
,我定义如下
---
swagger: "2.0"
info:
description: "This is a sample."
version: "1.0.0"
title: "Smart Community API Documents"
termsOfService: "http://swagger.io/terms/"
contact:
email: "email@gmail.com"
license:
name: "Apache 2.0"
url: "http://www.apache.org/licenses/LICENSE-2.0.html"
host: "localhost:4000"
basePath: "/"
tags:
- name: "user"
description: "Operations about user"
externalDocs:
description: "Find out more about our store"
url: "http://swagger.io"
schemes:
- "http"
paths:
/user:
post:
tags:
- "user"
summary: "Create user"
description: "This can only be done by the logged in user."
operationId: "createUser"
produces:
- "application/xml"
- "application/json"
parameters:
- in: "body"
name: "body"
description: "Created user object"
required: true
schema:
$ref: "#/definitions/User"
responses:
default:
description: "successful operation"
x-swagger-router-controller: "User"
securityDefinitions:
petstore_auth:
type: "oauth2"
authorizationUrl: "http://petstore.swagger.io/oauth/dialog"
flow: "implicit"
scopes:
write:pets: "modify pets in your account"
read:pets: "read your pets"
api_key:
type: "apiKey"
name: "api_key"
in: "header"
definitions:
User:
$ref: ./definitions/User.yaml
externalDocs:
description: "Find out more about Swagger"
url: "http://swagger.io"
然后,我得到了错误,
API 错误:
#/definitions/User/$ref:无法解析引用:./definitions/User.yaml
有人可以帮我吗?
解决方案
推荐阅读
- r - 为什么我不能在 `ggplot2::geom_col(aes(alpha = ...))` 中为不同的条映射不同的 alpha 值?
- go - 创建接收具有特定数量参数的任何函数的函数
- c# - 如何使用表格对象模型 (TOM) 在不更改数据源的情况下更改 Azure 分析服务数据库模型
- reactjs - 没有空路由的反应测试 /
- excel - 关闭未保存的工作簿
- php - Laravel 找不到存储的文件 404 NOT FOUND
- list - SwiftUI 列表未在 y 中扩展到所需的完整高度
- node.js - NodeJs - 使用 fs.createReadStream 读取文件时出错
- r - 使用可以每年更新的文本命名 .csv
- reactjs - 苹果m1中的Cocoapods安装问题