Skip to content

Commit

Permalink
fix($comment): add support for $comment keyword, add $comment to test…
Browse files Browse the repository at this point in the history
…schema_test ExampleBasic() (#33)
  • Loading branch information
eponymous301 authored and b5 committed Dec 20, 2018
1 parent d0d3b10 commit 3313399
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
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

0 comments on commit 3313399

Please sign in to comment.