Skip to content
Open
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
10 changes: 10 additions & 0 deletions .changesets/1792662097-11a83540.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
id: 1792662097-11a83540
features:
- constArrays
targets:
- terraform
type: feat
bump: minor
description: array properties with a const value are hidden from the resource schema and the const value is sent in request bodies
author: AshGodfrey
date: "2026-10-22"
11 changes: 11 additions & 0 deletions .changesets/1792662097-2435dcc7.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
id: 1792662097-2435dcc7
features:
- constsAndDefaults
targets:
- go
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
- cli
type: fix
bump: patch
description: const values on array and map fields are emitted when marshaling and accepted when unmarshaling
author: AshGodfrey
date: "2026-10-22"
10 changes: 10 additions & 0 deletions .changesets/1792662097-4b2c17a5.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
id: 1792662097-4b2c17a5
features:
- constObjects
targets:
- terraform
type: feat
bump: minor
description: map properties with a const value are hidden from the resource schema and the const value is sent in request bodies
author: AshGodfrey
date: "2026-10-22"
6 changes: 6 additions & 0 deletions internal/features/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ const (
// FeatureDefaultObjects relates to the ability to handle default values for objects
// Tier: Experimental
FeatureDefaultObjects
// FeatureConstArrays relates to the ability to handle const values for arrays
// Tier: Experimental
FeatureConstArrays
// FeatureConstObjects relates to the ability to handle const values for objects
// Tier: Experimental
FeatureConstObjects
// FeatureAdditionalProperties relates to the ability to deserialize any unknown properties into a map available as an extra property on the generated models for both request bodies and parameters
// Tier: Gold
FeatureAdditionalProperties
Expand Down
14 changes: 14 additions & 0 deletions internal/features/features_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

127 changes: 127 additions & 0 deletions internal/schemas/handle_array_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,106 @@ func TestHandleArray(t *testing.T) {
Build()).
Build(),
},
{
name: "ArrayWithConst",
schemasYAML: `TestSchema:
type: array
items:
type: string
const:
- read
- write`,
schemaName: "TestSchema",
mockFeatures: func() *testutils.MockFeaturesConfig {
config := testutils.NewMockFeaturesConfig()
config.SupportedFeatures = map[features.Feature]bool{
features.FeatureConstArrays: true,
features.FeatureConstsAndDefaults: true,
}
return config
},
expected: testutils.NewFieldDef("strings",
testutils.NewTypeDef(ast.DataTypeArray).
WithItemType(testutils.NewTypeDef(ast.DataTypeString).WithLocation(&yaml.Node{Line: 11, Column: 9}).WithValidations(&ast.Validations{}).Build()).
WithLocation(&yaml.Node{Line: 9, Column: 7}).
WithValidations(&ast.Validations{}).
Build()).
WithConst(&ast.AnyValue{Value: []interface{}{"read", "write"}}).
Build(),
},
{
name: "ArrayWithEmptyConst",
schemasYAML: `TestSchema:
type: array
items:
type: string
const: []`,
schemaName: "TestSchema",
mockFeatures: func() *testutils.MockFeaturesConfig {
config := testutils.NewMockFeaturesConfig()
config.SupportedFeatures = map[features.Feature]bool{
features.FeatureConstArrays: true,
features.FeatureConstsAndDefaults: true,
}
return config
},
expected: testutils.NewFieldDef("strings",
testutils.NewTypeDef(ast.DataTypeArray).
WithItemType(testutils.NewTypeDef(ast.DataTypeString).WithLocation(&yaml.Node{Line: 11, Column: 9}).WithValidations(&ast.Validations{}).Build()).
WithLocation(&yaml.Node{Line: 9, Column: 7}).
WithValidations(&ast.Validations{}).
Build()).
WithConst(&ast.AnyValue{Value: []interface{}{}}).
Build(),
},
{
name: "ArrayWithConstFeatureUnsupported",
schemasYAML: `TestSchema:
type: array
items:
type: string
const: []`,
schemaName: "TestSchema",
mockFeatures: func() *testutils.MockFeaturesConfig {
config := testutils.NewMockFeaturesConfig()
config.SupportedFeatures = map[features.Feature]bool{
features.FeatureConstsAndDefaults: true,
}
return config
},
expected: testutils.NewFieldDef("strings",
testutils.NewTypeDef(ast.DataTypeArray).
WithItemType(testutils.NewTypeDef(ast.DataTypeString).WithLocation(&yaml.Node{Line: 11, Column: 9}).WithValidations(&ast.Validations{}).Build()).
WithLocation(&yaml.Node{Line: 9, Column: 7}).
WithValidations(&ast.Validations{}).
Build()).
Build(),
},
{
name: "ArrayWithConstItemTypeMismatch",
Comment thread
AshGodfrey marked this conversation as resolved.
schemasYAML: `TestSchema:
type: array
items:
type: string
const:
- 1`,
schemaName: "TestSchema",
mockFeatures: func() *testutils.MockFeaturesConfig {
config := testutils.NewMockFeaturesConfig()
config.SupportedFeatures = map[features.Feature]bool{
features.FeatureConstArrays: true,
features.FeatureConstsAndDefaults: true,
}
return config
},
expected: testutils.NewFieldDef("strings",
testutils.NewTypeDef(ast.DataTypeArray).
WithItemType(testutils.NewTypeDef(ast.DataTypeString).WithLocation(&yaml.Node{Line: 11, Column: 9}).WithValidations(&ast.Validations{}).Build()).
WithLocation(&yaml.Node{Line: 9, Column: 7}).
WithValidations(&ast.Validations{}).
Build()).
Build(),
},
{
name: "ArrayWithMinMaxItems",
schemasYAML: `TestSchema:
Expand Down Expand Up @@ -165,6 +265,33 @@ func TestHandleArray(t *testing.T) {
Build()).
Build(),
},
{
name: "ArrayWithConstNullableItems",
schemasYAML: `TestSchema:
type: array
items:
type: string
nullable: true
const:
- read`,
schemaName: "TestSchema",
mockFeatures: func() *testutils.MockFeaturesConfig {
config := testutils.NewMockFeaturesConfig()
config.SupportedFeatures = map[features.Feature]bool{
features.FeatureConstArrays: true,
features.FeatureConstsAndDefaults: true,
}
return config
},
expected: testutils.NewFieldDef("strings",
testutils.NewTypeDef(ast.DataTypeArray).
WithItemType(testutils.NewTypeDef(ast.DataTypeString).WithLocation(&yaml.Node{Line: 11, Column: 9}).WithValidations(&ast.Validations{}).Build()).
WithContainsNull(true).
WithLocation(&yaml.Node{Line: 9, Column: 7}).
WithValidations(&ast.Validations{}).
Build()).
Build(),
},
{
name: "ArrayWithExample",
schemasYAML: `TestSchema:
Expand Down
96 changes: 96 additions & 0 deletions internal/schemas/handle_object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,102 @@ func TestHandleObject(t *testing.T) {
Build()).
Build(),
},
{
name: "MapWithConst",
schemasYAML: `TestSchema:
type: object
additionalProperties:
type: string
const:
key: value`,
schemaName: "TestSchema",
mockFeatures: func() *testutils.MockFeaturesConfig {
config := testutils.NewMockFeaturesConfig()
config.SupportedFeatures = map[features.Feature]bool{
features.FeatureConstObjects: true,
features.FeatureConstsAndDefaults: true,
}
return config
},
expected: testutils.NewFieldDef("object",
testutils.NewTypeDef(ast.DataTypeMap).
WithLocation(&yaml.Node{Line: 9, Column: 7}).
WithItemType(
testutils.NewTypeDef(ast.DataTypeString).
WithLocation(&yaml.Node{Line: 11, Column: 9}).
WithValidations(&ast.Validations{}).
Build(),
).
Build()).
WithConst(&ast.AnyValue{Value: map[string]interface{}{"key": "value"}}).
Build(),
},
{
name: "MapWithConstFeatureUnsupported",
schemasYAML: `TestSchema:
type: object
additionalProperties:
type: string
const: {}`,
schemaName: "TestSchema",
mockFeatures: func() *testutils.MockFeaturesConfig {
config := testutils.NewMockFeaturesConfig()
config.SupportedFeatures = map[features.Feature]bool{
features.FeatureConstsAndDefaults: true,
}
return config
},
expected: testutils.NewFieldDef("object",
testutils.NewTypeDef(ast.DataTypeMap).
WithLocation(&yaml.Node{Line: 9, Column: 7}).
WithItemType(
testutils.NewTypeDef(ast.DataTypeString).
WithLocation(&yaml.Node{Line: 11, Column: 9}).
WithValidations(&ast.Validations{}).
Build(),
).
Build()).
Build(),
},
{
name: "ObjectWithUnsupportedConst",
schemasYAML: `TestSchema:
type: object
properties:
name:
type: string
const:
name: "fixed"`,
schemaName: "TestSchema",
mockFeatures: func() *testutils.MockFeaturesConfig {
config := testutils.NewMockFeaturesConfig()
config.SupportedFeatures = map[features.Feature]bool{
features.FeatureConstObjects: true,
features.FeatureConstsAndDefaults: true,
}
return config
},
expected: testutils.NewFieldDef("object",
testutils.NewTypeDef(ast.DataTypeClass).
WithLocation(&yaml.Node{Line: 9, Column: 7}).
WithScope(ast.ScopeShared).
WithRegistered().
WithOriginalNameFrozen().
WithContextStack(ast.ContextStack{}).
WithFields(
testutils.NewFieldDef("name",
testutils.NewTypeDef(ast.DataTypeString).
WithLocation(&yaml.Node{Line: 12, Column: 11}).
WithValidations(&ast.Validations{}).
Build()).
WithOriginalName("name").
WithJSONAnnotation("name").
WithOptional(true).
Build(),
).
Build()).
Build(),
},
{
name: "ObjectWithExample",
schemasYAML: `TestSchema:
Expand Down
Loading
Loading