Skip to content
Open
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
40 changes: 40 additions & 0 deletions fixtures/schema_extend_description.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://github.com/invopop/jsonschema/extend-description-object",
"$ref": "#/$defs/ExtendDescriptionObject",
"$defs": {
"ExtendDescriptionObject": {
"properties": {
"extend": {
"type": "string",
"description": "extend description"
},
"tag": {
"type": "string",
"description": "tag description"
},
"tag_extend": {
"type": "string",
"description": "tag description"
},
"generic_tag": {
"type": "string",
"description": "generic description"
},
"generic_tag_extend": {
"type": "string",
"description": "generic description"
}
},
"additionalProperties": false,
"type": "object",
"required": [
"extend",
"tag",
"tag_extend",
"generic_tag",
"generic_tag_extend"
]
}
}
}
6 changes: 5 additions & 1 deletion reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,11 @@ func (r *Reflector) lookupID(t reflect.Type) ID {
}

func (t *Schema) structKeywordsFromTags(f reflect.StructField, parent *Schema, propertyName string) {
t.Description = f.Tag.Get("jsonschema_description")
description, ok := f.Tag.Lookup("jsonschema_description")
if ok {
t.Description = description
}


tags := splitOnUnescapedCommas(f.Tag.Get("jsonschema"))
tags = t.genericKeywords(tags, parent, propertyName)
Expand Down
21 changes: 21 additions & 0 deletions reflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,3 +675,24 @@ func TestJSONSchemaAlias(t *testing.T) {
compareSchemaOutput(t, "fixtures/schema_alias.json", r, &AliasObjectB{})
compareSchemaOutput(t, "fixtures/schema_alias_2.json", r, &AliasObjectC{})
}

type WithExtendDescription string

func (WithExtendDescription) JSONSchemaExtend(base *Schema) {
base.Description = "extend description"
}

type ExtendDescriptionObject struct {
Extend WithExtendDescription `json:"extend"`

Tag WithExtendDescription `json:"tag" jsonschema_description:"tag description"`
TagExtend WithExtendDescription `json:"tag_extend" jsonschema_description:"tag description"`

GenericTag WithExtendDescription `json:"generic_tag" jsonschema:"description=generic description"`
GenericTagExtend WithExtendDescription `json:"generic_tag_extend" jsonschema:"description=generic description"`
}

func TestJsonSchemaExtendDescription(t *testing.T) {
r := &Reflector{}
compareSchemaOutput(t, "fixtures/schema_extend_description.json", r, &ExtendDescriptionObject{})
}