Skip to content

Commit a97bf63

Browse files
Alex Botenomissis
Alex Boten
andcommitted
add support for additionalProperties when other fields exist
This is a proposed implementation to address the feature requested in #188. Tests still need fixing, but I want to get support on the implementation first. Signed-off-by: Alex Boten <[email protected]> Co-authored-by: Alex Boten <[email protected]> Co-authored-by: Claudio Beatrice <[email protected]>
1 parent 8228fbb commit a97bf63

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

pkg/generator/schema_generator.go

+15
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,21 @@ func (g *schemaGenerator) generateStructType(
531531
structType.AddField(structField)
532532
}
533533

534+
if t.AdditionalProperties != nil {
535+
if valueType, err := g.generateType(t.AdditionalProperties, nil); err != nil {
536+
return nil, err
537+
} else {
538+
structType.AddField(
539+
codegen.StructField{
540+
Name: "AdditionalProperties",
541+
DefaultValue: map[string]interface{}{},
542+
SchemaType: &schemas.Type{},
543+
Type: valueType,
544+
},
545+
)
546+
}
547+
}
548+
534549
return &structType, nil
535550
}
536551

tests/data/regressions/issue51/issue51.go

+22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/data/regressions/issue51/issue51.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "http://json-schema.org/draft-07/schema#",
33
"type": "object",
4-
"additionalProperties": true,
4+
"additionalProperties": {"type": "string"},
55
"properties": {
66
"name": {
77
"type": "string"

0 commit comments

Comments
 (0)