Skip to content

Commit 808300a

Browse files
committed
fix #582: define OpenAPI 3.1 string formats
1 parent 8057b5b commit 808300a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

openapi3/schema_formats.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,18 @@ func init() {
211211
// defined as date-time in https://www.rfc-editor.org/rfc/rfc3339#section-5.6
212212
DefineStringFormat("date-time", `^[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])T(23:59:60|(([01][0-9]|2[0-3])(:[0-5][0-9]){2}))(\.[0-9]+)?(Z|(\+|-)[0-9]{2}:[0-9]{2})?$`)
213213

214+
// defined as uuid in https://www.rfc-editor.org/rfc/rfc4122
215+
DefineStringFormat("uuid", FormatOfStringForUUIDOfRFC4122, FromOpenAPIMinorVersion(1))
216+
217+
// defined as ipv4 in
218+
DefineStringFormatCallback("ipv4", validateIPv4, FromOpenAPIMinorVersion(1))
219+
220+
// defined as ipv6 in https://www.rfc-editor.org/rfc/rfc4122
221+
DefineStringFormatCallback("ipv6", validateIPv6, FromOpenAPIMinorVersion(1))
222+
223+
// hostname as defined in https://www.rfc-editor.org/rfc/rfc1123#section-2.1
224+
DefineStringFormat(`hostname`, `^[a-zA-Z0-9][a-zA-Z0-9-.]+[a-zA-Z0-9]$`, FromOpenAPIMinorVersion(1))
225+
214226
defaultSchemaStringFormats = SaveStringFormats(SchemaStringFormats)
215227
}
216228

0 commit comments

Comments
 (0)