Skip to content

Commit be86de1

Browse files
committed
wip
Signed-off-by: Pierre Fenoll <[email protected]>
1 parent 3605205 commit be86de1

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

openapi3/schema.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -736,18 +736,23 @@ func (s *Schema) fromOpenAPISchema() (schema schemaJSON) {
736736
schema["enum"] = sEnum
737737
}
738738

739-
if sFormat := s.Format; sFormat != "" {
740-
schema["format"] = sFormat
741-
}
742739
if sMinLength := s.MinLength; sMinLength != 0 {
743740
schema["minLength"] = sMinLength
744741
}
745742
if sMaxLength := s.MaxLength; nil != sMaxLength {
746743
schema["maxLength"] = *sMaxLength
747744
}
745+
746+
if sFormat := s.Format; sFormat != "" {
747+
schema["format"] = sFormat
748+
}
748749
if sPattern := s.Pattern; sPattern != "" {
749750
schema["pattern"] = sPattern
750751
}
752+
if s.Format == "byte" {
753+
// Matches base64 (RFC 4648) `standard` base64 not `base64url`.
754+
schema["pattern"] = "^[\\w\\d+\\/=]*$"
755+
}
751756

752757
if nil != s.Min {
753758
schema["minimum"] = *s.Min
@@ -845,6 +850,9 @@ func (s *Schema) fromOpenAPISchema() (schema schemaJSON) {
845850
}
846851

847852
schema["$schema"] = "http://json-schema.org/draft-04/schema#"
853+
//FIXME
854+
//https://github.com/openapi-contrib/openapi-schema-to-json-schema/blob/45c080c38027c30652263b4cc44cd3534f5ccc1b/lib/converters/schema.js
855+
//https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#schemaObject
848856
return
849857
}
850858

openapi3/schema_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ var schemaExamples = []schemaExample{
311311
},
312312

313313
{
314-
Title: "STRING: format 'date-time'",
314+
Title: `STRING: format "byte"`,
315315
Schema: NewBytesSchema(),
316316
Serialization: map[string]interface{}{
317317
"type": "string",
@@ -326,13 +326,13 @@ var schemaExamples = []schemaExample{
326326
}
327327
return data
328328
}()),
329-
base64.URLEncoding.EncodeToString(func() []byte {
330-
data := make([]byte, 0, 1024)
331-
for i := 0; i < cap(data); i++ {
332-
data = append(data, byte(i))
333-
}
334-
return data
335-
}()),
329+
// base64.URLEncoding.EncodeToString(func() []byte {
330+
// data := make([]byte, 0, 1024)
331+
// for i := 0; i < cap(data); i++ {
332+
// data = append(data, byte(i))
333+
// }
334+
// return data
335+
// }()),
336336
},
337337
AllInvalid: []interface{}{
338338
nil,

0 commit comments

Comments
 (0)