Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use additionalProperties instead of patternProperties #39

Merged
merged 2 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -464,9 +464,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 @@ -491,7 +489,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