Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix support for $comment keyword, add $comment to schema_test ExampleBasic() #33

Merged
merged 1 commit into from
Dec 20, 2018
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
10 changes: 5 additions & 5 deletions schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ type Schema struct {
// unless the vocabulary specifically forbids it. Vocabularies MUST
// NOT specify any effect of "$comment" beyond what is described in
// this specification.
Comment string `json:"comment,omitempty"`
Comment string `json:"$comment,omitempty"`
// Ref is used to reference a schema, and provides the ability to
// validate recursive structures through self-reference. An object
// schema with a "$ref" property MUST be interpreted as a "$ref"
Expand Down Expand Up @@ -393,7 +393,7 @@ func (s Schema) JSONProp(name string) interface{} {
return s.ReadOnly
case "writeOnly":
return s.WriteOnly
case "comment":
case "$comment":
return s.Comment
case "$ref":
return s.Ref
Expand Down Expand Up @@ -444,7 +444,7 @@ type _schema struct {
Examples []interface{} `json:"examples,omitempty"`
ReadOnly *bool `json:"readOnly,omitempty"`
WriteOnly *bool `json:"writeOnly,omitempty"`
Comment string `json:"comment,omitempty"`
Comment string `json:"$comment,omitempty"`
Ref string `json:"$ref,omitempty"`
Definitions map[string]*Schema `json:"definitions,omitempty"`
Format string `json:"format,omitempty"`
Expand Down Expand Up @@ -508,7 +508,7 @@ func (s *Schema) UnmarshalJSON(data []byte) error {
} else {
switch prop {
// skip any already-parsed props
case "$schema", "$id", "title", "description", "default", "examples", "readOnly", "writeOnly", "comment", "$ref", "definitions", "format":
case "$schema", "$id", "title", "description", "default", "examples", "readOnly", "writeOnly", "$comment", "$ref", "definitions", "format":
continue
default:
// assume non-specified props are "extra definitions"
Expand Down Expand Up @@ -587,7 +587,7 @@ func (s Schema) MarshalJSON() ([]byte, error) {
obj["writeOnly"] = s.WriteOnly
}
if s.Comment != "" {
obj["comment"] = s.Comment
obj["$comment"] = s.Comment
}
if s.Ref != "" {
obj["$ref"] = s.Ref
Expand Down
1 change: 1 addition & 0 deletions schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func ExampleBasic() {
var schemaData = []byte(`{
"title": "Person",
"type": "object",
"$comment" : "sample comment",
"properties": {
"firstName": {
"type": "string"
Expand Down