Skip to content

Commit 72fb819

Browse files
authored
feat(openapi3gen): Customize json.RawMessage (#1050)
* feat(openapi3gen): Customize json.RawMessage * Add test case
1 parent cea0a13 commit 72fb819

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

openapi3gen/openapi3gen.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,10 @@ func (g *Generator) generateWithoutSaving(parents []*theTypeInfo, t reflect.Type
290290

291291
case reflect.Slice:
292292
if t.Elem().Kind() == reflect.Uint8 {
293-
if t == rawMessageType {
294-
return &openapi3.SchemaRef{Value: schema}, nil
293+
if t != rawMessageType {
294+
schema.Type = &openapi3.Types{"string"}
295+
schema.Format = "byte"
295296
}
296-
schema.Type = &openapi3.Types{"string"}
297-
schema.Format = "byte"
298297
} else {
299298
schema.Type = &openapi3.Types{"array"}
300299
items, err := g.generateSchemaRefFor(parents, t.Elem(), name, tag)

openapi3gen/openapi3gen_test.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,8 @@ func ExampleSchemaCustomizer() {
407407
InnerFieldWithTag int `mymintag:"-1" mymaxtag:"50"`
408408
NestedInnerBla
409409
}
410-
Enum2Field string `json:"enum2" myenumtag:"c,d"`
410+
Enum2Field string `json:"enum2" myenumtag:"c,d"`
411+
JsonField json.RawMessage `json:"rawmsg" myjsontag:"raw"`
411412
}
412413

413414
type Bla struct {
@@ -435,6 +436,9 @@ func ExampleSchemaCustomizer() {
435436
schema.Enum = append(schema.Enum, s)
436437
}
437438
}
439+
if tag.Get("myjsontag") != "" {
440+
schema.Description = "description"
441+
}
438442
return nil
439443
})
440444

@@ -487,6 +491,9 @@ func ExampleSchemaCustomizer() {
487491
// "f"
488492
// ],
489493
// "type": "string"
494+
// },
495+
// "rawmsg": {
496+
// "description": "description"
490497
// }
491498
// },
492499
// "type": "object"

0 commit comments

Comments
 (0)