openapi-ts
openapi-ts copied to clipboard
Allow user handling of `format` strings in OpenAPI
Description
From OpenAPI docs:
As defined by the JSON Schema Validation vocabulary, data types can have an optional modifier property: format. OAS defines additional formats to provide fine detail for primitive data type
The referenced JSON schema includes this:
Structural validation alone may be insufficient to allow an application to correctly utilize certain values. The "format" annotation keyword is defined to allow schema authors to convey semantic information for a fixed subset of values which are accurately described by authoritative resources, be they RFCs or other external specifications.
TLDR: It's a way for generic types like string to be given more semantic meaning (by defining a format: uuid as an example).
It would be great if openapi-ts allowed intercepting of common formats (as defined in the JSON spec referenced above), allowing clients to handle them as branded types / custom classes/validators / etc.
Here's one example that would be useful for me:
OpenAPI spec snippet:
"components": {
"schemas": {
"MyObject": {
"properties": {
"Id": {
"type": "string",
"format": "uuid4",
// ^ Relevant portion here
"title": "Id"
},
// ... definition continues
I'm not sure what a middleware spec inside hey-api would look like, but hopefully this issue gets the ball rolling on client-defined conversion of known subtypes of primitives like string/number.
Thanks for considering!