Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidfm committed Aug 4, 2022
1 parent ccf6347 commit 8078bcb
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 6 deletions.
23 changes: 20 additions & 3 deletions examples/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ type User struct {
// Unique sequential identifier.
ID int `json:"id" jsonschema:"required"`
// This comment will be ignored
Name string `json:"name" jsonschema:"required,minLength=1,maxLength=20,pattern=.*,description=this is a property,title=the name,example=joe,example=lucy,default=alex"`
Friends []int `json:"friends,omitempty" jsonschema_description:"list of IDs, omitted when empty"`
Tags map[string]interface{} `json:"tags,omitempty"`
Name string `json:"name" jsonschema:"required,minLength=1,maxLength=20,pattern=.*,description=this is a property,title=the name,example=joe,example=lucy,default=alex"`
Friends []struct {
// The ID of the friend
FriendID int `json:"friend_id"`
// A note about this friend
FriendNote string `json:"friend_note,omitempty"`
} `json:"friends,omitempty" jsonschema_description:"list of friends, omitted when empty"`
Tags map[string]interface{} `json:"tags,omitempty"`

// An array of pets the user cares for.
Pets nested.Pets `json:"pets"`
Expand All @@ -22,4 +27,16 @@ type User struct {

// Set of plants that the user likes
Plants []*nested.Plant `json:"plants" jsonschema:"title=Plants"`

// Additional data about this user
AdditionalData struct {
// This user's favorite color
FavoriteColor string `json:"favorite_color"`
} `json:"additional_data"`

// A mapping from friend IDs to notes
FriendToNote map[int]*struct {
// The note for this friend
Note string `json:"note"`
} `json:"friend_to_note,omitempty"`
}
55 changes: 52 additions & 3 deletions fixtures/go_comments.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,24 @@
},
"friends": {
"items": {
"type": "integer"
"type": "object",
"properties": {
"friend_id": {
"type": "integer",
"description": "The ID of the friend"
},
"friend_note": {
"type": "string",
"description": "A note about this friend"
}
},
"additionalProperties": false,
"required": [
"friend_id"
]
},
"type": "array",
"description": "list of IDs, omitted when empty"
"description": "list of friends, omitted when empty"
},
"tags": {
"type": "object"
Expand All @@ -92,6 +106,40 @@
"type": "array",
"title": "Plants",
"description": "Set of plants that the user likes"
},
"additional_data": {
"type": "object",
"properties": {
"favorite_color": {
"type": "string",
"description": "This user's favorite color"
}
},
"additionalProperties": false,
"description": "Additional data about this user",
"required": [
"favorite_color"
]
},
"friend_to_note": {
"type": "object",
"patternProperties": {
"^[0-9]+$": {
"type": "object",
"properties": {
"note": {
"type": "string",
"description": "The note for this friend"
}
},
"additionalProperties": false,
"required": [
"note"
]
}
},
"additionalProperties": false,
"description": "A mapping from friend IDs to notes"
}
},
"additionalProperties": false,
Expand All @@ -101,7 +149,8 @@
"name",
"pets",
"named_pets",
"plants"
"plants",
"additional_data"
],
"description": "User is used as a base to provide tests for comments."
}
Expand Down

0 comments on commit 8078bcb

Please sign in to comment.