-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add regression tests for additionalProperties as highlighted i…
- Loading branch information
Showing
5 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Code generated by github.com/atombender/go-jsonschema, DO NOT EDIT. | ||
|
||
package test | ||
|
||
import "encoding/json" | ||
import "fmt" | ||
|
||
type TestObject struct { | ||
// Config corresponds to the JSON schema field "config". | ||
Config TestObjectConfig `json:"config,omitempty" yaml:"config,omitempty" mapstructure:"config,omitempty"` | ||
|
||
// Name corresponds to the JSON schema field "name". | ||
Name string `json:"name" yaml:"name" mapstructure:"name"` | ||
|
||
// Owner corresponds to the JSON schema field "owner". | ||
Owner string `json:"owner" yaml:"owner" mapstructure:"owner"` | ||
} | ||
|
||
type TestObjectConfig map[string]interface{} | ||
|
||
// UnmarshalJSON implements json.Unmarshaler. | ||
func (j *TestObject) UnmarshalJSON(b []byte) error { | ||
var raw map[string]interface{} | ||
if err := json.Unmarshal(b, &raw); err != nil { | ||
return err | ||
} | ||
if v, ok := raw["name"]; !ok || v == nil { | ||
return fmt.Errorf("field name in TestObject: required") | ||
} | ||
if v, ok := raw["owner"]; !ok || v == nil { | ||
return fmt.Errorf("field owner in TestObject: required") | ||
} | ||
type Plain TestObject | ||
var plain Plain | ||
if err := json.Unmarshal(b, &plain); err != nil { | ||
return err | ||
} | ||
*j = TestObject(plain) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"$ref": "#/definitions/TestObject", | ||
"definitions": | ||
{ | ||
"TestObject": | ||
{ | ||
"required": | ||
[ | ||
"owner", | ||
"name" | ||
], | ||
"properties": | ||
{ | ||
"owner": | ||
{ | ||
"type": "string" | ||
}, | ||
"name": | ||
{ | ||
"type": "string" | ||
}, | ||
"config": | ||
{ | ||
"patternProperties": | ||
{ | ||
".*": | ||
{ | ||
"additionalProperties": true | ||
} | ||
}, | ||
"type": "object" | ||
} | ||
}, | ||
"additionalProperties": false, | ||
"type": "object" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Code generated by github.com/atombender/go-jsonschema, DO NOT EDIT. | ||
|
||
package test | ||
|
||
type Issue51 struct { | ||
// Name corresponds to the JSON schema field "name". | ||
Name *string `json:"name,omitempty" yaml:"name,omitempty" mapstructure:"name,omitempty"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"type": "object", | ||
"additionalProperties": true, | ||
"properties": { | ||
"name": { | ||
"type": "string" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters