如何在swagger API管线文档中指定模型属性的子集
正在使用swagger为我的服务编写API规范。我使用模型定义(“#/definitions/prototype”)作为如何在swagger API管线文档中指定模型属性的子集,swagger,swagger-2.0,swagger-editor,Swagger,Swagger 2.0,Swagger Editor,正在使用swagger为我的服务编写API规范。我使用模型定义(“#/definitions/prototype”)作为POST/prototype和PATCH/prototype/:id路由的主体参数 如何指定修补程序路由只接受POST路由执行的请求主体中的属性子集?例如,我希望PATCH/instances/:id路由只允许修改mobileDeviceIdprototype属性 swagger: "2.0" info: title: "" description: "" vers
POST/prototype
和PATCH/prototype/:id
路由的主体参数
如何指定修补程序路由只接受POST路由执行的请求主体中的属性子集?例如,我希望PATCH/instances/:id
路由只允许修改mobileDeviceId
prototype属性
swagger: "2.0"
info:
title: ""
description: ""
version: "1.0.0"
host: foo.example.com
schemes:
- https
basePath: /v1
produces:
- application/json
consumes:
- application/json
paths:
/prototypes:
post:
summary: Create new prototype
parameters:
- name: prototype
in: body
description: Prototype object
required: true
schema:
$ref: "#/definitions/Prototype"
responses:
201:
description: Success
schema:
$ref: "#/definitions/SuccessCreated"
403:
description: Prototype limit exceeded error
schema:
$ref: "#/definitions/Error"
default:
description: Unexpected error
schema:
$ref: "#/definitions/Error"
/prototypes/{id}:
patch:
summary: Update an existing prototype's properties
parameters:
- name: id
in: path
type: number
description: ID property of a prototype
required: true
- name: prototype
in: body
description: Prototype object
required: true
schema:
$ref: "#/definitions/Prototype"
responses:
200:
description: Success
definitions:
Prototype:
type: object
properties:
id:
type: integer
format: int64
name:
type: string
mobileDeviceId:
type: number
SuccessCreated:
type: object
description: Returned as response to successful resource create request
properties:
code:
type: number
default: 201
message:
type: string
Error:
type: object
properties:
code:
type: integer
format: int32
message:
type: string
fields:
type: string
Swagger使用json模式:
$ref
s为您提供了一种在新路径上重复现有json模式的方法。
请注意,您正在为修补程序/参数/-name:prototype/schema
使用$ref
。
您可以在“定义”部分中仅为修补程序创建一个新定义并引用它
swagger: "2.0"
info:
title: ""
description: ""
version: "1.0.0"
host: foo.example.com
schemes:
- https
basePath: /v1
produces:
- application/json
consumes:
- application/json
paths:
/prototypes:
post:
summary: Create new prototype
parameters:
- name: prototype
in: body
description: Prototype object
required: true
schema:
$ref: "#/definitions/Prototype"
responses:
201:
description: Success
schema:
$ref: "#/definitions/SuccessCreated"
403:
description: Prototype limit exceeded error
schema:
$ref: "#/definitions/Error"
default:
description: Unexpected error
schema:
$ref: "#/definitions/Error"
/prototypes/{id}:
patch:
summary: Update an existing prototype's properties
parameters:
- name: id
in: path
type: number
description: ID property of a prototype
required: true
- name: prototype
in: body
description: Prototype object
required: true
schema:
$ref: "#/definitions/PatchPrototype"
responses:
200:
description: Success
definitions:
Prototype:
type: object
properties:
id:
type: integer
format: int64
name:
type: string
mobileDeviceId:
type: number
PatchPrototype:
type: object
properties:
mobileDeviceId:
type: number
SuccessCreated:
type: object
description: Returned as response to successful resource create request
properties:
code:
type: number
default: 201
message:
type: string
Error:
type: object
properties:
code:
type: integer
format: int32
message:
type: string
fields:
type: string