-
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.
feat: refine additional properties default values, to make them bette…
…r match their value type in generated code
- Loading branch information
Showing
3 changed files
with
81 additions
and
1 deletion.
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
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,30 @@ | ||
// Code generated by github.com/atombender/go-jsonschema, DO NOT EDIT. | ||
|
||
package test | ||
|
||
import "encoding/json" | ||
|
||
type ObjectAdditionalProperties struct { | ||
// Foo corresponds to the JSON schema field "foo". | ||
Foo ObjectAdditionalPropertiesFoo `json:"foo,omitempty" yaml:"foo,omitempty" mapstructure:"foo,omitempty"` | ||
} | ||
|
||
type ObjectAdditionalPropertiesFoo map[string]string | ||
|
||
// UnmarshalJSON implements json.Unmarshaler. | ||
func (j *ObjectAdditionalProperties) UnmarshalJSON(b []byte) error { | ||
var raw map[string]interface{} | ||
if err := json.Unmarshal(b, &raw); err != nil { | ||
return err | ||
} | ||
type Plain ObjectAdditionalProperties | ||
var plain Plain | ||
if err := json.Unmarshal(b, &plain); err != nil { | ||
return err | ||
} | ||
if v, ok := raw["foo"]; !ok || v == nil { | ||
plain.Foo = map[string]string{} | ||
} | ||
*j = ObjectAdditionalProperties(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,14 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"type": "object", | ||
"properties": { | ||
"foo": { | ||
"type": "object", | ||
"additionalProperties": { | ||
"type": "string" | ||
}, | ||
"default": {} | ||
} | ||
}, | ||
"additionalProperties": false | ||
} |