Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 564
Slava Fomin II Avatar asked May 06 '18 21:05

Slava Fomin II


People also ask

Does JSON support UUID?

The JSON Schema Validation component spec was extended such that the existing 'format' keyword that can be specified for schema fields of type string now supports a new built-in format named "uuid".

Does open API use JSON Schema?

OpenAPI 3.0 uses an extended subset of JSON Schema Specification Wright Draft 00 (aka Draft 5) to describe the data formats.

What is OAS format?

The OpenAPI Specification (OAS) defines a standard, programming language-agnostic interface description for HTTP APIs, which allows both humans and computers to discover and understand the capabilities of a service without requiring access to source code, additional documentation, or inspection of network traffic.


1 Answers

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):

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.

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.

like image 108
Helen Avatar answered Sep 18 '22 09:09

Helen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!