How to define UUID property in JSON Schema and Open API (OAS)

Slava Fomin II picture Slava Fomin II · May 6, 2018 · Viewed 21.4k times · Source

When using JSON Schema and Open API specification (OAS) to document a REST API, how do I define the UUID property?

Answer

Helen picture Helen · May 7, 2018

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.