如何在JSON模式和开放API(OAS)中定义UUID属性 [英] How to define UUID property in JSON Schema and Open API (OAS)
问题描述
When using JSON Schema and Open API specification (OAS) to document a REST API, how do I define the UUID property?
推荐答案
UUID没有内置的type
,但OpenAPI规范建议使用
There's no built-in type
for UUID, but the OpenAPI Specification suggests using
type: string
format: uuid
从数据类型部分(重点是我的):
From the Data Types section (emphasis mine):
原语具有可选的修饰符属性:
format
. OAS使用几种已知格式来详细定义所使用的数据类型.但是,为了满足文档需求,format
属性是一个开放的字符串值属性,并且可以具有任何值. 即使未由本规范定义,也可以使用诸如"email"
,"uuid"
之类的格式.
Primitives have an optional modifier property:
format
. OAS uses several known formats to define in fine detail the data type being used. However, to support documentation needs, theformat
property is an open string-valued property, and can have any value. Formats such as"email"
,"uuid"
, and so on, MAY be used even though undefined by this specification.
例如,Swagger Codegen在C#中将format: uuid
映射到System.Guid
或在Java中将java.util.UUID
映射.不支持format: uuid
的工具将像type: string
一样处理它.
For example, Swagger Codegen maps format: uuid
to System.Guid
in C# or java.util.UUID
in Java. Tools that don't support format: uuid
will handle it as just type: string
.
这篇关于如何在JSON模式和开放API(OAS)中定义UUID属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!