Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions field_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ func (ps *tagBaseFieldParser) CustomSchema() (*spec.Schema, error) {
}

type structField struct {
title string
schemaType string
arrayType string
formatType string
Expand Down Expand Up @@ -274,6 +275,7 @@ func (ps *tagBaseFieldParser) complementSchema(schema *spec.Schema, types []stri
field := &structField{
schemaType: types[0],
formatType: ps.tag.Get(formatTag),
title: ps.tag.Get(titleTag),
}

if len(types) > 1 && (types[0] == ARRAY || types[0] == OBJECT) {
Expand Down Expand Up @@ -414,6 +416,7 @@ func (ps *tagBaseFieldParser) complementSchema(schema *spec.Schema, types []stri
if field.schemaType != ARRAY {
schema.Format = field.formatType
}
schema.Title = field.title

extensionsTagValue := ps.tag.Get(extensionsTag)
if extensionsTagValue != "" {
Expand Down
15 changes: 15 additions & 0 deletions field_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ func TestDefaultFieldParser(t *testing.T) {
assert.Equal(t, "csv", schema.Format)
})

t.Run("Title tag", func(t *testing.T) {
t.Parallel()

schema := spec.Schema{}
schema.Type = []string{"string"}
err := newTagBaseFieldParser(
&Parser{},
&ast.Field{Tag: &ast.BasicLit{
Value: `json:"test" title:"myfield"`,
}},
).ComplementSchema(&schema)
assert.NoError(t, err)
assert.Equal(t, "myfield", schema.Title)
})

t.Run("Required tag", func(t *testing.T) {
t.Parallel()

Expand Down
1 change: 1 addition & 0 deletions operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ const (
exampleTag = "example"
schemaExampleTag = "schemaExample"
formatTag = "format"
titleTag = "title"
validateTag = "validate"
minimumTag = "minimum"
maximumTag = "maximum"
Expand Down