Skip to content

Commit

Permalink
add example
Browse files Browse the repository at this point in the history
  • Loading branch information
candiduslynx committed Oct 4, 2023
1 parent da5a0b6 commit 26eed64
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
26 changes: 26 additions & 0 deletions fixtures/nullable_field.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://github.com/invopop/jsonschema/test-nullable-field",
"$ref": "#/$defs/TestNullableField",
"$defs": {
"TestNullableField": {
"properties": {
"a": {
"oneOf": [
{
"type": "string"
},
{
"type": "null"
}
]
}
},
"additionalProperties": false,
"type": "object",
"required": [
"a"
]
}
}
}
19 changes: 19 additions & 0 deletions fixtures/nullable_from_tags_field.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://github.com/invopop/jsonschema/test-nullable-field",
"$ref": "#/$defs/TestNullableField",
"$defs": {
"TestNullableField": {
"properties": {
"a": {
"type": "string"
}
},
"additionalProperties": false,
"type": "object",
"required": [
"a"
]
}
}
}
6 changes: 6 additions & 0 deletions reflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ type TestNullable struct {
Child1 string `json:"child1" jsonschema:"nullable"`
}

type TestNullableField struct {
A *string `json:"a"`
}

type CompactDate struct {
Year int
Month int
Expand Down Expand Up @@ -426,6 +430,8 @@ func TestSchemaGeneration(t *testing.T) {
{&OuterPtr{}, &Reflector{ExpandedStruct: true}, "fixtures/inlining_ptr.json"},
{&MinValue{}, &Reflector{}, "fixtures/schema_with_minimum.json"},
{&TestNullable{}, &Reflector{NullableFromJSONSchemaTags: true}, "fixtures/nullable.json"},
{&TestNullableField{}, &Reflector{}, "fixtures/nullable_field.json"},
{&TestNullableField{}, &Reflector{NullableFromJSONSchemaTags: true}, "fixtures/nullable_from_tags_field.json"},
{&GrandfatherType{}, &Reflector{
AdditionalFields: func(r reflect.Type) []reflect.StructField {
return []reflect.StructField{
Expand Down

0 comments on commit 26eed64

Please sign in to comment.