Swagger 如何在定义中重用招摇过市定义?
代码如下:Swagger 如何在定义中重用招摇过市定义?,swagger,Swagger,代码如下: definitions: Result: type: object properties: code: type: integer format: int32 message: type: string FindUID: type: object properties: code: type: integer format: in
definitions:
Result:
type: object
properties:
code:
type: integer
format: int32
message:
type: string
FindUID:
type: object
properties:
code:
type: integer
format: int32
message:
type: string
data:
type: object
properties:
uid:
type: integer
format: int64
FindUsername:
type: object
properties:
code:
type: integer
format: int32
message:
type: string
data:
type: object
properties:
username:
type: string
如您所见,
FindUID
和FindUsername
的第一部分与Result
相同。如何用Result
替换那些重复的代码?您可以使用allOf
组合定义,下面是一个完整的示例,其中在FindUID和FindUsername中使用Result:
swagger: '2.0'
info:
description: Example API Description
title: Example Title
version: 1.0.0
paths: {}
definitions:
Result:
type: object
properties:
code:
type: integer
format: int32
message:
type: string
FindUID:
allOf:
- $ref: "#/definitions/Result"
- type: object
properties:
data:
type: object
properties:
uid:
type: integer
format: int64
FindUsername:
allOf:
- $ref: "#/definitions/Result"
- type: object
properties:
data:
type: object
properties:
username:
type: string
更多信息请参见:(披露:我编写了本教程)