Skip to content

Commit d8d80ca

Browse files
committed
Define hint in ast hints.go
1 parent d9be4ed commit d8d80ca

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

internal/ast/hints.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ const (
2727
// HintStringFormatDateTime hints refers to a string that should be formatted
2828
// as a datetime as defined by RFC 3339, section 5.6 (ex: 2017-07-21T17:32:28Z)
2929
HintStringFormatDateTime = "string_format_datetime"
30+
31+
// HintOpenStruct hints that the struct is to be considered open even if not type Any
32+
// when generating outputs which make explicit allowances for
33+
// arbitrary additional properties, such as OpenAPI/JSONSchema.
34+
HintOpenStruct = "open"
3035
)
3136

3237
const DiscriminatorCatchAll = "cog_discriminator_catch_all"

internal/jennies/jsonschema/schema.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ 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' {
205+
if typeDef.HasHint(ast.HintOpenStruct) {
206+
if val, _ := typeDef.Hints[ast.HintOpenStruct].(string); strings.ToLower(val)[0] == 't' {
207207
definition.Set("additionalProperties", map[string]any{})
208208
}
209209
}

0 commit comments

Comments
 (0)