Skip to content

Commit 3313399

Browse files
eponymous301b5
authored andcommitted
fix($comment): add support for $comment keyword, add $comment to testschema_test ExampleBasic() (#33)
1 parent d0d3b10 commit 3313399

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

schema.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ type Schema struct {
311311
// unless the vocabulary specifically forbids it. Vocabularies MUST
312312
// NOT specify any effect of "$comment" beyond what is described in
313313
// this specification.
314-
Comment string `json:"comment,omitempty"`
314+
Comment string `json:"$comment,omitempty"`
315315
// Ref is used to reference a schema, and provides the ability to
316316
// validate recursive structures through self-reference. An object
317317
// schema with a "$ref" property MUST be interpreted as a "$ref"
@@ -393,7 +393,7 @@ func (s Schema) JSONProp(name string) interface{} {
393393
return s.ReadOnly
394394
case "writeOnly":
395395
return s.WriteOnly
396-
case "comment":
396+
case "$comment":
397397
return s.Comment
398398
case "$ref":
399399
return s.Ref
@@ -444,7 +444,7 @@ type _schema struct {
444444
Examples []interface{} `json:"examples,omitempty"`
445445
ReadOnly *bool `json:"readOnly,omitempty"`
446446
WriteOnly *bool `json:"writeOnly,omitempty"`
447-
Comment string `json:"comment,omitempty"`
447+
Comment string `json:"$comment,omitempty"`
448448
Ref string `json:"$ref,omitempty"`
449449
Definitions map[string]*Schema `json:"definitions,omitempty"`
450450
Format string `json:"format,omitempty"`
@@ -508,7 +508,7 @@ func (s *Schema) UnmarshalJSON(data []byte) error {
508508
} else {
509509
switch prop {
510510
// skip any already-parsed props
511-
case "$schema", "$id", "title", "description", "default", "examples", "readOnly", "writeOnly", "comment", "$ref", "definitions", "format":
511+
case "$schema", "$id", "title", "description", "default", "examples", "readOnly", "writeOnly", "$comment", "$ref", "definitions", "format":
512512
continue
513513
default:
514514
// assume non-specified props are "extra definitions"
@@ -587,7 +587,7 @@ func (s Schema) MarshalJSON() ([]byte, error) {
587587
obj["writeOnly"] = s.WriteOnly
588588
}
589589
if s.Comment != "" {
590-
obj["comment"] = s.Comment
590+
obj["$comment"] = s.Comment
591591
}
592592
if s.Ref != "" {
593593
obj["$ref"] = s.Ref

schema_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ func ExampleBasic() {
1616
var schemaData = []byte(`{
1717
"title": "Person",
1818
"type": "object",
19+
"$comment" : "sample comment",
1920
"properties": {
2021
"firstName": {
2122
"type": "string"

0 commit comments

Comments
 (0)