krakenjs/hapi-openapi

PR for uuid

ozum opened this issue · 4 comments

ozum commented

Hi,

I would like to create a simple PR for uuid format using regexp /[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}/.

However I'm confused where to create it.

There is hapi-openapi/lib/validators.js, but I thought validations belong to enjoi and see there is enjoi/lib/resolver.js.

Could you please advise where to create it? Also why do we need format definitions in hapi-openapi/lib/validators.js besides enjoi?

Many thanks,

enjoi converts json schema into Joi schema. This is what hapi-openapi used for parameter validation.

Since swagger “extends” json schema with things like the file primitive, we define those types here.

I don’t think Swagger defines uuid as a format so not sure it is appropriate to impose here. Let me know if I am wrong.

ozum commented

I encountered uuid and email in a lot of OpenAPI documents and JSON Schema validators. I checked OAS again, and you are right. I'm surprised to see that they are mentioned in OpenAPI specification as they MAY be used. So they are not one of the defined formats of OAS, although seems to be used frequently. (Additionally email is defined in JSON schema as seen here)

On the other hand, uuid and email are also compatible with Joi too, and I think, it would be very useful to add frequently used formats such as uuid and email.

From https://swagger.io/specification/

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.

I believe I added email format to enjoi already. Maybe just add format support for uuid there too.

Otherwise I should be able to get to this over the weekend.

This is part of enjoi@4.1.0 and should be useable in the current version of hapi-openapi as well.