When using JSON Schema and Open API specification (OAS) to document a REST API, how do I define the UUID property?
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, 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.
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
.