Skip to content

Commit

Permalink
handle generic types
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidfm committed Jan 30, 2024
1 parent 2a5a5ef commit 82f5004
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
6 changes: 6 additions & 0 deletions examples/nested/nested.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ type (
// Multicellular is true if the plant is multicellular
Multicellular bool `json:"multicellular,omitempty" jsonschema:"title=Multicellular"` // This comment will be ignored
}

// Metadata is additional arbitrary metadata to embed in a struct.
Metadata[T any] struct {
// The value of the metadata
Data T `json:"metadata"`
}
)
2 changes: 2 additions & 0 deletions examples/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ type User struct {
// The note for this friend
Note string `json:"note"`
} `json:"friend_to_note,omitempty"`

nested.Metadata[string]
}
7 changes: 6 additions & 1 deletion fixtures/go_comments.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@
},
"additionalProperties": false,
"description": "A mapping from friend IDs to notes"
},
"metadata": {
"type": "string",
"description": "The value of the metadata"
}
},
"additionalProperties": false,
Expand All @@ -154,7 +158,8 @@
"pets",
"named_pets",
"plants",
"additional_data"
"additional_data",
"metadata"
],
"description": "User is used as a base to provide tests for comments."
}
Expand Down
3 changes: 2 additions & 1 deletion reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,8 @@ func splitOnUnescapedCommas(tagString string) []string {
}

func fullyQualifiedTypeName(t reflect.Type) breadcrumb {
return breadcrumb{t.PkgPath(), t.Name()}
nameWithoutTypeParams := strings.Split(t.Name(), "[")[0]
return breadcrumb{t.PkgPath(), nameWithoutTypeParams}
}

// AddGoComments will update the reflectors comment map with all the comments
Expand Down

0 comments on commit 82f5004

Please sign in to comment.