When using JSON Schema and Open API specification (OAS) to document a REST API, how do I define the UUID property?
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".
OpenAPI 3.0 uses an extended subset of JSON Schema Specification Wright Draft 00 (aka Draft 5) to describe the data formats.
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.
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, theformatproperty 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With