Skip to content

Commit d9be4ed

Browse files
committed
Add hints to AST struct type, and use the 'open' hint to add additionalProperties in openAPI generation.
1 parent eda7037 commit d9be4ed

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

internal/jennies/jsonschema/schema.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@ func (jenny Schema) formatStruct(typeDef ast.Type) Definition {
202202

203203
definition.Set("type", "object")
204204
definition.Set("additionalProperties", false)
205+
if typeDef.HasHint("open") {
206+
if val, _ := typeDef.Hints["open"].(string); strings.ToLower(val)[0] == 't' {
207+
definition.Set("additionalProperties", map[string]any{})
208+
}
209+
}
205210

206211
properties := orderedmap.New[string, any]()
207212
var required []string

internal/simplecue/generator.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,8 @@ func (g *generator) declareNode(v cue.Value) (ast.Type, error) {
404404
}
405405

406406
def := ast.NewStruct(fields...)
407+
// Add the hints since we can't supply them in the constructor
408+
def.Hints = hints
407409
def.Default = defVal
408410

409411
return def, nil

0 commit comments

Comments
 (0)