如何在JSON模式和开放API(OAS)中定义UUID属性 [英] How to define UUID property in JSON Schema and Open API (OAS)

查看:181
本文介绍了如何在JSON模式和开放API(OAS)中定义UUID属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 JSON模式 UUID 属性?

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, the format 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆