Skip to content

Commit

Permalink
Merge pull request #39 from arvidfm/additional-properties
Browse files Browse the repository at this point in the history
Use additionalProperties instead of patternProperties
  • Loading branch information
samlown authored Sep 6, 2023
2 parents 0d62e11 + fbf400c commit b954aa2
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 40 deletions.
6 changes: 2 additions & 4 deletions fixtures/allow_additional_props.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,8 @@
"description": "list of IDs, omitted when empty"
},
"tags": {
"patternProperties": {
".*": {
"type": "string"
}
"additionalProperties": {
"type": "string"
},
"type": "object"
},
Expand Down
6 changes: 2 additions & 4 deletions fixtures/defaults_expanded_toplevel.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,8 @@
"description": "list of IDs, omitted when empty"
},
"tags": {
"patternProperties": {
".*": {
"type": "string"
}
"additionalProperties": {
"type": "string"
},
"type": "object"
},
Expand Down
6 changes: 2 additions & 4 deletions fixtures/go_comments.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
"$ref": "#/$defs/User",
"$defs": {
"NamedPets": {
"patternProperties": {
".*": {
"$ref": "#/$defs/Pet"
}
"additionalProperties": {
"$ref": "#/$defs/Pet"
},
"type": "object",
"description": "NamedPets is a map of animal names to pets."
Expand Down
6 changes: 2 additions & 4 deletions fixtures/ignore_type.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,8 @@
"description": "list of IDs, omitted when empty"
},
"tags": {
"patternProperties": {
".*": {
"type": "string"
}
"additionalProperties": {
"type": "string"
},
"type": "object"
},
Expand Down
6 changes: 2 additions & 4 deletions fixtures/no_reference.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,8 @@
"description": "list of IDs, omitted when empty"
},
"tags": {
"patternProperties": {
".*": {
"type": "string"
}
"additionalProperties": {
"type": "string"
},
"type": "object"
},
Expand Down
6 changes: 2 additions & 4 deletions fixtures/no_reference_anchor.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,8 @@
"description": "list of IDs, omitted when empty"
},
"tags": {
"patternProperties": {
".*": {
"type": "string"
}
"additionalProperties": {
"type": "string"
},
"type": "object"
},
Expand Down
6 changes: 2 additions & 4 deletions fixtures/required_from_jsontags.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,8 @@
"description": "list of IDs, omitted when empty"
},
"tags": {
"patternProperties": {
".*": {
"type": "string"
}
"additionalProperties": {
"type": "string"
},
"type": "object"
},
Expand Down
6 changes: 2 additions & 4 deletions fixtures/test_user.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,8 @@
"description": "list of IDs, omitted when empty"
},
"tags": {
"patternProperties": {
".*": {
"type": "string"
}
"additionalProperties": {
"type": "string"
},
"type": "object"
},
Expand Down
6 changes: 2 additions & 4 deletions fixtures/test_user_assign_anchor.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,8 @@
"description": "list of IDs, omitted when empty"
},
"tags": {
"patternProperties": {
".*": {
"type": "string"
}
"additionalProperties": {
"type": "string"
},
"type": "object"
},
Expand Down
6 changes: 2 additions & 4 deletions reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,7 @@ func (r *Reflector) reflectMap(definitions Definitions, t reflect.Type, st *Sche
return
}
if t.Elem().Kind() != reflect.Interface {
st.PatternProperties = map[string]*Schema{
".*": r.refOrReflectTypeToSchema(definitions, t.Elem()),
}
st.AdditionalProperties = r.refOrReflectTypeToSchema(definitions, t.Elem())
}
}

Expand All @@ -516,7 +514,7 @@ func (r *Reflector) reflectStruct(definitions Definitions, t reflect.Type, s *Sc
if r.AssignAnchor {
s.Anchor = t.Name()
}
if !r.AllowAdditionalProperties {
if !r.AllowAdditionalProperties && s.AdditionalProperties == nil {
s.AdditionalProperties = FalseSchema
}

Expand Down

0 comments on commit b954aa2

Please sign in to comment.