我的文件夹结构如下
/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
有人可以帮助我吗?