From 48234ba365013a0fbe7249e672aa1469fdf00e2d Mon Sep 17 00:00:00 2001 From: Ash Godfrey Date: Thu, 22 Oct 2026 10:52:39 +0100 Subject: [PATCH 01/22] feat(terraform): honor const values on array and map properties Array and map properties that declare a const value were parsed as ordinary fields: the schema parser only attached const/default metadata to containers when a default was present. Terraform therefore exposed them as configurable attributes and sent whatever was in state instead of the const value. - Parser: attach const metadata to arrays, sets and maps behind the new constArrays and constObjects features, and drop consts whose elements are not scalars with a validation warning. - Go models: emit a const struct tag carrying the JSON encoding for container fields, render Go literals for their getters, and compare received const values structurally when unmarshaling. - Terraform: declare the new features; the existing const handling already hides the fields from the resource schema and skips them when building requests, so the SDK model injects the value. Regenerates the review Go, CLI and Terraform fixtures and adds a ConstContainer entity with an acceptance test asserting the request body. --- .changesets/1792662097-11a83540.yaml | 10 + .changesets/1792662097-2435dcc7.yaml | 10 + .changesets/1792662097-4b2c17a5.yaml | 10 + internal/features/features.go | 6 + internal/features/features_generated.go | 14 + internal/schemas/handle_array_test.go | 100 +++++ internal/schemas/handle_object_test.go | 96 +++++ internal/schemas/schemas.go | 103 ++++- .../templates/common/common/features.d.ts | 2 + templates/templates/common/go/annotations.ts | 15 +- templates/templates/common/go/sanitization.ts | 33 ++ .../{{getUtilsLocation}}/json.go.stmpl | 13 +- templates/templates/terraform/features.ts | 2 + tests/specs/review-terraform.yaml | 122 ++++++ zSDKs/sdk-cli/.speakeasy/gen.lock | 2 +- .../internal/sdk/sdkinternal/utils/json.go | 13 +- zSDKs/sdk-go/.speakeasy/gen.lock | 2 +- zSDKs/sdk-go/internal/utils/json.go | 13 +- .../.speakeasy/gen.lock | 56 ++- .../.speakeasy/logs/naming.log | 18 + zSDKs/terraform-provider-testing/README.md | 2 + .../docs/data-sources/const_container.md | 27 ++ .../docs/resources/const_container.md | 49 +++ .../testing_const_container/data-source.tf | 3 + .../import-by-string-id.tf | 4 + .../testing_const_container/import.sh | 1 + .../testing_const_container/resource.tf | 3 + .../provider/constcontainer_data_source.go | 128 ++++++ .../constcontainer_data_source_sdk.go | 35 ++ .../provider/constcontainer_resource.go | 268 ++++++++++++ .../provider/constcontainer_resource_sdk.go | 61 +++ .../internal/provider/provider.go | 2 + .../internal/sdk/internal/utils/json.go | 13 +- .../models/operations/createconstcontainer.go | 47 +++ .../models/operations/deleteconstcontainer.go | 48 +++ .../models/operations/getconstcontainer.go | 58 +++ .../models/shared/constcontainerrequest.go | 84 ++++ .../models/shared/constcontainerresponse.go | 92 +++++ .../internal/sdk/sdk.go | 381 ++++++++++++++++++ 39 files changed, 1926 insertions(+), 20 deletions(-) create mode 100644 .changesets/1792662097-11a83540.yaml create mode 100644 .changesets/1792662097-2435dcc7.yaml create mode 100644 .changesets/1792662097-4b2c17a5.yaml create mode 100644 zSDKs/terraform-provider-testing/docs/data-sources/const_container.md create mode 100644 zSDKs/terraform-provider-testing/docs/resources/const_container.md create mode 100644 zSDKs/terraform-provider-testing/examples/data-sources/testing_const_container/data-source.tf create mode 100644 zSDKs/terraform-provider-testing/examples/resources/testing_const_container/import-by-string-id.tf create mode 100644 zSDKs/terraform-provider-testing/examples/resources/testing_const_container/import.sh create mode 100644 zSDKs/terraform-provider-testing/examples/resources/testing_const_container/resource.tf create mode 100644 zSDKs/terraform-provider-testing/internal/provider/constcontainer_data_source.go create mode 100644 zSDKs/terraform-provider-testing/internal/provider/constcontainer_data_source_sdk.go create mode 100644 zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource.go create mode 100644 zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource_sdk.go create mode 100644 zSDKs/terraform-provider-testing/internal/sdk/models/operations/createconstcontainer.go create mode 100644 zSDKs/terraform-provider-testing/internal/sdk/models/operations/deleteconstcontainer.go create mode 100644 zSDKs/terraform-provider-testing/internal/sdk/models/operations/getconstcontainer.go create mode 100644 zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerrequest.go create mode 100644 zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerresponse.go diff --git a/.changesets/1792662097-11a83540.yaml b/.changesets/1792662097-11a83540.yaml new file mode 100644 index 000000000..71464cfb3 --- /dev/null +++ b/.changesets/1792662097-11a83540.yaml @@ -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" diff --git a/.changesets/1792662097-2435dcc7.yaml b/.changesets/1792662097-2435dcc7.yaml new file mode 100644 index 000000000..ef6e758ff --- /dev/null +++ b/.changesets/1792662097-2435dcc7.yaml @@ -0,0 +1,10 @@ +id: 1792662097-2435dcc7 +features: + - constsAndDefaults +targets: + - go +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" diff --git a/.changesets/1792662097-4b2c17a5.yaml b/.changesets/1792662097-4b2c17a5.yaml new file mode 100644 index 000000000..af2bcc2df --- /dev/null +++ b/.changesets/1792662097-4b2c17a5.yaml @@ -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" diff --git a/internal/features/features.go b/internal/features/features.go index ff07148e8..1bc3574f0 100644 --- a/internal/features/features.go +++ b/internal/features/features.go @@ -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 diff --git a/internal/features/features_generated.go b/internal/features/features_generated.go index a3bb2c2ec..1c7661d2e 100644 --- a/internal/features/features_generated.go +++ b/internal/features/features_generated.go @@ -20,6 +20,10 @@ func (f Feature) String() string { return "callbacks" case FeatureConfigurableModuleName: return "configurableModuleName" + case FeatureConstArrays: + return "constArrays" + case FeatureConstObjects: + return "constObjects" case FeatureConstsAndDefaults: return "constsAndDefaults" case FeatureContentMediaTypeApplicationJSON: @@ -198,6 +202,10 @@ func FeatureFromString(s string) Feature { return FeatureCallbacks case "configurableModuleName": return FeatureConfigurableModuleName + case "constArrays": + return FeatureConstArrays + case "constObjects": + return FeatureConstObjects case "constsAndDefaults": return FeatureConstsAndDefaults case "contentMediaTypeApplicationJSON": @@ -367,6 +375,8 @@ var featureList = []Feature{ FeatureCLICommands, FeatureCallbacks, FeatureConfigurableModuleName, + FeatureConstArrays, + FeatureConstObjects, FeatureConstsAndDefaults, FeatureContentMediaTypeApplicationJSON, FeatureCore, @@ -456,6 +466,8 @@ var featureTiers = map[Feature]string{ FeatureCLICommands: TierExperimental, FeatureCallbacks: TierCore, FeatureConfigurableModuleName: TierExperimental, + FeatureConstArrays: TierExperimental, + FeatureConstObjects: TierExperimental, FeatureConstsAndDefaults: TierBeta, FeatureContentMediaTypeApplicationJSON: TierExperimental, FeatureCore: TierCore, @@ -571,6 +583,8 @@ var tierCoreFeatures = []Feature{ var tierExperimentalFeatures = []Feature{ FeatureCLICommands, FeatureConfigurableModuleName, + FeatureConstArrays, + FeatureConstObjects, FeatureContentMediaTypeApplicationJSON, FeatureCustomCodeRegions, FeatureCustomSecuritySchemes, diff --git a/internal/schemas/handle_array_test.go b/internal/schemas/handle_array_test.go index 5f8943a9a..001150af7 100644 --- a/internal/schemas/handle_array_test.go +++ b/internal/schemas/handle_array_test.go @@ -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", + 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: diff --git a/internal/schemas/handle_object_test.go b/internal/schemas/handle_object_test.go index bce54b65d..7e5906855 100644 --- a/internal/schemas/handle_object_test.go +++ b/internal/schemas/handle_object_test.go @@ -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: diff --git a/internal/schemas/schemas.go b/internal/schemas/schemas.go index 26cec94b9..b735eaa14 100644 --- a/internal/schemas/schemas.go +++ b/internal/schemas/schemas.go @@ -562,8 +562,9 @@ func (s *Schemas) handleArray(ctx context.Context, params Params, nullable bool) Optional: nullable, Nullable: nullable, } - if s.Subsystem.Features.IsFeatureSupported(ctx, features.FeatureDefaultArrays) && schema.Default != nil { + if s.containerMetaDataApplies(ctx, schema, features.FeatureDefaultArrays, features.FeatureConstArrays) { fieldDef = s.handleFieldDefMetaData(ctx, fieldDef, nullable, schema) + s.recordContainerConstUsage(ctx, fieldDef, features.FeatureConstArrays) } // We need to inherit the multipart annotations @@ -818,12 +819,18 @@ func (s *Schemas) handleObject(ctx context.Context, params Params, nullable bool typeDef.Extensions = extensions - return &ast.FieldDef{ + mapField := &ast.FieldDef{ Name: fieldName, Type: ast.NewType(typeDef, nil), Optional: nullable, Nullable: nullable, - }, nil + } + if schema.Const != nil && s.Subsystem.Features.IsFeatureSupported(ctx, features.FeatureConstObjects) { + mapField = s.handleFieldDefMetaData(ctx, mapField, nullable, schema) + s.recordContainerConstUsage(ctx, mapField, features.FeatureConstObjects) + } + + return mapField, nil } case recurseAdditionalProperties: additionalPropertiesParams := params @@ -891,12 +898,18 @@ func (s *Schemas) handleObject(ctx context.Context, params Params, nullable bool typeDef.Extensions = extensions - return &ast.FieldDef{ + mapField := &ast.FieldDef{ Name: fieldName, Type: ast.NewType(typeDef, nil), Optional: nullable, Nullable: nullable, - }, nil + } + if schema.Const != nil && s.Subsystem.Features.IsFeatureSupported(ctx, features.FeatureConstObjects) { + mapField = s.handleFieldDefMetaData(ctx, mapField, nullable, schema) + s.recordContainerConstUsage(ctx, mapField, features.FeatureConstObjects) + } + + return mapField, nil } } } @@ -1298,8 +1311,9 @@ func (s *Schemas) handleObject(ctx context.Context, params Params, nullable bool Nullable: nullable, } - if s.Subsystem.Features.IsFeatureSupported(ctx, features.FeatureDefaultObjects) && schema.Default != nil { + if s.containerMetaDataApplies(ctx, schema, features.FeatureDefaultObjects, features.FeatureConstObjects) { fieldDef = s.handleFieldDefMetaData(ctx, fieldDef, nullable, schema) + s.recordContainerConstUsage(ctx, fieldDef, features.FeatureConstObjects) } s.setCachedType(fieldType, ¶ms) @@ -1660,6 +1674,17 @@ func (s *Schemas) checkDefaultConformsToType(ctx context.Context, field *ast.Fie continue } + if pair.label == "const" && (field.Type.IsContainer() || field.Type.Type == ast.DataTypeClass) { + if !constContainerValueSupported(v.Value, field.Type) { + logging.LogWarning(ctx, "validation warning", errors.NewValidationWarning( + fmt.Sprintf("const value %v is not supported for type %q, only arrays and maps of scalar values are supported, omitting const", v.Value, dataType), + schema.GetPropertyNode("Const"), nil, + )) + *pair.val = nil + } + continue + } + if !defaultValueMatchesType(v.Value, dataType) { // Before clearing, try to coerce string values to the target type. // Many real-world specs have string defaults on numeric fields (e.g. default: "0.00"). @@ -1681,6 +1706,56 @@ func (s *Schemas) checkDefaultConformsToType(ctx context.Context, field *ast.Fie } } +func constContainerValueSupported(val any, typ *ast.TypeDef) bool { + switch typ.Type { + case ast.DataTypeArray, ast.DataTypeSet: + items, ok := val.([]any) + if !ok { + return false + } + for _, item := range items { + if !constScalarMatchesType(item, typ.ItemType) { + return false + } + } + return true + case ast.DataTypeMap: + entries, ok := val.(map[string]any) + if !ok { + return false + } + for _, item := range entries { + if !constScalarMatchesType(item, typ.ItemType) { + return false + } + } + return true + default: + return false + } +} + +func constScalarMatchesType(val any, itemType *ast.TypeDef) bool { + if val == nil || itemType == nil { + return false + } + + switch itemType.Type { + case ast.DataTypeEnum: + return itemType.Enum != nil && slices.Contains(itemType.Enum.Values, fmt.Sprint(val)) + case ast.DataTypeBoolean, ast.DataTypeInteger, ast.DataTypeInt32, ast.DataTypeBigInt, + ast.DataTypeNumber, ast.DataTypeFloat32, ast.DataTypeDecimal, + ast.DataTypeString, ast.DataTypeDate, ast.DataTypeDateTime: + dataType := itemType.Type + if itemType.Format == "string" { + dataType = ast.DataTypeString + } + return defaultValueMatchesType(val, dataType) + default: + return false + } +} + // defaultValueMatchesType checks whether a decoded default/const value is compatible // with the given AST data type. func defaultValueMatchesType(val any, dataType ast.DataType) bool { @@ -2752,6 +2827,22 @@ func (s *Schemas) handleFieldDefMetaData(ctx context.Context, fieldDef *ast.Fiel return fieldDef } +func (s *Schemas) containerMetaDataApplies(ctx context.Context, schema *oas3.Schema, defaultFeature, constFeature features.Feature) bool { + if schema.Default != nil && s.Subsystem.Features.IsFeatureSupported(ctx, defaultFeature) { + return true + } + + return schema.Const != nil && s.Subsystem.Features.IsFeatureSupported(ctx, constFeature) +} + +func (s *Schemas) recordContainerConstUsage(ctx context.Context, fieldDef *ast.FieldDef, constFeature features.Feature) { + if fieldDef.Const == nil { + return + } + + s.Subsystem.Features.RecordFeatureUsage(ctx, constFeature) +} + func (s *Schemas) sanitizeDefaultConstValue(ctx context.Context, value values.Value) *ast.AnyValue { if value == nil { return nil diff --git a/templates/templates/common/common/features.d.ts b/templates/templates/common/common/features.d.ts index faa544746..773e3374e 100644 --- a/templates/templates/common/common/features.d.ts +++ b/templates/templates/common/common/features.d.ts @@ -15,6 +15,8 @@ declare global { | "cliCommands" | "callbacks" | "configurableModuleName" + | "constArrays" + | "constObjects" | "constsAndDefaults" | "contentMediaTypeApplicationJSON" | "core" diff --git a/templates/templates/common/go/annotations.ts b/templates/templates/common/go/annotations.ts index 91d4b6efb..77292fc16 100644 --- a/templates/templates/common/go/annotations.ts +++ b/templates/templates/common/go/annotations.ts @@ -295,10 +295,6 @@ function templateFormAnnotation( function templateConstsAndDefaultsAnnotation( fieldDef: FieldDef, ): TemplatedAnnotation | null { - if (fieldDef.Type.IsContainer()) { - return null; - } - function sanitizeValue(value: any): string { if (value === null) { return "null"; @@ -311,6 +307,17 @@ function templateConstsAndDefaultsAnnotation( return value; } + if (fieldDef.Type.IsContainer()) { + if (fieldDef.Const) { + return { + Tag: "const", + Value: sanitizeValue(JSON.stringify(fieldDef.Const.Value)), + }; + } + + return null; + } + if (fieldDef.Const) { return { Tag: "const", diff --git a/templates/templates/common/go/sanitization.ts b/templates/templates/common/go/sanitization.ts index 0fa062913..9f4d2e0c0 100644 --- a/templates/templates/common/go/sanitization.ts +++ b/templates/templates/common/go/sanitization.ts @@ -736,6 +736,10 @@ function templateConstValue( useTypesPackage: true, skipPointerWrapping, }); + case "array": + case "set": + case "map": + return templateConstContainerValue(fieldDef, usageLocation); case "bytes": default: throw new Error( @@ -746,6 +750,35 @@ function templateConstValue( registerTemplateFunc("templateConstValue", templateConstValue); +function templateConstContainerValue( + fieldDef: FieldDef, + usageLocation: string, +): string { + const containerType = sanitizeType(fieldDef.Type, false, usageLocation); + const renderItem = (value: any): string => + templateConstValue( + { + ...fieldDef, + Type: fieldDef.Type.ItemType, + Optional: false, + Nullable: false, + Const: { Value: value }, + } as FieldDef, + usageLocation, + true, + ); + + if (fieldDef.Type.Type.toString() === "map") { + const entries = Object.entries(fieldDef.Const.Value ?? {}).map( + ([key, value]) => `${JSON.stringify(key)}: ${renderItem(value)}`, + ); + return `${containerType}{${entries.join(", ")}}`; + } + + const items = ((fieldDef.Const.Value ?? []) as any[]).map(renderItem); + return `${containerType}{${items.join(", ")}}`; +} + // @ts-ignore function templateArrayValue(value: any): string { return value; diff --git a/templates/templates/go/auxiliary/{{getUtilsLocation}}/json.go.stmpl b/templates/templates/go/auxiliary/{{getUtilsLocation}}/json.go.stmpl index ffb6afffd..7c319ca06 100644 --- a/templates/templates/go/auxiliary/{{getUtilsLocation}}/json.go.stmpl +++ b/templates/templates/go/auxiliary/{{getUtilsLocation}}/json.go.stmpl @@ -215,7 +215,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue { + if val != constValue && !constJSONValuesEqual(r, constValue) { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -447,6 +447,17 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } +func constJSONValuesEqual(received json.RawMessage, constValue string) bool { + var got, want interface{} + if err := json.Unmarshal(received, &got); err != nil { + return false + } + if err := json.Unmarshal([]byte(constValue), &want); err != nil { + return false + } + return reflect.DeepEqual(got, want) +} + func handleDefaultConstValue(tagValue string, val interface{}, tag reflect.StructTag) json.RawMessage { if tagValue == "null" { return []byte("null") diff --git a/templates/templates/terraform/features.ts b/templates/templates/terraform/features.ts index ed42926a7..b249b429b 100644 --- a/templates/templates/terraform/features.ts +++ b/templates/templates/terraform/features.ts @@ -26,6 +26,8 @@ const supportedFeatures = { constsAndDefaults: "0.3.2", defaultArrays: "0.2.0", defaultObjects: "0.1.2", + constArrays: "0.1.0", + constObjects: "0.1.0", additionalProperties: "0.1.5", disallowCircularRefs: "0.0.0", oauth2ClientCredentials: "0.3.5", diff --git a/tests/specs/review-terraform.yaml b/tests/specs/review-terraform.yaml index 4c85fff0c..4651ffcb2 100644 --- a/tests/specs/review-terraform.yaml +++ b/tests/specs/review-terraform.yaml @@ -5697,6 +5697,54 @@ paths: responses: '200': description: OK + /v0/constcontainers: + post: + x-speakeasy-entity-operation: ConstContainer#create + description: | + Create a resource whose request schema declares const values on array + and map properties. Terraform must hide those properties from the + resource schema and send the const values in the request body. + operationId: create-const-container + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/ConstContainerRequest' + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/ConstContainerResponse' + /v0/constcontainer/{id}: + parameters: + - name: id + in: path + required: true + schema: + type: string + get: + x-speakeasy-entity-operation: ConstContainer#read + description: Get a const container resource + operationId: get-const-container + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/ConstContainerResponse' + '404': + description: Not Found + delete: + x-speakeasy-entity-operation: ConstContainer#delete + description: Delete a const container resource + operationId: delete-const-container + responses: + '200': + description: OK components: parameters: GlobalBoolean: @@ -5917,6 +5965,80 @@ components: type: string default: DEFAULT schemas: + ConstContainerRequest: + type: object + additionalProperties: false + x-speakeasy-entity: ConstContainer + properties: + name: + type: string + empty_list: + type: array + items: + type: string + const: [] + fixed_list: + type: array + items: + type: string + enum: + - read + - write + - admin + const: + - read + - write + empty_map: + type: object + additionalProperties: + type: string + const: {} + fixed_map: + type: object + additionalProperties: + type: integer + const: + max: 10 + required: + - name + - empty_list + - empty_map + ConstContainerResponse: + type: object + additionalProperties: false + x-speakeasy-entity: ConstContainer + properties: + id: + type: string + name: + type: string + empty_list: + type: array + items: + type: string + const: [] + fixed_list: + type: array + items: + type: string + enum: + - read + - write + - admin + const: + - read + - write + empty_map: + type: object + additionalProperties: + type: string + const: {} + fixed_map: + type: object + additionalProperties: + type: integer + const: + max: 10 DiscriminatedUnionCreateRequest: x-speakeasy-entity: DiscriminatedUnion type: object diff --git a/zSDKs/sdk-cli/.speakeasy/gen.lock b/zSDKs/sdk-cli/.speakeasy/gen.lock index f9b725c8f..dbcc53eb4 100644 --- a/zSDKs/sdk-cli/.speakeasy/gen.lock +++ b/zSDKs/sdk-cli/.speakeasy/gen.lock @@ -598,7 +598,7 @@ trackedFiles: internal/sdk/sdkinternal/utils/headers.go: last_write_checksum: sha1:1b0bd68e1ea0bce8c5a42b5de9fd020fede7aecc internal/sdk/sdkinternal/utils/json.go: - last_write_checksum: sha1:cbddebcd3cd06c607a5c462eab1d490f62bcdc1a + last_write_checksum: sha1:156c99b390e19b755a3acda6f2f57dcdefcb6206 internal/sdk/sdkinternal/utils/oauth2_credentials.go: last_write_checksum: sha1:f9218b6b3dbd11494cc353bf22eb37f0ca654a7d internal/sdk/sdkinternal/utils/oauth2_sessions.go: diff --git a/zSDKs/sdk-cli/internal/sdk/sdkinternal/utils/json.go b/zSDKs/sdk-cli/internal/sdk/sdkinternal/utils/json.go index bf44ff6e5..c8f90dd87 100644 --- a/zSDKs/sdk-cli/internal/sdk/sdkinternal/utils/json.go +++ b/zSDKs/sdk-cli/internal/sdk/sdkinternal/utils/json.go @@ -216,7 +216,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue { + if val != constValue && !constJSONValuesEqual(r, constValue) { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -446,6 +446,17 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } +func constJSONValuesEqual(received json.RawMessage, constValue string) bool { + var got, want interface{} + if err := json.Unmarshal(received, &got); err != nil { + return false + } + if err := json.Unmarshal([]byte(constValue), &want); err != nil { + return false + } + return reflect.DeepEqual(got, want) +} + func handleDefaultConstValue(tagValue string, val interface{}, tag reflect.StructTag) json.RawMessage { if tagValue == "null" { return []byte("null") diff --git a/zSDKs/sdk-go/.speakeasy/gen.lock b/zSDKs/sdk-go/.speakeasy/gen.lock index 5032e8a95..7498b2596 100644 --- a/zSDKs/sdk-go/.speakeasy/gen.lock +++ b/zSDKs/sdk-go/.speakeasy/gen.lock @@ -713,7 +713,7 @@ trackedFiles: internal/utils/headers.go: last_write_checksum: sha1:e529ca3d7ab96a091021bcd471ba2cbef50286b3 internal/utils/json.go: - last_write_checksum: sha1:785278d21e06d3c0b820630fc9d5ca38d364f9ee + last_write_checksum: sha1:3ed843422cdd78c41282fe4ab6f22bef8b389c40 internal/utils/pathparams.go: last_write_checksum: sha1:440aadb18d886ea0a79af0772eb65cdddc9eee60 internal/utils/queryparams.go: diff --git a/zSDKs/sdk-go/internal/utils/json.go b/zSDKs/sdk-go/internal/utils/json.go index 5e6fb780d..8106a80db 100644 --- a/zSDKs/sdk-go/internal/utils/json.go +++ b/zSDKs/sdk-go/internal/utils/json.go @@ -216,7 +216,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue { + if val != constValue && !constJSONValuesEqual(r, constValue) { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -446,6 +446,17 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } +func constJSONValuesEqual(received json.RawMessage, constValue string) bool { + var got, want interface{} + if err := json.Unmarshal(received, &got); err != nil { + return false + } + if err := json.Unmarshal([]byte(constValue), &want); err != nil { + return false + } + return reflect.DeepEqual(got, want) +} + func handleDefaultConstValue(tagValue string, val interface{}, tag reflect.StructTag) json.RawMessage { if tagValue == "null" { return []byte("null") diff --git a/zSDKs/terraform-provider-testing/.speakeasy/gen.lock b/zSDKs/terraform-provider-testing/.speakeasy/gen.lock index 8fffcb37d..a9345b240 100644 --- a/zSDKs/terraform-provider-testing/.speakeasy/gen.lock +++ b/zSDKs/terraform-provider-testing/.speakeasy/gen.lock @@ -1,7 +1,7 @@ lockVersion: 2.0.0 id: review-sdk-test-id management: - docChecksum: fccaa1943b7d99936e3cf386d6aef8ac + docChecksum: b5e0ebee357a2bc4151a20fb322e722c docVersion: 0.0.1 speakeasyVersion: internal generationVersion: internal @@ -11,6 +11,8 @@ features: terraform: additionalDependencies: 0.1.0 additionalProperties: 0.1.5 + constArrays: 0.1.0 + constObjects: 0.1.0 constsAndDefaults: 0.3.2 contentMediaTypeApplicationJSON: 0.1.1 core: 3.50.2 @@ -51,6 +53,8 @@ trackedFiles: last_write_checksum: sha1:d84cd84fe166ec2d063ebb13a1845e744425693c examples/data-sources/testing_basic/data-source.tf: last_write_checksum: sha1:02bc159abd38449bcddcff2ed9eb7daf0b5cf5b4 + examples/data-sources/testing_const_container/data-source.tf: + last_write_checksum: sha1:a45dc527c9b2b2404f3ce3797f8a0c3009de47dd examples/data-sources/testing_discriminated_union/data-source.tf: last_write_checksum: sha1:a21b63c90ce67e7b78e103fb57e8b55ba8ab4073 examples/data-sources/testing_framework_type/data-source.tf: @@ -275,6 +279,12 @@ trackedFiles: last_write_checksum: sha1:056e42f5b27cbc4a7e5b4a14c154ad4084026594 examples/resources/testing_basic/resource.tf: last_write_checksum: sha1:60780e18fdeae0f7305502bd819092015c9e36b5 + examples/resources/testing_const_container/import-by-string-id.tf: + last_write_checksum: sha1:094ecf7d894ef2ef5a9a4669ec05ef7c75bdceaa + examples/resources/testing_const_container/import.sh: + last_write_checksum: sha1:dc82e240078029b62b56bb695067d4c5e9cb4264 + examples/resources/testing_const_container/resource.tf: + last_write_checksum: sha1:73c7ef301934066294a6aa619b7a7e4268581b95 examples/resources/testing_discriminated_union/import-by-string-id.tf: last_write_checksum: sha1:61473f31485ac280bfa6943e7580d1bdd1e43413 examples/resources/testing_discriminated_union/import.sh: @@ -763,6 +773,14 @@ trackedFiles: last_write_checksum: sha1:550b1c9370c6f1e389f6145f4ab522df9c855e76 internal/provider/basic_resource_sdk.go: last_write_checksum: sha1:c7327b7ec6b530ccb4ba940c83953e7b58b092a4 + internal/provider/constcontainer_data_source.go: + last_write_checksum: sha1:3af6b6a8ec4bc9b019d8c83c297577266be2cb05 + internal/provider/constcontainer_data_source_sdk.go: + last_write_checksum: sha1:a3d2f26a22da0b68da7f73523f16dec043d43c59 + internal/provider/constcontainer_resource.go: + last_write_checksum: sha1:1c82779f3e4d07d9145f3c49abc8ecbf21b390af + internal/provider/constcontainer_resource_sdk.go: + last_write_checksum: sha1:e8e60887a5d623a9cdaef5a5d0f38884b3cc56a5 internal/provider/discriminatedunion_data_source.go: last_write_checksum: sha1:dd97963488cb1994321bf5e3f813917c80a7d7b5 internal/provider/discriminatedunion_data_source_sdk.go: @@ -1066,7 +1084,7 @@ trackedFiles: internal/provider/patch_resource_sdk.go: last_write_checksum: sha1:9b583e2ac47191350373ce5a86408c118bd606b1 internal/provider/provider.go: - last_write_checksum: sha1:a333255d3d9585c5700d3059b03e9b0dbf388774 + last_write_checksum: sha1:8b1723df0915047021b8fd1b267f93dc19808e67 internal/provider/reflect/diags.go: last_write_checksum: sha1:ace8bc53054bb1d8ee8689acf3e4323de75a6297 internal/provider/reflect/doc.go: @@ -2404,7 +2422,7 @@ trackedFiles: internal/sdk/internal/utils/jq.go: last_write_checksum: sha1:2e75ed7a7db1f91e97dac1ac4ca7801b2beb69b5 internal/sdk/internal/utils/json.go: - last_write_checksum: sha1:bc34328ed29902c9f3bbeb04b5706a684e9bccc1 + last_write_checksum: sha1:e4afb6c5125227acd6366acac653831f4d01cd0c internal/sdk/internal/utils/oauth2_credentials.go: last_write_checksum: sha1:f9218b6b3dbd11494cc353bf22eb37f0ca654a7d internal/sdk/internal/utils/oauth2_sessions.go: @@ -2439,6 +2457,8 @@ trackedFiles: last_write_checksum: sha1:5b080b285280d5f8a012138b77c848c3118bddb0 internal/sdk/models/operations/createbasic.go: last_write_checksum: sha1:0fdbac8d615b203c4f6054f9f44176e1c4ce564a + internal/sdk/models/operations/createconstcontainer.go: + last_write_checksum: sha1:892a2934f9b5cc0d5e40335502d20c3750702b95 internal/sdk/models/operations/creatediscriminatedunion.go: last_write_checksum: sha1:68d916f8c709a15e2a564066dbc9317502aecf13 internal/sdk/models/operations/creatediscriminatedunionarray.go: @@ -2587,6 +2607,8 @@ trackedFiles: last_write_checksum: sha1:5b31482c4b581bc143b0403060004849179d8ffd internal/sdk/models/operations/deletebasic.go: last_write_checksum: sha1:2d991f9ce3b49547f88d3ed69a9a4e01ccc135a8 + internal/sdk/models/operations/deleteconstcontainer.go: + last_write_checksum: sha1:443d6380ef9a4f9405c655078371ab2c13e633fa internal/sdk/models/operations/deletecustomplanmodifiers.go: last_write_checksum: sha1:8bcb2a4f56d57265de023e41d21617f5b88a7bc6 internal/sdk/models/operations/deletediscriminatedunion.go: @@ -2727,6 +2749,8 @@ trackedFiles: last_write_checksum: sha1:3bcc0082028b5f01a4d13f84072629b010550da0 internal/sdk/models/operations/getbasic.go: last_write_checksum: sha1:73ada8ac1a2cec3987eb5b93f78f815934067b9d + internal/sdk/models/operations/getconstcontainer.go: + last_write_checksum: sha1:c4ac02b538bdf08901d302a4d4c07a6a18cb2536 internal/sdk/models/operations/getcustomplanmodifiers.go: last_write_checksum: sha1:c6f5938cb6330969450186336a3085558bcd6d1c internal/sdk/models/operations/getdiscriminatedunion.go: @@ -3073,6 +3097,10 @@ trackedFiles: last_write_checksum: sha1:34cb7c7fc9ab32b03e7c6a0875e7e6fec5805577 internal/sdk/models/shared/basicsearch.go: last_write_checksum: sha1:ebc8943a31148f7623c5f8ff940dd81c1b52f23d + internal/sdk/models/shared/constcontainerrequest.go: + last_write_checksum: sha1:3cdb41c7b838e1c15dd0483ce7f685fdc6e7d480 + internal/sdk/models/shared/constcontainerresponse.go: + last_write_checksum: sha1:d94a9a07729db01d47dd0ff890a363406d2169e5 internal/sdk/models/shared/discriminatedobject.go: last_write_checksum: sha1:9bb5641a1bcb27ec59c1f16d82d8a251ec733286 internal/sdk/models/shared/discriminatedunionarraycreaterequest.go: @@ -3578,7 +3606,7 @@ trackedFiles: internal/sdk/retry/config.go: last_write_checksum: sha1:102d1953fbd7e9f312c4442c71ccca2eaaeaa27d internal/sdk/sdk.go: - last_write_checksum: sha1:a2997f8af41cead3493768284c9cc8c950f8f57c + last_write_checksum: sha1:f390c541016ad47b4744f87a396fc36e8590d9f4 internal/sdk/types/bigint.go: last_write_checksum: sha1:49b004005d0461fb04b846eca062b070b0360b31 internal/sdk/types/date.go: @@ -6020,4 +6048,24 @@ examples: responses: "200": application/json: {} + create-const-container: + speakeasy-default-create-const-container: + requestBody: + application/json: {"name": "", "empty_list": [], "fixed_list": ["read", "write"], "empty_map": {}, "fixed_map": {"max": 10}} + responses: + "200": + application/json: {"empty_list": [], "fixed_list": ["read", "write"], "empty_map": {}, "fixed_map": {"max": 10}} + get-const-container: + speakeasy-default-get-const-container: + parameters: + path: + id: "" + responses: + "200": + application/json: {"empty_list": [], "fixed_list": ["read", "write"], "empty_map": {}, "fixed_map": {"max": 10}} + delete-const-container: + speakeasy-default-delete-const-container: + parameters: + path: + id: "" examplesVersion: 1.0.2 diff --git a/zSDKs/terraform-provider-testing/.speakeasy/logs/naming.log b/zSDKs/terraform-provider-testing/.speakeasy/logs/naming.log index 9f3e6a51d..73705617c 100644 --- a/zSDKs/terraform-provider-testing/.speakeasy/logs/naming.log +++ b/zSDKs/terraform-provider-testing/.speakeasy/logs/naming.log @@ -2238,6 +2238,15 @@ DEBUG discriminated: Renamed to "XUnknownValuesResponse_closed_enum_string" registrationID: "scope:shared refType:Schemas refName:XUnknownValuesResponse originalName:closed_enum_string" DEBUG +--- Renaming 2 types with name "fixed_list" --- +DEBUG discriminated: Renamed to "ConstContainerRequest_fixed_list" + labels: "original_name:fixed_list scope:shared data_type:enum refName:ConstContainerRequest" + registrationID: "scope:shared refType:Schemas refName:ConstContainerRequest originalName:fixed_list" +DEBUG discriminated: Renamed to "ConstContainerResponse_fixed_list" + labels: "original_name:fixed_list scope:shared data_type:enum refName:ConstContainerResponse" + registrationID: "scope:shared refType:Schemas refName:ConstContainerResponse originalName:fixed_list" +DEBUG + --- Renaming 3 types with name "tier" --- DEBUG discriminated: Renamed to "create_import_defaulted_id_tier" labels: "original_name:tier operation:create_import_defaulted_id data_type:enum parameter:pathParam" @@ -3813,6 +3822,15 @@ UpdateOasContentMediaTypeRequest (id: string, OASContentMediaTypeRequest: OASCon UpdateOasContentMediaTypeResponse (ContentType: string, StatusCode: int32, RawResponse: response ...) DeleteOasContentMediaTypeRequest (id: string) DeleteOasContentMediaTypeResponse (ContentType: string, StatusCode: int32, RawResponse: response) +ConstContainerRequest (name: string, empty_list: array, fixed_list: array ...) + ConstContainerRequestFixedList (enum: read, write, admin) +CreateConstContainerResponse (ContentType: string, StatusCode: int32, RawResponse: response ...) + ConstContainerResponse (id: string, name: string, empty_list: array ...) + ConstContainerResponseFixedList (enum: read, write, admin) +GetConstContainerRequest (id: string) +GetConstContainerResponse (ContentType: string, StatusCode: int32, RawResponse: response ...) +DeleteConstContainerRequest (id: string) +DeleteConstContainerResponse (ContentType: string, StatusCode: int32, RawResponse: response) Globals (globalBoolean: boolean, globalBooleanWithDefault: boolean, globalEnumFloat32: float32 ...) UpdateXGlobalsGlobals (globalBoolean: boolean, globalBooleanWithDefault: boolean, globalEnumFloat32: float32 ...) diff --git a/zSDKs/terraform-provider-testing/README.md b/zSDKs/terraform-provider-testing/README.md index f26d58fe8..62129d589 100644 --- a/zSDKs/terraform-provider-testing/README.md +++ b/zSDKs/terraform-provider-testing/README.md @@ -102,6 +102,7 @@ Available configuration: * [testing_api_create_and_update](docs/resources/api_create_and_update.md) * [testing_basic](docs/resources/basic.md) +* [testing_const_container](docs/resources/const_container.md) * [testing_discriminated_union](docs/resources/discriminated_union.md) * [testing_discriminated_union_array](docs/resources/discriminated_union_array.md) * [testing_framework_type](docs/resources/framework_type.md) @@ -179,6 +180,7 @@ Available configuration: * [testing_api_create_and_update](docs/data-sources/api_create_and_update.md) * [testing_basic](docs/data-sources/basic.md) +* [testing_const_container](docs/data-sources/const_container.md) * [testing_discriminated_union](docs/data-sources/discriminated_union.md) * [testing_framework_type](docs/data-sources/framework_type.md) * [testing_import_defaulted_id](docs/data-sources/import_defaulted_id.md) diff --git a/zSDKs/terraform-provider-testing/docs/data-sources/const_container.md b/zSDKs/terraform-provider-testing/docs/data-sources/const_container.md new file mode 100644 index 000000000..d32d01fab --- /dev/null +++ b/zSDKs/terraform-provider-testing/docs/data-sources/const_container.md @@ -0,0 +1,27 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "testing_const_container Data Source - terraform-provider-testing" +subcategory: "" +description: |- + ConstContainer DataSource +--- + +# testing_const_container (Data Source) + +ConstContainer DataSource + +## Example Usage + +```terraform +data "testing_const_container" "my_constcontainer" { + id = "...my_id..." +} +``` + + +## Schema + +### Read-Only + +- `id` (String) The ID of this resource. +- `name` (String) diff --git a/zSDKs/terraform-provider-testing/docs/resources/const_container.md b/zSDKs/terraform-provider-testing/docs/resources/const_container.md new file mode 100644 index 000000000..665204c33 --- /dev/null +++ b/zSDKs/terraform-provider-testing/docs/resources/const_container.md @@ -0,0 +1,49 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "testing_const_container Resource - terraform-provider-testing" +subcategory: "" +description: |- + ConstContainer Resource +--- + +# testing_const_container (Resource) + +ConstContainer Resource + +## Example Usage + +```terraform +resource "testing_const_container" "my_constcontainer" { + name = "...my_name..." +} +``` + + +## Schema + +### Required + +- `name` (String) Requires replacement if changed. + +### Read-Only + +- `id` (String) The ID of this resource. + +## Import + +Import is supported using the following syntax: + +In Terraform v1.5.0 and later, the [`import` block](https://developer.hashicorp.com/terraform/language/import) can be used with the `id` attribute, for example: + +```terraform +import { + to = testing_const_container.my_testing_const_container + id = "..." +} +``` + +The [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import) can be used, for example: + +```shell +terraform import testing_const_container.my_testing_const_container "..." +``` diff --git a/zSDKs/terraform-provider-testing/examples/data-sources/testing_const_container/data-source.tf b/zSDKs/terraform-provider-testing/examples/data-sources/testing_const_container/data-source.tf new file mode 100644 index 000000000..96013b05a --- /dev/null +++ b/zSDKs/terraform-provider-testing/examples/data-sources/testing_const_container/data-source.tf @@ -0,0 +1,3 @@ +data "testing_const_container" "my_constcontainer" { + id = "...my_id..." +} \ No newline at end of file diff --git a/zSDKs/terraform-provider-testing/examples/resources/testing_const_container/import-by-string-id.tf b/zSDKs/terraform-provider-testing/examples/resources/testing_const_container/import-by-string-id.tf new file mode 100644 index 000000000..51488fd18 --- /dev/null +++ b/zSDKs/terraform-provider-testing/examples/resources/testing_const_container/import-by-string-id.tf @@ -0,0 +1,4 @@ +import { + to = testing_const_container.my_testing_const_container + id = "..." +} diff --git a/zSDKs/terraform-provider-testing/examples/resources/testing_const_container/import.sh b/zSDKs/terraform-provider-testing/examples/resources/testing_const_container/import.sh new file mode 100644 index 000000000..1b394b9c7 --- /dev/null +++ b/zSDKs/terraform-provider-testing/examples/resources/testing_const_container/import.sh @@ -0,0 +1 @@ +terraform import testing_const_container.my_testing_const_container "..." diff --git a/zSDKs/terraform-provider-testing/examples/resources/testing_const_container/resource.tf b/zSDKs/terraform-provider-testing/examples/resources/testing_const_container/resource.tf new file mode 100644 index 000000000..871e0d3f3 --- /dev/null +++ b/zSDKs/terraform-provider-testing/examples/resources/testing_const_container/resource.tf @@ -0,0 +1,3 @@ +resource "testing_const_container" "my_constcontainer" { + name = "...my_name..." +} \ No newline at end of file diff --git a/zSDKs/terraform-provider-testing/internal/provider/constcontainer_data_source.go b/zSDKs/terraform-provider-testing/internal/provider/constcontainer_data_source.go new file mode 100644 index 000000000..4b2b78c30 --- /dev/null +++ b/zSDKs/terraform-provider-testing/internal/provider/constcontainer_data_source.go @@ -0,0 +1,128 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package provider + +import ( + "context" + "fmt" + "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-framework/types/basetypes" + "github.com/hashicorp/terraform-provider-testing/internal/sdk" +) + +// Ensure provider defined types fully satisfy framework interfaces. +var _ datasource.DataSource = &ConstContainerDataSource{} +var _ datasource.DataSourceWithConfigure = &ConstContainerDataSource{} + +func NewConstContainerDataSource() datasource.DataSource { + return &ConstContainerDataSource{} +} + +// ConstContainerDataSource is the data source implementation. +type ConstContainerDataSource struct { + // Provider configured SDK client. + client *sdk.SDK +} + +// ConstContainerDataSourceModel describes the data model. +type ConstContainerDataSourceModel struct { + ID types.String `tfsdk:"id"` + Name types.String `tfsdk:"name"` +} + +// Metadata returns the data source type name. +func (r *ConstContainerDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_const_container" +} + +// Schema defines the schema for the data source. +func (r *ConstContainerDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { + resp.Schema = schema.Schema{ + MarkdownDescription: "ConstContainer DataSource", + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Required: true, + }, + "name": schema.StringAttribute{ + Computed: true, + }, + }, + } +} + +func (r *ConstContainerDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { + // Prevent panic if the provider has not been configured. + if req.ProviderData == nil { + return + } + + providerData, ok := req.ProviderData.(*TestingProviderConfigureData) + + if !ok { + resp.Diagnostics.AddError( + "Unexpected DataSource Configure Type", + fmt.Sprintf("Expected *TestingProviderConfigureData, got: %T. Please report this issue to the provider developers.", req.ProviderData), + ) + + return + } + + r.client = providerData.SDKClient +} + +func (r *ConstContainerDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var data *ConstContainerDataSourceModel + var item types.Object + + resp.Diagnostics.Append(req.Config.Get(ctx, &item)...) + if resp.Diagnostics.HasError() { + return + } + + resp.Diagnostics.Append(item.As(ctx, &data, basetypes.ObjectAsOptions{ + UnhandledNullAsEmpty: true, + UnhandledUnknownAsEmpty: true, + })...) + + if resp.Diagnostics.HasError() { + return + } + + request, requestDiags := data.ToOperationsGetConstContainerRequest(ctx) + resp.Diagnostics.Append(requestDiags...) + + if resp.Diagnostics.HasError() { + return + } + res, err := r.client.GetConstContainer(ctx, *request) + if err != nil { + resp.Diagnostics.AddError("failure to invoke API", redactSensitiveValues(ctx, err.Error())) + if res != nil && res.RawResponse != nil { + resp.Diagnostics.AddError("unexpected http request/response", debugResponse(res.RawResponse)) + } + return + } + if res == nil { + resp.Diagnostics.AddError("unexpected response from API", fmt.Sprintf("%v", res)) + return + } + if res.StatusCode != 200 { + resp.Diagnostics.AddError(fmt.Sprintf("unexpected response from API. Got an unexpected response code %v", res.StatusCode), debugResponse(res.RawResponse)) + return + } + if !(res.ConstContainerResponse != nil) { + resp.Diagnostics.AddError("unexpected response from API. Got an unexpected response body", debugResponse(res.RawResponse)) + return + } + resp.Diagnostics.Append(data.RefreshFromSharedConstContainerResponse(ctx, res.ConstContainerResponse)...) + + if resp.Diagnostics.HasError() { + return + } + + // Save updated data into Terraform state + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) +} diff --git a/zSDKs/terraform-provider-testing/internal/provider/constcontainer_data_source_sdk.go b/zSDKs/terraform-provider-testing/internal/provider/constcontainer_data_source_sdk.go new file mode 100644 index 000000000..0dfce4980 --- /dev/null +++ b/zSDKs/terraform-provider-testing/internal/provider/constcontainer_data_source_sdk.go @@ -0,0 +1,35 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package provider + +import ( + "context" + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-provider-testing/internal/sdk/models/operations" + "github.com/hashicorp/terraform-provider-testing/internal/sdk/models/shared" +) + +func (r *ConstContainerDataSourceModel) RefreshFromSharedConstContainerResponse(ctx context.Context, resp *shared.ConstContainerResponse) diag.Diagnostics { + var diags diag.Diagnostics + + if resp != nil { + r.ID = types.StringPointerValue(resp.ID) + r.Name = types.StringPointerValue(resp.Name) + } + + return diags +} + +func (r *ConstContainerDataSourceModel) ToOperationsGetConstContainerRequest(ctx context.Context) (*operations.GetConstContainerRequest, diag.Diagnostics) { + var diags diag.Diagnostics + + var id string + id = r.ID.ValueString() + + out := operations.GetConstContainerRequest{ + ID: id, + } + + return &out, diags +} diff --git a/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource.go b/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource.go new file mode 100644 index 000000000..3cd47c03e --- /dev/null +++ b/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource.go @@ -0,0 +1,268 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package provider + +import ( + "context" + "fmt" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-framework/types/basetypes" + speakeasy_stringplanmodifier "github.com/hashicorp/terraform-provider-testing/internal/planmodifiers/stringplanmodifier" + "github.com/hashicorp/terraform-provider-testing/internal/sdk" +) + +// Ensure provider defined types fully satisfy framework interfaces. +var _ resource.Resource = &ConstContainerResource{} +var _ resource.ResourceWithImportState = &ConstContainerResource{} + +func NewConstContainerResource() resource.Resource { + return &ConstContainerResource{} +} + +// ConstContainerResource defines the resource implementation. +type ConstContainerResource struct { + // Provider configured SDK client. + client *sdk.SDK +} + +// ConstContainerResourceModel describes the resource data model. +type ConstContainerResourceModel struct { + ID types.String `tfsdk:"id"` + Name types.String `tfsdk:"name"` +} + +func (r *ConstContainerResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_const_container" +} + +func (r *ConstContainerResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { + resp.Schema = schema.Schema{ + MarkdownDescription: "ConstContainer Resource", + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + }, + "name": schema.StringAttribute{ + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplaceIfConfigured(), + speakeasy_stringplanmodifier.SuppressDiff(speakeasy_stringplanmodifier.ExplicitSuppress), + }, + Description: `Requires replacement if changed.`, + }, + }, + } +} + +func (r *ConstContainerResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { + // Prevent panic if the provider has not been configured. + if req.ProviderData == nil { + return + } + + providerData, ok := req.ProviderData.(*TestingProviderConfigureData) + + if !ok { + resp.Diagnostics.AddError( + "Unexpected Resource Configure Type", + fmt.Sprintf("Expected *TestingProviderConfigureData, got: %T. Please report this issue to the provider developers.", req.ProviderData), + ) + + return + } + + r.client = providerData.SDKClient +} + +func (r *ConstContainerResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var data *ConstContainerResourceModel + var plan types.Object + + resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) + if resp.Diagnostics.HasError() { + return + } + + resp.Diagnostics.Append(plan.As(ctx, &data, basetypes.ObjectAsOptions{ + UnhandledNullAsEmpty: true, + UnhandledUnknownAsEmpty: true, + })...) + + if resp.Diagnostics.HasError() { + return + } + + request, requestDiags := data.ToSharedConstContainerRequest(ctx) + resp.Diagnostics.Append(requestDiags...) + + if resp.Diagnostics.HasError() { + return + } + res, err := r.client.CreateConstContainer(ctx, *request) + if err != nil { + resp.Diagnostics.AddError("failure to invoke API", redactSensitiveValues(ctx, err.Error())) + if res != nil && res.RawResponse != nil { + resp.Diagnostics.AddError("unexpected http request/response", debugResponse(res.RawResponse)) + } + return + } + if res == nil { + resp.Diagnostics.AddError("unexpected response from API", fmt.Sprintf("%v", res)) + return + } + if res.StatusCode != 200 { + resp.Diagnostics.AddError(fmt.Sprintf("unexpected response from API. Got an unexpected response code %v", res.StatusCode), debugResponse(res.RawResponse)) + return + } + if !(res.ConstContainerResponse != nil) { + resp.Diagnostics.AddError("unexpected response from API. Got an unexpected response body", debugResponse(res.RawResponse)) + return + } + resp.Diagnostics.Append(data.RefreshFromSharedConstContainerResponse(ctx, res.ConstContainerResponse)...) + + if resp.Diagnostics.HasError() { + return + } + + resp.Diagnostics.Append(refreshPlan(ctx, plan, &data)...) + + if resp.Diagnostics.HasError() { + return + } + + // Save updated data into Terraform state + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) +} + +func (r *ConstContainerResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var data *ConstContainerResourceModel + var item types.Object + + resp.Diagnostics.Append(req.State.Get(ctx, &item)...) + if resp.Diagnostics.HasError() { + return + } + + resp.Diagnostics.Append(item.As(ctx, &data, basetypes.ObjectAsOptions{ + UnhandledNullAsEmpty: true, + UnhandledUnknownAsEmpty: true, + })...) + + if resp.Diagnostics.HasError() { + return + } + + request, requestDiags := data.ToOperationsGetConstContainerRequest(ctx) + resp.Diagnostics.Append(requestDiags...) + + if resp.Diagnostics.HasError() { + return + } + res, err := r.client.GetConstContainer(ctx, *request) + if err != nil { + resp.Diagnostics.AddError("failure to invoke API", redactSensitiveValues(ctx, err.Error())) + if res != nil && res.RawResponse != nil { + resp.Diagnostics.AddError("unexpected http request/response", debugResponse(res.RawResponse)) + } + return + } + if res == nil { + resp.Diagnostics.AddError("unexpected response from API", fmt.Sprintf("%v", res)) + return + } + if res.StatusCode == 404 { + resp.State.RemoveResource(ctx) + return + } + if res.StatusCode != 200 { + resp.Diagnostics.AddError(fmt.Sprintf("unexpected response from API. Got an unexpected response code %v", res.StatusCode), debugResponse(res.RawResponse)) + return + } + if !(res.ConstContainerResponse != nil) { + resp.Diagnostics.AddError("unexpected response from API. Got an unexpected response body", debugResponse(res.RawResponse)) + return + } + resp.Diagnostics.Append(data.RefreshFromSharedConstContainerResponse(ctx, res.ConstContainerResponse)...) + + if resp.Diagnostics.HasError() { + return + } + + // Save updated data into Terraform state + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) +} + +func (r *ConstContainerResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var data *ConstContainerResourceModel + var plan types.Object + + resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) + if resp.Diagnostics.HasError() { + return + } + + merge(ctx, req, resp, &data) + if resp.Diagnostics.HasError() { + return + } + + // Not Implemented; all attributes marked as RequiresReplace + + // Save updated data into Terraform state + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) +} + +func (r *ConstContainerResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var data *ConstContainerResourceModel + var item types.Object + + resp.Diagnostics.Append(req.State.Get(ctx, &item)...) + if resp.Diagnostics.HasError() { + return + } + + resp.Diagnostics.Append(item.As(ctx, &data, basetypes.ObjectAsOptions{ + UnhandledNullAsEmpty: true, + UnhandledUnknownAsEmpty: true, + })...) + + if resp.Diagnostics.HasError() { + return + } + + request, requestDiags := data.ToOperationsDeleteConstContainerRequest(ctx) + resp.Diagnostics.Append(requestDiags...) + + if resp.Diagnostics.HasError() { + return + } + res, err := r.client.DeleteConstContainer(ctx, *request) + if err != nil { + resp.Diagnostics.AddError("failure to invoke API", redactSensitiveValues(ctx, err.Error())) + if res != nil && res.RawResponse != nil { + resp.Diagnostics.AddError("unexpected http request/response", debugResponse(res.RawResponse)) + } + return + } + if res == nil { + resp.Diagnostics.AddError("unexpected response from API", fmt.Sprintf("%v", res)) + return + } + switch res.StatusCode { + case 200, 404: + break + default: + resp.Diagnostics.AddError(fmt.Sprintf("unexpected response from API. Got an unexpected response code %v", res.StatusCode), debugResponse(res.RawResponse)) + return + } + +} + +func (r *ConstContainerResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), req.ID)...) +} diff --git a/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource_sdk.go b/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource_sdk.go new file mode 100644 index 000000000..f6f4a0ed4 --- /dev/null +++ b/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource_sdk.go @@ -0,0 +1,61 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package provider + +import ( + "context" + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-provider-testing/internal/sdk/models/operations" + "github.com/hashicorp/terraform-provider-testing/internal/sdk/models/shared" +) + +func (r *ConstContainerResourceModel) RefreshFromSharedConstContainerResponse(ctx context.Context, resp *shared.ConstContainerResponse) diag.Diagnostics { + var diags diag.Diagnostics + + if resp != nil { + r.ID = types.StringPointerValue(resp.ID) + r.Name = types.StringPointerValue(resp.Name) + } + + return diags +} + +func (r *ConstContainerResourceModel) ToOperationsDeleteConstContainerRequest(ctx context.Context) (*operations.DeleteConstContainerRequest, diag.Diagnostics) { + var diags diag.Diagnostics + + var id string + id = r.ID.ValueString() + + out := operations.DeleteConstContainerRequest{ + ID: id, + } + + return &out, diags +} + +func (r *ConstContainerResourceModel) ToOperationsGetConstContainerRequest(ctx context.Context) (*operations.GetConstContainerRequest, diag.Diagnostics) { + var diags diag.Diagnostics + + var id string + id = r.ID.ValueString() + + out := operations.GetConstContainerRequest{ + ID: id, + } + + return &out, diags +} + +func (r *ConstContainerResourceModel) ToSharedConstContainerRequest(ctx context.Context) (*shared.ConstContainerRequest, diag.Diagnostics) { + var diags diag.Diagnostics + + var name string + name = r.Name.ValueString() + + out := shared.ConstContainerRequest{ + Name: name, + } + + return &out, diags +} diff --git a/zSDKs/terraform-provider-testing/internal/provider/provider.go b/zSDKs/terraform-provider-testing/internal/provider/provider.go index c558c318a..06585ae95 100644 --- a/zSDKs/terraform-provider-testing/internal/provider/provider.go +++ b/zSDKs/terraform-provider-testing/internal/provider/provider.go @@ -808,6 +808,7 @@ func (p *TestingProvider) Resources(ctx context.Context) []func() resource.Resou return []func() resource.Resource{ NewAPICreateAndUpdateResource, NewBasicResource, + NewConstContainerResource, NewDiscriminatedUnionResource, NewDiscriminatedUnionArrayResource, NewFrameworkTypeResource, @@ -888,6 +889,7 @@ func (p *TestingProvider) DataSources(ctx context.Context) []func() datasource.D return []func() datasource.DataSource{ NewAPICreateAndUpdateDataSource, NewBasicDataSource, + NewConstContainerDataSource, NewDiscriminatedUnionDataSource, NewFrameworkTypeDataSource, NewImportDefaultedIDDataSource, diff --git a/zSDKs/terraform-provider-testing/internal/sdk/internal/utils/json.go b/zSDKs/terraform-provider-testing/internal/sdk/internal/utils/json.go index d49c56d68..13a99d20d 100644 --- a/zSDKs/terraform-provider-testing/internal/sdk/internal/utils/json.go +++ b/zSDKs/terraform-provider-testing/internal/sdk/internal/utils/json.go @@ -214,7 +214,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue { + if val != constValue && !constJSONValuesEqual(r, constValue) { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -433,6 +433,17 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } +func constJSONValuesEqual(received json.RawMessage, constValue string) bool { + var got, want interface{} + if err := json.Unmarshal(received, &got); err != nil { + return false + } + if err := json.Unmarshal([]byte(constValue), &want); err != nil { + return false + } + return reflect.DeepEqual(got, want) +} + func handleDefaultConstValue(tagValue string, val interface{}, tag reflect.StructTag) json.RawMessage { if tagValue == "null" { return []byte("null") diff --git a/zSDKs/terraform-provider-testing/internal/sdk/models/operations/createconstcontainer.go b/zSDKs/terraform-provider-testing/internal/sdk/models/operations/createconstcontainer.go new file mode 100644 index 000000000..7f223e99e --- /dev/null +++ b/zSDKs/terraform-provider-testing/internal/sdk/models/operations/createconstcontainer.go @@ -0,0 +1,47 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package operations + +import ( + "github.com/hashicorp/terraform-provider-testing/internal/sdk/models/shared" + "net/http" +) + +type CreateConstContainerResponse struct { + // HTTP response content type for this operation + ContentType string + // HTTP response status code for this operation + StatusCode int + // Raw HTTP response; suitable for custom response parsing + RawResponse *http.Response + // OK + ConstContainerResponse *shared.ConstContainerResponse +} + +func (c *CreateConstContainerResponse) GetContentType() string { + if c == nil { + return "" + } + return c.ContentType +} + +func (c *CreateConstContainerResponse) GetStatusCode() int { + if c == nil { + return 0 + } + return c.StatusCode +} + +func (c *CreateConstContainerResponse) GetRawResponse() *http.Response { + if c == nil { + return nil + } + return c.RawResponse +} + +func (c *CreateConstContainerResponse) GetConstContainerResponse() *shared.ConstContainerResponse { + if c == nil { + return nil + } + return c.ConstContainerResponse +} diff --git a/zSDKs/terraform-provider-testing/internal/sdk/models/operations/deleteconstcontainer.go b/zSDKs/terraform-provider-testing/internal/sdk/models/operations/deleteconstcontainer.go new file mode 100644 index 000000000..d2937f78e --- /dev/null +++ b/zSDKs/terraform-provider-testing/internal/sdk/models/operations/deleteconstcontainer.go @@ -0,0 +1,48 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package operations + +import ( + "net/http" +) + +type DeleteConstContainerRequest struct { + ID string `pathParam:"style=simple,explode=false,name=id"` +} + +func (d *DeleteConstContainerRequest) GetID() string { + if d == nil { + return "" + } + return d.ID +} + +type DeleteConstContainerResponse struct { + // HTTP response content type for this operation + ContentType string + // HTTP response status code for this operation + StatusCode int + // Raw HTTP response; suitable for custom response parsing + RawResponse *http.Response +} + +func (d *DeleteConstContainerResponse) GetContentType() string { + if d == nil { + return "" + } + return d.ContentType +} + +func (d *DeleteConstContainerResponse) GetStatusCode() int { + if d == nil { + return 0 + } + return d.StatusCode +} + +func (d *DeleteConstContainerResponse) GetRawResponse() *http.Response { + if d == nil { + return nil + } + return d.RawResponse +} diff --git a/zSDKs/terraform-provider-testing/internal/sdk/models/operations/getconstcontainer.go b/zSDKs/terraform-provider-testing/internal/sdk/models/operations/getconstcontainer.go new file mode 100644 index 000000000..b9d5e2846 --- /dev/null +++ b/zSDKs/terraform-provider-testing/internal/sdk/models/operations/getconstcontainer.go @@ -0,0 +1,58 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package operations + +import ( + "github.com/hashicorp/terraform-provider-testing/internal/sdk/models/shared" + "net/http" +) + +type GetConstContainerRequest struct { + ID string `pathParam:"style=simple,explode=false,name=id"` +} + +func (g *GetConstContainerRequest) GetID() string { + if g == nil { + return "" + } + return g.ID +} + +type GetConstContainerResponse struct { + // HTTP response content type for this operation + ContentType string + // HTTP response status code for this operation + StatusCode int + // Raw HTTP response; suitable for custom response parsing + RawResponse *http.Response + // OK + ConstContainerResponse *shared.ConstContainerResponse +} + +func (g *GetConstContainerResponse) GetContentType() string { + if g == nil { + return "" + } + return g.ContentType +} + +func (g *GetConstContainerResponse) GetStatusCode() int { + if g == nil { + return 0 + } + return g.StatusCode +} + +func (g *GetConstContainerResponse) GetRawResponse() *http.Response { + if g == nil { + return nil + } + return g.RawResponse +} + +func (g *GetConstContainerResponse) GetConstContainerResponse() *shared.ConstContainerResponse { + if g == nil { + return nil + } + return g.ConstContainerResponse +} diff --git a/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerrequest.go b/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerrequest.go new file mode 100644 index 000000000..b8e5b45f3 --- /dev/null +++ b/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerrequest.go @@ -0,0 +1,84 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package shared + +import ( + "encoding/json" + "fmt" + "github.com/hashicorp/terraform-provider-testing/internal/sdk/internal/utils" +) + +type ConstContainerRequestFixedList string + +const ( + ConstContainerRequestFixedListRead ConstContainerRequestFixedList = "read" + ConstContainerRequestFixedListWrite ConstContainerRequestFixedList = "write" + ConstContainerRequestFixedListAdmin ConstContainerRequestFixedList = "admin" +) + +func (e ConstContainerRequestFixedList) ToPointer() *ConstContainerRequestFixedList { + return &e +} +func (e *ConstContainerRequestFixedList) UnmarshalJSON(data []byte) error { + var v string + if err := json.Unmarshal(data, &v); err != nil { + return err + } + switch v { + case "read": + fallthrough + case "write": + fallthrough + case "admin": + *e = ConstContainerRequestFixedList(v) + return nil + default: + return fmt.Errorf("invalid value for ConstContainerRequestFixedList: %v", v) + } +} + +type ConstContainerRequest struct { + Name string `json:"name"` + //lint:ignore U1000 accessed via reflection for JSON marshaling + emptyList []string `const:"[]" json:"empty_list"` + //lint:ignore U1000 accessed via reflection for JSON marshaling + fixedList []ConstContainerRequestFixedList `const:"[\"read\",\"write\"]" json:"fixed_list,omitempty"` + //lint:ignore U1000 accessed via reflection for JSON marshaling + emptyMap map[string]string `const:"{}" json:"empty_map"` + //lint:ignore U1000 accessed via reflection for JSON marshaling + fixedMap map[string]int64 `const:"{\"max\":10}" json:"fixed_map,omitempty"` +} + +func (c ConstContainerRequest) MarshalJSON() ([]byte, error) { + return utils.MarshalJSON(c, "", false) +} + +func (c *ConstContainerRequest) UnmarshalJSON(data []byte) error { + if err := utils.UnmarshalJSON(data, &c, "", false, nil); err != nil { + return err + } + return nil +} + +func (c *ConstContainerRequest) GetName() string { + if c == nil { + return "" + } + return c.Name +} + +func (c *ConstContainerRequest) GetEmptyList() []string { + return []string{} +} + +func (c *ConstContainerRequest) GetFixedList() []ConstContainerRequestFixedList { + return []ConstContainerRequestFixedList{ConstContainerRequestFixedListRead, ConstContainerRequestFixedListWrite} +} + +func (c *ConstContainerRequest) GetEmptyMap() map[string]string { + return map[string]string{} +} + +func (c *ConstContainerRequest) GetFixedMap() map[string]int64 { + return map[string]int64{"max": 10} +} diff --git a/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerresponse.go b/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerresponse.go new file mode 100644 index 000000000..67ae54213 --- /dev/null +++ b/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerresponse.go @@ -0,0 +1,92 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package shared + +import ( + "encoding/json" + "fmt" + "github.com/hashicorp/terraform-provider-testing/internal/sdk/internal/utils" +) + +type ConstContainerResponseFixedList string + +const ( + ConstContainerResponseFixedListRead ConstContainerResponseFixedList = "read" + ConstContainerResponseFixedListWrite ConstContainerResponseFixedList = "write" + ConstContainerResponseFixedListAdmin ConstContainerResponseFixedList = "admin" +) + +func (e ConstContainerResponseFixedList) ToPointer() *ConstContainerResponseFixedList { + return &e +} +func (e *ConstContainerResponseFixedList) UnmarshalJSON(data []byte) error { + var v string + if err := json.Unmarshal(data, &v); err != nil { + return err + } + switch v { + case "read": + fallthrough + case "write": + fallthrough + case "admin": + *e = ConstContainerResponseFixedList(v) + return nil + default: + return fmt.Errorf("invalid value for ConstContainerResponseFixedList: %v", v) + } +} + +type ConstContainerResponse struct { + ID *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + //lint:ignore U1000 accessed via reflection for JSON marshaling + emptyList []string `const:"[]" json:"empty_list,omitempty"` + //lint:ignore U1000 accessed via reflection for JSON marshaling + fixedList []ConstContainerResponseFixedList `const:"[\"read\",\"write\"]" json:"fixed_list,omitempty"` + //lint:ignore U1000 accessed via reflection for JSON marshaling + emptyMap map[string]string `const:"{}" json:"empty_map,omitempty"` + //lint:ignore U1000 accessed via reflection for JSON marshaling + fixedMap map[string]int64 `const:"{\"max\":10}" json:"fixed_map,omitempty"` +} + +func (c ConstContainerResponse) MarshalJSON() ([]byte, error) { + return utils.MarshalJSON(c, "", false) +} + +func (c *ConstContainerResponse) UnmarshalJSON(data []byte) error { + if err := utils.UnmarshalJSON(data, &c, "", false, nil); err != nil { + return err + } + return nil +} + +func (c *ConstContainerResponse) GetID() *string { + if c == nil { + return nil + } + return c.ID +} + +func (c *ConstContainerResponse) GetName() *string { + if c == nil { + return nil + } + return c.Name +} + +func (c *ConstContainerResponse) GetEmptyList() []string { + return []string{} +} + +func (c *ConstContainerResponse) GetFixedList() []ConstContainerResponseFixedList { + return []ConstContainerResponseFixedList{ConstContainerResponseFixedListRead, ConstContainerResponseFixedListWrite} +} + +func (c *ConstContainerResponse) GetEmptyMap() map[string]string { + return map[string]string{} +} + +func (c *ConstContainerResponse) GetFixedMap() map[string]int64 { + return map[string]int64{"max": 10} +} diff --git a/zSDKs/terraform-provider-testing/internal/sdk/sdk.go b/zSDKs/terraform-provider-testing/internal/sdk/sdk.go index 461079173..a31c2eb1d 100644 --- a/zSDKs/terraform-provider-testing/internal/sdk/sdk.go +++ b/zSDKs/terraform-provider-testing/internal/sdk/sdk.go @@ -42192,3 +42192,384 @@ func (s *SDK) DeleteOasContentMediaType(ctx context.Context, request operations. return res, nil } + +// CreateConstContainer - Create a resource whose request schema declares const values on array +// and map properties. Terraform must hide those properties from the +// resource schema and send the const values in the request body. +func (s *SDK) CreateConstContainer(ctx context.Context, request shared.ConstContainerRequest, opts ...operations.Option) (*operations.CreateConstContainerResponse, error) { + o := operations.Options{} + supportedOptions := []string{ + operations.SupportedOptionTimeout, + } + + for _, opt := range opts { + if err := opt(&o, supportedOptions...); err != nil { + return nil, fmt.Errorf("error applying option: %w", err) + } + } + + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } + opURL, err := url.JoinPath(baseURL, "/v0/constcontainers") + if err != nil { + return nil, fmt.Errorf("error generating URL: %w", err) + } + + hookCtx := hooks.HookContext{ + SDK: s, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "create-const-container", + OAuth2Scopes: []string{}, + SecuritySource: s.sdkConfiguration.Security, + } + bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, false, false, "Request", "json", `request:"mediaType=application/json"`) + if err != nil { + return nil, err + } + + timeout := o.Timeout + if timeout == nil { + timeout = s.sdkConfiguration.Timeout + } + + if timeout != nil { + var cancel context.CancelFunc + ctx, cancel = context.WithTimeout(ctx, *timeout) + defer cancel() + } + + req, err := http.NewRequestWithContext(ctx, "POST", opURL, bodyReader) + if err != nil { + return nil, fmt.Errorf("error creating request: %w", err) + } + req.Header.Set("Accept", "application/json") + req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) + if reqContentType != "" { + req.Header.Set("Content-Type", reqContentType) + } + + if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil { + return nil, err + } + + for k, v := range o.SetHeaders { + req.Header.Set(k, v) + } + + req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + if err != nil { + return nil, err + } + + httpRes, err := s.sdkConfiguration.Client.Do(req) + if err != nil || httpRes == nil { + if err != nil { + err = fmt.Errorf("error sending request: %w", err) + } else { + err = fmt.Errorf("error sending request: no response") + } + + _, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + return nil, err + } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { + _httpRes, err := s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) + if err != nil { + return nil, err + } else if _httpRes != nil { + httpRes = _httpRes + } + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { + return nil, err + } + } + + res := &operations.CreateConstContainerResponse{ + StatusCode: httpRes.StatusCode, + ContentType: httpRes.Header.Get("Content-Type"), + RawResponse: httpRes, + } + + switch { + case httpRes.StatusCode == 200: + switch { + case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + + var out shared.ConstContainerResponse + if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { + return nil, err + } + + res.ConstContainerResponse = &out + default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + return nil, errors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) + } + default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + return nil, errors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) + } + + return res, nil + +} + +// GetConstContainer - Get a const container resource +func (s *SDK) GetConstContainer(ctx context.Context, request operations.GetConstContainerRequest, opts ...operations.Option) (*operations.GetConstContainerResponse, error) { + o := operations.Options{} + supportedOptions := []string{ + operations.SupportedOptionTimeout, + } + + for _, opt := range opts { + if err := opt(&o, supportedOptions...); err != nil { + return nil, fmt.Errorf("error applying option: %w", err) + } + } + + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } + opURL, err := utils.GenerateURL(ctx, baseURL, "/v0/constcontainer/{id}", request, nil) + if err != nil { + return nil, fmt.Errorf("error generating URL: %w", err) + } + + hookCtx := hooks.HookContext{ + SDK: s, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "get-const-container", + OAuth2Scopes: []string{}, + SecuritySource: s.sdkConfiguration.Security, + } + + timeout := o.Timeout + if timeout == nil { + timeout = s.sdkConfiguration.Timeout + } + + if timeout != nil { + var cancel context.CancelFunc + ctx, cancel = context.WithTimeout(ctx, *timeout) + defer cancel() + } + + req, err := http.NewRequestWithContext(ctx, "GET", opURL, nil) + if err != nil { + return nil, fmt.Errorf("error creating request: %w", err) + } + req.Header.Set("Accept", "application/json") + req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) + + if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil { + return nil, err + } + + for k, v := range o.SetHeaders { + req.Header.Set(k, v) + } + + req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + if err != nil { + return nil, err + } + + httpRes, err := s.sdkConfiguration.Client.Do(req) + if err != nil || httpRes == nil { + if err != nil { + err = fmt.Errorf("error sending request: %w", err) + } else { + err = fmt.Errorf("error sending request: no response") + } + + _, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + return nil, err + } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { + _httpRes, err := s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) + if err != nil { + return nil, err + } else if _httpRes != nil { + httpRes = _httpRes + } + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { + return nil, err + } + } + + res := &operations.GetConstContainerResponse{ + StatusCode: httpRes.StatusCode, + ContentType: httpRes.Header.Get("Content-Type"), + RawResponse: httpRes, + } + + switch { + case httpRes.StatusCode == 200: + switch { + case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + + var out shared.ConstContainerResponse + if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { + return nil, err + } + + res.ConstContainerResponse = &out + default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + return nil, errors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) + } + case httpRes.StatusCode == 404: + utils.DrainBody(httpRes) + default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + return nil, errors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) + } + + return res, nil + +} + +// DeleteConstContainer - Delete a const container resource +func (s *SDK) DeleteConstContainer(ctx context.Context, request operations.DeleteConstContainerRequest, opts ...operations.Option) (*operations.DeleteConstContainerResponse, error) { + o := operations.Options{} + supportedOptions := []string{ + operations.SupportedOptionTimeout, + } + + for _, opt := range opts { + if err := opt(&o, supportedOptions...); err != nil { + return nil, fmt.Errorf("error applying option: %w", err) + } + } + + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } + opURL, err := utils.GenerateURL(ctx, baseURL, "/v0/constcontainer/{id}", request, nil) + if err != nil { + return nil, fmt.Errorf("error generating URL: %w", err) + } + + hookCtx := hooks.HookContext{ + SDK: s, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "delete-const-container", + OAuth2Scopes: []string{}, + SecuritySource: s.sdkConfiguration.Security, + } + + timeout := o.Timeout + if timeout == nil { + timeout = s.sdkConfiguration.Timeout + } + + if timeout != nil { + var cancel context.CancelFunc + ctx, cancel = context.WithTimeout(ctx, *timeout) + defer cancel() + } + + req, err := http.NewRequestWithContext(ctx, "DELETE", opURL, nil) + if err != nil { + return nil, fmt.Errorf("error creating request: %w", err) + } + req.Header.Set("Accept", "*/*") + req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) + + if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil { + return nil, err + } + + for k, v := range o.SetHeaders { + req.Header.Set(k, v) + } + + req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + if err != nil { + return nil, err + } + + httpRes, err := s.sdkConfiguration.Client.Do(req) + if err != nil || httpRes == nil { + if err != nil { + err = fmt.Errorf("error sending request: %w", err) + } else { + err = fmt.Errorf("error sending request: no response") + } + + _, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + return nil, err + } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { + _httpRes, err := s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) + if err != nil { + return nil, err + } else if _httpRes != nil { + httpRes = _httpRes + } + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { + return nil, err + } + } + + res := &operations.DeleteConstContainerResponse{ + StatusCode: httpRes.StatusCode, + ContentType: httpRes.Header.Get("Content-Type"), + RawResponse: httpRes, + } + + switch { + case httpRes.StatusCode == 200: + utils.DrainBody(httpRes) + case httpRes.StatusCode == 404: + utils.DrainBody(httpRes) + default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + return nil, errors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) + } + + return res, nil + +} From df8db20a0774c426376b6550f48b74a250dbc3d5 Mon Sep 17 00:00:00 2001 From: Ash Godfrey Date: Thu, 22 Oct 2026 11:16:37 +0100 Subject: [PATCH 02/22] fix: address review findings for container const support - Gate container default and const metadata independently so a const cannot ride along on a target that only supports container defaults. - Reject consts on containers with nullable items, whose Go element type is a pointer the const renderer does not produce. - Accept uuid and duration items in container consts. - Compare received const values with exact JSON numbers instead of float64. - Record the cli target on the Go runtime changeset. --- .changesets/1792662097-2435dcc7.yaml | 1 + internal/schemas/handle_array_test.go | 27 ++++++++ internal/schemas/schemas.go | 62 ++++++++----------- .../{{getUtilsLocation}}/json.go.stmpl | 57 +++++++++++++++-- zSDKs/sdk-cli/.speakeasy/gen.lock | 2 +- .../internal/sdk/sdkinternal/utils/json.go | 57 +++++++++++++++-- zSDKs/sdk-go/.speakeasy/gen.lock | 2 +- zSDKs/sdk-go/internal/utils/json.go | 57 +++++++++++++++-- .../.speakeasy/gen.lock | 2 +- .../internal/sdk/internal/utils/json.go | 57 +++++++++++++++-- 10 files changed, 270 insertions(+), 54 deletions(-) diff --git a/.changesets/1792662097-2435dcc7.yaml b/.changesets/1792662097-2435dcc7.yaml index ef6e758ff..daeefe689 100644 --- a/.changesets/1792662097-2435dcc7.yaml +++ b/.changesets/1792662097-2435dcc7.yaml @@ -3,6 +3,7 @@ features: - constsAndDefaults targets: - go + - cli type: fix bump: patch description: const values on array and map fields are emitted when marshaling and accepted when unmarshaling diff --git a/internal/schemas/handle_array_test.go b/internal/schemas/handle_array_test.go index 001150af7..5d4e71f1e 100644 --- a/internal/schemas/handle_array_test.go +++ b/internal/schemas/handle_array_test.go @@ -265,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: diff --git a/internal/schemas/schemas.go b/internal/schemas/schemas.go index b735eaa14..a63fc9414 100644 --- a/internal/schemas/schemas.go +++ b/internal/schemas/schemas.go @@ -562,10 +562,7 @@ func (s *Schemas) handleArray(ctx context.Context, params Params, nullable bool) Optional: nullable, Nullable: nullable, } - if s.containerMetaDataApplies(ctx, schema, features.FeatureDefaultArrays, features.FeatureConstArrays) { - fieldDef = s.handleFieldDefMetaData(ctx, fieldDef, nullable, schema) - s.recordContainerConstUsage(ctx, fieldDef, features.FeatureConstArrays) - } + fieldDef = s.handleContainerMetaData(ctx, fieldDef, nullable, schema, s.Subsystem.Features.IsFeatureSupported(ctx, features.FeatureDefaultArrays), features.FeatureConstArrays) // We need to inherit the multipart annotations if itemField != nil { @@ -819,18 +816,12 @@ func (s *Schemas) handleObject(ctx context.Context, params Params, nullable bool typeDef.Extensions = extensions - mapField := &ast.FieldDef{ + return s.handleContainerMetaData(ctx, &ast.FieldDef{ Name: fieldName, Type: ast.NewType(typeDef, nil), Optional: nullable, Nullable: nullable, - } - if schema.Const != nil && s.Subsystem.Features.IsFeatureSupported(ctx, features.FeatureConstObjects) { - mapField = s.handleFieldDefMetaData(ctx, mapField, nullable, schema) - s.recordContainerConstUsage(ctx, mapField, features.FeatureConstObjects) - } - - return mapField, nil + }, nullable, schema, false, features.FeatureConstObjects), nil } case recurseAdditionalProperties: additionalPropertiesParams := params @@ -898,18 +889,12 @@ func (s *Schemas) handleObject(ctx context.Context, params Params, nullable bool typeDef.Extensions = extensions - mapField := &ast.FieldDef{ + return s.handleContainerMetaData(ctx, &ast.FieldDef{ Name: fieldName, Type: ast.NewType(typeDef, nil), Optional: nullable, Nullable: nullable, - } - if schema.Const != nil && s.Subsystem.Features.IsFeatureSupported(ctx, features.FeatureConstObjects) { - mapField = s.handleFieldDefMetaData(ctx, mapField, nullable, schema) - s.recordContainerConstUsage(ctx, mapField, features.FeatureConstObjects) - } - - return mapField, nil + }, nullable, schema, false, features.FeatureConstObjects), nil } } } @@ -1311,10 +1296,7 @@ func (s *Schemas) handleObject(ctx context.Context, params Params, nullable bool Nullable: nullable, } - if s.containerMetaDataApplies(ctx, schema, features.FeatureDefaultObjects, features.FeatureConstObjects) { - fieldDef = s.handleFieldDefMetaData(ctx, fieldDef, nullable, schema) - s.recordContainerConstUsage(ctx, fieldDef, features.FeatureConstObjects) - } + fieldDef = s.handleContainerMetaData(ctx, fieldDef, nullable, schema, s.Subsystem.Features.IsFeatureSupported(ctx, features.FeatureDefaultObjects), features.FeatureConstObjects) s.setCachedType(fieldType, ¶ms) @@ -1707,6 +1689,10 @@ func (s *Schemas) checkDefaultConformsToType(ctx context.Context, field *ast.Fie } func constContainerValueSupported(val any, typ *ast.TypeDef) bool { + if typ.ContainsNull { + return false + } + switch typ.Type { case ast.DataTypeArray, ast.DataTypeSet: items, ok := val.([]any) @@ -1745,7 +1731,7 @@ func constScalarMatchesType(val any, itemType *ast.TypeDef) bool { return itemType.Enum != nil && slices.Contains(itemType.Enum.Values, fmt.Sprint(val)) case ast.DataTypeBoolean, ast.DataTypeInteger, ast.DataTypeInt32, ast.DataTypeBigInt, ast.DataTypeNumber, ast.DataTypeFloat32, ast.DataTypeDecimal, - ast.DataTypeString, ast.DataTypeDate, ast.DataTypeDateTime: + ast.DataTypeString, ast.DataTypeDate, ast.DataTypeDateTime, ast.DataTypeUUID, ast.DataTypeDuration: dataType := itemType.Type if itemType.Format == "string" { dataType = ast.DataTypeString @@ -2827,20 +2813,26 @@ func (s *Schemas) handleFieldDefMetaData(ctx context.Context, fieldDef *ast.Fiel return fieldDef } -func (s *Schemas) containerMetaDataApplies(ctx context.Context, schema *oas3.Schema, defaultFeature, constFeature features.Feature) bool { - if schema.Default != nil && s.Subsystem.Features.IsFeatureSupported(ctx, defaultFeature) { - return true +func (s *Schemas) handleContainerMetaData(ctx context.Context, fieldDef *ast.FieldDef, nullable bool, schema *oas3.Schema, defaultSupported bool, constFeature features.Feature) *ast.FieldDef { + applyDefault := schema.Default != nil && defaultSupported + applyConst := schema.Const != nil && s.Subsystem.Features.IsFeatureSupported(ctx, constFeature) + if !applyDefault && !applyConst { + return fieldDef } - return schema.Const != nil && s.Subsystem.Features.IsFeatureSupported(ctx, constFeature) -} - -func (s *Schemas) recordContainerConstUsage(ctx context.Context, fieldDef *ast.FieldDef, constFeature features.Feature) { - if fieldDef.Const == nil { - return + fieldDef = s.handleFieldDefMetaData(ctx, fieldDef, nullable, schema) + if !applyDefault { + fieldDef.Default = nil + fieldDef.Optional = nullable + } + if !applyConst { + fieldDef.Const = nil + } + if fieldDef.Const != nil { + s.Subsystem.Features.RecordFeatureUsage(ctx, constFeature) } - s.Subsystem.Features.RecordFeatureUsage(ctx, constFeature) + return fieldDef } func (s *Schemas) sanitizeDefaultConstValue(ctx context.Context, value values.Value) *ast.AnyValue { diff --git a/templates/templates/go/auxiliary/{{getUtilsLocation}}/json.go.stmpl b/templates/templates/go/auxiliary/{{getUtilsLocation}}/json.go.stmpl index 7c319ca06..e8da8c543 100644 --- a/templates/templates/go/auxiliary/{{getUtilsLocation}}/json.go.stmpl +++ b/templates/templates/go/auxiliary/{{getUtilsLocation}}/json.go.stmpl @@ -448,14 +448,63 @@ func implementsJSONMarshaler(v interface{}) bool { } func constJSONValuesEqual(received json.RawMessage, constValue string) bool { - var got, want interface{} - if err := json.Unmarshal(received, &got); err != nil { + got, err := decodeJSONWithNumbers(received) + if err != nil { return false } - if err := json.Unmarshal([]byte(constValue), &want); err != nil { + want, err := decodeJSONWithNumbers([]byte(constValue)) + if err != nil { return false } - return reflect.DeepEqual(got, want) + return jsonValuesEqual(got, want) +} + +func decodeJSONWithNumbers(data []byte) (interface{}, error) { + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.UseNumber() + var value interface{} + if err := decoder.Decode(&value); err != nil { + return nil, err + } + return value, nil +} + +func jsonValuesEqual(a, b interface{}) bool { + switch av := a.(type) { + case json.Number: + bv, ok := b.(json.Number) + if !ok { + return false + } + ar, aok := new(big.Rat).SetString(av.String()) + br, bok := new(big.Rat).SetString(bv.String()) + return aok && bok && ar.Cmp(br) == 0 + case map[string]interface{}: + bv, ok := b.(map[string]interface{}) + if !ok || len(av) != len(bv) { + return false + } + for key, value := range av { + other, ok := bv[key] + if !ok || !jsonValuesEqual(value, other) { + return false + } + } + return true + case []interface{}: + bv, ok := b.([]interface{}) + if !ok || len(av) != len(bv) { + return false + } + for i := range av { + if !jsonValuesEqual(av[i], bv[i]) { + return false + } + } + return true + default: + return reflect.DeepEqual(a, b) + } } func handleDefaultConstValue(tagValue string, val interface{}, tag reflect.StructTag) json.RawMessage { diff --git a/zSDKs/sdk-cli/.speakeasy/gen.lock b/zSDKs/sdk-cli/.speakeasy/gen.lock index dbcc53eb4..db5cded35 100644 --- a/zSDKs/sdk-cli/.speakeasy/gen.lock +++ b/zSDKs/sdk-cli/.speakeasy/gen.lock @@ -598,7 +598,7 @@ trackedFiles: internal/sdk/sdkinternal/utils/headers.go: last_write_checksum: sha1:1b0bd68e1ea0bce8c5a42b5de9fd020fede7aecc internal/sdk/sdkinternal/utils/json.go: - last_write_checksum: sha1:156c99b390e19b755a3acda6f2f57dcdefcb6206 + last_write_checksum: sha1:7230262498cf1d11a4ca8e4b12e3e9354f1db635 internal/sdk/sdkinternal/utils/oauth2_credentials.go: last_write_checksum: sha1:f9218b6b3dbd11494cc353bf22eb37f0ca654a7d internal/sdk/sdkinternal/utils/oauth2_sessions.go: diff --git a/zSDKs/sdk-cli/internal/sdk/sdkinternal/utils/json.go b/zSDKs/sdk-cli/internal/sdk/sdkinternal/utils/json.go index c8f90dd87..9c7d5d75f 100644 --- a/zSDKs/sdk-cli/internal/sdk/sdkinternal/utils/json.go +++ b/zSDKs/sdk-cli/internal/sdk/sdkinternal/utils/json.go @@ -447,14 +447,63 @@ func implementsJSONMarshaler(v interface{}) bool { } func constJSONValuesEqual(received json.RawMessage, constValue string) bool { - var got, want interface{} - if err := json.Unmarshal(received, &got); err != nil { + got, err := decodeJSONWithNumbers(received) + if err != nil { return false } - if err := json.Unmarshal([]byte(constValue), &want); err != nil { + want, err := decodeJSONWithNumbers([]byte(constValue)) + if err != nil { return false } - return reflect.DeepEqual(got, want) + return jsonValuesEqual(got, want) +} + +func decodeJSONWithNumbers(data []byte) (interface{}, error) { + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.UseNumber() + var value interface{} + if err := decoder.Decode(&value); err != nil { + return nil, err + } + return value, nil +} + +func jsonValuesEqual(a, b interface{}) bool { + switch av := a.(type) { + case json.Number: + bv, ok := b.(json.Number) + if !ok { + return false + } + ar, aok := new(big.Rat).SetString(av.String()) + br, bok := new(big.Rat).SetString(bv.String()) + return aok && bok && ar.Cmp(br) == 0 + case map[string]interface{}: + bv, ok := b.(map[string]interface{}) + if !ok || len(av) != len(bv) { + return false + } + for key, value := range av { + other, ok := bv[key] + if !ok || !jsonValuesEqual(value, other) { + return false + } + } + return true + case []interface{}: + bv, ok := b.([]interface{}) + if !ok || len(av) != len(bv) { + return false + } + for i := range av { + if !jsonValuesEqual(av[i], bv[i]) { + return false + } + } + return true + default: + return reflect.DeepEqual(a, b) + } } func handleDefaultConstValue(tagValue string, val interface{}, tag reflect.StructTag) json.RawMessage { diff --git a/zSDKs/sdk-go/.speakeasy/gen.lock b/zSDKs/sdk-go/.speakeasy/gen.lock index 7498b2596..40d67eac8 100644 --- a/zSDKs/sdk-go/.speakeasy/gen.lock +++ b/zSDKs/sdk-go/.speakeasy/gen.lock @@ -713,7 +713,7 @@ trackedFiles: internal/utils/headers.go: last_write_checksum: sha1:e529ca3d7ab96a091021bcd471ba2cbef50286b3 internal/utils/json.go: - last_write_checksum: sha1:3ed843422cdd78c41282fe4ab6f22bef8b389c40 + last_write_checksum: sha1:031133cd77b7fb3478635075efe7f830be401140 internal/utils/pathparams.go: last_write_checksum: sha1:440aadb18d886ea0a79af0772eb65cdddc9eee60 internal/utils/queryparams.go: diff --git a/zSDKs/sdk-go/internal/utils/json.go b/zSDKs/sdk-go/internal/utils/json.go index 8106a80db..906ea3072 100644 --- a/zSDKs/sdk-go/internal/utils/json.go +++ b/zSDKs/sdk-go/internal/utils/json.go @@ -447,14 +447,63 @@ func implementsJSONMarshaler(v interface{}) bool { } func constJSONValuesEqual(received json.RawMessage, constValue string) bool { - var got, want interface{} - if err := json.Unmarshal(received, &got); err != nil { + got, err := decodeJSONWithNumbers(received) + if err != nil { return false } - if err := json.Unmarshal([]byte(constValue), &want); err != nil { + want, err := decodeJSONWithNumbers([]byte(constValue)) + if err != nil { return false } - return reflect.DeepEqual(got, want) + return jsonValuesEqual(got, want) +} + +func decodeJSONWithNumbers(data []byte) (interface{}, error) { + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.UseNumber() + var value interface{} + if err := decoder.Decode(&value); err != nil { + return nil, err + } + return value, nil +} + +func jsonValuesEqual(a, b interface{}) bool { + switch av := a.(type) { + case json.Number: + bv, ok := b.(json.Number) + if !ok { + return false + } + ar, aok := new(big.Rat).SetString(av.String()) + br, bok := new(big.Rat).SetString(bv.String()) + return aok && bok && ar.Cmp(br) == 0 + case map[string]interface{}: + bv, ok := b.(map[string]interface{}) + if !ok || len(av) != len(bv) { + return false + } + for key, value := range av { + other, ok := bv[key] + if !ok || !jsonValuesEqual(value, other) { + return false + } + } + return true + case []interface{}: + bv, ok := b.([]interface{}) + if !ok || len(av) != len(bv) { + return false + } + for i := range av { + if !jsonValuesEqual(av[i], bv[i]) { + return false + } + } + return true + default: + return reflect.DeepEqual(a, b) + } } func handleDefaultConstValue(tagValue string, val interface{}, tag reflect.StructTag) json.RawMessage { diff --git a/zSDKs/terraform-provider-testing/.speakeasy/gen.lock b/zSDKs/terraform-provider-testing/.speakeasy/gen.lock index a9345b240..67cd62b22 100644 --- a/zSDKs/terraform-provider-testing/.speakeasy/gen.lock +++ b/zSDKs/terraform-provider-testing/.speakeasy/gen.lock @@ -2422,7 +2422,7 @@ trackedFiles: internal/sdk/internal/utils/jq.go: last_write_checksum: sha1:2e75ed7a7db1f91e97dac1ac4ca7801b2beb69b5 internal/sdk/internal/utils/json.go: - last_write_checksum: sha1:e4afb6c5125227acd6366acac653831f4d01cd0c + last_write_checksum: sha1:5d331461a0348861323c12b9489fefa388dd6a76 internal/sdk/internal/utils/oauth2_credentials.go: last_write_checksum: sha1:f9218b6b3dbd11494cc353bf22eb37f0ca654a7d internal/sdk/internal/utils/oauth2_sessions.go: diff --git a/zSDKs/terraform-provider-testing/internal/sdk/internal/utils/json.go b/zSDKs/terraform-provider-testing/internal/sdk/internal/utils/json.go index 13a99d20d..83cf65606 100644 --- a/zSDKs/terraform-provider-testing/internal/sdk/internal/utils/json.go +++ b/zSDKs/terraform-provider-testing/internal/sdk/internal/utils/json.go @@ -434,14 +434,63 @@ func implementsJSONMarshaler(v interface{}) bool { } func constJSONValuesEqual(received json.RawMessage, constValue string) bool { - var got, want interface{} - if err := json.Unmarshal(received, &got); err != nil { + got, err := decodeJSONWithNumbers(received) + if err != nil { return false } - if err := json.Unmarshal([]byte(constValue), &want); err != nil { + want, err := decodeJSONWithNumbers([]byte(constValue)) + if err != nil { return false } - return reflect.DeepEqual(got, want) + return jsonValuesEqual(got, want) +} + +func decodeJSONWithNumbers(data []byte) (interface{}, error) { + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.UseNumber() + var value interface{} + if err := decoder.Decode(&value); err != nil { + return nil, err + } + return value, nil +} + +func jsonValuesEqual(a, b interface{}) bool { + switch av := a.(type) { + case json.Number: + bv, ok := b.(json.Number) + if !ok { + return false + } + ar, aok := new(big.Rat).SetString(av.String()) + br, bok := new(big.Rat).SetString(bv.String()) + return aok && bok && ar.Cmp(br) == 0 + case map[string]interface{}: + bv, ok := b.(map[string]interface{}) + if !ok || len(av) != len(bv) { + return false + } + for key, value := range av { + other, ok := bv[key] + if !ok || !jsonValuesEqual(value, other) { + return false + } + } + return true + case []interface{}: + bv, ok := b.([]interface{}) + if !ok || len(av) != len(bv) { + return false + } + for i := range av { + if !jsonValuesEqual(av[i], bv[i]) { + return false + } + } + return true + default: + return reflect.DeepEqual(a, b) + } } func handleDefaultConstValue(tagValue string, val interface{}, tag reflect.StructTag) json.RawMessage { From 957323e35a74a6daef7afc2d009342a33aeb3997 Mon Sep 17 00:00:00 2001 From: Ash Godfrey Date: Fri, 30 Oct 2026 12:08:05 +0000 Subject: [PATCH 03/22] fix(terraform): validate container consts strictly and prove them end to end Reject container consts whose value is null, whose array has uniqueItems (the server may return the elements in any order), or whose items are bigint, decimal or string-serialized numbers (the const JSON would not match the field's wire form). The mockserver's unmarshaler compares received const values structurally like the SDK does. Parser tests capture validation warnings and cover sets, nested arrays, null, mixed and bigint items, uuid items, default plus const, free-form and array-valued maps, and value type mismatches. Terraform acceptance tests assert the create request body carries only name and the four const values, that a read accepting differently formatted const values refreshes cleanly, and that the data source reads it. --- internal/schemas/handle_array_test.go | 228 +++++++++++++++++- internal/schemas/handle_object_test.go | 101 +++++++- internal/schemas/schemas.go | 33 ++- .../internal/sdk/utils/json.go.stmpl | 62 ++++- .../constcontainer_data_source_test.go | 64 +++++ .../provider/constcontainer_resource_test.go | 104 ++++++++ .../TestConstContainerDataSource/main.tf | 15 ++ .../main.tf | 11 + 8 files changed, 598 insertions(+), 20 deletions(-) create mode 100644 zSDKs/terraform-provider-testing/internal/provider/constcontainer_data_source_test.go create mode 100644 zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource_test.go create mode 100644 zSDKs/terraform-provider-testing/internal/provider/testdata/TestConstContainerDataSource/main.tf create mode 100644 zSDKs/terraform-provider-testing/internal/provider/testdata/TestConstContainerResourceLifecycle/main.tf diff --git a/internal/schemas/handle_array_test.go b/internal/schemas/handle_array_test.go index 5d4e71f1e..bef2e5030 100644 --- a/internal/schemas/handle_array_test.go +++ b/internal/schemas/handle_array_test.go @@ -2,12 +2,14 @@ package schemas import ( "context" + "strings" "testing" "github.com/speakeasy-api/openapi-generation/v2/internal/ast" "github.com/speakeasy-api/openapi-generation/v2/internal/features" "github.com/speakeasy-api/openapi-generation/v2/internal/testutils" "github.com/speakeasy-api/openapi-generation/v2/internal/types" + "github.com/speakeasy-api/openapi-generation/v2/pkg/logging" "github.com/speakeasy-api/openapi/pointer" config "github.com/speakeasy-api/sdk-gen-config" "github.com/stretchr/testify/assert" @@ -15,6 +17,21 @@ import ( "gopkg.in/yaml.v3" ) +func assertSingleWarning(t *testing.T, warnings []error, expected string) { + t.Helper() + if expected == "" { + require.Empty(t, warnings) + return + } + var matched []error + for _, warning := range warnings { + if strings.Contains(warning.Error(), expected) { + matched = append(matched, warning) + } + } + require.Len(t, matched, 1, "warnings: %v", warnings) +} + // TestHandleArray tests the handleArray method with various array scenarios func TestHandleArray(t *testing.T) { tests := []struct { @@ -25,6 +42,8 @@ func TestHandleArray(t *testing.T) { mockFeatures func() *testutils.MockFeaturesConfig // nil means use default (all features supported) isRequest *bool // nil means use default (false), otherwise use specified value expected *ast.FieldDef + // expectedWarning, when set, must match exactly one logged validation warning + expectedWarning string }{ { name: "StringArray", @@ -168,6 +187,208 @@ func TestHandleArray(t *testing.T) { WithValidations(&ast.Validations{}). Build()). Build(), + expectedWarning: "only arrays without uniqueItems and maps of scalar values are supported, omitting const", + }, + { + name: "SetWithConst", + schemasYAML: `TestSchema: + type: array + items: + type: string + uniqueItems: 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()). + WithLocation(&yaml.Node{Line: 9, Column: 7}). + WithValidations(&ast.Validations{ + UniqueItems: pointer.From(true), + }). + Build()). + Build(), + expectedWarning: "only arrays without uniqueItems and maps of scalar values are supported, omitting const", + }, + { + name: "ArrayWithConstNull", + schemasYAML: `TestSchema: + type: array + items: + type: string + const: null`, + 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(), + expectedWarning: "only arrays without uniqueItems and maps of scalar values are supported, omitting const", + }, + { + name: "ArrayWithConstMixedItems", + schemasYAML: `TestSchema: + type: array + items: + type: string + const: + - read + - 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(), + expectedWarning: "only arrays without uniqueItems and maps of scalar values are supported, omitting const", + }, + { + name: "ArrayWithConstBigIntItems", + schemasYAML: `TestSchema: + type: array + items: + type: integer + format: bigint + const: + - 1`, + schemaName: "TestSchema", + mockFeatures: func() *testutils.MockFeaturesConfig { + config := testutils.NewMockFeaturesConfig() + config.SupportedFeatures = map[features.Feature]bool{ + features.FeatureConstArrays: true, + features.FeatureConstsAndDefaults: true, + features.FeatureBigInt: true, + } + return config + }, + expected: testutils.NewFieldDef("bigints", + testutils.NewTypeDef(ast.DataTypeArray). + WithItemType(testutils.NewTypeDef(ast.DataTypeBigInt).WithLocation(&yaml.Node{Line: 11, Column: 9}).WithValidations(&ast.Validations{}).Build()). + WithLocation(&yaml.Node{Line: 9, Column: 7}). + WithValidations(&ast.Validations{}). + Build()). + Build(), + expectedWarning: "only arrays without uniqueItems and maps of scalar values are supported, omitting const", + }, + { + name: "ArrayWithConstUUIDItems", + schemasYAML: `TestSchema: + type: array + items: + type: string + format: uuid + const: + - 123e4567-e89b-12d3-a456-426614174000`, + 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("uuids", + testutils.NewTypeDef(ast.DataTypeArray). + WithItemType(testutils.NewTypeDef(ast.DataTypeUUID).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{}{"123e4567-e89b-12d3-a456-426614174000"}}). + Build(), + }, + { + name: "ArrayWithDefaultAndConst", + schemasYAML: `TestSchema: + type: array + items: + type: string + default: + - read + const: + - read`, + schemaName: "TestSchema", + mockFeatures: func() *testutils.MockFeaturesConfig { + config := testutils.NewMockFeaturesConfig() + config.SupportedFeatures = map[features.Feature]bool{ + features.FeatureConstArrays: true, + features.FeatureConstsAndDefaults: true, + features.FeatureDefaultArrays: 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()). + WithDefault(&ast.AnyValue{Value: []interface{}{"read"}}). + WithOptional(true). + WithConst(&ast.AnyValue{Value: []interface{}{"read"}}). + Build(), + }, + { + name: "NestedArrayWithConst", + schemasYAML: `TestSchema: + type: array + items: + type: array + items: + type: string + 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("arrays", + testutils.NewTypeDef(ast.DataTypeArray). + WithItemType( + testutils.NewTypeDef(ast.DataTypeArray). + WithItemType(testutils.NewTypeDef(ast.DataTypeString).WithLocation(&yaml.Node{Line: 13, Column: 11}).WithValidations(&ast.Validations{}).Build()). + WithLocation(&yaml.Node{Line: 11, Column: 9}). + WithValidations(&ast.Validations{}). + Build(), + ). + WithLocation(&yaml.Node{Line: 9, Column: 7}). + WithValidations(&ast.Validations{}). + Build()). + Build(), + expectedWarning: "only arrays without uniqueItems and maps of scalar values are supported, omitting const", }, { name: "ArrayWithMinMaxItems", @@ -291,6 +512,7 @@ func TestHandleArray(t *testing.T) { WithValidations(&ast.Validations{}). Build()). Build(), + expectedWarning: "only arrays without uniqueItems and maps of scalar values are supported, omitting const", }, { name: "ArrayWithExample", @@ -438,9 +660,13 @@ TestSchema: params.IsRequest = *tt.isRequest } + warningLogger := logging.NewWarningLogger(false, nil) + ctx := logging.WithWarningLogger(context.Background(), warningLogger) + // Call HandleSchema - let it handle nullable extraction and routing - result, err := schemas.HandleSchema(context.Background(), params) + result, err := schemas.HandleSchema(ctx, params) require.NoError(t, err) + assertSingleWarning(t, warningLogger.GetWarnings(), tt.expectedWarning) // Use deep comparison from the working test isEqual := testutils.DeepCompare(t, tt.expected, result) diff --git a/internal/schemas/handle_object_test.go b/internal/schemas/handle_object_test.go index 7e5906855..98ec89070 100644 --- a/internal/schemas/handle_object_test.go +++ b/internal/schemas/handle_object_test.go @@ -7,6 +7,7 @@ import ( "github.com/speakeasy-api/openapi-generation/v2/internal/ast" "github.com/speakeasy-api/openapi-generation/v2/internal/features" "github.com/speakeasy-api/openapi-generation/v2/internal/testutils" + "github.com/speakeasy-api/openapi-generation/v2/pkg/logging" config "github.com/speakeasy-api/sdk-gen-config" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -24,6 +25,8 @@ func TestHandleObject(t *testing.T) { isRequest *bool // nil means use default (false), otherwise use specified value serializationMethod *ast.SerializationMethod // nil means use default (JSON) expected *ast.FieldDef + // expectedWarning, when set, must match exactly one logged validation warning + expectedWarning string }{ { name: "BasicObject", @@ -340,6 +343,98 @@ func TestHandleObject(t *testing.T) { ). Build()). Build(), + expectedWarning: "only arrays without uniqueItems and maps of scalar values are supported, omitting const", + }, + { + name: "MapWithConstFreeFormValues", + schemasYAML: `TestSchema: + type: object + additionalProperties: true + 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.DataTypeAny). + Build(), + ). + Build()). + Build(), + expectedWarning: "only arrays without uniqueItems and maps of scalar values are supported, omitting const", + }, + { + name: "MapWithConstArrayValues", + schemasYAML: `TestSchema: + type: object + additionalProperties: + type: array + items: + 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.DataTypeArray). + WithItemType(testutils.NewTypeDef(ast.DataTypeString).WithLocation(&yaml.Node{Line: 13, Column: 11}).WithValidations(&ast.Validations{}).Build()). + WithLocation(&yaml.Node{Line: 11, Column: 9}). + WithValidations(&ast.Validations{}). + Build(), + ). + Build()). + Build(), + expectedWarning: "only arrays without uniqueItems and maps of scalar values are supported, omitting const", + }, + { + name: "MapWithConstValueTypeMismatch", + schemasYAML: `TestSchema: + type: object + additionalProperties: + type: integer + 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.DataTypeInteger). + WithLocation(&yaml.Node{Line: 11, Column: 9}). + WithValidations(&ast.Validations{}). + Build(), + ). + Build()). + Build(), + expectedWarning: "only arrays without uniqueItems and maps of scalar values are supported, omitting const", }, { name: "ObjectWithExample", @@ -2804,9 +2899,13 @@ TestSchema: params.IsRequest = *tt.isRequest } + warningLogger := logging.NewWarningLogger(false, nil) + ctx := logging.WithWarningLogger(context.Background(), warningLogger) + // Call HandleSchema - let it handle nullable extraction and routing - result, err := schemas.HandleSchema(context.Background(), params) + result, err := schemas.HandleSchema(ctx, params) require.NoError(t, err) + assertSingleWarning(t, warningLogger.GetWarnings(), tt.expectedWarning) // Use deep comparison from the working test isEqual := testutils.DeepCompare(t, tt.expected, result) diff --git a/internal/schemas/schemas.go b/internal/schemas/schemas.go index a63fc9414..9bd913051 100644 --- a/internal/schemas/schemas.go +++ b/internal/schemas/schemas.go @@ -1648,18 +1648,11 @@ func (s *Schemas) checkDefaultConformsToType(ctx context.Context, field *ast.Fie if v == nil { continue } - // null is a valid default for nullable fields - if v.Value == nil && field.Nullable { - continue - } - if v.Value == nil { - continue - } if pair.label == "const" && (field.Type.IsContainer() || field.Type.Type == ast.DataTypeClass) { if !constContainerValueSupported(v.Value, field.Type) { logging.LogWarning(ctx, "validation warning", errors.NewValidationWarning( - fmt.Sprintf("const value %v is not supported for type %q, only arrays and maps of scalar values are supported, omitting const", v.Value, dataType), + fmt.Sprintf("const value %v is not supported for type %q, only arrays without uniqueItems and maps of scalar values are supported, omitting const", v.Value, dataType), schema.GetPropertyNode("Const"), nil, )) *pair.val = nil @@ -1667,6 +1660,14 @@ func (s *Schemas) checkDefaultConformsToType(ctx context.Context, field *ast.Fie continue } + // null is a valid default for nullable fields + if v.Value == nil && field.Nullable { + continue + } + if v.Value == nil { + continue + } + if !defaultValueMatchesType(v.Value, dataType) { // Before clearing, try to coerce string values to the target type. // Many real-world specs have string defaults on numeric fields (e.g. default: "0.00"). @@ -1689,12 +1690,15 @@ func (s *Schemas) checkDefaultConformsToType(ctx context.Context, field *ast.Fie } func constContainerValueSupported(val any, typ *ast.TypeDef) bool { - if typ.ContainsNull { + if val == nil || typ.ContainsNull { return false } switch typ.Type { - case ast.DataTypeArray, ast.DataTypeSet: + case ast.DataTypeArray: + if typ.Validations != nil && typ.Validations.UniqueItems != nil && *typ.Validations.UniqueItems { + return false + } items, ok := val.([]any) if !ok { return false @@ -1729,14 +1733,9 @@ func constScalarMatchesType(val any, itemType *ast.TypeDef) bool { switch itemType.Type { case ast.DataTypeEnum: return itemType.Enum != nil && slices.Contains(itemType.Enum.Values, fmt.Sprint(val)) - case ast.DataTypeBoolean, ast.DataTypeInteger, ast.DataTypeInt32, ast.DataTypeBigInt, - ast.DataTypeNumber, ast.DataTypeFloat32, ast.DataTypeDecimal, + case ast.DataTypeBoolean, ast.DataTypeInteger, ast.DataTypeInt32, ast.DataTypeNumber, ast.DataTypeFloat32, ast.DataTypeString, ast.DataTypeDate, ast.DataTypeDateTime, ast.DataTypeUUID, ast.DataTypeDuration: - dataType := itemType.Type - if itemType.Format == "string" { - dataType = ast.DataTypeString - } - return defaultValueMatchesType(val, dataType) + return itemType.Format != "string" && defaultValueMatchesType(val, itemType.Type) default: return false } diff --git a/templates/templates/mockserver/auxiliary/internal/sdk/utils/json.go.stmpl b/templates/templates/mockserver/auxiliary/internal/sdk/utils/json.go.stmpl index ba33a3081..13a66c805 100644 --- a/templates/templates/mockserver/auxiliary/internal/sdk/utils/json.go.stmpl +++ b/templates/templates/mockserver/auxiliary/internal/sdk/utils/json.go.stmpl @@ -199,7 +199,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue { + if val != constValue && !constJSONValuesEqual(r, constValue) { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -422,6 +422,66 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } +func constJSONValuesEqual(received json.RawMessage, constValue string) bool { + got, err := decodeJSONWithNumbers(received) + if err != nil { + return false + } + want, err := decodeJSONWithNumbers([]byte(constValue)) + if err != nil { + return false + } + return jsonValuesEqual(got, want) +} + +func decodeJSONWithNumbers(data []byte) (interface{}, error) { + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.UseNumber() + var value interface{} + if err := decoder.Decode(&value); err != nil { + return nil, err + } + return value, nil +} + +func jsonValuesEqual(a, b interface{}) bool { + switch av := a.(type) { + case json.Number: + bv, ok := b.(json.Number) + if !ok { + return false + } + ar, aok := new(big.Rat).SetString(av.String()) + br, bok := new(big.Rat).SetString(bv.String()) + return aok && bok && ar.Cmp(br) == 0 + case map[string]interface{}: + bv, ok := b.(map[string]interface{}) + if !ok || len(av) != len(bv) { + return false + } + for key, value := range av { + other, ok := bv[key] + if !ok || !jsonValuesEqual(value, other) { + return false + } + } + return true + case []interface{}: + bv, ok := b.([]interface{}) + if !ok || len(av) != len(bv) { + return false + } + for i := range av { + if !jsonValuesEqual(av[i], bv[i]) { + return false + } + } + return true + default: + return reflect.DeepEqual(a, b) + } +} + func handleDefaultConstValue(tagValue string, val interface{}, tag reflect.StructTag) json.RawMessage { if tagValue == "null" { return []byte("null") diff --git a/zSDKs/terraform-provider-testing/internal/provider/constcontainer_data_source_test.go b/zSDKs/terraform-provider-testing/internal/provider/constcontainer_data_source_test.go new file mode 100644 index 000000000..2e283dd28 --- /dev/null +++ b/zSDKs/terraform-provider-testing/internal/provider/constcontainer_data_source_test.go @@ -0,0 +1,64 @@ +package provider_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-testing/compare" + "github.com/hashicorp/terraform-plugin-testing/config" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/statecheck" + "github.com/hashicorp/terraform-plugin-testing/tfjsonpath" + "github.com/hashicorp/terraform-provider-testing/internal/provider" + "github.com/hashicorp/terraform-provider-testing/internal/tfmockserver" +) + +// The data source schema hides the const properties and reads a response +// that carries them. +func TestConstContainerDataSource(t *testing.T) { + t.Parallel() + + endpoints := tfmockserver.ResourceEndpoints{ + Create: tfmockserver.Endpoints{ + { + Endpoint: "POST /v0/constcontainers", + }, + }, + Get: tfmockserver.Endpoints{ + { + Endpoint: "GET /v0/constcontainer/{id}", + }, + }, + Delete: tfmockserver.Endpoints{ + { + Endpoint: "DELETE /v0/constcontainer/{id}", + }, + }, + } + + mockServer := tfmockserver.StartServer(endpoints, t) + defer mockServer.Close() + + dataResourceAddress := "data.testing_const_container.test" + managedResourceAddress := "testing_const_container.test" + + resource.Test(t, resource.TestCase{ + Steps: []resource.TestStep{ + { + ConfigDirectory: config.TestNameDirectory(), + ProtoV6ProviderFactories: provider.GetTestProviders(), + ConfigVariables: config.Variables{ + "server_url": config.StringVariable(mockServer.URL), + }, + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.CompareValuePairs( + managedResourceAddress, + tfjsonpath.New("name"), + dataResourceAddress, + tfjsonpath.New("name"), + compare.ValuesSame(), + ), + }, + }, + }, + }) +} diff --git a/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource_test.go b/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource_test.go new file mode 100644 index 000000000..6fdbbb93b --- /dev/null +++ b/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource_test.go @@ -0,0 +1,104 @@ +package provider_test + +import ( + "net/http" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/config" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/knownvalue" + "github.com/hashicorp/terraform-plugin-testing/statecheck" + "github.com/hashicorp/terraform-plugin-testing/tfjsonpath" + "github.com/hashicorp/terraform-provider-testing/internal/provider" + "github.com/hashicorp/terraform-provider-testing/internal/tfmockserver" + "github.com/stretchr/testify/require" +) + +// The request schema declares const values on array and map properties. The +// provider must hide them from the resource schema and send them verbatim, +// and a read must accept the const values however the server formats them. +func TestConstContainerResourceLifecycle(t *testing.T) { + t.Parallel() + + endpoints := tfmockserver.ResourceEndpoints{ + Create: tfmockserver.Endpoints{ + { + Endpoint: "POST /v0/constcontainers", + }, + }, + Get: tfmockserver.Endpoints{ + { + Endpoint: "GET /v0/constcontainer/{id}", + // Return the const values with whitespace, map key order and + // number formatting the client did not send. + ResponseFuncWithStore: func(r *http.Request, w http.ResponseWriter, storedData map[string]any) { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(`{ + "id": "` + tfmockserver.StoreKey + `", + "name": "` + storedData["name"].(string) + `", + "empty_list": [ ], + "fixed_list": [ "read" , "write" ], + "empty_map": { }, + "fixed_map": { "max" : 1e1 } + }`)) + }, + }, + }, + Delete: tfmockserver.Endpoints{ + { + Endpoint: "DELETE /v0/constcontainer/{id}", + }, + }, + } + + mockServer := tfmockserver.StartServer(endpoints, t) + defer mockServer.Close() + + resourceAddress := "testing_const_container.test" + + resource.Test(t, resource.TestCase{ + Steps: []resource.TestStep{ + { + ConfigDirectory: config.TestNameDirectory(), + ProtoV6ProviderFactories: provider.GetTestProviders(), + ConfigVariables: config.Variables{ + "server_url": config.StringVariable(mockServer.URL), + }, + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue( + resourceAddress, + tfjsonpath.New("id"), + knownvalue.StringExact(tfmockserver.StoreKey), + ), + statecheck.ExpectKnownValue( + resourceAddress, + tfjsonpath.New("name"), + knownvalue.StringExact("test-const-container"), + ), + }, + }, + { + ConfigDirectory: config.TestNameDirectory(), + ProtoV6ProviderFactories: provider.GetTestProviders(), + ConfigVariables: config.Variables{ + "server_url": config.StringVariable(mockServer.URL), + }, + ResourceName: resourceAddress, + ImportState: true, + ImportStateId: tfmockserver.StoreKey, + ImportStateVerify: true, + }, + }, + }) + + creates := endpoints.Create[0].Requests.Bodies() + require.Len(t, creates, 1) + body := creates[0] + tfmockserver.AssertRequestBodyField(t, body, "name", "test-const-container") + tfmockserver.AssertRequestBodyFieldEmptyArray(t, body, "empty_list") + tfmockserver.AssertRequestBodyFieldArray(t, body, "fixed_list", []any{"read", "write"}) + tfmockserver.AssertRequestBodyField(t, body, "empty_map", map[string]any{}) + tfmockserver.AssertRequestBodyField(t, body, "fixed_map", map[string]any{"max": float64(10)}) + require.Len(t, body, 5, "request body carries only name and the four const fields: %v", body) +} diff --git a/zSDKs/terraform-provider-testing/internal/provider/testdata/TestConstContainerDataSource/main.tf b/zSDKs/terraform-provider-testing/internal/provider/testdata/TestConstContainerDataSource/main.tf new file mode 100644 index 000000000..7e4ad2f49 --- /dev/null +++ b/zSDKs/terraform-provider-testing/internal/provider/testdata/TestConstContainerDataSource/main.tf @@ -0,0 +1,15 @@ +variable "server_url" { + type = string +} + +provider "testing" { + server_url = var.server_url +} + +resource "testing_const_container" "test" { + name = "test-const-container" +} + +data "testing_const_container" "test" { + id = testing_const_container.test.id +} diff --git a/zSDKs/terraform-provider-testing/internal/provider/testdata/TestConstContainerResourceLifecycle/main.tf b/zSDKs/terraform-provider-testing/internal/provider/testdata/TestConstContainerResourceLifecycle/main.tf new file mode 100644 index 000000000..c8a2e559a --- /dev/null +++ b/zSDKs/terraform-provider-testing/internal/provider/testdata/TestConstContainerResourceLifecycle/main.tf @@ -0,0 +1,11 @@ +variable "server_url" { + type = string +} + +provider "testing" { + server_url = var.server_url +} + +resource "testing_const_container" "test" { + name = "test-const-container" +} From c9f8bfc7c9808f18291e938e7bf63a2db68b3a74 Mon Sep 17 00:00:00 2001 From: Ash Godfrey Date: Fri, 30 Oct 2026 13:27:16 +0000 Subject: [PATCH 04/22] chore: regenerate the review mockservers' JSON utils for structural const comparison --- zSDKs/mcp-typescript/.speakeasy/gen.lock | 2 +- .../mockserver/internal/sdk/utils/json.go | 62 ++++++++++++++++++- zSDKs/sdk-cli/.speakeasy/gen.lock | 2 +- .../mockserver/internal/sdk/utils/json.go | 62 ++++++++++++++++++- zSDKs/sdk-csharp/.speakeasy/gen.lock | 2 +- .../mockserver/internal/sdk/utils/json.go | 62 ++++++++++++++++++- zSDKs/sdk-go/.speakeasy/gen.lock | 2 +- .../mockserver/internal/sdk/utils/json.go | 62 ++++++++++++++++++- zSDKs/sdk-javav2/.speakeasy/gen.lock | 2 +- .../mockserver/internal/sdk/utils/json.go | 62 ++++++++++++++++++- zSDKs/sdk-mcp-typescript/.speakeasy/gen.lock | 2 +- .../mockserver/internal/sdk/utils/json.go | 62 ++++++++++++++++++- zSDKs/sdk-pythonv2/.speakeasy/gen.lock | 2 +- .../mockserver/internal/sdk/utils/json.go | 62 ++++++++++++++++++- zSDKs/sdk-ruby/.speakeasy/gen.lock | 2 +- .../mockserver/internal/sdk/utils/json.go | 62 ++++++++++++++++++- zSDKs/sdk-typescriptv2/.speakeasy/gen.lock | 2 +- .../mockserver/internal/sdk/utils/json.go | 62 ++++++++++++++++++- 18 files changed, 558 insertions(+), 18 deletions(-) diff --git a/zSDKs/mcp-typescript/.speakeasy/gen.lock b/zSDKs/mcp-typescript/.speakeasy/gen.lock index c96b942b9..686c00fd9 100644 --- a/zSDKs/mcp-typescript/.speakeasy/gen.lock +++ b/zSDKs/mcp-typescript/.speakeasy/gen.lock @@ -412,7 +412,7 @@ trackedFiles: src/__tests__/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd src/__tests__/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:5e20daa1ddf6ebe49c4c0f34fd0051c43e6b7ff9 + last_write_checksum: sha1:a79de1a199a6ae298f673b1aa07de4d7ee61eff5 src/__tests__/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 src/__tests__/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go b/zSDKs/mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go index 6ec0f8449..260fa7a12 100644 --- a/zSDKs/mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go @@ -201,7 +201,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue { + if val != constValue && !constJSONValuesEqual(r, constValue) { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -424,6 +424,66 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } +func constJSONValuesEqual(received json.RawMessage, constValue string) bool { + got, err := decodeJSONWithNumbers(received) + if err != nil { + return false + } + want, err := decodeJSONWithNumbers([]byte(constValue)) + if err != nil { + return false + } + return jsonValuesEqual(got, want) +} + +func decodeJSONWithNumbers(data []byte) (interface{}, error) { + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.UseNumber() + var value interface{} + if err := decoder.Decode(&value); err != nil { + return nil, err + } + return value, nil +} + +func jsonValuesEqual(a, b interface{}) bool { + switch av := a.(type) { + case json.Number: + bv, ok := b.(json.Number) + if !ok { + return false + } + ar, aok := new(big.Rat).SetString(av.String()) + br, bok := new(big.Rat).SetString(bv.String()) + return aok && bok && ar.Cmp(br) == 0 + case map[string]interface{}: + bv, ok := b.(map[string]interface{}) + if !ok || len(av) != len(bv) { + return false + } + for key, value := range av { + other, ok := bv[key] + if !ok || !jsonValuesEqual(value, other) { + return false + } + } + return true + case []interface{}: + bv, ok := b.([]interface{}) + if !ok || len(av) != len(bv) { + return false + } + for i := range av { + if !jsonValuesEqual(av[i], bv[i]) { + return false + } + } + return true + default: + return reflect.DeepEqual(a, b) + } +} + func handleDefaultConstValue(tagValue string, val interface{}, tag reflect.StructTag) json.RawMessage { if tagValue == "null" { return []byte("null") diff --git a/zSDKs/sdk-cli/.speakeasy/gen.lock b/zSDKs/sdk-cli/.speakeasy/gen.lock index 01a168821..a772c6cf4 100644 --- a/zSDKs/sdk-cli/.speakeasy/gen.lock +++ b/zSDKs/sdk-cli/.speakeasy/gen.lock @@ -1076,7 +1076,7 @@ trackedFiles: tests/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd tests/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:5e20daa1ddf6ebe49c4c0f34fd0051c43e6b7ff9 + last_write_checksum: sha1:a79de1a199a6ae298f673b1aa07de4d7ee61eff5 tests/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 tests/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-cli/tests/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-cli/tests/mockserver/internal/sdk/utils/json.go index 6ec0f8449..260fa7a12 100644 --- a/zSDKs/sdk-cli/tests/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-cli/tests/mockserver/internal/sdk/utils/json.go @@ -201,7 +201,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue { + if val != constValue && !constJSONValuesEqual(r, constValue) { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -424,6 +424,66 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } +func constJSONValuesEqual(received json.RawMessage, constValue string) bool { + got, err := decodeJSONWithNumbers(received) + if err != nil { + return false + } + want, err := decodeJSONWithNumbers([]byte(constValue)) + if err != nil { + return false + } + return jsonValuesEqual(got, want) +} + +func decodeJSONWithNumbers(data []byte) (interface{}, error) { + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.UseNumber() + var value interface{} + if err := decoder.Decode(&value); err != nil { + return nil, err + } + return value, nil +} + +func jsonValuesEqual(a, b interface{}) bool { + switch av := a.(type) { + case json.Number: + bv, ok := b.(json.Number) + if !ok { + return false + } + ar, aok := new(big.Rat).SetString(av.String()) + br, bok := new(big.Rat).SetString(bv.String()) + return aok && bok && ar.Cmp(br) == 0 + case map[string]interface{}: + bv, ok := b.(map[string]interface{}) + if !ok || len(av) != len(bv) { + return false + } + for key, value := range av { + other, ok := bv[key] + if !ok || !jsonValuesEqual(value, other) { + return false + } + } + return true + case []interface{}: + bv, ok := b.([]interface{}) + if !ok || len(av) != len(bv) { + return false + } + for i := range av { + if !jsonValuesEqual(av[i], bv[i]) { + return false + } + } + return true + default: + return reflect.DeepEqual(a, b) + } +} + func handleDefaultConstValue(tagValue string, val interface{}, tag reflect.StructTag) json.RawMessage { if tagValue == "null" { return []byte("null") diff --git a/zSDKs/sdk-csharp/.speakeasy/gen.lock b/zSDKs/sdk-csharp/.speakeasy/gen.lock index aa8317805..84edf7c89 100644 --- a/zSDKs/sdk-csharp/.speakeasy/gen.lock +++ b/zSDKs/sdk-csharp/.speakeasy/gen.lock @@ -458,7 +458,7 @@ trackedFiles: Tests/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd Tests/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:5e20daa1ddf6ebe49c4c0f34fd0051c43e6b7ff9 + last_write_checksum: sha1:a79de1a199a6ae298f673b1aa07de4d7ee61eff5 Tests/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 Tests/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-csharp/Tests/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-csharp/Tests/mockserver/internal/sdk/utils/json.go index 6ec0f8449..260fa7a12 100644 --- a/zSDKs/sdk-csharp/Tests/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-csharp/Tests/mockserver/internal/sdk/utils/json.go @@ -201,7 +201,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue { + if val != constValue && !constJSONValuesEqual(r, constValue) { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -424,6 +424,66 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } +func constJSONValuesEqual(received json.RawMessage, constValue string) bool { + got, err := decodeJSONWithNumbers(received) + if err != nil { + return false + } + want, err := decodeJSONWithNumbers([]byte(constValue)) + if err != nil { + return false + } + return jsonValuesEqual(got, want) +} + +func decodeJSONWithNumbers(data []byte) (interface{}, error) { + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.UseNumber() + var value interface{} + if err := decoder.Decode(&value); err != nil { + return nil, err + } + return value, nil +} + +func jsonValuesEqual(a, b interface{}) bool { + switch av := a.(type) { + case json.Number: + bv, ok := b.(json.Number) + if !ok { + return false + } + ar, aok := new(big.Rat).SetString(av.String()) + br, bok := new(big.Rat).SetString(bv.String()) + return aok && bok && ar.Cmp(br) == 0 + case map[string]interface{}: + bv, ok := b.(map[string]interface{}) + if !ok || len(av) != len(bv) { + return false + } + for key, value := range av { + other, ok := bv[key] + if !ok || !jsonValuesEqual(value, other) { + return false + } + } + return true + case []interface{}: + bv, ok := b.([]interface{}) + if !ok || len(av) != len(bv) { + return false + } + for i := range av { + if !jsonValuesEqual(av[i], bv[i]) { + return false + } + } + return true + default: + return reflect.DeepEqual(a, b) + } +} + func handleDefaultConstValue(tagValue string, val interface{}, tag reflect.StructTag) json.RawMessage { if tagValue == "null" { return []byte("null") diff --git a/zSDKs/sdk-go/.speakeasy/gen.lock b/zSDKs/sdk-go/.speakeasy/gen.lock index 539bb5a12..a4c19d0f0 100644 --- a/zSDKs/sdk-go/.speakeasy/gen.lock +++ b/zSDKs/sdk-go/.speakeasy/gen.lock @@ -1233,7 +1233,7 @@ trackedFiles: tests/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd tests/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:5e20daa1ddf6ebe49c4c0f34fd0051c43e6b7ff9 + last_write_checksum: sha1:a79de1a199a6ae298f673b1aa07de4d7ee61eff5 tests/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 tests/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-go/tests/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-go/tests/mockserver/internal/sdk/utils/json.go index 6ec0f8449..260fa7a12 100644 --- a/zSDKs/sdk-go/tests/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-go/tests/mockserver/internal/sdk/utils/json.go @@ -201,7 +201,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue { + if val != constValue && !constJSONValuesEqual(r, constValue) { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -424,6 +424,66 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } +func constJSONValuesEqual(received json.RawMessage, constValue string) bool { + got, err := decodeJSONWithNumbers(received) + if err != nil { + return false + } + want, err := decodeJSONWithNumbers([]byte(constValue)) + if err != nil { + return false + } + return jsonValuesEqual(got, want) +} + +func decodeJSONWithNumbers(data []byte) (interface{}, error) { + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.UseNumber() + var value interface{} + if err := decoder.Decode(&value); err != nil { + return nil, err + } + return value, nil +} + +func jsonValuesEqual(a, b interface{}) bool { + switch av := a.(type) { + case json.Number: + bv, ok := b.(json.Number) + if !ok { + return false + } + ar, aok := new(big.Rat).SetString(av.String()) + br, bok := new(big.Rat).SetString(bv.String()) + return aok && bok && ar.Cmp(br) == 0 + case map[string]interface{}: + bv, ok := b.(map[string]interface{}) + if !ok || len(av) != len(bv) { + return false + } + for key, value := range av { + other, ok := bv[key] + if !ok || !jsonValuesEqual(value, other) { + return false + } + } + return true + case []interface{}: + bv, ok := b.([]interface{}) + if !ok || len(av) != len(bv) { + return false + } + for i := range av { + if !jsonValuesEqual(av[i], bv[i]) { + return false + } + } + return true + default: + return reflect.DeepEqual(a, b) + } +} + func handleDefaultConstValue(tagValue string, val interface{}, tag reflect.StructTag) json.RawMessage { if tagValue == "null" { return []byte("null") diff --git a/zSDKs/sdk-javav2/.speakeasy/gen.lock b/zSDKs/sdk-javav2/.speakeasy/gen.lock index 09dbfdbce..28631b003 100644 --- a/zSDKs/sdk-javav2/.speakeasy/gen.lock +++ b/zSDKs/sdk-javav2/.speakeasy/gen.lock @@ -1983,7 +1983,7 @@ trackedFiles: tests/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd tests/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:5e20daa1ddf6ebe49c4c0f34fd0051c43e6b7ff9 + last_write_checksum: sha1:a79de1a199a6ae298f673b1aa07de4d7ee61eff5 tests/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 tests/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-javav2/tests/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-javav2/tests/mockserver/internal/sdk/utils/json.go index 6ec0f8449..260fa7a12 100644 --- a/zSDKs/sdk-javav2/tests/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-javav2/tests/mockserver/internal/sdk/utils/json.go @@ -201,7 +201,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue { + if val != constValue && !constJSONValuesEqual(r, constValue) { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -424,6 +424,66 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } +func constJSONValuesEqual(received json.RawMessage, constValue string) bool { + got, err := decodeJSONWithNumbers(received) + if err != nil { + return false + } + want, err := decodeJSONWithNumbers([]byte(constValue)) + if err != nil { + return false + } + return jsonValuesEqual(got, want) +} + +func decodeJSONWithNumbers(data []byte) (interface{}, error) { + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.UseNumber() + var value interface{} + if err := decoder.Decode(&value); err != nil { + return nil, err + } + return value, nil +} + +func jsonValuesEqual(a, b interface{}) bool { + switch av := a.(type) { + case json.Number: + bv, ok := b.(json.Number) + if !ok { + return false + } + ar, aok := new(big.Rat).SetString(av.String()) + br, bok := new(big.Rat).SetString(bv.String()) + return aok && bok && ar.Cmp(br) == 0 + case map[string]interface{}: + bv, ok := b.(map[string]interface{}) + if !ok || len(av) != len(bv) { + return false + } + for key, value := range av { + other, ok := bv[key] + if !ok || !jsonValuesEqual(value, other) { + return false + } + } + return true + case []interface{}: + bv, ok := b.([]interface{}) + if !ok || len(av) != len(bv) { + return false + } + for i := range av { + if !jsonValuesEqual(av[i], bv[i]) { + return false + } + } + return true + default: + return reflect.DeepEqual(a, b) + } +} + func handleDefaultConstValue(tagValue string, val interface{}, tag reflect.StructTag) json.RawMessage { if tagValue == "null" { return []byte("null") diff --git a/zSDKs/sdk-mcp-typescript/.speakeasy/gen.lock b/zSDKs/sdk-mcp-typescript/.speakeasy/gen.lock index 416c39fa8..94dc901ab 100644 --- a/zSDKs/sdk-mcp-typescript/.speakeasy/gen.lock +++ b/zSDKs/sdk-mcp-typescript/.speakeasy/gen.lock @@ -370,7 +370,7 @@ trackedFiles: src/__tests__/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd src/__tests__/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:5e20daa1ddf6ebe49c4c0f34fd0051c43e6b7ff9 + last_write_checksum: sha1:a79de1a199a6ae298f673b1aa07de4d7ee61eff5 src/__tests__/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 src/__tests__/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go index 6ec0f8449..260fa7a12 100644 --- a/zSDKs/sdk-mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go @@ -201,7 +201,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue { + if val != constValue && !constJSONValuesEqual(r, constValue) { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -424,6 +424,66 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } +func constJSONValuesEqual(received json.RawMessage, constValue string) bool { + got, err := decodeJSONWithNumbers(received) + if err != nil { + return false + } + want, err := decodeJSONWithNumbers([]byte(constValue)) + if err != nil { + return false + } + return jsonValuesEqual(got, want) +} + +func decodeJSONWithNumbers(data []byte) (interface{}, error) { + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.UseNumber() + var value interface{} + if err := decoder.Decode(&value); err != nil { + return nil, err + } + return value, nil +} + +func jsonValuesEqual(a, b interface{}) bool { + switch av := a.(type) { + case json.Number: + bv, ok := b.(json.Number) + if !ok { + return false + } + ar, aok := new(big.Rat).SetString(av.String()) + br, bok := new(big.Rat).SetString(bv.String()) + return aok && bok && ar.Cmp(br) == 0 + case map[string]interface{}: + bv, ok := b.(map[string]interface{}) + if !ok || len(av) != len(bv) { + return false + } + for key, value := range av { + other, ok := bv[key] + if !ok || !jsonValuesEqual(value, other) { + return false + } + } + return true + case []interface{}: + bv, ok := b.([]interface{}) + if !ok || len(av) != len(bv) { + return false + } + for i := range av { + if !jsonValuesEqual(av[i], bv[i]) { + return false + } + } + return true + default: + return reflect.DeepEqual(a, b) + } +} + func handleDefaultConstValue(tagValue string, val interface{}, tag reflect.StructTag) json.RawMessage { if tagValue == "null" { return []byte("null") diff --git a/zSDKs/sdk-pythonv2/.speakeasy/gen.lock b/zSDKs/sdk-pythonv2/.speakeasy/gen.lock index 433d499af..052fae58e 100644 --- a/zSDKs/sdk-pythonv2/.speakeasy/gen.lock +++ b/zSDKs/sdk-pythonv2/.speakeasy/gen.lock @@ -1176,7 +1176,7 @@ trackedFiles: tests/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd tests/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:5e20daa1ddf6ebe49c4c0f34fd0051c43e6b7ff9 + last_write_checksum: sha1:a79de1a199a6ae298f673b1aa07de4d7ee61eff5 tests/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 tests/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-pythonv2/tests/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-pythonv2/tests/mockserver/internal/sdk/utils/json.go index 6ec0f8449..260fa7a12 100644 --- a/zSDKs/sdk-pythonv2/tests/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-pythonv2/tests/mockserver/internal/sdk/utils/json.go @@ -201,7 +201,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue { + if val != constValue && !constJSONValuesEqual(r, constValue) { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -424,6 +424,66 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } +func constJSONValuesEqual(received json.RawMessage, constValue string) bool { + got, err := decodeJSONWithNumbers(received) + if err != nil { + return false + } + want, err := decodeJSONWithNumbers([]byte(constValue)) + if err != nil { + return false + } + return jsonValuesEqual(got, want) +} + +func decodeJSONWithNumbers(data []byte) (interface{}, error) { + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.UseNumber() + var value interface{} + if err := decoder.Decode(&value); err != nil { + return nil, err + } + return value, nil +} + +func jsonValuesEqual(a, b interface{}) bool { + switch av := a.(type) { + case json.Number: + bv, ok := b.(json.Number) + if !ok { + return false + } + ar, aok := new(big.Rat).SetString(av.String()) + br, bok := new(big.Rat).SetString(bv.String()) + return aok && bok && ar.Cmp(br) == 0 + case map[string]interface{}: + bv, ok := b.(map[string]interface{}) + if !ok || len(av) != len(bv) { + return false + } + for key, value := range av { + other, ok := bv[key] + if !ok || !jsonValuesEqual(value, other) { + return false + } + } + return true + case []interface{}: + bv, ok := b.([]interface{}) + if !ok || len(av) != len(bv) { + return false + } + for i := range av { + if !jsonValuesEqual(av[i], bv[i]) { + return false + } + } + return true + default: + return reflect.DeepEqual(a, b) + } +} + func handleDefaultConstValue(tagValue string, val interface{}, tag reflect.StructTag) json.RawMessage { if tagValue == "null" { return []byte("null") diff --git a/zSDKs/sdk-ruby/.speakeasy/gen.lock b/zSDKs/sdk-ruby/.speakeasy/gen.lock index 37b28302d..c213d72a8 100644 --- a/zSDKs/sdk-ruby/.speakeasy/gen.lock +++ b/zSDKs/sdk-ruby/.speakeasy/gen.lock @@ -1835,7 +1835,7 @@ trackedFiles: test/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd test/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:5e20daa1ddf6ebe49c4c0f34fd0051c43e6b7ff9 + last_write_checksum: sha1:a79de1a199a6ae298f673b1aa07de4d7ee61eff5 test/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 test/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-ruby/test/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-ruby/test/mockserver/internal/sdk/utils/json.go index 6ec0f8449..260fa7a12 100644 --- a/zSDKs/sdk-ruby/test/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-ruby/test/mockserver/internal/sdk/utils/json.go @@ -201,7 +201,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue { + if val != constValue && !constJSONValuesEqual(r, constValue) { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -424,6 +424,66 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } +func constJSONValuesEqual(received json.RawMessage, constValue string) bool { + got, err := decodeJSONWithNumbers(received) + if err != nil { + return false + } + want, err := decodeJSONWithNumbers([]byte(constValue)) + if err != nil { + return false + } + return jsonValuesEqual(got, want) +} + +func decodeJSONWithNumbers(data []byte) (interface{}, error) { + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.UseNumber() + var value interface{} + if err := decoder.Decode(&value); err != nil { + return nil, err + } + return value, nil +} + +func jsonValuesEqual(a, b interface{}) bool { + switch av := a.(type) { + case json.Number: + bv, ok := b.(json.Number) + if !ok { + return false + } + ar, aok := new(big.Rat).SetString(av.String()) + br, bok := new(big.Rat).SetString(bv.String()) + return aok && bok && ar.Cmp(br) == 0 + case map[string]interface{}: + bv, ok := b.(map[string]interface{}) + if !ok || len(av) != len(bv) { + return false + } + for key, value := range av { + other, ok := bv[key] + if !ok || !jsonValuesEqual(value, other) { + return false + } + } + return true + case []interface{}: + bv, ok := b.([]interface{}) + if !ok || len(av) != len(bv) { + return false + } + for i := range av { + if !jsonValuesEqual(av[i], bv[i]) { + return false + } + } + return true + default: + return reflect.DeepEqual(a, b) + } +} + func handleDefaultConstValue(tagValue string, val interface{}, tag reflect.StructTag) json.RawMessage { if tagValue == "null" { return []byte("null") diff --git a/zSDKs/sdk-typescriptv2/.speakeasy/gen.lock b/zSDKs/sdk-typescriptv2/.speakeasy/gen.lock index d7a926475..fb8e4efd4 100644 --- a/zSDKs/sdk-typescriptv2/.speakeasy/gen.lock +++ b/zSDKs/sdk-typescriptv2/.speakeasy/gen.lock @@ -867,7 +867,7 @@ trackedFiles: src/__tests__/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd src/__tests__/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:5e20daa1ddf6ebe49c4c0f34fd0051c43e6b7ff9 + last_write_checksum: sha1:a79de1a199a6ae298f673b1aa07de4d7ee61eff5 src/__tests__/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 src/__tests__/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-typescriptv2/src/__tests__/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-typescriptv2/src/__tests__/mockserver/internal/sdk/utils/json.go index 6ec0f8449..260fa7a12 100644 --- a/zSDKs/sdk-typescriptv2/src/__tests__/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-typescriptv2/src/__tests__/mockserver/internal/sdk/utils/json.go @@ -201,7 +201,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue { + if val != constValue && !constJSONValuesEqual(r, constValue) { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -424,6 +424,66 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } +func constJSONValuesEqual(received json.RawMessage, constValue string) bool { + got, err := decodeJSONWithNumbers(received) + if err != nil { + return false + } + want, err := decodeJSONWithNumbers([]byte(constValue)) + if err != nil { + return false + } + return jsonValuesEqual(got, want) +} + +func decodeJSONWithNumbers(data []byte) (interface{}, error) { + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.UseNumber() + var value interface{} + if err := decoder.Decode(&value); err != nil { + return nil, err + } + return value, nil +} + +func jsonValuesEqual(a, b interface{}) bool { + switch av := a.(type) { + case json.Number: + bv, ok := b.(json.Number) + if !ok { + return false + } + ar, aok := new(big.Rat).SetString(av.String()) + br, bok := new(big.Rat).SetString(bv.String()) + return aok && bok && ar.Cmp(br) == 0 + case map[string]interface{}: + bv, ok := b.(map[string]interface{}) + if !ok || len(av) != len(bv) { + return false + } + for key, value := range av { + other, ok := bv[key] + if !ok || !jsonValuesEqual(value, other) { + return false + } + } + return true + case []interface{}: + bv, ok := b.([]interface{}) + if !ok || len(av) != len(bv) { + return false + } + for i := range av { + if !jsonValuesEqual(av[i], bv[i]) { + return false + } + } + return true + default: + return reflect.DeepEqual(a, b) + } +} + func handleDefaultConstValue(tagValue string, val interface{}, tag reflect.StructTag) json.RawMessage { if tagValue == "null" { return []byte("null") From 4108a85c44a899e80222e4a47d31e289c419422c Mon Sep 17 00:00:00 2001 From: Ash Godfrey Date: Fri, 30 Oct 2026 13:51:19 +0000 Subject: [PATCH 05/22] fix(terraform): keep structural const comparison to containers and allow string items with a string format Only a const tag that holds a JSON array or object is compared structurally, so a scalar string const such as 1.0 no longer accepts the JSON number 1 in either the SDK or the mockserver. The string-serialized-number guard applies to numeric item types only. The review const container gains a two-key map so the acceptance test covers key-order-insensitive comparison on read. --- internal/schemas/schemas.go | 5 +- templates/perms.go | 226 +++++++++--------- .../{{getUtilsLocation}}/json.go.stmpl | 6 +- .../internal/sdk/utils/json.go.stmpl | 6 +- tests/specs/review-terraform.yaml | 2 + zSDKs/mcp-typescript/.speakeasy/gen.lock | 2 +- .../mockserver/internal/sdk/utils/json.go | 6 +- zSDKs/sdk-cli/.speakeasy/gen.lock | 4 +- .../internal/sdk/sdkinternal/utils/json.go | 6 +- .../mockserver/internal/sdk/utils/json.go | 6 +- zSDKs/sdk-csharp/.speakeasy/gen.lock | 2 +- .../mockserver/internal/sdk/utils/json.go | 6 +- zSDKs/sdk-go/.speakeasy/gen.lock | 4 +- zSDKs/sdk-go/internal/utils/json.go | 6 +- .../mockserver/internal/sdk/utils/json.go | 6 +- zSDKs/sdk-javav2/.speakeasy/gen.lock | 2 +- .../mockserver/internal/sdk/utils/json.go | 6 +- zSDKs/sdk-mcp-typescript/.speakeasy/gen.lock | 2 +- .../mockserver/internal/sdk/utils/json.go | 6 +- zSDKs/sdk-pythonv2/.speakeasy/gen.lock | 2 +- .../mockserver/internal/sdk/utils/json.go | 6 +- zSDKs/sdk-ruby/.speakeasy/gen.lock | 2 +- .../mockserver/internal/sdk/utils/json.go | 6 +- zSDKs/sdk-typescriptv2/.speakeasy/gen.lock | 2 +- .../mockserver/internal/sdk/utils/json.go | 6 +- .../.speakeasy/gen.lock | 14 +- .../provider/constcontainer_resource_test.go | 4 +- .../internal/sdk/internal/utils/json.go | 6 +- .../models/shared/constcontainerrequest.go | 4 +- .../models/shared/constcontainerresponse.go | 4 +- 30 files changed, 212 insertions(+), 153 deletions(-) diff --git a/internal/schemas/schemas.go b/internal/schemas/schemas.go index 9bd913051..7dfa6964b 100644 --- a/internal/schemas/schemas.go +++ b/internal/schemas/schemas.go @@ -1733,9 +1733,10 @@ func constScalarMatchesType(val any, itemType *ast.TypeDef) bool { switch itemType.Type { case ast.DataTypeEnum: return itemType.Enum != nil && slices.Contains(itemType.Enum.Values, fmt.Sprint(val)) - case ast.DataTypeBoolean, ast.DataTypeInteger, ast.DataTypeInt32, ast.DataTypeNumber, ast.DataTypeFloat32, - ast.DataTypeString, ast.DataTypeDate, ast.DataTypeDateTime, ast.DataTypeUUID, ast.DataTypeDuration: + case ast.DataTypeInteger, ast.DataTypeInt32, ast.DataTypeNumber, ast.DataTypeFloat32: return itemType.Format != "string" && defaultValueMatchesType(val, itemType.Type) + case ast.DataTypeBoolean, ast.DataTypeString, ast.DataTypeDate, ast.DataTypeDateTime, ast.DataTypeUUID, ast.DataTypeDuration: + return defaultValueMatchesType(val, itemType.Type) default: return false } diff --git a/templates/perms.go b/templates/perms.go index ca046ab3a..5da351967 100644 --- a/templates/perms.go +++ b/templates/perms.go @@ -2547,119 +2547,119 @@ var fileMode = map[string]fs.FileMode{ "templates/unity/auxiliary/{{ getSDKTopLevelFolder }}/{{ getPackageId }}.csproj.stmpl": 0o644, "templates/unity/auxiliary/{{ getSDKTopLevelFolder }}/{{getErrorsLocation}}": 0o20000000755, "templates/unity/auxiliary/{{ getSDKTopLevelFolder }}/{{getErrorsLocation}}/{{getDefaultErrorFileName}}.cs.stmpl": 0o644, - "templates/unity/config.ts": 0o644, - "templates/unity/enum.cs.stmpl": 0o644, - "templates/unity/error.cs.stmpl": 0o644, - "templates/unity/examples.ts": 0o644, - "templates/unity/exclusions.ts": 0o644, - "templates/unity/features.ts": 0o644, - "templates/unity/includes": 0o20000000755, - "templates/unity/includes/annotations.ts": 0o644, - "templates/unity/includes/documentation.ts": 0o644, - "templates/unity/includes/enums.ts": 0o644, - "templates/unity/includes/errors.ts": 0o644, - "templates/unity/includes/imports.ts": 0o644, - "templates/unity/includes/index.ts": 0o644, - "templates/unity/includes/models.ts": 0o644, - "templates/unity/includes/modelusage.ts": 0o644, - "templates/unity/includes/namespaces.ts": 0o644, - "templates/unity/includes/pagination.ts": 0o644, - "templates/unity/includes/responses.ts": 0o644, - "templates/unity/includes/sanitization.ts": 0o644, - "templates/unity/includes/security.ts": 0o644, - "templates/unity/includes/serverusage.ts": 0o644, - "templates/unity/includes/templating.ts": 0o644, - "templates/unity/includes/unimplemented.ts": 0o644, - "templates/unity/includes/utils.ts": 0o644, - "templates/unity/main.ts": 0o644, - "templates/unity/method.cs.stmpl": 0o644, - "templates/unity/model.cs.stmpl": 0o644, - "templates/unity/modelfile.cs.stmpl": 0o644, - "templates/unity/pagination.cs.stmpl": 0o644, - "templates/unity/readme": 0o20000000755, - "templates/unity/readme/errors.stmpl": 0o644, - "templates/unity/readme/installation.stmpl": 0o644, - "templates/unity/readme/pagination.stmpl": 0o644, - "templates/unity/readme/security.stmpl": 0o644, - "templates/unity/sdk.cs.stmpl": 0o644, - "templates/unity/servers.cs.stmpl": 0o644, - "templates/unity/standalone.ts": 0o644, - "templates/unity/subsdk.cs.stmpl": 0o644, - "templates/unity/tests": 0o20000000755, - "templates/unity/tests/Project": 0o20000000755, - "templates/unity/tests/Project/.gitignore": 0o644, - "templates/unity/tests/Project/Assets": 0o20000000755, - "templates/unity/tests/Project/Assets/Tests": 0o20000000755, - "templates/unity/tests/Project/Assets/Tests/CommonHelpers.cs": 0o644, - "templates/unity/tests/Project/Assets/Tests/Tests.asmdef.stmpl": 0o644, - "templates/unity/tests/Project/Assets/Tests/Tests.meta": 0o644, - "templates/unity/tests/Project/Assets/Tests/UnityTestUtils.cs": 0o644, - "templates/unity/tests/Project/Assets/Tests/base.unity": 0o644, - "templates/unity/tests/Project/Assets/Tests/base.unity.meta": 0o644, - "templates/unity/tests/Project/Packages": 0o20000000755, - "templates/unity/tests/Project/Packages/manifest.json": 0o644, - "templates/unity/tests/Project/Packages/packages-lock.json": 0o644, - "templates/unity/tests/Project/ProjectSettings": 0o20000000755, - "templates/unity/tests/Project/ProjectSettings/AudioManager.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/ClusterInputManager.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/DynamicsManager.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/EditorBuildSettings.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/EditorSettings.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/GraphicsSettings.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/InputManager.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/MemorySettings.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/NavMeshAreas.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/PackageManagerSettings.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/Physics2DSettings.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/PresetManager.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/ProjectSettings.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/ProjectVersion.txt": 0o644, - "templates/unity/tests/Project/ProjectSettings/QualitySettings.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/SceneTemplateSettings.json": 0o644, - "templates/unity/tests/Project/ProjectSettings/TagManager.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/TimeManager.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/UnityConnectSettings.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/VFXManager.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/VersionControlSettings.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/boot.config": 0o644, - "templates/unity/tests/Project/Tests.csproj.stmpl": 0o644, - "templates/unity/tests/Tests": 0o20000000755, - "templates/unity/tests/Tests/client-credentials": 0o20000000755, - "templates/unity/tests/Tests/client-credentials/ClientCredentialsShould.cs": 0o644, - "templates/unity/tests/Tests/primary": 0o20000000755, - "templates/unity/tests/Tests/primary/AuthShould.cs": 0o644, - "templates/unity/tests/Tests/primary/ErrorsShould.cs": 0o644, - "templates/unity/tests/Tests/primary/FlatteningShould.cs": 0o644, - "templates/unity/tests/Tests/primary/GlobalsAdditionalShould.cs": 0o644, - "templates/unity/tests/Tests/primary/Helpers.cs": 0o644, - "templates/unity/tests/Tests/primary/MultiLevelShould.cs": 0o644, - "templates/unity/tests/Tests/primary/PaginationShould.cs": 0o644, - "templates/unity/tests/Tests/primary/ParametersShould.cs": 0o644, - "templates/unity/tests/Tests/primary/RequestBodiesShould.cs": 0o644, - "templates/unity/tests/Tests/primary/ResponseBodiesShould.cs": 0o644, - "templates/unity/tests/Tests/primary/ServersShould.cs": 0o644, - "templates/unity/tests/Tests/primary/TelemetryShould.cs.stmpl": 0o644, - "templates/unity/tests/Tests/primary/UnionsShould.cs": 0o644, - "templates/unity/tests/Tests/quaternary": 0o20000000755, - "templates/unity/tests/Tests/quaternary/AuthShould.cs": 0o644, - "templates/unity/tests/Tests/quaternary/ServersShould.cs": 0o644, - "templates/unity/tests/Tests/secondary": 0o20000000755, - "templates/unity/tests/Tests/secondary/AuthShould.cs": 0o644, - "templates/unity/tests/Tests/secondary/ServersShould.cs": 0o644, - "templates/unity/tests/Tests/tertiary": 0o20000000755, - "templates/unity/tests/Tests/tertiary/AuthShould.cs": 0o644, - "templates/unity/tests/Tests/tertiary/ServersShould.cs": 0o644, - "templates/unity/testusage": 0o20000000755, - "templates/unity/testusage/testusage.csproj.stmpl": 0o644, - "templates/unity/tsconfig.json": 0o644, - "templates/unity/union.cs.stmpl": 0o644, - "templates/unity/usage": 0o20000000755, - "templates/unity/usage/call.stmpl": 0o644, - "templates/unity/usage/errors.stmpl": 0o644, - "templates/unity/usage/init.stmpl": 0o644, - "templates/unity/usage/pagination.stmpl": 0o644, - "templates/unity/usage/result.stmpl": 0o644, - "templates/unity/usage/snippet.stmpl": 0o644, + "templates/unity/config.ts": 0o644, + "templates/unity/enum.cs.stmpl": 0o644, + "templates/unity/error.cs.stmpl": 0o644, + "templates/unity/examples.ts": 0o644, + "templates/unity/exclusions.ts": 0o644, + "templates/unity/features.ts": 0o644, + "templates/unity/includes": 0o20000000755, + "templates/unity/includes/annotations.ts": 0o644, + "templates/unity/includes/documentation.ts": 0o644, + "templates/unity/includes/enums.ts": 0o644, + "templates/unity/includes/errors.ts": 0o644, + "templates/unity/includes/imports.ts": 0o644, + "templates/unity/includes/index.ts": 0o644, + "templates/unity/includes/models.ts": 0o644, + "templates/unity/includes/modelusage.ts": 0o644, + "templates/unity/includes/namespaces.ts": 0o644, + "templates/unity/includes/pagination.ts": 0o644, + "templates/unity/includes/responses.ts": 0o644, + "templates/unity/includes/sanitization.ts": 0o644, + "templates/unity/includes/security.ts": 0o644, + "templates/unity/includes/serverusage.ts": 0o644, + "templates/unity/includes/templating.ts": 0o644, + "templates/unity/includes/unimplemented.ts": 0o644, + "templates/unity/includes/utils.ts": 0o644, + "templates/unity/main.ts": 0o644, + "templates/unity/method.cs.stmpl": 0o644, + "templates/unity/model.cs.stmpl": 0o644, + "templates/unity/modelfile.cs.stmpl": 0o644, + "templates/unity/pagination.cs.stmpl": 0o644, + "templates/unity/readme": 0o20000000755, + "templates/unity/readme/errors.stmpl": 0o644, + "templates/unity/readme/installation.stmpl": 0o644, + "templates/unity/readme/pagination.stmpl": 0o644, + "templates/unity/readme/security.stmpl": 0o644, + "templates/unity/sdk.cs.stmpl": 0o644, + "templates/unity/servers.cs.stmpl": 0o644, + "templates/unity/standalone.ts": 0o644, + "templates/unity/subsdk.cs.stmpl": 0o644, + "templates/unity/tests": 0o20000000755, + "templates/unity/tests/Project": 0o20000000755, + "templates/unity/tests/Project/.gitignore": 0o644, + "templates/unity/tests/Project/Assets": 0o20000000755, + "templates/unity/tests/Project/Assets/Tests": 0o20000000755, + "templates/unity/tests/Project/Assets/Tests/CommonHelpers.cs": 0o644, + "templates/unity/tests/Project/Assets/Tests/Tests.asmdef.stmpl": 0o644, + "templates/unity/tests/Project/Assets/Tests/Tests.meta": 0o644, + "templates/unity/tests/Project/Assets/Tests/UnityTestUtils.cs": 0o644, + "templates/unity/tests/Project/Assets/Tests/base.unity": 0o644, + "templates/unity/tests/Project/Assets/Tests/base.unity.meta": 0o644, + "templates/unity/tests/Project/Packages": 0o20000000755, + "templates/unity/tests/Project/Packages/manifest.json": 0o644, + "templates/unity/tests/Project/Packages/packages-lock.json": 0o644, + "templates/unity/tests/Project/ProjectSettings": 0o20000000755, + "templates/unity/tests/Project/ProjectSettings/AudioManager.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/ClusterInputManager.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/DynamicsManager.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/EditorBuildSettings.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/EditorSettings.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/GraphicsSettings.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/InputManager.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/MemorySettings.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/NavMeshAreas.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/PackageManagerSettings.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/Physics2DSettings.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/PresetManager.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/ProjectSettings.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/ProjectVersion.txt": 0o644, + "templates/unity/tests/Project/ProjectSettings/QualitySettings.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/SceneTemplateSettings.json": 0o644, + "templates/unity/tests/Project/ProjectSettings/TagManager.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/TimeManager.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/UnityConnectSettings.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/VFXManager.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/VersionControlSettings.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/boot.config": 0o644, + "templates/unity/tests/Project/Tests.csproj.stmpl": 0o644, + "templates/unity/tests/Tests": 0o20000000755, + "templates/unity/tests/Tests/client-credentials": 0o20000000755, + "templates/unity/tests/Tests/client-credentials/ClientCredentialsShould.cs": 0o644, + "templates/unity/tests/Tests/primary": 0o20000000755, + "templates/unity/tests/Tests/primary/AuthShould.cs": 0o644, + "templates/unity/tests/Tests/primary/ErrorsShould.cs": 0o644, + "templates/unity/tests/Tests/primary/FlatteningShould.cs": 0o644, + "templates/unity/tests/Tests/primary/GlobalsAdditionalShould.cs": 0o644, + "templates/unity/tests/Tests/primary/Helpers.cs": 0o644, + "templates/unity/tests/Tests/primary/MultiLevelShould.cs": 0o644, + "templates/unity/tests/Tests/primary/PaginationShould.cs": 0o644, + "templates/unity/tests/Tests/primary/ParametersShould.cs": 0o644, + "templates/unity/tests/Tests/primary/RequestBodiesShould.cs": 0o644, + "templates/unity/tests/Tests/primary/ResponseBodiesShould.cs": 0o644, + "templates/unity/tests/Tests/primary/ServersShould.cs": 0o644, + "templates/unity/tests/Tests/primary/TelemetryShould.cs.stmpl": 0o644, + "templates/unity/tests/Tests/primary/UnionsShould.cs": 0o644, + "templates/unity/tests/Tests/quaternary": 0o20000000755, + "templates/unity/tests/Tests/quaternary/AuthShould.cs": 0o644, + "templates/unity/tests/Tests/quaternary/ServersShould.cs": 0o644, + "templates/unity/tests/Tests/secondary": 0o20000000755, + "templates/unity/tests/Tests/secondary/AuthShould.cs": 0o644, + "templates/unity/tests/Tests/secondary/ServersShould.cs": 0o644, + "templates/unity/tests/Tests/tertiary": 0o20000000755, + "templates/unity/tests/Tests/tertiary/AuthShould.cs": 0o644, + "templates/unity/tests/Tests/tertiary/ServersShould.cs": 0o644, + "templates/unity/testusage": 0o20000000755, + "templates/unity/testusage/testusage.csproj.stmpl": 0o644, + "templates/unity/tsconfig.json": 0o644, + "templates/unity/union.cs.stmpl": 0o644, + "templates/unity/usage": 0o20000000755, + "templates/unity/usage/call.stmpl": 0o644, + "templates/unity/usage/errors.stmpl": 0o644, + "templates/unity/usage/init.stmpl": 0o644, + "templates/unity/usage/pagination.stmpl": 0o644, + "templates/unity/usage/result.stmpl": 0o644, + "templates/unity/usage/snippet.stmpl": 0o644, } // IsBinary returns true if the given path is a known binary file. diff --git a/templates/templates/go/auxiliary/{{getUtilsLocation}}/json.go.stmpl b/templates/templates/go/auxiliary/{{getUtilsLocation}}/json.go.stmpl index e8da8c543..5a65140cc 100644 --- a/templates/templates/go/auxiliary/{{getUtilsLocation}}/json.go.stmpl +++ b/templates/templates/go/auxiliary/{{getUtilsLocation}}/json.go.stmpl @@ -215,7 +215,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue && !constJSONValuesEqual(r, constValue) { + if val != constValue && !(isJSONContainer(constValue) && constJSONValuesEqual(r, constValue)) { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -447,6 +447,10 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } +func isJSONContainer(value string) bool { + return strings.HasPrefix(value, "[") || strings.HasPrefix(value, "{") +} + func constJSONValuesEqual(received json.RawMessage, constValue string) bool { got, err := decodeJSONWithNumbers(received) if err != nil { diff --git a/templates/templates/mockserver/auxiliary/internal/sdk/utils/json.go.stmpl b/templates/templates/mockserver/auxiliary/internal/sdk/utils/json.go.stmpl index 13a66c805..eaa6aea80 100644 --- a/templates/templates/mockserver/auxiliary/internal/sdk/utils/json.go.stmpl +++ b/templates/templates/mockserver/auxiliary/internal/sdk/utils/json.go.stmpl @@ -199,7 +199,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue && !constJSONValuesEqual(r, constValue) { + if val != constValue && !(isJSONContainer(constValue) && constJSONValuesEqual(r, constValue)) { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -422,6 +422,10 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } +func isJSONContainer(value string) bool { + return strings.HasPrefix(value, "[") || strings.HasPrefix(value, "{") +} + func constJSONValuesEqual(received json.RawMessage, constValue string) bool { got, err := decodeJSONWithNumbers(received) if err != nil { diff --git a/tests/specs/review-terraform.yaml b/tests/specs/review-terraform.yaml index 4651ffcb2..0038bd887 100644 --- a/tests/specs/review-terraform.yaml +++ b/tests/specs/review-terraform.yaml @@ -5999,6 +5999,7 @@ components: type: integer const: max: 10 + min: 1 required: - name - empty_list @@ -6039,6 +6040,7 @@ components: type: integer const: max: 10 + min: 1 DiscriminatedUnionCreateRequest: x-speakeasy-entity: DiscriminatedUnion type: object diff --git a/zSDKs/mcp-typescript/.speakeasy/gen.lock b/zSDKs/mcp-typescript/.speakeasy/gen.lock index 686c00fd9..b1b69b2f3 100644 --- a/zSDKs/mcp-typescript/.speakeasy/gen.lock +++ b/zSDKs/mcp-typescript/.speakeasy/gen.lock @@ -412,7 +412,7 @@ trackedFiles: src/__tests__/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd src/__tests__/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:a79de1a199a6ae298f673b1aa07de4d7ee61eff5 + last_write_checksum: sha1:66bc354bf281916b0ee3bb77bdb0f173d82dab38 src/__tests__/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 src/__tests__/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go b/zSDKs/mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go index 260fa7a12..e53a81f39 100644 --- a/zSDKs/mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go @@ -201,7 +201,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue && !constJSONValuesEqual(r, constValue) { + if val != constValue && !(isJSONContainer(constValue) && constJSONValuesEqual(r, constValue)) { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -424,6 +424,10 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } +func isJSONContainer(value string) bool { + return strings.HasPrefix(value, "[") || strings.HasPrefix(value, "{") +} + func constJSONValuesEqual(received json.RawMessage, constValue string) bool { got, err := decodeJSONWithNumbers(received) if err != nil { diff --git a/zSDKs/sdk-cli/.speakeasy/gen.lock b/zSDKs/sdk-cli/.speakeasy/gen.lock index a772c6cf4..e253c0618 100644 --- a/zSDKs/sdk-cli/.speakeasy/gen.lock +++ b/zSDKs/sdk-cli/.speakeasy/gen.lock @@ -602,7 +602,7 @@ trackedFiles: internal/sdk/sdkinternal/utils/headers.go: last_write_checksum: sha1:1b0bd68e1ea0bce8c5a42b5de9fd020fede7aecc internal/sdk/sdkinternal/utils/json.go: - last_write_checksum: sha1:7230262498cf1d11a4ca8e4b12e3e9354f1db635 + last_write_checksum: sha1:ec04c01892273a2e2d2436075ea3d290468ef74c internal/sdk/sdkinternal/utils/oauth2_credentials.go: last_write_checksum: sha1:f9218b6b3dbd11494cc353bf22eb37f0ca654a7d internal/sdk/sdkinternal/utils/oauth2_sessions.go: @@ -1076,7 +1076,7 @@ trackedFiles: tests/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd tests/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:a79de1a199a6ae298f673b1aa07de4d7ee61eff5 + last_write_checksum: sha1:66bc354bf281916b0ee3bb77bdb0f173d82dab38 tests/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 tests/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-cli/internal/sdk/sdkinternal/utils/json.go b/zSDKs/sdk-cli/internal/sdk/sdkinternal/utils/json.go index 9c7d5d75f..8f3ee92e1 100644 --- a/zSDKs/sdk-cli/internal/sdk/sdkinternal/utils/json.go +++ b/zSDKs/sdk-cli/internal/sdk/sdkinternal/utils/json.go @@ -216,7 +216,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue && !constJSONValuesEqual(r, constValue) { + if val != constValue && !(isJSONContainer(constValue) && constJSONValuesEqual(r, constValue)) { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -446,6 +446,10 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } +func isJSONContainer(value string) bool { + return strings.HasPrefix(value, "[") || strings.HasPrefix(value, "{") +} + func constJSONValuesEqual(received json.RawMessage, constValue string) bool { got, err := decodeJSONWithNumbers(received) if err != nil { diff --git a/zSDKs/sdk-cli/tests/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-cli/tests/mockserver/internal/sdk/utils/json.go index 260fa7a12..e53a81f39 100644 --- a/zSDKs/sdk-cli/tests/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-cli/tests/mockserver/internal/sdk/utils/json.go @@ -201,7 +201,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue && !constJSONValuesEqual(r, constValue) { + if val != constValue && !(isJSONContainer(constValue) && constJSONValuesEqual(r, constValue)) { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -424,6 +424,10 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } +func isJSONContainer(value string) bool { + return strings.HasPrefix(value, "[") || strings.HasPrefix(value, "{") +} + func constJSONValuesEqual(received json.RawMessage, constValue string) bool { got, err := decodeJSONWithNumbers(received) if err != nil { diff --git a/zSDKs/sdk-csharp/.speakeasy/gen.lock b/zSDKs/sdk-csharp/.speakeasy/gen.lock index 84edf7c89..1d8118815 100644 --- a/zSDKs/sdk-csharp/.speakeasy/gen.lock +++ b/zSDKs/sdk-csharp/.speakeasy/gen.lock @@ -458,7 +458,7 @@ trackedFiles: Tests/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd Tests/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:a79de1a199a6ae298f673b1aa07de4d7ee61eff5 + last_write_checksum: sha1:66bc354bf281916b0ee3bb77bdb0f173d82dab38 Tests/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 Tests/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-csharp/Tests/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-csharp/Tests/mockserver/internal/sdk/utils/json.go index 260fa7a12..e53a81f39 100644 --- a/zSDKs/sdk-csharp/Tests/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-csharp/Tests/mockserver/internal/sdk/utils/json.go @@ -201,7 +201,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue && !constJSONValuesEqual(r, constValue) { + if val != constValue && !(isJSONContainer(constValue) && constJSONValuesEqual(r, constValue)) { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -424,6 +424,10 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } +func isJSONContainer(value string) bool { + return strings.HasPrefix(value, "[") || strings.HasPrefix(value, "{") +} + func constJSONValuesEqual(received json.RawMessage, constValue string) bool { got, err := decodeJSONWithNumbers(received) if err != nil { diff --git a/zSDKs/sdk-go/.speakeasy/gen.lock b/zSDKs/sdk-go/.speakeasy/gen.lock index a4c19d0f0..4a929a26a 100644 --- a/zSDKs/sdk-go/.speakeasy/gen.lock +++ b/zSDKs/sdk-go/.speakeasy/gen.lock @@ -713,7 +713,7 @@ trackedFiles: internal/utils/headers.go: last_write_checksum: sha1:e529ca3d7ab96a091021bcd471ba2cbef50286b3 internal/utils/json.go: - last_write_checksum: sha1:031133cd77b7fb3478635075efe7f830be401140 + last_write_checksum: sha1:990470ab3df4c670d7110b3d598bd4c1185ffb53 internal/utils/pathparams.go: last_write_checksum: sha1:a092fc31b7c8fac29c359ddfa8bf2e02763fa097 internal/utils/queryparams.go: @@ -1233,7 +1233,7 @@ trackedFiles: tests/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd tests/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:a79de1a199a6ae298f673b1aa07de4d7ee61eff5 + last_write_checksum: sha1:66bc354bf281916b0ee3bb77bdb0f173d82dab38 tests/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 tests/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-go/internal/utils/json.go b/zSDKs/sdk-go/internal/utils/json.go index 906ea3072..bfdf9ac73 100644 --- a/zSDKs/sdk-go/internal/utils/json.go +++ b/zSDKs/sdk-go/internal/utils/json.go @@ -216,7 +216,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue && !constJSONValuesEqual(r, constValue) { + if val != constValue && !(isJSONContainer(constValue) && constJSONValuesEqual(r, constValue)) { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -446,6 +446,10 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } +func isJSONContainer(value string) bool { + return strings.HasPrefix(value, "[") || strings.HasPrefix(value, "{") +} + func constJSONValuesEqual(received json.RawMessage, constValue string) bool { got, err := decodeJSONWithNumbers(received) if err != nil { diff --git a/zSDKs/sdk-go/tests/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-go/tests/mockserver/internal/sdk/utils/json.go index 260fa7a12..e53a81f39 100644 --- a/zSDKs/sdk-go/tests/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-go/tests/mockserver/internal/sdk/utils/json.go @@ -201,7 +201,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue && !constJSONValuesEqual(r, constValue) { + if val != constValue && !(isJSONContainer(constValue) && constJSONValuesEqual(r, constValue)) { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -424,6 +424,10 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } +func isJSONContainer(value string) bool { + return strings.HasPrefix(value, "[") || strings.HasPrefix(value, "{") +} + func constJSONValuesEqual(received json.RawMessage, constValue string) bool { got, err := decodeJSONWithNumbers(received) if err != nil { diff --git a/zSDKs/sdk-javav2/.speakeasy/gen.lock b/zSDKs/sdk-javav2/.speakeasy/gen.lock index 28631b003..10dde5753 100644 --- a/zSDKs/sdk-javav2/.speakeasy/gen.lock +++ b/zSDKs/sdk-javav2/.speakeasy/gen.lock @@ -1983,7 +1983,7 @@ trackedFiles: tests/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd tests/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:a79de1a199a6ae298f673b1aa07de4d7ee61eff5 + last_write_checksum: sha1:66bc354bf281916b0ee3bb77bdb0f173d82dab38 tests/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 tests/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-javav2/tests/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-javav2/tests/mockserver/internal/sdk/utils/json.go index 260fa7a12..e53a81f39 100644 --- a/zSDKs/sdk-javav2/tests/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-javav2/tests/mockserver/internal/sdk/utils/json.go @@ -201,7 +201,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue && !constJSONValuesEqual(r, constValue) { + if val != constValue && !(isJSONContainer(constValue) && constJSONValuesEqual(r, constValue)) { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -424,6 +424,10 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } +func isJSONContainer(value string) bool { + return strings.HasPrefix(value, "[") || strings.HasPrefix(value, "{") +} + func constJSONValuesEqual(received json.RawMessage, constValue string) bool { got, err := decodeJSONWithNumbers(received) if err != nil { diff --git a/zSDKs/sdk-mcp-typescript/.speakeasy/gen.lock b/zSDKs/sdk-mcp-typescript/.speakeasy/gen.lock index 94dc901ab..d3faa3767 100644 --- a/zSDKs/sdk-mcp-typescript/.speakeasy/gen.lock +++ b/zSDKs/sdk-mcp-typescript/.speakeasy/gen.lock @@ -370,7 +370,7 @@ trackedFiles: src/__tests__/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd src/__tests__/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:a79de1a199a6ae298f673b1aa07de4d7ee61eff5 + last_write_checksum: sha1:66bc354bf281916b0ee3bb77bdb0f173d82dab38 src/__tests__/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 src/__tests__/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go index 260fa7a12..e53a81f39 100644 --- a/zSDKs/sdk-mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go @@ -201,7 +201,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue && !constJSONValuesEqual(r, constValue) { + if val != constValue && !(isJSONContainer(constValue) && constJSONValuesEqual(r, constValue)) { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -424,6 +424,10 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } +func isJSONContainer(value string) bool { + return strings.HasPrefix(value, "[") || strings.HasPrefix(value, "{") +} + func constJSONValuesEqual(received json.RawMessage, constValue string) bool { got, err := decodeJSONWithNumbers(received) if err != nil { diff --git a/zSDKs/sdk-pythonv2/.speakeasy/gen.lock b/zSDKs/sdk-pythonv2/.speakeasy/gen.lock index 052fae58e..5201d758e 100644 --- a/zSDKs/sdk-pythonv2/.speakeasy/gen.lock +++ b/zSDKs/sdk-pythonv2/.speakeasy/gen.lock @@ -1176,7 +1176,7 @@ trackedFiles: tests/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd tests/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:a79de1a199a6ae298f673b1aa07de4d7ee61eff5 + last_write_checksum: sha1:66bc354bf281916b0ee3bb77bdb0f173d82dab38 tests/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 tests/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-pythonv2/tests/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-pythonv2/tests/mockserver/internal/sdk/utils/json.go index 260fa7a12..e53a81f39 100644 --- a/zSDKs/sdk-pythonv2/tests/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-pythonv2/tests/mockserver/internal/sdk/utils/json.go @@ -201,7 +201,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue && !constJSONValuesEqual(r, constValue) { + if val != constValue && !(isJSONContainer(constValue) && constJSONValuesEqual(r, constValue)) { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -424,6 +424,10 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } +func isJSONContainer(value string) bool { + return strings.HasPrefix(value, "[") || strings.HasPrefix(value, "{") +} + func constJSONValuesEqual(received json.RawMessage, constValue string) bool { got, err := decodeJSONWithNumbers(received) if err != nil { diff --git a/zSDKs/sdk-ruby/.speakeasy/gen.lock b/zSDKs/sdk-ruby/.speakeasy/gen.lock index c213d72a8..430bdb819 100644 --- a/zSDKs/sdk-ruby/.speakeasy/gen.lock +++ b/zSDKs/sdk-ruby/.speakeasy/gen.lock @@ -1835,7 +1835,7 @@ trackedFiles: test/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd test/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:a79de1a199a6ae298f673b1aa07de4d7ee61eff5 + last_write_checksum: sha1:66bc354bf281916b0ee3bb77bdb0f173d82dab38 test/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 test/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-ruby/test/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-ruby/test/mockserver/internal/sdk/utils/json.go index 260fa7a12..e53a81f39 100644 --- a/zSDKs/sdk-ruby/test/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-ruby/test/mockserver/internal/sdk/utils/json.go @@ -201,7 +201,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue && !constJSONValuesEqual(r, constValue) { + if val != constValue && !(isJSONContainer(constValue) && constJSONValuesEqual(r, constValue)) { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -424,6 +424,10 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } +func isJSONContainer(value string) bool { + return strings.HasPrefix(value, "[") || strings.HasPrefix(value, "{") +} + func constJSONValuesEqual(received json.RawMessage, constValue string) bool { got, err := decodeJSONWithNumbers(received) if err != nil { diff --git a/zSDKs/sdk-typescriptv2/.speakeasy/gen.lock b/zSDKs/sdk-typescriptv2/.speakeasy/gen.lock index fb8e4efd4..c5dedec78 100644 --- a/zSDKs/sdk-typescriptv2/.speakeasy/gen.lock +++ b/zSDKs/sdk-typescriptv2/.speakeasy/gen.lock @@ -867,7 +867,7 @@ trackedFiles: src/__tests__/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd src/__tests__/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:a79de1a199a6ae298f673b1aa07de4d7ee61eff5 + last_write_checksum: sha1:66bc354bf281916b0ee3bb77bdb0f173d82dab38 src/__tests__/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 src/__tests__/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-typescriptv2/src/__tests__/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-typescriptv2/src/__tests__/mockserver/internal/sdk/utils/json.go index 260fa7a12..e53a81f39 100644 --- a/zSDKs/sdk-typescriptv2/src/__tests__/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-typescriptv2/src/__tests__/mockserver/internal/sdk/utils/json.go @@ -201,7 +201,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue && !constJSONValuesEqual(r, constValue) { + if val != constValue && !(isJSONContainer(constValue) && constJSONValuesEqual(r, constValue)) { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -424,6 +424,10 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } +func isJSONContainer(value string) bool { + return strings.HasPrefix(value, "[") || strings.HasPrefix(value, "{") +} + func constJSONValuesEqual(received json.RawMessage, constValue string) bool { got, err := decodeJSONWithNumbers(received) if err != nil { diff --git a/zSDKs/terraform-provider-testing/.speakeasy/gen.lock b/zSDKs/terraform-provider-testing/.speakeasy/gen.lock index 18d06ead2..63f45c876 100644 --- a/zSDKs/terraform-provider-testing/.speakeasy/gen.lock +++ b/zSDKs/terraform-provider-testing/.speakeasy/gen.lock @@ -1,7 +1,7 @@ lockVersion: 2.0.0 id: review-sdk-test-id management: - docChecksum: b5e0ebee357a2bc4151a20fb322e722c + docChecksum: 7e117218d1b4664bc4b4b9360bfcebcf docVersion: 0.0.1 speakeasyVersion: internal generationVersion: internal @@ -2422,7 +2422,7 @@ trackedFiles: internal/sdk/internal/utils/jq.go: last_write_checksum: sha1:2e75ed7a7db1f91e97dac1ac4ca7801b2beb69b5 internal/sdk/internal/utils/json.go: - last_write_checksum: sha1:5d331461a0348861323c12b9489fefa388dd6a76 + last_write_checksum: sha1:998dc779115be1a9c7ebebf7221a4d8424141c6f internal/sdk/internal/utils/oauth2_credentials.go: last_write_checksum: sha1:f9218b6b3dbd11494cc353bf22eb37f0ca654a7d internal/sdk/internal/utils/oauth2_sessions.go: @@ -3098,9 +3098,9 @@ trackedFiles: internal/sdk/models/shared/basicsearch.go: last_write_checksum: sha1:ebc8943a31148f7623c5f8ff940dd81c1b52f23d internal/sdk/models/shared/constcontainerrequest.go: - last_write_checksum: sha1:3cdb41c7b838e1c15dd0483ce7f685fdc6e7d480 + last_write_checksum: sha1:08457751e87b9249244c6a938fbe5db31a5561e8 internal/sdk/models/shared/constcontainerresponse.go: - last_write_checksum: sha1:d94a9a07729db01d47dd0ff890a363406d2169e5 + last_write_checksum: sha1:6b4bad498e1a600df8da2db7d8e6e7ce1aa999aa internal/sdk/models/shared/discriminatedobject.go: last_write_checksum: sha1:9bb5641a1bcb27ec59c1f16d82d8a251ec733286 internal/sdk/models/shared/discriminatedunionarraycreaterequest.go: @@ -6051,10 +6051,10 @@ examples: create-const-container: speakeasy-default-create-const-container: requestBody: - application/json: {"name": "", "empty_list": [], "fixed_list": ["read", "write"], "empty_map": {}, "fixed_map": {"max": 10}} + application/json: {"name": "", "empty_list": [], "fixed_list": ["read", "write"], "empty_map": {}, "fixed_map": {"max": 10, "min": 1}} responses: "200": - application/json: {"empty_list": [], "fixed_list": ["read", "write"], "empty_map": {}, "fixed_map": {"max": 10}} + application/json: {"empty_list": [], "fixed_list": ["read", "write"], "empty_map": {}, "fixed_map": {"max": 10, "min": 1}} get-const-container: speakeasy-default-get-const-container: parameters: @@ -6062,7 +6062,7 @@ examples: id: "" responses: "200": - application/json: {"empty_list": [], "fixed_list": ["read", "write"], "empty_map": {}, "fixed_map": {"max": 10}} + application/json: {"empty_list": [], "fixed_list": ["read", "write"], "empty_map": {}, "fixed_map": {"min": 1, "max": 10}} delete-const-container: speakeasy-default-delete-const-container: parameters: diff --git a/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource_test.go b/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource_test.go index 6fdbbb93b..2f6e978e7 100644 --- a/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource_test.go +++ b/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource_test.go @@ -40,7 +40,7 @@ func TestConstContainerResourceLifecycle(t *testing.T) { "empty_list": [ ], "fixed_list": [ "read" , "write" ], "empty_map": { }, - "fixed_map": { "max" : 1e1 } + "fixed_map": { "min" : 1, "max" : 1e1 } }`)) }, }, @@ -99,6 +99,6 @@ func TestConstContainerResourceLifecycle(t *testing.T) { tfmockserver.AssertRequestBodyFieldEmptyArray(t, body, "empty_list") tfmockserver.AssertRequestBodyFieldArray(t, body, "fixed_list", []any{"read", "write"}) tfmockserver.AssertRequestBodyField(t, body, "empty_map", map[string]any{}) - tfmockserver.AssertRequestBodyField(t, body, "fixed_map", map[string]any{"max": float64(10)}) + tfmockserver.AssertRequestBodyField(t, body, "fixed_map", map[string]any{"max": float64(10), "min": float64(1)}) require.Len(t, body, 5, "request body carries only name and the four const fields: %v", body) } diff --git a/zSDKs/terraform-provider-testing/internal/sdk/internal/utils/json.go b/zSDKs/terraform-provider-testing/internal/sdk/internal/utils/json.go index 83cf65606..a15f0804f 100644 --- a/zSDKs/terraform-provider-testing/internal/sdk/internal/utils/json.go +++ b/zSDKs/terraform-provider-testing/internal/sdk/internal/utils/json.go @@ -214,7 +214,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue && !constJSONValuesEqual(r, constValue) { + if val != constValue && !(isJSONContainer(constValue) && constJSONValuesEqual(r, constValue)) { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -433,6 +433,10 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } +func isJSONContainer(value string) bool { + return strings.HasPrefix(value, "[") || strings.HasPrefix(value, "{") +} + func constJSONValuesEqual(received json.RawMessage, constValue string) bool { got, err := decodeJSONWithNumbers(received) if err != nil { diff --git a/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerrequest.go b/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerrequest.go index b8e5b45f3..6b00bac40 100644 --- a/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerrequest.go +++ b/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerrequest.go @@ -46,7 +46,7 @@ type ConstContainerRequest struct { //lint:ignore U1000 accessed via reflection for JSON marshaling emptyMap map[string]string `const:"{}" json:"empty_map"` //lint:ignore U1000 accessed via reflection for JSON marshaling - fixedMap map[string]int64 `const:"{\"max\":10}" json:"fixed_map,omitempty"` + fixedMap map[string]int64 `const:"{\"max\":10,\"min\":1}" json:"fixed_map,omitempty"` } func (c ConstContainerRequest) MarshalJSON() ([]byte, error) { @@ -80,5 +80,5 @@ func (c *ConstContainerRequest) GetEmptyMap() map[string]string { } func (c *ConstContainerRequest) GetFixedMap() map[string]int64 { - return map[string]int64{"max": 10} + return map[string]int64{"min": 1, "max": 10} } diff --git a/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerresponse.go b/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerresponse.go index 67ae54213..a11552c93 100644 --- a/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerresponse.go +++ b/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerresponse.go @@ -47,7 +47,7 @@ type ConstContainerResponse struct { //lint:ignore U1000 accessed via reflection for JSON marshaling emptyMap map[string]string `const:"{}" json:"empty_map,omitempty"` //lint:ignore U1000 accessed via reflection for JSON marshaling - fixedMap map[string]int64 `const:"{\"max\":10}" json:"fixed_map,omitempty"` + fixedMap map[string]int64 `const:"{\"min\":1,\"max\":10}" json:"fixed_map,omitempty"` } func (c ConstContainerResponse) MarshalJSON() ([]byte, error) { @@ -88,5 +88,5 @@ func (c *ConstContainerResponse) GetEmptyMap() map[string]string { } func (c *ConstContainerResponse) GetFixedMap() map[string]int64 { - return map[string]int64{"max": 10} + return map[string]int64{"max": 10, "min": 1} } From 9bc6357e4b6c3f07c62b5d96245353b1cbfab0b3 Mon Sep 17 00:00:00 2001 From: Ash Godfrey Date: Fri, 30 Oct 2026 13:54:07 +0000 Subject: [PATCH 06/22] chore: regenerate templates/perms.go with the go.mod toolchain --- templates/perms.go | 226 ++++++++++++++++++++++----------------------- 1 file changed, 113 insertions(+), 113 deletions(-) diff --git a/templates/perms.go b/templates/perms.go index 5da351967..ca046ab3a 100644 --- a/templates/perms.go +++ b/templates/perms.go @@ -2547,119 +2547,119 @@ var fileMode = map[string]fs.FileMode{ "templates/unity/auxiliary/{{ getSDKTopLevelFolder }}/{{ getPackageId }}.csproj.stmpl": 0o644, "templates/unity/auxiliary/{{ getSDKTopLevelFolder }}/{{getErrorsLocation}}": 0o20000000755, "templates/unity/auxiliary/{{ getSDKTopLevelFolder }}/{{getErrorsLocation}}/{{getDefaultErrorFileName}}.cs.stmpl": 0o644, - "templates/unity/config.ts": 0o644, - "templates/unity/enum.cs.stmpl": 0o644, - "templates/unity/error.cs.stmpl": 0o644, - "templates/unity/examples.ts": 0o644, - "templates/unity/exclusions.ts": 0o644, - "templates/unity/features.ts": 0o644, - "templates/unity/includes": 0o20000000755, - "templates/unity/includes/annotations.ts": 0o644, - "templates/unity/includes/documentation.ts": 0o644, - "templates/unity/includes/enums.ts": 0o644, - "templates/unity/includes/errors.ts": 0o644, - "templates/unity/includes/imports.ts": 0o644, - "templates/unity/includes/index.ts": 0o644, - "templates/unity/includes/models.ts": 0o644, - "templates/unity/includes/modelusage.ts": 0o644, - "templates/unity/includes/namespaces.ts": 0o644, - "templates/unity/includes/pagination.ts": 0o644, - "templates/unity/includes/responses.ts": 0o644, - "templates/unity/includes/sanitization.ts": 0o644, - "templates/unity/includes/security.ts": 0o644, - "templates/unity/includes/serverusage.ts": 0o644, - "templates/unity/includes/templating.ts": 0o644, - "templates/unity/includes/unimplemented.ts": 0o644, - "templates/unity/includes/utils.ts": 0o644, - "templates/unity/main.ts": 0o644, - "templates/unity/method.cs.stmpl": 0o644, - "templates/unity/model.cs.stmpl": 0o644, - "templates/unity/modelfile.cs.stmpl": 0o644, - "templates/unity/pagination.cs.stmpl": 0o644, - "templates/unity/readme": 0o20000000755, - "templates/unity/readme/errors.stmpl": 0o644, - "templates/unity/readme/installation.stmpl": 0o644, - "templates/unity/readme/pagination.stmpl": 0o644, - "templates/unity/readme/security.stmpl": 0o644, - "templates/unity/sdk.cs.stmpl": 0o644, - "templates/unity/servers.cs.stmpl": 0o644, - "templates/unity/standalone.ts": 0o644, - "templates/unity/subsdk.cs.stmpl": 0o644, - "templates/unity/tests": 0o20000000755, - "templates/unity/tests/Project": 0o20000000755, - "templates/unity/tests/Project/.gitignore": 0o644, - "templates/unity/tests/Project/Assets": 0o20000000755, - "templates/unity/tests/Project/Assets/Tests": 0o20000000755, - "templates/unity/tests/Project/Assets/Tests/CommonHelpers.cs": 0o644, - "templates/unity/tests/Project/Assets/Tests/Tests.asmdef.stmpl": 0o644, - "templates/unity/tests/Project/Assets/Tests/Tests.meta": 0o644, - "templates/unity/tests/Project/Assets/Tests/UnityTestUtils.cs": 0o644, - "templates/unity/tests/Project/Assets/Tests/base.unity": 0o644, - "templates/unity/tests/Project/Assets/Tests/base.unity.meta": 0o644, - "templates/unity/tests/Project/Packages": 0o20000000755, - "templates/unity/tests/Project/Packages/manifest.json": 0o644, - "templates/unity/tests/Project/Packages/packages-lock.json": 0o644, - "templates/unity/tests/Project/ProjectSettings": 0o20000000755, - "templates/unity/tests/Project/ProjectSettings/AudioManager.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/ClusterInputManager.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/DynamicsManager.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/EditorBuildSettings.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/EditorSettings.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/GraphicsSettings.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/InputManager.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/MemorySettings.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/NavMeshAreas.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/PackageManagerSettings.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/Physics2DSettings.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/PresetManager.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/ProjectSettings.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/ProjectVersion.txt": 0o644, - "templates/unity/tests/Project/ProjectSettings/QualitySettings.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/SceneTemplateSettings.json": 0o644, - "templates/unity/tests/Project/ProjectSettings/TagManager.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/TimeManager.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/UnityConnectSettings.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/VFXManager.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/VersionControlSettings.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/boot.config": 0o644, - "templates/unity/tests/Project/Tests.csproj.stmpl": 0o644, - "templates/unity/tests/Tests": 0o20000000755, - "templates/unity/tests/Tests/client-credentials": 0o20000000755, - "templates/unity/tests/Tests/client-credentials/ClientCredentialsShould.cs": 0o644, - "templates/unity/tests/Tests/primary": 0o20000000755, - "templates/unity/tests/Tests/primary/AuthShould.cs": 0o644, - "templates/unity/tests/Tests/primary/ErrorsShould.cs": 0o644, - "templates/unity/tests/Tests/primary/FlatteningShould.cs": 0o644, - "templates/unity/tests/Tests/primary/GlobalsAdditionalShould.cs": 0o644, - "templates/unity/tests/Tests/primary/Helpers.cs": 0o644, - "templates/unity/tests/Tests/primary/MultiLevelShould.cs": 0o644, - "templates/unity/tests/Tests/primary/PaginationShould.cs": 0o644, - "templates/unity/tests/Tests/primary/ParametersShould.cs": 0o644, - "templates/unity/tests/Tests/primary/RequestBodiesShould.cs": 0o644, - "templates/unity/tests/Tests/primary/ResponseBodiesShould.cs": 0o644, - "templates/unity/tests/Tests/primary/ServersShould.cs": 0o644, - "templates/unity/tests/Tests/primary/TelemetryShould.cs.stmpl": 0o644, - "templates/unity/tests/Tests/primary/UnionsShould.cs": 0o644, - "templates/unity/tests/Tests/quaternary": 0o20000000755, - "templates/unity/tests/Tests/quaternary/AuthShould.cs": 0o644, - "templates/unity/tests/Tests/quaternary/ServersShould.cs": 0o644, - "templates/unity/tests/Tests/secondary": 0o20000000755, - "templates/unity/tests/Tests/secondary/AuthShould.cs": 0o644, - "templates/unity/tests/Tests/secondary/ServersShould.cs": 0o644, - "templates/unity/tests/Tests/tertiary": 0o20000000755, - "templates/unity/tests/Tests/tertiary/AuthShould.cs": 0o644, - "templates/unity/tests/Tests/tertiary/ServersShould.cs": 0o644, - "templates/unity/testusage": 0o20000000755, - "templates/unity/testusage/testusage.csproj.stmpl": 0o644, - "templates/unity/tsconfig.json": 0o644, - "templates/unity/union.cs.stmpl": 0o644, - "templates/unity/usage": 0o20000000755, - "templates/unity/usage/call.stmpl": 0o644, - "templates/unity/usage/errors.stmpl": 0o644, - "templates/unity/usage/init.stmpl": 0o644, - "templates/unity/usage/pagination.stmpl": 0o644, - "templates/unity/usage/result.stmpl": 0o644, - "templates/unity/usage/snippet.stmpl": 0o644, + "templates/unity/config.ts": 0o644, + "templates/unity/enum.cs.stmpl": 0o644, + "templates/unity/error.cs.stmpl": 0o644, + "templates/unity/examples.ts": 0o644, + "templates/unity/exclusions.ts": 0o644, + "templates/unity/features.ts": 0o644, + "templates/unity/includes": 0o20000000755, + "templates/unity/includes/annotations.ts": 0o644, + "templates/unity/includes/documentation.ts": 0o644, + "templates/unity/includes/enums.ts": 0o644, + "templates/unity/includes/errors.ts": 0o644, + "templates/unity/includes/imports.ts": 0o644, + "templates/unity/includes/index.ts": 0o644, + "templates/unity/includes/models.ts": 0o644, + "templates/unity/includes/modelusage.ts": 0o644, + "templates/unity/includes/namespaces.ts": 0o644, + "templates/unity/includes/pagination.ts": 0o644, + "templates/unity/includes/responses.ts": 0o644, + "templates/unity/includes/sanitization.ts": 0o644, + "templates/unity/includes/security.ts": 0o644, + "templates/unity/includes/serverusage.ts": 0o644, + "templates/unity/includes/templating.ts": 0o644, + "templates/unity/includes/unimplemented.ts": 0o644, + "templates/unity/includes/utils.ts": 0o644, + "templates/unity/main.ts": 0o644, + "templates/unity/method.cs.stmpl": 0o644, + "templates/unity/model.cs.stmpl": 0o644, + "templates/unity/modelfile.cs.stmpl": 0o644, + "templates/unity/pagination.cs.stmpl": 0o644, + "templates/unity/readme": 0o20000000755, + "templates/unity/readme/errors.stmpl": 0o644, + "templates/unity/readme/installation.stmpl": 0o644, + "templates/unity/readme/pagination.stmpl": 0o644, + "templates/unity/readme/security.stmpl": 0o644, + "templates/unity/sdk.cs.stmpl": 0o644, + "templates/unity/servers.cs.stmpl": 0o644, + "templates/unity/standalone.ts": 0o644, + "templates/unity/subsdk.cs.stmpl": 0o644, + "templates/unity/tests": 0o20000000755, + "templates/unity/tests/Project": 0o20000000755, + "templates/unity/tests/Project/.gitignore": 0o644, + "templates/unity/tests/Project/Assets": 0o20000000755, + "templates/unity/tests/Project/Assets/Tests": 0o20000000755, + "templates/unity/tests/Project/Assets/Tests/CommonHelpers.cs": 0o644, + "templates/unity/tests/Project/Assets/Tests/Tests.asmdef.stmpl": 0o644, + "templates/unity/tests/Project/Assets/Tests/Tests.meta": 0o644, + "templates/unity/tests/Project/Assets/Tests/UnityTestUtils.cs": 0o644, + "templates/unity/tests/Project/Assets/Tests/base.unity": 0o644, + "templates/unity/tests/Project/Assets/Tests/base.unity.meta": 0o644, + "templates/unity/tests/Project/Packages": 0o20000000755, + "templates/unity/tests/Project/Packages/manifest.json": 0o644, + "templates/unity/tests/Project/Packages/packages-lock.json": 0o644, + "templates/unity/tests/Project/ProjectSettings": 0o20000000755, + "templates/unity/tests/Project/ProjectSettings/AudioManager.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/ClusterInputManager.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/DynamicsManager.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/EditorBuildSettings.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/EditorSettings.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/GraphicsSettings.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/InputManager.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/MemorySettings.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/NavMeshAreas.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/PackageManagerSettings.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/Physics2DSettings.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/PresetManager.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/ProjectSettings.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/ProjectVersion.txt": 0o644, + "templates/unity/tests/Project/ProjectSettings/QualitySettings.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/SceneTemplateSettings.json": 0o644, + "templates/unity/tests/Project/ProjectSettings/TagManager.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/TimeManager.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/UnityConnectSettings.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/VFXManager.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/VersionControlSettings.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/boot.config": 0o644, + "templates/unity/tests/Project/Tests.csproj.stmpl": 0o644, + "templates/unity/tests/Tests": 0o20000000755, + "templates/unity/tests/Tests/client-credentials": 0o20000000755, + "templates/unity/tests/Tests/client-credentials/ClientCredentialsShould.cs": 0o644, + "templates/unity/tests/Tests/primary": 0o20000000755, + "templates/unity/tests/Tests/primary/AuthShould.cs": 0o644, + "templates/unity/tests/Tests/primary/ErrorsShould.cs": 0o644, + "templates/unity/tests/Tests/primary/FlatteningShould.cs": 0o644, + "templates/unity/tests/Tests/primary/GlobalsAdditionalShould.cs": 0o644, + "templates/unity/tests/Tests/primary/Helpers.cs": 0o644, + "templates/unity/tests/Tests/primary/MultiLevelShould.cs": 0o644, + "templates/unity/tests/Tests/primary/PaginationShould.cs": 0o644, + "templates/unity/tests/Tests/primary/ParametersShould.cs": 0o644, + "templates/unity/tests/Tests/primary/RequestBodiesShould.cs": 0o644, + "templates/unity/tests/Tests/primary/ResponseBodiesShould.cs": 0o644, + "templates/unity/tests/Tests/primary/ServersShould.cs": 0o644, + "templates/unity/tests/Tests/primary/TelemetryShould.cs.stmpl": 0o644, + "templates/unity/tests/Tests/primary/UnionsShould.cs": 0o644, + "templates/unity/tests/Tests/quaternary": 0o20000000755, + "templates/unity/tests/Tests/quaternary/AuthShould.cs": 0o644, + "templates/unity/tests/Tests/quaternary/ServersShould.cs": 0o644, + "templates/unity/tests/Tests/secondary": 0o20000000755, + "templates/unity/tests/Tests/secondary/AuthShould.cs": 0o644, + "templates/unity/tests/Tests/secondary/ServersShould.cs": 0o644, + "templates/unity/tests/Tests/tertiary": 0o20000000755, + "templates/unity/tests/Tests/tertiary/AuthShould.cs": 0o644, + "templates/unity/tests/Tests/tertiary/ServersShould.cs": 0o644, + "templates/unity/testusage": 0o20000000755, + "templates/unity/testusage/testusage.csproj.stmpl": 0o644, + "templates/unity/tsconfig.json": 0o644, + "templates/unity/union.cs.stmpl": 0o644, + "templates/unity/usage": 0o20000000755, + "templates/unity/usage/call.stmpl": 0o644, + "templates/unity/usage/errors.stmpl": 0o644, + "templates/unity/usage/init.stmpl": 0o644, + "templates/unity/usage/pagination.stmpl": 0o644, + "templates/unity/usage/result.stmpl": 0o644, + "templates/unity/usage/snippet.stmpl": 0o644, } // IsBinary returns true if the given path is a known binary file. From e28dbe20efbd339e2720923febad40042e671233 Mon Sep 17 00:00:00 2001 From: Ash Godfrey Date: Fri, 30 Oct 2026 14:59:37 +0000 Subject: [PATCH 07/22] fix(terraform): render container const values with sorted keys Const values decoded from the document reach the templates as Go maps whose key order is unstable, so the const struct tag, the getter literal and the request body examples changed between generation runs. Rebuild map values with sorted keys where they are rendered. --- templates/perms.go | 226 +++++++++--------- templates/templates/common/common/examples.ts | 18 +- templates/templates/common/go/annotations.ts | 4 +- templates/templates/common/go/sanitization.ts | 6 +- .../.speakeasy/gen.lock | 6 +- .../models/shared/constcontainerrequest.go | 2 +- .../models/shared/constcontainerresponse.go | 2 +- 7 files changed, 141 insertions(+), 123 deletions(-) diff --git a/templates/perms.go b/templates/perms.go index ca046ab3a..5da351967 100644 --- a/templates/perms.go +++ b/templates/perms.go @@ -2547,119 +2547,119 @@ var fileMode = map[string]fs.FileMode{ "templates/unity/auxiliary/{{ getSDKTopLevelFolder }}/{{ getPackageId }}.csproj.stmpl": 0o644, "templates/unity/auxiliary/{{ getSDKTopLevelFolder }}/{{getErrorsLocation}}": 0o20000000755, "templates/unity/auxiliary/{{ getSDKTopLevelFolder }}/{{getErrorsLocation}}/{{getDefaultErrorFileName}}.cs.stmpl": 0o644, - "templates/unity/config.ts": 0o644, - "templates/unity/enum.cs.stmpl": 0o644, - "templates/unity/error.cs.stmpl": 0o644, - "templates/unity/examples.ts": 0o644, - "templates/unity/exclusions.ts": 0o644, - "templates/unity/features.ts": 0o644, - "templates/unity/includes": 0o20000000755, - "templates/unity/includes/annotations.ts": 0o644, - "templates/unity/includes/documentation.ts": 0o644, - "templates/unity/includes/enums.ts": 0o644, - "templates/unity/includes/errors.ts": 0o644, - "templates/unity/includes/imports.ts": 0o644, - "templates/unity/includes/index.ts": 0o644, - "templates/unity/includes/models.ts": 0o644, - "templates/unity/includes/modelusage.ts": 0o644, - "templates/unity/includes/namespaces.ts": 0o644, - "templates/unity/includes/pagination.ts": 0o644, - "templates/unity/includes/responses.ts": 0o644, - "templates/unity/includes/sanitization.ts": 0o644, - "templates/unity/includes/security.ts": 0o644, - "templates/unity/includes/serverusage.ts": 0o644, - "templates/unity/includes/templating.ts": 0o644, - "templates/unity/includes/unimplemented.ts": 0o644, - "templates/unity/includes/utils.ts": 0o644, - "templates/unity/main.ts": 0o644, - "templates/unity/method.cs.stmpl": 0o644, - "templates/unity/model.cs.stmpl": 0o644, - "templates/unity/modelfile.cs.stmpl": 0o644, - "templates/unity/pagination.cs.stmpl": 0o644, - "templates/unity/readme": 0o20000000755, - "templates/unity/readme/errors.stmpl": 0o644, - "templates/unity/readme/installation.stmpl": 0o644, - "templates/unity/readme/pagination.stmpl": 0o644, - "templates/unity/readme/security.stmpl": 0o644, - "templates/unity/sdk.cs.stmpl": 0o644, - "templates/unity/servers.cs.stmpl": 0o644, - "templates/unity/standalone.ts": 0o644, - "templates/unity/subsdk.cs.stmpl": 0o644, - "templates/unity/tests": 0o20000000755, - "templates/unity/tests/Project": 0o20000000755, - "templates/unity/tests/Project/.gitignore": 0o644, - "templates/unity/tests/Project/Assets": 0o20000000755, - "templates/unity/tests/Project/Assets/Tests": 0o20000000755, - "templates/unity/tests/Project/Assets/Tests/CommonHelpers.cs": 0o644, - "templates/unity/tests/Project/Assets/Tests/Tests.asmdef.stmpl": 0o644, - "templates/unity/tests/Project/Assets/Tests/Tests.meta": 0o644, - "templates/unity/tests/Project/Assets/Tests/UnityTestUtils.cs": 0o644, - "templates/unity/tests/Project/Assets/Tests/base.unity": 0o644, - "templates/unity/tests/Project/Assets/Tests/base.unity.meta": 0o644, - "templates/unity/tests/Project/Packages": 0o20000000755, - "templates/unity/tests/Project/Packages/manifest.json": 0o644, - "templates/unity/tests/Project/Packages/packages-lock.json": 0o644, - "templates/unity/tests/Project/ProjectSettings": 0o20000000755, - "templates/unity/tests/Project/ProjectSettings/AudioManager.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/ClusterInputManager.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/DynamicsManager.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/EditorBuildSettings.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/EditorSettings.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/GraphicsSettings.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/InputManager.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/MemorySettings.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/NavMeshAreas.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/PackageManagerSettings.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/Physics2DSettings.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/PresetManager.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/ProjectSettings.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/ProjectVersion.txt": 0o644, - "templates/unity/tests/Project/ProjectSettings/QualitySettings.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/SceneTemplateSettings.json": 0o644, - "templates/unity/tests/Project/ProjectSettings/TagManager.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/TimeManager.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/UnityConnectSettings.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/VFXManager.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/VersionControlSettings.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/boot.config": 0o644, - "templates/unity/tests/Project/Tests.csproj.stmpl": 0o644, - "templates/unity/tests/Tests": 0o20000000755, - "templates/unity/tests/Tests/client-credentials": 0o20000000755, - "templates/unity/tests/Tests/client-credentials/ClientCredentialsShould.cs": 0o644, - "templates/unity/tests/Tests/primary": 0o20000000755, - "templates/unity/tests/Tests/primary/AuthShould.cs": 0o644, - "templates/unity/tests/Tests/primary/ErrorsShould.cs": 0o644, - "templates/unity/tests/Tests/primary/FlatteningShould.cs": 0o644, - "templates/unity/tests/Tests/primary/GlobalsAdditionalShould.cs": 0o644, - "templates/unity/tests/Tests/primary/Helpers.cs": 0o644, - "templates/unity/tests/Tests/primary/MultiLevelShould.cs": 0o644, - "templates/unity/tests/Tests/primary/PaginationShould.cs": 0o644, - "templates/unity/tests/Tests/primary/ParametersShould.cs": 0o644, - "templates/unity/tests/Tests/primary/RequestBodiesShould.cs": 0o644, - "templates/unity/tests/Tests/primary/ResponseBodiesShould.cs": 0o644, - "templates/unity/tests/Tests/primary/ServersShould.cs": 0o644, - "templates/unity/tests/Tests/primary/TelemetryShould.cs.stmpl": 0o644, - "templates/unity/tests/Tests/primary/UnionsShould.cs": 0o644, - "templates/unity/tests/Tests/quaternary": 0o20000000755, - "templates/unity/tests/Tests/quaternary/AuthShould.cs": 0o644, - "templates/unity/tests/Tests/quaternary/ServersShould.cs": 0o644, - "templates/unity/tests/Tests/secondary": 0o20000000755, - "templates/unity/tests/Tests/secondary/AuthShould.cs": 0o644, - "templates/unity/tests/Tests/secondary/ServersShould.cs": 0o644, - "templates/unity/tests/Tests/tertiary": 0o20000000755, - "templates/unity/tests/Tests/tertiary/AuthShould.cs": 0o644, - "templates/unity/tests/Tests/tertiary/ServersShould.cs": 0o644, - "templates/unity/testusage": 0o20000000755, - "templates/unity/testusage/testusage.csproj.stmpl": 0o644, - "templates/unity/tsconfig.json": 0o644, - "templates/unity/union.cs.stmpl": 0o644, - "templates/unity/usage": 0o20000000755, - "templates/unity/usage/call.stmpl": 0o644, - "templates/unity/usage/errors.stmpl": 0o644, - "templates/unity/usage/init.stmpl": 0o644, - "templates/unity/usage/pagination.stmpl": 0o644, - "templates/unity/usage/result.stmpl": 0o644, - "templates/unity/usage/snippet.stmpl": 0o644, + "templates/unity/config.ts": 0o644, + "templates/unity/enum.cs.stmpl": 0o644, + "templates/unity/error.cs.stmpl": 0o644, + "templates/unity/examples.ts": 0o644, + "templates/unity/exclusions.ts": 0o644, + "templates/unity/features.ts": 0o644, + "templates/unity/includes": 0o20000000755, + "templates/unity/includes/annotations.ts": 0o644, + "templates/unity/includes/documentation.ts": 0o644, + "templates/unity/includes/enums.ts": 0o644, + "templates/unity/includes/errors.ts": 0o644, + "templates/unity/includes/imports.ts": 0o644, + "templates/unity/includes/index.ts": 0o644, + "templates/unity/includes/models.ts": 0o644, + "templates/unity/includes/modelusage.ts": 0o644, + "templates/unity/includes/namespaces.ts": 0o644, + "templates/unity/includes/pagination.ts": 0o644, + "templates/unity/includes/responses.ts": 0o644, + "templates/unity/includes/sanitization.ts": 0o644, + "templates/unity/includes/security.ts": 0o644, + "templates/unity/includes/serverusage.ts": 0o644, + "templates/unity/includes/templating.ts": 0o644, + "templates/unity/includes/unimplemented.ts": 0o644, + "templates/unity/includes/utils.ts": 0o644, + "templates/unity/main.ts": 0o644, + "templates/unity/method.cs.stmpl": 0o644, + "templates/unity/model.cs.stmpl": 0o644, + "templates/unity/modelfile.cs.stmpl": 0o644, + "templates/unity/pagination.cs.stmpl": 0o644, + "templates/unity/readme": 0o20000000755, + "templates/unity/readme/errors.stmpl": 0o644, + "templates/unity/readme/installation.stmpl": 0o644, + "templates/unity/readme/pagination.stmpl": 0o644, + "templates/unity/readme/security.stmpl": 0o644, + "templates/unity/sdk.cs.stmpl": 0o644, + "templates/unity/servers.cs.stmpl": 0o644, + "templates/unity/standalone.ts": 0o644, + "templates/unity/subsdk.cs.stmpl": 0o644, + "templates/unity/tests": 0o20000000755, + "templates/unity/tests/Project": 0o20000000755, + "templates/unity/tests/Project/.gitignore": 0o644, + "templates/unity/tests/Project/Assets": 0o20000000755, + "templates/unity/tests/Project/Assets/Tests": 0o20000000755, + "templates/unity/tests/Project/Assets/Tests/CommonHelpers.cs": 0o644, + "templates/unity/tests/Project/Assets/Tests/Tests.asmdef.stmpl": 0o644, + "templates/unity/tests/Project/Assets/Tests/Tests.meta": 0o644, + "templates/unity/tests/Project/Assets/Tests/UnityTestUtils.cs": 0o644, + "templates/unity/tests/Project/Assets/Tests/base.unity": 0o644, + "templates/unity/tests/Project/Assets/Tests/base.unity.meta": 0o644, + "templates/unity/tests/Project/Packages": 0o20000000755, + "templates/unity/tests/Project/Packages/manifest.json": 0o644, + "templates/unity/tests/Project/Packages/packages-lock.json": 0o644, + "templates/unity/tests/Project/ProjectSettings": 0o20000000755, + "templates/unity/tests/Project/ProjectSettings/AudioManager.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/ClusterInputManager.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/DynamicsManager.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/EditorBuildSettings.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/EditorSettings.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/GraphicsSettings.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/InputManager.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/MemorySettings.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/NavMeshAreas.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/PackageManagerSettings.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/Physics2DSettings.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/PresetManager.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/ProjectSettings.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/ProjectVersion.txt": 0o644, + "templates/unity/tests/Project/ProjectSettings/QualitySettings.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/SceneTemplateSettings.json": 0o644, + "templates/unity/tests/Project/ProjectSettings/TagManager.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/TimeManager.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/UnityConnectSettings.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/VFXManager.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/VersionControlSettings.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/boot.config": 0o644, + "templates/unity/tests/Project/Tests.csproj.stmpl": 0o644, + "templates/unity/tests/Tests": 0o20000000755, + "templates/unity/tests/Tests/client-credentials": 0o20000000755, + "templates/unity/tests/Tests/client-credentials/ClientCredentialsShould.cs": 0o644, + "templates/unity/tests/Tests/primary": 0o20000000755, + "templates/unity/tests/Tests/primary/AuthShould.cs": 0o644, + "templates/unity/tests/Tests/primary/ErrorsShould.cs": 0o644, + "templates/unity/tests/Tests/primary/FlatteningShould.cs": 0o644, + "templates/unity/tests/Tests/primary/GlobalsAdditionalShould.cs": 0o644, + "templates/unity/tests/Tests/primary/Helpers.cs": 0o644, + "templates/unity/tests/Tests/primary/MultiLevelShould.cs": 0o644, + "templates/unity/tests/Tests/primary/PaginationShould.cs": 0o644, + "templates/unity/tests/Tests/primary/ParametersShould.cs": 0o644, + "templates/unity/tests/Tests/primary/RequestBodiesShould.cs": 0o644, + "templates/unity/tests/Tests/primary/ResponseBodiesShould.cs": 0o644, + "templates/unity/tests/Tests/primary/ServersShould.cs": 0o644, + "templates/unity/tests/Tests/primary/TelemetryShould.cs.stmpl": 0o644, + "templates/unity/tests/Tests/primary/UnionsShould.cs": 0o644, + "templates/unity/tests/Tests/quaternary": 0o20000000755, + "templates/unity/tests/Tests/quaternary/AuthShould.cs": 0o644, + "templates/unity/tests/Tests/quaternary/ServersShould.cs": 0o644, + "templates/unity/tests/Tests/secondary": 0o20000000755, + "templates/unity/tests/Tests/secondary/AuthShould.cs": 0o644, + "templates/unity/tests/Tests/secondary/ServersShould.cs": 0o644, + "templates/unity/tests/Tests/tertiary": 0o20000000755, + "templates/unity/tests/Tests/tertiary/AuthShould.cs": 0o644, + "templates/unity/tests/Tests/tertiary/ServersShould.cs": 0o644, + "templates/unity/testusage": 0o20000000755, + "templates/unity/testusage/testusage.csproj.stmpl": 0o644, + "templates/unity/tsconfig.json": 0o644, + "templates/unity/union.cs.stmpl": 0o644, + "templates/unity/usage": 0o20000000755, + "templates/unity/usage/call.stmpl": 0o644, + "templates/unity/usage/errors.stmpl": 0o644, + "templates/unity/usage/init.stmpl": 0o644, + "templates/unity/usage/pagination.stmpl": 0o644, + "templates/unity/usage/result.stmpl": 0o644, + "templates/unity/usage/snippet.stmpl": 0o644, } // IsBinary returns true if the given path is a known binary file. diff --git a/templates/templates/common/common/examples.ts b/templates/templates/common/common/examples.ts index cabaac2ae..40065a09b 100644 --- a/templates/templates/common/common/examples.ts +++ b/templates/templates/common/common/examples.ts @@ -547,7 +547,7 @@ function calculateExample( // If we have a const value always use this as nothing else is valid if (fieldDef.Const) { - example = fieldDef.Const.Value; + example = withSortedKeys(fieldDef.Const.Value); } // If we have no example try to find a source @@ -2326,3 +2326,19 @@ function getExampleByName(examples: Example[], name: string): Example | null { function getExampleFileDeclaration() { return `${FILE_DIRECTIVE_KEY} ${EXAMPLE_FILE}`; } + +// Values decoded from the document into Go maps reach templates with an +// unstable key order; rebuild them so rendered output is deterministic. +function withSortedKeys(value: any): any { + if (Array.isArray(value)) { + return value.map(withSortedKeys); + } + if (value !== null && typeof value === "object") { + const sorted: Record = {}; + for (const key of Object.keys(value).sort()) { + sorted[key] = withSortedKeys(value[key]); + } + return sorted; + } + return value; +} diff --git a/templates/templates/common/go/annotations.ts b/templates/templates/common/go/annotations.ts index cc31dc648..f4fcfec09 100644 --- a/templates/templates/common/go/annotations.ts +++ b/templates/templates/common/go/annotations.ts @@ -311,7 +311,9 @@ function templateConstsAndDefaultsAnnotation( if (fieldDef.Const) { return { Tag: "const", - Value: sanitizeValue(JSON.stringify(fieldDef.Const.Value)), + Value: sanitizeValue( + JSON.stringify(withSortedKeys(fieldDef.Const.Value)), + ), }; } diff --git a/templates/templates/common/go/sanitization.ts b/templates/templates/common/go/sanitization.ts index 9f4d2e0c0..aa4cd270a 100644 --- a/templates/templates/common/go/sanitization.ts +++ b/templates/templates/common/go/sanitization.ts @@ -769,9 +769,9 @@ function templateConstContainerValue( ); if (fieldDef.Type.Type.toString() === "map") { - const entries = Object.entries(fieldDef.Const.Value ?? {}).map( - ([key, value]) => `${JSON.stringify(key)}: ${renderItem(value)}`, - ); + const entries = Object.entries( + withSortedKeys(fieldDef.Const.Value ?? {}), + ).map(([key, value]) => `${JSON.stringify(key)}: ${renderItem(value)}`); return `${containerType}{${entries.join(", ")}}`; } diff --git a/zSDKs/terraform-provider-testing/.speakeasy/gen.lock b/zSDKs/terraform-provider-testing/.speakeasy/gen.lock index 63f45c876..705bfcdfe 100644 --- a/zSDKs/terraform-provider-testing/.speakeasy/gen.lock +++ b/zSDKs/terraform-provider-testing/.speakeasy/gen.lock @@ -3098,9 +3098,9 @@ trackedFiles: internal/sdk/models/shared/basicsearch.go: last_write_checksum: sha1:ebc8943a31148f7623c5f8ff940dd81c1b52f23d internal/sdk/models/shared/constcontainerrequest.go: - last_write_checksum: sha1:08457751e87b9249244c6a938fbe5db31a5561e8 + last_write_checksum: sha1:9c257c5ba13e6c10ddc608feaf41b8f4a09450e4 internal/sdk/models/shared/constcontainerresponse.go: - last_write_checksum: sha1:6b4bad498e1a600df8da2db7d8e6e7ce1aa999aa + last_write_checksum: sha1:c6ea7685379a02992ab06367f585c921571896d7 internal/sdk/models/shared/discriminatedobject.go: last_write_checksum: sha1:9bb5641a1bcb27ec59c1f16d82d8a251ec733286 internal/sdk/models/shared/discriminatedunionarraycreaterequest.go: @@ -6062,7 +6062,7 @@ examples: id: "" responses: "200": - application/json: {"empty_list": [], "fixed_list": ["read", "write"], "empty_map": {}, "fixed_map": {"min": 1, "max": 10}} + application/json: {"empty_list": [], "fixed_list": ["read", "write"], "empty_map": {}, "fixed_map": {"max": 10, "min": 1}} delete-const-container: speakeasy-default-delete-const-container: parameters: diff --git a/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerrequest.go b/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerrequest.go index 6b00bac40..638bbe163 100644 --- a/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerrequest.go +++ b/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerrequest.go @@ -80,5 +80,5 @@ func (c *ConstContainerRequest) GetEmptyMap() map[string]string { } func (c *ConstContainerRequest) GetFixedMap() map[string]int64 { - return map[string]int64{"min": 1, "max": 10} + return map[string]int64{"max": 10, "min": 1} } diff --git a/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerresponse.go b/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerresponse.go index a11552c93..5cd99cd30 100644 --- a/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerresponse.go +++ b/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerresponse.go @@ -47,7 +47,7 @@ type ConstContainerResponse struct { //lint:ignore U1000 accessed via reflection for JSON marshaling emptyMap map[string]string `const:"{}" json:"empty_map,omitempty"` //lint:ignore U1000 accessed via reflection for JSON marshaling - fixedMap map[string]int64 `const:"{\"min\":1,\"max\":10}" json:"fixed_map,omitempty"` + fixedMap map[string]int64 `const:"{\"max\":10,\"min\":1}" json:"fixed_map,omitempty"` } func (c ConstContainerResponse) MarshalJSON() ([]byte, error) { From 59635ea34b5d5a9c6bb2b9adc43b734df0f51b0f Mon Sep 17 00:00:00 2001 From: Ash Godfrey Date: Fri, 30 Oct 2026 15:13:31 +0000 Subject: [PATCH 08/22] chore: regenerate templates/perms.go with the go.mod toolchain --- templates/perms.go | 226 ++++++++++++++++++++++----------------------- 1 file changed, 113 insertions(+), 113 deletions(-) diff --git a/templates/perms.go b/templates/perms.go index 5da351967..ca046ab3a 100644 --- a/templates/perms.go +++ b/templates/perms.go @@ -2547,119 +2547,119 @@ var fileMode = map[string]fs.FileMode{ "templates/unity/auxiliary/{{ getSDKTopLevelFolder }}/{{ getPackageId }}.csproj.stmpl": 0o644, "templates/unity/auxiliary/{{ getSDKTopLevelFolder }}/{{getErrorsLocation}}": 0o20000000755, "templates/unity/auxiliary/{{ getSDKTopLevelFolder }}/{{getErrorsLocation}}/{{getDefaultErrorFileName}}.cs.stmpl": 0o644, - "templates/unity/config.ts": 0o644, - "templates/unity/enum.cs.stmpl": 0o644, - "templates/unity/error.cs.stmpl": 0o644, - "templates/unity/examples.ts": 0o644, - "templates/unity/exclusions.ts": 0o644, - "templates/unity/features.ts": 0o644, - "templates/unity/includes": 0o20000000755, - "templates/unity/includes/annotations.ts": 0o644, - "templates/unity/includes/documentation.ts": 0o644, - "templates/unity/includes/enums.ts": 0o644, - "templates/unity/includes/errors.ts": 0o644, - "templates/unity/includes/imports.ts": 0o644, - "templates/unity/includes/index.ts": 0o644, - "templates/unity/includes/models.ts": 0o644, - "templates/unity/includes/modelusage.ts": 0o644, - "templates/unity/includes/namespaces.ts": 0o644, - "templates/unity/includes/pagination.ts": 0o644, - "templates/unity/includes/responses.ts": 0o644, - "templates/unity/includes/sanitization.ts": 0o644, - "templates/unity/includes/security.ts": 0o644, - "templates/unity/includes/serverusage.ts": 0o644, - "templates/unity/includes/templating.ts": 0o644, - "templates/unity/includes/unimplemented.ts": 0o644, - "templates/unity/includes/utils.ts": 0o644, - "templates/unity/main.ts": 0o644, - "templates/unity/method.cs.stmpl": 0o644, - "templates/unity/model.cs.stmpl": 0o644, - "templates/unity/modelfile.cs.stmpl": 0o644, - "templates/unity/pagination.cs.stmpl": 0o644, - "templates/unity/readme": 0o20000000755, - "templates/unity/readme/errors.stmpl": 0o644, - "templates/unity/readme/installation.stmpl": 0o644, - "templates/unity/readme/pagination.stmpl": 0o644, - "templates/unity/readme/security.stmpl": 0o644, - "templates/unity/sdk.cs.stmpl": 0o644, - "templates/unity/servers.cs.stmpl": 0o644, - "templates/unity/standalone.ts": 0o644, - "templates/unity/subsdk.cs.stmpl": 0o644, - "templates/unity/tests": 0o20000000755, - "templates/unity/tests/Project": 0o20000000755, - "templates/unity/tests/Project/.gitignore": 0o644, - "templates/unity/tests/Project/Assets": 0o20000000755, - "templates/unity/tests/Project/Assets/Tests": 0o20000000755, - "templates/unity/tests/Project/Assets/Tests/CommonHelpers.cs": 0o644, - "templates/unity/tests/Project/Assets/Tests/Tests.asmdef.stmpl": 0o644, - "templates/unity/tests/Project/Assets/Tests/Tests.meta": 0o644, - "templates/unity/tests/Project/Assets/Tests/UnityTestUtils.cs": 0o644, - "templates/unity/tests/Project/Assets/Tests/base.unity": 0o644, - "templates/unity/tests/Project/Assets/Tests/base.unity.meta": 0o644, - "templates/unity/tests/Project/Packages": 0o20000000755, - "templates/unity/tests/Project/Packages/manifest.json": 0o644, - "templates/unity/tests/Project/Packages/packages-lock.json": 0o644, - "templates/unity/tests/Project/ProjectSettings": 0o20000000755, - "templates/unity/tests/Project/ProjectSettings/AudioManager.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/ClusterInputManager.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/DynamicsManager.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/EditorBuildSettings.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/EditorSettings.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/GraphicsSettings.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/InputManager.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/MemorySettings.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/NavMeshAreas.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/PackageManagerSettings.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/Physics2DSettings.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/PresetManager.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/ProjectSettings.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/ProjectVersion.txt": 0o644, - "templates/unity/tests/Project/ProjectSettings/QualitySettings.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/SceneTemplateSettings.json": 0o644, - "templates/unity/tests/Project/ProjectSettings/TagManager.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/TimeManager.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/UnityConnectSettings.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/VFXManager.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/VersionControlSettings.asset": 0o644, - "templates/unity/tests/Project/ProjectSettings/boot.config": 0o644, - "templates/unity/tests/Project/Tests.csproj.stmpl": 0o644, - "templates/unity/tests/Tests": 0o20000000755, - "templates/unity/tests/Tests/client-credentials": 0o20000000755, - "templates/unity/tests/Tests/client-credentials/ClientCredentialsShould.cs": 0o644, - "templates/unity/tests/Tests/primary": 0o20000000755, - "templates/unity/tests/Tests/primary/AuthShould.cs": 0o644, - "templates/unity/tests/Tests/primary/ErrorsShould.cs": 0o644, - "templates/unity/tests/Tests/primary/FlatteningShould.cs": 0o644, - "templates/unity/tests/Tests/primary/GlobalsAdditionalShould.cs": 0o644, - "templates/unity/tests/Tests/primary/Helpers.cs": 0o644, - "templates/unity/tests/Tests/primary/MultiLevelShould.cs": 0o644, - "templates/unity/tests/Tests/primary/PaginationShould.cs": 0o644, - "templates/unity/tests/Tests/primary/ParametersShould.cs": 0o644, - "templates/unity/tests/Tests/primary/RequestBodiesShould.cs": 0o644, - "templates/unity/tests/Tests/primary/ResponseBodiesShould.cs": 0o644, - "templates/unity/tests/Tests/primary/ServersShould.cs": 0o644, - "templates/unity/tests/Tests/primary/TelemetryShould.cs.stmpl": 0o644, - "templates/unity/tests/Tests/primary/UnionsShould.cs": 0o644, - "templates/unity/tests/Tests/quaternary": 0o20000000755, - "templates/unity/tests/Tests/quaternary/AuthShould.cs": 0o644, - "templates/unity/tests/Tests/quaternary/ServersShould.cs": 0o644, - "templates/unity/tests/Tests/secondary": 0o20000000755, - "templates/unity/tests/Tests/secondary/AuthShould.cs": 0o644, - "templates/unity/tests/Tests/secondary/ServersShould.cs": 0o644, - "templates/unity/tests/Tests/tertiary": 0o20000000755, - "templates/unity/tests/Tests/tertiary/AuthShould.cs": 0o644, - "templates/unity/tests/Tests/tertiary/ServersShould.cs": 0o644, - "templates/unity/testusage": 0o20000000755, - "templates/unity/testusage/testusage.csproj.stmpl": 0o644, - "templates/unity/tsconfig.json": 0o644, - "templates/unity/union.cs.stmpl": 0o644, - "templates/unity/usage": 0o20000000755, - "templates/unity/usage/call.stmpl": 0o644, - "templates/unity/usage/errors.stmpl": 0o644, - "templates/unity/usage/init.stmpl": 0o644, - "templates/unity/usage/pagination.stmpl": 0o644, - "templates/unity/usage/result.stmpl": 0o644, - "templates/unity/usage/snippet.stmpl": 0o644, + "templates/unity/config.ts": 0o644, + "templates/unity/enum.cs.stmpl": 0o644, + "templates/unity/error.cs.stmpl": 0o644, + "templates/unity/examples.ts": 0o644, + "templates/unity/exclusions.ts": 0o644, + "templates/unity/features.ts": 0o644, + "templates/unity/includes": 0o20000000755, + "templates/unity/includes/annotations.ts": 0o644, + "templates/unity/includes/documentation.ts": 0o644, + "templates/unity/includes/enums.ts": 0o644, + "templates/unity/includes/errors.ts": 0o644, + "templates/unity/includes/imports.ts": 0o644, + "templates/unity/includes/index.ts": 0o644, + "templates/unity/includes/models.ts": 0o644, + "templates/unity/includes/modelusage.ts": 0o644, + "templates/unity/includes/namespaces.ts": 0o644, + "templates/unity/includes/pagination.ts": 0o644, + "templates/unity/includes/responses.ts": 0o644, + "templates/unity/includes/sanitization.ts": 0o644, + "templates/unity/includes/security.ts": 0o644, + "templates/unity/includes/serverusage.ts": 0o644, + "templates/unity/includes/templating.ts": 0o644, + "templates/unity/includes/unimplemented.ts": 0o644, + "templates/unity/includes/utils.ts": 0o644, + "templates/unity/main.ts": 0o644, + "templates/unity/method.cs.stmpl": 0o644, + "templates/unity/model.cs.stmpl": 0o644, + "templates/unity/modelfile.cs.stmpl": 0o644, + "templates/unity/pagination.cs.stmpl": 0o644, + "templates/unity/readme": 0o20000000755, + "templates/unity/readme/errors.stmpl": 0o644, + "templates/unity/readme/installation.stmpl": 0o644, + "templates/unity/readme/pagination.stmpl": 0o644, + "templates/unity/readme/security.stmpl": 0o644, + "templates/unity/sdk.cs.stmpl": 0o644, + "templates/unity/servers.cs.stmpl": 0o644, + "templates/unity/standalone.ts": 0o644, + "templates/unity/subsdk.cs.stmpl": 0o644, + "templates/unity/tests": 0o20000000755, + "templates/unity/tests/Project": 0o20000000755, + "templates/unity/tests/Project/.gitignore": 0o644, + "templates/unity/tests/Project/Assets": 0o20000000755, + "templates/unity/tests/Project/Assets/Tests": 0o20000000755, + "templates/unity/tests/Project/Assets/Tests/CommonHelpers.cs": 0o644, + "templates/unity/tests/Project/Assets/Tests/Tests.asmdef.stmpl": 0o644, + "templates/unity/tests/Project/Assets/Tests/Tests.meta": 0o644, + "templates/unity/tests/Project/Assets/Tests/UnityTestUtils.cs": 0o644, + "templates/unity/tests/Project/Assets/Tests/base.unity": 0o644, + "templates/unity/tests/Project/Assets/Tests/base.unity.meta": 0o644, + "templates/unity/tests/Project/Packages": 0o20000000755, + "templates/unity/tests/Project/Packages/manifest.json": 0o644, + "templates/unity/tests/Project/Packages/packages-lock.json": 0o644, + "templates/unity/tests/Project/ProjectSettings": 0o20000000755, + "templates/unity/tests/Project/ProjectSettings/AudioManager.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/ClusterInputManager.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/DynamicsManager.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/EditorBuildSettings.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/EditorSettings.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/GraphicsSettings.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/InputManager.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/MemorySettings.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/NavMeshAreas.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/PackageManagerSettings.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/Physics2DSettings.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/PresetManager.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/ProjectSettings.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/ProjectVersion.txt": 0o644, + "templates/unity/tests/Project/ProjectSettings/QualitySettings.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/SceneTemplateSettings.json": 0o644, + "templates/unity/tests/Project/ProjectSettings/TagManager.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/TimeManager.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/UnityConnectSettings.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/VFXManager.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/VersionControlSettings.asset": 0o644, + "templates/unity/tests/Project/ProjectSettings/boot.config": 0o644, + "templates/unity/tests/Project/Tests.csproj.stmpl": 0o644, + "templates/unity/tests/Tests": 0o20000000755, + "templates/unity/tests/Tests/client-credentials": 0o20000000755, + "templates/unity/tests/Tests/client-credentials/ClientCredentialsShould.cs": 0o644, + "templates/unity/tests/Tests/primary": 0o20000000755, + "templates/unity/tests/Tests/primary/AuthShould.cs": 0o644, + "templates/unity/tests/Tests/primary/ErrorsShould.cs": 0o644, + "templates/unity/tests/Tests/primary/FlatteningShould.cs": 0o644, + "templates/unity/tests/Tests/primary/GlobalsAdditionalShould.cs": 0o644, + "templates/unity/tests/Tests/primary/Helpers.cs": 0o644, + "templates/unity/tests/Tests/primary/MultiLevelShould.cs": 0o644, + "templates/unity/tests/Tests/primary/PaginationShould.cs": 0o644, + "templates/unity/tests/Tests/primary/ParametersShould.cs": 0o644, + "templates/unity/tests/Tests/primary/RequestBodiesShould.cs": 0o644, + "templates/unity/tests/Tests/primary/ResponseBodiesShould.cs": 0o644, + "templates/unity/tests/Tests/primary/ServersShould.cs": 0o644, + "templates/unity/tests/Tests/primary/TelemetryShould.cs.stmpl": 0o644, + "templates/unity/tests/Tests/primary/UnionsShould.cs": 0o644, + "templates/unity/tests/Tests/quaternary": 0o20000000755, + "templates/unity/tests/Tests/quaternary/AuthShould.cs": 0o644, + "templates/unity/tests/Tests/quaternary/ServersShould.cs": 0o644, + "templates/unity/tests/Tests/secondary": 0o20000000755, + "templates/unity/tests/Tests/secondary/AuthShould.cs": 0o644, + "templates/unity/tests/Tests/secondary/ServersShould.cs": 0o644, + "templates/unity/tests/Tests/tertiary": 0o20000000755, + "templates/unity/tests/Tests/tertiary/AuthShould.cs": 0o644, + "templates/unity/tests/Tests/tertiary/ServersShould.cs": 0o644, + "templates/unity/testusage": 0o20000000755, + "templates/unity/testusage/testusage.csproj.stmpl": 0o644, + "templates/unity/tsconfig.json": 0o644, + "templates/unity/union.cs.stmpl": 0o644, + "templates/unity/usage": 0o20000000755, + "templates/unity/usage/call.stmpl": 0o644, + "templates/unity/usage/errors.stmpl": 0o644, + "templates/unity/usage/init.stmpl": 0o644, + "templates/unity/usage/pagination.stmpl": 0o644, + "templates/unity/usage/result.stmpl": 0o644, + "templates/unity/usage/snippet.stmpl": 0o644, } // IsBinary returns true if the given path is a known binary file. From 255cbc70b7b27407066808e4520fd3c3cae8d4c3 Mon Sep 17 00:00:00 2001 From: Ash Godfrey Date: Fri, 30 Oct 2026 15:43:52 +0000 Subject: [PATCH 09/22] fix: keep a __proto__ key when sorting const map values --- templates/templates/common/common/examples.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/templates/common/common/examples.ts b/templates/templates/common/common/examples.ts index 40065a09b..798b3b516 100644 --- a/templates/templates/common/common/examples.ts +++ b/templates/templates/common/common/examples.ts @@ -2334,7 +2334,7 @@ function withSortedKeys(value: any): any { return value.map(withSortedKeys); } if (value !== null && typeof value === "object") { - const sorted: Record = {}; + const sorted: Record = Object.create(null); for (const key of Object.keys(value).sort()) { sorted[key] = withSortedKeys(value[key]); } From 4039153d373e6f08c469166b3680f2ab38f4b000 Mon Sep 17 00:00:00 2001 From: Ash Godfrey Date: Fri, 30 Oct 2026 15:57:53 +0000 Subject: [PATCH 10/22] chore: merge the Terraform container const changesets --- .changesets/1792662097-11a83540.yaml | 3 ++- .changesets/1792662097-4b2c17a5.yaml | 10 ---------- 2 files changed, 2 insertions(+), 11 deletions(-) delete mode 100644 .changesets/1792662097-4b2c17a5.yaml diff --git a/.changesets/1792662097-11a83540.yaml b/.changesets/1792662097-11a83540.yaml index 71464cfb3..d184a4721 100644 --- a/.changesets/1792662097-11a83540.yaml +++ b/.changesets/1792662097-11a83540.yaml @@ -1,10 +1,11 @@ id: 1792662097-11a83540 features: - constArrays + - constObjects 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 +description: array and 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" diff --git a/.changesets/1792662097-4b2c17a5.yaml b/.changesets/1792662097-4b2c17a5.yaml deleted file mode 100644 index af2bcc2df..000000000 --- a/.changesets/1792662097-4b2c17a5.yaml +++ /dev/null @@ -1,10 +0,0 @@ -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" From 117863045b721ac6ee7a33fb275fb039ce2070e6 Mon Sep 17 00:00:00 2001 From: Ash Godfrey Date: Mon, 2 Nov 2026 09:00:44 +0000 Subject: [PATCH 11/22] fix(go): decide container const comparison by field kind and type-check enum const items Unmarshaling used the const tag text to detect container consts, so a JSON string whose text matched the tag was accepted for a slice or map field, and a string const beginning with a bracket could be satisfied by an equivalent array body. The structural comparison now applies only when the Go field is a slice or map, and scalar fields keep the exact-text check. Enum items in a container const must match the enum's underlying type before the value is looked up in the enum's members. The go/cli changeset now describes the unmarshaling change those targets actually receive. --- .changesets/1792662097-2435dcc7.yaml | 2 +- internal/schemas/handle_array_test.go | 36 +++++++++++++++++++ internal/schemas/schemas.go | 5 ++- .../{{getUtilsLocation}}/json.go.stmpl | 15 ++++++-- .../internal/sdk/utils/json.go.stmpl | 15 ++++++-- zSDKs/mcp-typescript/.speakeasy/gen.lock | 2 +- .../mockserver/internal/sdk/utils/json.go | 15 ++++++-- zSDKs/sdk-cli/.speakeasy/gen.lock | 4 +-- .../internal/sdk/sdkinternal/utils/json.go | 15 ++++++-- .../mockserver/internal/sdk/utils/json.go | 15 ++++++-- zSDKs/sdk-csharp/.speakeasy/gen.lock | 2 +- .../mockserver/internal/sdk/utils/json.go | 15 ++++++-- zSDKs/sdk-go/.speakeasy/gen.lock | 4 +-- zSDKs/sdk-go/internal/utils/json.go | 15 ++++++-- .../mockserver/internal/sdk/utils/json.go | 15 ++++++-- zSDKs/sdk-javav2/.speakeasy/gen.lock | 2 +- .../mockserver/internal/sdk/utils/json.go | 15 ++++++-- zSDKs/sdk-mcp-typescript/.speakeasy/gen.lock | 2 +- .../mockserver/internal/sdk/utils/json.go | 15 ++++++-- zSDKs/sdk-pythonv2/.speakeasy/gen.lock | 2 +- .../mockserver/internal/sdk/utils/json.go | 15 ++++++-- zSDKs/sdk-ruby/.speakeasy/gen.lock | 2 +- .../mockserver/internal/sdk/utils/json.go | 15 ++++++-- zSDKs/sdk-typescriptv2/.speakeasy/gen.lock | 2 +- .../mockserver/internal/sdk/utils/json.go | 15 ++++++-- .../.speakeasy/gen.lock | 2 +- .../internal/sdk/internal/utils/json.go | 15 ++++++-- 27 files changed, 221 insertions(+), 56 deletions(-) diff --git a/.changesets/1792662097-2435dcc7.yaml b/.changesets/1792662097-2435dcc7.yaml index daeefe689..d5028978c 100644 --- a/.changesets/1792662097-2435dcc7.yaml +++ b/.changesets/1792662097-2435dcc7.yaml @@ -6,6 +6,6 @@ targets: - cli type: fix bump: patch -description: const values on array and map fields are emitted when marshaling and accepted when unmarshaling +description: JSON unmarshaling compares array and map const values structurally instead of by exact text author: AshGodfrey date: "2026-10-22" diff --git a/internal/schemas/handle_array_test.go b/internal/schemas/handle_array_test.go index bef2e5030..949f2a700 100644 --- a/internal/schemas/handle_array_test.go +++ b/internal/schemas/handle_array_test.go @@ -270,6 +270,42 @@ func TestHandleArray(t *testing.T) { Build(), expectedWarning: "only arrays without uniqueItems and maps of scalar values are supported, omitting const", }, + { + name: "ArrayWithConstEnumItemTypeMismatch", + schemasYAML: `TestSchema: + type: array + items: + type: integer + enum: + - 1 + - 2 + const: + - "1"`, + schemaName: "TestSchema", + mockFeatures: func() *testutils.MockFeaturesConfig { + config := testutils.NewMockFeaturesConfig() + config.SupportedFeatures = map[features.Feature]bool{ + features.FeatureConstArrays: true, + features.FeatureConstsAndDefaults: true, + features.FeatureEnums: true, + } + return config + }, + expected: testutils.NewFieldDef("enums", + testutils.NewTypeDef(ast.DataTypeArray). + WithItemType(testutils.NewEnumTypeDef(ast.DataTypeInteger, []string{"1", "2"}, ""). + WithScope(ast.ScopeShared). + WithRegistered(). + WithOriginalNameFrozen(). + WithContextStack(ast.ContextStack{}). + WithEnumUnderlyingLocation(&yaml.Node{Line: 11, Column: 9}). + Build()). + WithLocation(&yaml.Node{Line: 9, Column: 7}). + WithValidations(&ast.Validations{}). + Build()). + Build(), + expectedWarning: "only arrays without uniqueItems and maps of scalar values are supported, omitting const", + }, { name: "ArrayWithConstBigIntItems", schemasYAML: `TestSchema: diff --git a/internal/schemas/schemas.go b/internal/schemas/schemas.go index 7dfa6964b..77c4bd595 100644 --- a/internal/schemas/schemas.go +++ b/internal/schemas/schemas.go @@ -1732,7 +1732,10 @@ func constScalarMatchesType(val any, itemType *ast.TypeDef) bool { switch itemType.Type { case ast.DataTypeEnum: - return itemType.Enum != nil && slices.Contains(itemType.Enum.Values, fmt.Sprint(val)) + if itemType.Enum == nil || itemType.Enum.Type == nil || !defaultValueMatchesType(val, itemType.Enum.Type.Type) { + return false + } + return slices.Contains(itemType.Enum.Values, fmt.Sprint(val)) case ast.DataTypeInteger, ast.DataTypeInt32, ast.DataTypeNumber, ast.DataTypeFloat32: return itemType.Format != "string" && defaultValueMatchesType(val, itemType.Type) case ast.DataTypeBoolean, ast.DataTypeString, ast.DataTypeDate, ast.DataTypeDateTime, ast.DataTypeUUID, ast.DataTypeDuration: diff --git a/templates/templates/go/auxiliary/{{getUtilsLocation}}/json.go.stmpl b/templates/templates/go/auxiliary/{{getUtilsLocation}}/json.go.stmpl index 5a65140cc..a5ad54c12 100644 --- a/templates/templates/go/auxiliary/{{getUtilsLocation}}/json.go.stmpl +++ b/templates/templates/go/auxiliary/{{getUtilsLocation}}/json.go.stmpl @@ -215,7 +215,11 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue && !(isJSONContainer(constValue) && constJSONValuesEqual(r, constValue)) { + matches := val == constValue + if isContainerKind(field.Type) { + matches = constJSONValuesEqual(r, constValue) + } + if !matches { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -447,8 +451,13 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } -func isJSONContainer(value string) bool { - return strings.HasPrefix(value, "[") || strings.HasPrefix(value, "{") +func isContainerKind(typ reflect.Type) bool { + switch dereferenceTypePointer(typ).Kind() { + case reflect.Slice, reflect.Map: + return true + default: + return false + } } func constJSONValuesEqual(received json.RawMessage, constValue string) bool { diff --git a/templates/templates/mockserver/auxiliary/internal/sdk/utils/json.go.stmpl b/templates/templates/mockserver/auxiliary/internal/sdk/utils/json.go.stmpl index eaa6aea80..95b5e6ad8 100644 --- a/templates/templates/mockserver/auxiliary/internal/sdk/utils/json.go.stmpl +++ b/templates/templates/mockserver/auxiliary/internal/sdk/utils/json.go.stmpl @@ -199,7 +199,11 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue && !(isJSONContainer(constValue) && constJSONValuesEqual(r, constValue)) { + matches := val == constValue + if isContainerKind(field.Type) { + matches = constJSONValuesEqual(r, constValue) + } + if !matches { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -422,8 +426,13 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } -func isJSONContainer(value string) bool { - return strings.HasPrefix(value, "[") || strings.HasPrefix(value, "{") +func isContainerKind(typ reflect.Type) bool { + switch dereferenceTypePointer(typ).Kind() { + case reflect.Slice, reflect.Map: + return true + default: + return false + } } func constJSONValuesEqual(received json.RawMessage, constValue string) bool { diff --git a/zSDKs/mcp-typescript/.speakeasy/gen.lock b/zSDKs/mcp-typescript/.speakeasy/gen.lock index b1b69b2f3..acc0fbc8c 100644 --- a/zSDKs/mcp-typescript/.speakeasy/gen.lock +++ b/zSDKs/mcp-typescript/.speakeasy/gen.lock @@ -412,7 +412,7 @@ trackedFiles: src/__tests__/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd src/__tests__/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:66bc354bf281916b0ee3bb77bdb0f173d82dab38 + last_write_checksum: sha1:642159c8ddd0e1d4f69146b64af207f6a7c0cd76 src/__tests__/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 src/__tests__/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go b/zSDKs/mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go index e53a81f39..d59d5e51c 100644 --- a/zSDKs/mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go @@ -201,7 +201,11 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue && !(isJSONContainer(constValue) && constJSONValuesEqual(r, constValue)) { + matches := val == constValue + if isContainerKind(field.Type) { + matches = constJSONValuesEqual(r, constValue) + } + if !matches { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -424,8 +428,13 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } -func isJSONContainer(value string) bool { - return strings.HasPrefix(value, "[") || strings.HasPrefix(value, "{") +func isContainerKind(typ reflect.Type) bool { + switch dereferenceTypePointer(typ).Kind() { + case reflect.Slice, reflect.Map: + return true + default: + return false + } } func constJSONValuesEqual(received json.RawMessage, constValue string) bool { diff --git a/zSDKs/sdk-cli/.speakeasy/gen.lock b/zSDKs/sdk-cli/.speakeasy/gen.lock index e253c0618..9ab7799cc 100644 --- a/zSDKs/sdk-cli/.speakeasy/gen.lock +++ b/zSDKs/sdk-cli/.speakeasy/gen.lock @@ -602,7 +602,7 @@ trackedFiles: internal/sdk/sdkinternal/utils/headers.go: last_write_checksum: sha1:1b0bd68e1ea0bce8c5a42b5de9fd020fede7aecc internal/sdk/sdkinternal/utils/json.go: - last_write_checksum: sha1:ec04c01892273a2e2d2436075ea3d290468ef74c + last_write_checksum: sha1:019b03979496abc305273aa8a995adce357bcc1a internal/sdk/sdkinternal/utils/oauth2_credentials.go: last_write_checksum: sha1:f9218b6b3dbd11494cc353bf22eb37f0ca654a7d internal/sdk/sdkinternal/utils/oauth2_sessions.go: @@ -1076,7 +1076,7 @@ trackedFiles: tests/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd tests/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:66bc354bf281916b0ee3bb77bdb0f173d82dab38 + last_write_checksum: sha1:642159c8ddd0e1d4f69146b64af207f6a7c0cd76 tests/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 tests/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-cli/internal/sdk/sdkinternal/utils/json.go b/zSDKs/sdk-cli/internal/sdk/sdkinternal/utils/json.go index 8f3ee92e1..b7b564a01 100644 --- a/zSDKs/sdk-cli/internal/sdk/sdkinternal/utils/json.go +++ b/zSDKs/sdk-cli/internal/sdk/sdkinternal/utils/json.go @@ -216,7 +216,11 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue && !(isJSONContainer(constValue) && constJSONValuesEqual(r, constValue)) { + matches := val == constValue + if isContainerKind(field.Type) { + matches = constJSONValuesEqual(r, constValue) + } + if !matches { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -446,8 +450,13 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } -func isJSONContainer(value string) bool { - return strings.HasPrefix(value, "[") || strings.HasPrefix(value, "{") +func isContainerKind(typ reflect.Type) bool { + switch dereferenceTypePointer(typ).Kind() { + case reflect.Slice, reflect.Map: + return true + default: + return false + } } func constJSONValuesEqual(received json.RawMessage, constValue string) bool { diff --git a/zSDKs/sdk-cli/tests/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-cli/tests/mockserver/internal/sdk/utils/json.go index e53a81f39..d59d5e51c 100644 --- a/zSDKs/sdk-cli/tests/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-cli/tests/mockserver/internal/sdk/utils/json.go @@ -201,7 +201,11 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue && !(isJSONContainer(constValue) && constJSONValuesEqual(r, constValue)) { + matches := val == constValue + if isContainerKind(field.Type) { + matches = constJSONValuesEqual(r, constValue) + } + if !matches { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -424,8 +428,13 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } -func isJSONContainer(value string) bool { - return strings.HasPrefix(value, "[") || strings.HasPrefix(value, "{") +func isContainerKind(typ reflect.Type) bool { + switch dereferenceTypePointer(typ).Kind() { + case reflect.Slice, reflect.Map: + return true + default: + return false + } } func constJSONValuesEqual(received json.RawMessage, constValue string) bool { diff --git a/zSDKs/sdk-csharp/.speakeasy/gen.lock b/zSDKs/sdk-csharp/.speakeasy/gen.lock index 1d8118815..651faf679 100644 --- a/zSDKs/sdk-csharp/.speakeasy/gen.lock +++ b/zSDKs/sdk-csharp/.speakeasy/gen.lock @@ -458,7 +458,7 @@ trackedFiles: Tests/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd Tests/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:66bc354bf281916b0ee3bb77bdb0f173d82dab38 + last_write_checksum: sha1:642159c8ddd0e1d4f69146b64af207f6a7c0cd76 Tests/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 Tests/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-csharp/Tests/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-csharp/Tests/mockserver/internal/sdk/utils/json.go index e53a81f39..d59d5e51c 100644 --- a/zSDKs/sdk-csharp/Tests/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-csharp/Tests/mockserver/internal/sdk/utils/json.go @@ -201,7 +201,11 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue && !(isJSONContainer(constValue) && constJSONValuesEqual(r, constValue)) { + matches := val == constValue + if isContainerKind(field.Type) { + matches = constJSONValuesEqual(r, constValue) + } + if !matches { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -424,8 +428,13 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } -func isJSONContainer(value string) bool { - return strings.HasPrefix(value, "[") || strings.HasPrefix(value, "{") +func isContainerKind(typ reflect.Type) bool { + switch dereferenceTypePointer(typ).Kind() { + case reflect.Slice, reflect.Map: + return true + default: + return false + } } func constJSONValuesEqual(received json.RawMessage, constValue string) bool { diff --git a/zSDKs/sdk-go/.speakeasy/gen.lock b/zSDKs/sdk-go/.speakeasy/gen.lock index 4a929a26a..7f80c5259 100644 --- a/zSDKs/sdk-go/.speakeasy/gen.lock +++ b/zSDKs/sdk-go/.speakeasy/gen.lock @@ -713,7 +713,7 @@ trackedFiles: internal/utils/headers.go: last_write_checksum: sha1:e529ca3d7ab96a091021bcd471ba2cbef50286b3 internal/utils/json.go: - last_write_checksum: sha1:990470ab3df4c670d7110b3d598bd4c1185ffb53 + last_write_checksum: sha1:c3b8298dcb759309db7e312f3d04993cfd41643a internal/utils/pathparams.go: last_write_checksum: sha1:a092fc31b7c8fac29c359ddfa8bf2e02763fa097 internal/utils/queryparams.go: @@ -1233,7 +1233,7 @@ trackedFiles: tests/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd tests/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:66bc354bf281916b0ee3bb77bdb0f173d82dab38 + last_write_checksum: sha1:642159c8ddd0e1d4f69146b64af207f6a7c0cd76 tests/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 tests/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-go/internal/utils/json.go b/zSDKs/sdk-go/internal/utils/json.go index bfdf9ac73..a245cbee6 100644 --- a/zSDKs/sdk-go/internal/utils/json.go +++ b/zSDKs/sdk-go/internal/utils/json.go @@ -216,7 +216,11 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue && !(isJSONContainer(constValue) && constJSONValuesEqual(r, constValue)) { + matches := val == constValue + if isContainerKind(field.Type) { + matches = constJSONValuesEqual(r, constValue) + } + if !matches { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -446,8 +450,13 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } -func isJSONContainer(value string) bool { - return strings.HasPrefix(value, "[") || strings.HasPrefix(value, "{") +func isContainerKind(typ reflect.Type) bool { + switch dereferenceTypePointer(typ).Kind() { + case reflect.Slice, reflect.Map: + return true + default: + return false + } } func constJSONValuesEqual(received json.RawMessage, constValue string) bool { diff --git a/zSDKs/sdk-go/tests/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-go/tests/mockserver/internal/sdk/utils/json.go index e53a81f39..d59d5e51c 100644 --- a/zSDKs/sdk-go/tests/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-go/tests/mockserver/internal/sdk/utils/json.go @@ -201,7 +201,11 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue && !(isJSONContainer(constValue) && constJSONValuesEqual(r, constValue)) { + matches := val == constValue + if isContainerKind(field.Type) { + matches = constJSONValuesEqual(r, constValue) + } + if !matches { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -424,8 +428,13 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } -func isJSONContainer(value string) bool { - return strings.HasPrefix(value, "[") || strings.HasPrefix(value, "{") +func isContainerKind(typ reflect.Type) bool { + switch dereferenceTypePointer(typ).Kind() { + case reflect.Slice, reflect.Map: + return true + default: + return false + } } func constJSONValuesEqual(received json.RawMessage, constValue string) bool { diff --git a/zSDKs/sdk-javav2/.speakeasy/gen.lock b/zSDKs/sdk-javav2/.speakeasy/gen.lock index 10dde5753..25cb31c21 100644 --- a/zSDKs/sdk-javav2/.speakeasy/gen.lock +++ b/zSDKs/sdk-javav2/.speakeasy/gen.lock @@ -1983,7 +1983,7 @@ trackedFiles: tests/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd tests/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:66bc354bf281916b0ee3bb77bdb0f173d82dab38 + last_write_checksum: sha1:642159c8ddd0e1d4f69146b64af207f6a7c0cd76 tests/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 tests/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-javav2/tests/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-javav2/tests/mockserver/internal/sdk/utils/json.go index e53a81f39..d59d5e51c 100644 --- a/zSDKs/sdk-javav2/tests/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-javav2/tests/mockserver/internal/sdk/utils/json.go @@ -201,7 +201,11 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue && !(isJSONContainer(constValue) && constJSONValuesEqual(r, constValue)) { + matches := val == constValue + if isContainerKind(field.Type) { + matches = constJSONValuesEqual(r, constValue) + } + if !matches { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -424,8 +428,13 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } -func isJSONContainer(value string) bool { - return strings.HasPrefix(value, "[") || strings.HasPrefix(value, "{") +func isContainerKind(typ reflect.Type) bool { + switch dereferenceTypePointer(typ).Kind() { + case reflect.Slice, reflect.Map: + return true + default: + return false + } } func constJSONValuesEqual(received json.RawMessage, constValue string) bool { diff --git a/zSDKs/sdk-mcp-typescript/.speakeasy/gen.lock b/zSDKs/sdk-mcp-typescript/.speakeasy/gen.lock index d3faa3767..974b45e02 100644 --- a/zSDKs/sdk-mcp-typescript/.speakeasy/gen.lock +++ b/zSDKs/sdk-mcp-typescript/.speakeasy/gen.lock @@ -370,7 +370,7 @@ trackedFiles: src/__tests__/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd src/__tests__/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:66bc354bf281916b0ee3bb77bdb0f173d82dab38 + last_write_checksum: sha1:642159c8ddd0e1d4f69146b64af207f6a7c0cd76 src/__tests__/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 src/__tests__/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go index e53a81f39..d59d5e51c 100644 --- a/zSDKs/sdk-mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go @@ -201,7 +201,11 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue && !(isJSONContainer(constValue) && constJSONValuesEqual(r, constValue)) { + matches := val == constValue + if isContainerKind(field.Type) { + matches = constJSONValuesEqual(r, constValue) + } + if !matches { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -424,8 +428,13 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } -func isJSONContainer(value string) bool { - return strings.HasPrefix(value, "[") || strings.HasPrefix(value, "{") +func isContainerKind(typ reflect.Type) bool { + switch dereferenceTypePointer(typ).Kind() { + case reflect.Slice, reflect.Map: + return true + default: + return false + } } func constJSONValuesEqual(received json.RawMessage, constValue string) bool { diff --git a/zSDKs/sdk-pythonv2/.speakeasy/gen.lock b/zSDKs/sdk-pythonv2/.speakeasy/gen.lock index 5201d758e..0344f6a25 100644 --- a/zSDKs/sdk-pythonv2/.speakeasy/gen.lock +++ b/zSDKs/sdk-pythonv2/.speakeasy/gen.lock @@ -1176,7 +1176,7 @@ trackedFiles: tests/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd tests/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:66bc354bf281916b0ee3bb77bdb0f173d82dab38 + last_write_checksum: sha1:642159c8ddd0e1d4f69146b64af207f6a7c0cd76 tests/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 tests/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-pythonv2/tests/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-pythonv2/tests/mockserver/internal/sdk/utils/json.go index e53a81f39..d59d5e51c 100644 --- a/zSDKs/sdk-pythonv2/tests/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-pythonv2/tests/mockserver/internal/sdk/utils/json.go @@ -201,7 +201,11 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue && !(isJSONContainer(constValue) && constJSONValuesEqual(r, constValue)) { + matches := val == constValue + if isContainerKind(field.Type) { + matches = constJSONValuesEqual(r, constValue) + } + if !matches { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -424,8 +428,13 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } -func isJSONContainer(value string) bool { - return strings.HasPrefix(value, "[") || strings.HasPrefix(value, "{") +func isContainerKind(typ reflect.Type) bool { + switch dereferenceTypePointer(typ).Kind() { + case reflect.Slice, reflect.Map: + return true + default: + return false + } } func constJSONValuesEqual(received json.RawMessage, constValue string) bool { diff --git a/zSDKs/sdk-ruby/.speakeasy/gen.lock b/zSDKs/sdk-ruby/.speakeasy/gen.lock index 430bdb819..5bf7a29a2 100644 --- a/zSDKs/sdk-ruby/.speakeasy/gen.lock +++ b/zSDKs/sdk-ruby/.speakeasy/gen.lock @@ -1835,7 +1835,7 @@ trackedFiles: test/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd test/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:66bc354bf281916b0ee3bb77bdb0f173d82dab38 + last_write_checksum: sha1:642159c8ddd0e1d4f69146b64af207f6a7c0cd76 test/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 test/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-ruby/test/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-ruby/test/mockserver/internal/sdk/utils/json.go index e53a81f39..d59d5e51c 100644 --- a/zSDKs/sdk-ruby/test/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-ruby/test/mockserver/internal/sdk/utils/json.go @@ -201,7 +201,11 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue && !(isJSONContainer(constValue) && constJSONValuesEqual(r, constValue)) { + matches := val == constValue + if isContainerKind(field.Type) { + matches = constJSONValuesEqual(r, constValue) + } + if !matches { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -424,8 +428,13 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } -func isJSONContainer(value string) bool { - return strings.HasPrefix(value, "[") || strings.HasPrefix(value, "{") +func isContainerKind(typ reflect.Type) bool { + switch dereferenceTypePointer(typ).Kind() { + case reflect.Slice, reflect.Map: + return true + default: + return false + } } func constJSONValuesEqual(received json.RawMessage, constValue string) bool { diff --git a/zSDKs/sdk-typescriptv2/.speakeasy/gen.lock b/zSDKs/sdk-typescriptv2/.speakeasy/gen.lock index c5dedec78..1fcbdf6fb 100644 --- a/zSDKs/sdk-typescriptv2/.speakeasy/gen.lock +++ b/zSDKs/sdk-typescriptv2/.speakeasy/gen.lock @@ -867,7 +867,7 @@ trackedFiles: src/__tests__/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd src/__tests__/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:66bc354bf281916b0ee3bb77bdb0f173d82dab38 + last_write_checksum: sha1:642159c8ddd0e1d4f69146b64af207f6a7c0cd76 src/__tests__/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 src/__tests__/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-typescriptv2/src/__tests__/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-typescriptv2/src/__tests__/mockserver/internal/sdk/utils/json.go index e53a81f39..d59d5e51c 100644 --- a/zSDKs/sdk-typescriptv2/src/__tests__/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-typescriptv2/src/__tests__/mockserver/internal/sdk/utils/json.go @@ -201,7 +201,11 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue && !(isJSONContainer(constValue) && constJSONValuesEqual(r, constValue)) { + matches := val == constValue + if isContainerKind(field.Type) { + matches = constJSONValuesEqual(r, constValue) + } + if !matches { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -424,8 +428,13 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } -func isJSONContainer(value string) bool { - return strings.HasPrefix(value, "[") || strings.HasPrefix(value, "{") +func isContainerKind(typ reflect.Type) bool { + switch dereferenceTypePointer(typ).Kind() { + case reflect.Slice, reflect.Map: + return true + default: + return false + } } func constJSONValuesEqual(received json.RawMessage, constValue string) bool { diff --git a/zSDKs/terraform-provider-testing/.speakeasy/gen.lock b/zSDKs/terraform-provider-testing/.speakeasy/gen.lock index 705bfcdfe..fd109aa97 100644 --- a/zSDKs/terraform-provider-testing/.speakeasy/gen.lock +++ b/zSDKs/terraform-provider-testing/.speakeasy/gen.lock @@ -2422,7 +2422,7 @@ trackedFiles: internal/sdk/internal/utils/jq.go: last_write_checksum: sha1:2e75ed7a7db1f91e97dac1ac4ca7801b2beb69b5 internal/sdk/internal/utils/json.go: - last_write_checksum: sha1:998dc779115be1a9c7ebebf7221a4d8424141c6f + last_write_checksum: sha1:1c9d6f7c612b8041b7ef3098eae1b145f6260e54 internal/sdk/internal/utils/oauth2_credentials.go: last_write_checksum: sha1:f9218b6b3dbd11494cc353bf22eb37f0ca654a7d internal/sdk/internal/utils/oauth2_sessions.go: diff --git a/zSDKs/terraform-provider-testing/internal/sdk/internal/utils/json.go b/zSDKs/terraform-provider-testing/internal/sdk/internal/utils/json.go index a15f0804f..84fbf1af1 100644 --- a/zSDKs/terraform-provider-testing/internal/sdk/internal/utils/json.go +++ b/zSDKs/terraform-provider-testing/internal/sdk/internal/utils/json.go @@ -214,7 +214,11 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } constValue := field.Tag.Get("const") - if val != constValue && !(isJSONContainer(constValue) && constJSONValuesEqual(r, constValue)) { + matches := val == constValue + if isContainerKind(field.Type) { + matches = constJSONValuesEqual(r, constValue) + } + if !matches { return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } @@ -433,8 +437,13 @@ func implementsJSONMarshaler(v interface{}) bool { return reflect.PtrTo(vType).Implements(marshalerType) } -func isJSONContainer(value string) bool { - return strings.HasPrefix(value, "[") || strings.HasPrefix(value, "{") +func isContainerKind(typ reflect.Type) bool { + switch dereferenceTypePointer(typ).Kind() { + case reflect.Slice, reflect.Map: + return true + default: + return false + } } func constJSONValuesEqual(received json.RawMessage, constValue string) bool { From 1f45e716beae1c608c44f0678c742511864609ba Mon Sep 17 00:00:00 2001 From: Ash Godfrey Date: Mon, 2 Nov 2026 12:53:16 +0000 Subject: [PATCH 12/22] fix: accept an empty const on set-format and uniqueItems arrays An array declared with `format: set` or `uniqueItems: true` and `const: []` had its const dropped, because set types were rejected outright. Element order cannot matter for an empty list, so an empty const is now accepted on those arrays regardless of item type; a non-empty const on them is still rejected. This covers request bodies that must send an empty set, such as a teardown operation that replaces a collection of object items with `[]`. The review Terraform ConstContainer entity gains an `empty_set` property (a set of objects with `const: []`) and its acceptance test asserts the request body carries it. --- internal/schemas/handle_array_test.go | 83 +++++++++++++++++++ internal/schemas/schemas.go | 11 ++- tests/specs/review-terraform.yaml | 21 +++++ .../.speakeasy/gen.lock | 12 +-- .../.speakeasy/logs/naming.log | 11 +++ .../provider/constcontainer_resource_test.go | 4 +- .../models/shared/constcontainerrequest.go | 17 ++++ .../models/shared/constcontainerresponse.go | 17 ++++ 8 files changed, 165 insertions(+), 11 deletions(-) diff --git a/internal/schemas/handle_array_test.go b/internal/schemas/handle_array_test.go index 949f2a700..fe749b48e 100644 --- a/internal/schemas/handle_array_test.go +++ b/internal/schemas/handle_array_test.go @@ -218,6 +218,89 @@ func TestHandleArray(t *testing.T) { Build(), expectedWarning: "only arrays without uniqueItems and maps of scalar values are supported, omitting const", }, + { + name: "UniqueItemsArrayWithEmptyConst", + schemasYAML: `TestSchema: + type: array + items: + type: string + uniqueItems: true + 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{ + UniqueItems: pointer.From(true), + }). + Build()). + WithConst(&ast.AnyValue{Value: []interface{}{}}). + Build(), + }, + { + name: "SetFormatWithEmptyConst", + schemasYAML: `TestSchema: + type: array + format: set + items: + type: string + const: []`, + schemaName: "TestSchema", + mockFeatures: func() *testutils.MockFeaturesConfig { + config := testutils.NewMockFeaturesConfig().WithTarget(types.Target{Target: "go"}) + config.SupportedFeatures = map[features.Feature]bool{ + features.FeatureSets: true, + features.FeatureConstArrays: true, + features.FeatureConstsAndDefaults: true, + } + return config + }, + expected: testutils.NewFieldDef("strings", + testutils.NewTypeDef(ast.DataTypeSet). + WithItemType(testutils.NewTypeDef(ast.DataTypeString).WithLocation(&yaml.Node{Line: 12, Column: 9}).WithValidations(&ast.Validations{}).Build()). + WithLocation(&yaml.Node{Line: 9, Column: 7}). + WithValidations(&ast.Validations{}). + Build()). + WithConst(&ast.AnyValue{Value: []interface{}{}}). + Build(), + }, + { + name: "SetFormatWithConst", + schemasYAML: `TestSchema: + type: array + format: set + items: + type: string + const: + - read`, + schemaName: "TestSchema", + mockFeatures: func() *testutils.MockFeaturesConfig { + config := testutils.NewMockFeaturesConfig().WithTarget(types.Target{Target: "go"}) + config.SupportedFeatures = map[features.Feature]bool{ + features.FeatureSets: true, + features.FeatureConstArrays: true, + features.FeatureConstsAndDefaults: true, + } + return config + }, + expected: testutils.NewFieldDef("strings", + testutils.NewTypeDef(ast.DataTypeSet). + WithItemType(testutils.NewTypeDef(ast.DataTypeString).WithLocation(&yaml.Node{Line: 12, Column: 9}).WithValidations(&ast.Validations{}).Build()). + WithLocation(&yaml.Node{Line: 9, Column: 7}). + WithValidations(&ast.Validations{}). + Build()). + Build(), + expectedWarning: "only arrays without uniqueItems and maps of scalar values are supported, omitting const", + }, { name: "ArrayWithConstNull", schemasYAML: `TestSchema: diff --git a/internal/schemas/schemas.go b/internal/schemas/schemas.go index 77c4bd595..a7e5365c5 100644 --- a/internal/schemas/schemas.go +++ b/internal/schemas/schemas.go @@ -1695,14 +1695,17 @@ func constContainerValueSupported(val any, typ *ast.TypeDef) bool { } switch typ.Type { - case ast.DataTypeArray: - if typ.Validations != nil && typ.Validations.UniqueItems != nil && *typ.Validations.UniqueItems { - return false - } + case ast.DataTypeArray, ast.DataTypeSet: items, ok := val.([]any) if !ok { return false } + if len(items) == 0 { + return true + } + if typ.Type == ast.DataTypeSet || (typ.Validations != nil && typ.Validations.UniqueItems != nil && *typ.Validations.UniqueItems) { + return false + } for _, item := range items { if !constScalarMatchesType(item, typ.ItemType) { return false diff --git a/tests/specs/review-terraform.yaml b/tests/specs/review-terraform.yaml index 0038bd887..b21fdd521 100644 --- a/tests/specs/review-terraform.yaml +++ b/tests/specs/review-terraform.yaml @@ -5988,6 +5988,16 @@ components: const: - read - write + empty_set: + type: array + format: set + items: + type: object + additionalProperties: false + properties: + key: + type: string + const: [] empty_map: type: object additionalProperties: @@ -6004,6 +6014,7 @@ components: - name - empty_list - empty_map + - empty_set ConstContainerResponse: type: object additionalProperties: false @@ -6029,6 +6040,16 @@ components: const: - read - write + empty_set: + type: array + format: set + items: + type: object + additionalProperties: false + properties: + key: + type: string + const: [] empty_map: type: object additionalProperties: diff --git a/zSDKs/terraform-provider-testing/.speakeasy/gen.lock b/zSDKs/terraform-provider-testing/.speakeasy/gen.lock index fd109aa97..e9060f782 100644 --- a/zSDKs/terraform-provider-testing/.speakeasy/gen.lock +++ b/zSDKs/terraform-provider-testing/.speakeasy/gen.lock @@ -1,7 +1,7 @@ lockVersion: 2.0.0 id: review-sdk-test-id management: - docChecksum: 7e117218d1b4664bc4b4b9360bfcebcf + docChecksum: f8647c8985caf59cadd9e2438073ca25 docVersion: 0.0.1 speakeasyVersion: internal generationVersion: internal @@ -3098,9 +3098,9 @@ trackedFiles: internal/sdk/models/shared/basicsearch.go: last_write_checksum: sha1:ebc8943a31148f7623c5f8ff940dd81c1b52f23d internal/sdk/models/shared/constcontainerrequest.go: - last_write_checksum: sha1:9c257c5ba13e6c10ddc608feaf41b8f4a09450e4 + last_write_checksum: sha1:040d3355c429964b952a6bb74e7fcb40971c3ebc internal/sdk/models/shared/constcontainerresponse.go: - last_write_checksum: sha1:c6ea7685379a02992ab06367f585c921571896d7 + last_write_checksum: sha1:b1dab8efea26ccee13f869bb633e5c918032ee3e internal/sdk/models/shared/discriminatedobject.go: last_write_checksum: sha1:9bb5641a1bcb27ec59c1f16d82d8a251ec733286 internal/sdk/models/shared/discriminatedunionarraycreaterequest.go: @@ -6051,10 +6051,10 @@ examples: create-const-container: speakeasy-default-create-const-container: requestBody: - application/json: {"name": "", "empty_list": [], "fixed_list": ["read", "write"], "empty_map": {}, "fixed_map": {"max": 10, "min": 1}} + application/json: {"name": "", "empty_list": [], "fixed_list": ["read", "write"], "empty_set": [], "empty_map": {}, "fixed_map": {"max": 10, "min": 1}} responses: "200": - application/json: {"empty_list": [], "fixed_list": ["read", "write"], "empty_map": {}, "fixed_map": {"max": 10, "min": 1}} + application/json: {"empty_list": [], "fixed_list": ["read", "write"], "empty_set": [], "empty_map": {}, "fixed_map": {"max": 10, "min": 1}} get-const-container: speakeasy-default-get-const-container: parameters: @@ -6062,7 +6062,7 @@ examples: id: "" responses: "200": - application/json: {"empty_list": [], "fixed_list": ["read", "write"], "empty_map": {}, "fixed_map": {"max": 10, "min": 1}} + application/json: {"empty_list": [], "fixed_list": ["read", "write"], "empty_set": [], "empty_map": {}, "fixed_map": {"max": 10, "min": 1}} delete-const-container: speakeasy-default-delete-const-container: parameters: diff --git a/zSDKs/terraform-provider-testing/.speakeasy/logs/naming.log b/zSDKs/terraform-provider-testing/.speakeasy/logs/naming.log index 73705617c..5bf896489 100644 --- a/zSDKs/terraform-provider-testing/.speakeasy/logs/naming.log +++ b/zSDKs/terraform-provider-testing/.speakeasy/logs/naming.log @@ -2247,6 +2247,15 @@ DEBUG discriminated: Renamed to "ConstContainerResponse_fixed_list" registrationID: "scope:shared refType:Schemas refName:ConstContainerResponse originalName:fixed_list" DEBUG +--- Renaming 2 types with name "empty_set" --- +DEBUG discriminated: Renamed to "ConstContainerRequest_empty_set" + labels: "original_name:empty_set scope:shared refName:ConstContainerRequest" + registrationID: "scope:shared refType:Schemas refName:ConstContainerRequest originalName:empty_set" +DEBUG discriminated: Renamed to "ConstContainerResponse_empty_set" + labels: "original_name:empty_set scope:shared refName:ConstContainerResponse" + registrationID: "scope:shared refType:Schemas refName:ConstContainerResponse originalName:empty_set" +DEBUG + --- Renaming 3 types with name "tier" --- DEBUG discriminated: Renamed to "create_import_defaulted_id_tier" labels: "original_name:tier operation:create_import_defaulted_id data_type:enum parameter:pathParam" @@ -3824,9 +3833,11 @@ DeleteOasContentMediaTypeRequest (id: string) DeleteOasContentMediaTypeResponse (ContentType: string, StatusCode: int32, RawResponse: response) ConstContainerRequest (name: string, empty_list: array, fixed_list: array ...) ConstContainerRequestFixedList (enum: read, write, admin) + ConstContainerRequestEmptySet (key: string) CreateConstContainerResponse (ContentType: string, StatusCode: int32, RawResponse: response ...) ConstContainerResponse (id: string, name: string, empty_list: array ...) ConstContainerResponseFixedList (enum: read, write, admin) + ConstContainerResponseEmptySet (key: string) GetConstContainerRequest (id: string) GetConstContainerResponse (ContentType: string, StatusCode: int32, RawResponse: response ...) DeleteConstContainerRequest (id: string) diff --git a/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource_test.go b/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource_test.go index 2f6e978e7..b8e04f623 100644 --- a/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource_test.go +++ b/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource_test.go @@ -40,6 +40,7 @@ func TestConstContainerResourceLifecycle(t *testing.T) { "empty_list": [ ], "fixed_list": [ "read" , "write" ], "empty_map": { }, + "empty_set": [ ], "fixed_map": { "min" : 1, "max" : 1e1 } }`)) }, @@ -99,6 +100,7 @@ func TestConstContainerResourceLifecycle(t *testing.T) { tfmockserver.AssertRequestBodyFieldEmptyArray(t, body, "empty_list") tfmockserver.AssertRequestBodyFieldArray(t, body, "fixed_list", []any{"read", "write"}) tfmockserver.AssertRequestBodyField(t, body, "empty_map", map[string]any{}) + tfmockserver.AssertRequestBodyFieldEmptyArray(t, body, "empty_set") tfmockserver.AssertRequestBodyField(t, body, "fixed_map", map[string]any{"max": float64(10), "min": float64(1)}) - require.Len(t, body, 5, "request body carries only name and the four const fields: %v", body) + require.Len(t, body, 6, "request body carries only name and the five const fields: %v", body) } diff --git a/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerrequest.go b/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerrequest.go index 638bbe163..0dea978da 100644 --- a/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerrequest.go +++ b/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerrequest.go @@ -37,6 +37,17 @@ func (e *ConstContainerRequestFixedList) UnmarshalJSON(data []byte) error { } } +type ConstContainerRequestEmptySet struct { + Key *string `json:"key,omitempty"` +} + +func (c *ConstContainerRequestEmptySet) GetKey() *string { + if c == nil { + return nil + } + return c.Key +} + type ConstContainerRequest struct { Name string `json:"name"` //lint:ignore U1000 accessed via reflection for JSON marshaling @@ -44,6 +55,8 @@ type ConstContainerRequest struct { //lint:ignore U1000 accessed via reflection for JSON marshaling fixedList []ConstContainerRequestFixedList `const:"[\"read\",\"write\"]" json:"fixed_list,omitempty"` //lint:ignore U1000 accessed via reflection for JSON marshaling + emptySet []ConstContainerRequestEmptySet `const:"[]" json:"empty_set"` + //lint:ignore U1000 accessed via reflection for JSON marshaling emptyMap map[string]string `const:"{}" json:"empty_map"` //lint:ignore U1000 accessed via reflection for JSON marshaling fixedMap map[string]int64 `const:"{\"max\":10,\"min\":1}" json:"fixed_map,omitempty"` @@ -75,6 +88,10 @@ func (c *ConstContainerRequest) GetFixedList() []ConstContainerRequestFixedList return []ConstContainerRequestFixedList{ConstContainerRequestFixedListRead, ConstContainerRequestFixedListWrite} } +func (c *ConstContainerRequest) GetEmptySet() []ConstContainerRequestEmptySet { + return []ConstContainerRequestEmptySet{} +} + func (c *ConstContainerRequest) GetEmptyMap() map[string]string { return map[string]string{} } diff --git a/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerresponse.go b/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerresponse.go index 5cd99cd30..ea9e7727d 100644 --- a/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerresponse.go +++ b/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerresponse.go @@ -37,6 +37,17 @@ func (e *ConstContainerResponseFixedList) UnmarshalJSON(data []byte) error { } } +type ConstContainerResponseEmptySet struct { + Key *string `json:"key,omitempty"` +} + +func (c *ConstContainerResponseEmptySet) GetKey() *string { + if c == nil { + return nil + } + return c.Key +} + type ConstContainerResponse struct { ID *string `json:"id,omitempty"` Name *string `json:"name,omitempty"` @@ -45,6 +56,8 @@ type ConstContainerResponse struct { //lint:ignore U1000 accessed via reflection for JSON marshaling fixedList []ConstContainerResponseFixedList `const:"[\"read\",\"write\"]" json:"fixed_list,omitempty"` //lint:ignore U1000 accessed via reflection for JSON marshaling + emptySet []ConstContainerResponseEmptySet `const:"[]" json:"empty_set,omitempty"` + //lint:ignore U1000 accessed via reflection for JSON marshaling emptyMap map[string]string `const:"{}" json:"empty_map,omitempty"` //lint:ignore U1000 accessed via reflection for JSON marshaling fixedMap map[string]int64 `const:"{\"max\":10,\"min\":1}" json:"fixed_map,omitempty"` @@ -83,6 +96,10 @@ func (c *ConstContainerResponse) GetFixedList() []ConstContainerResponseFixedLis return []ConstContainerResponseFixedList{ConstContainerResponseFixedListRead, ConstContainerResponseFixedListWrite} } +func (c *ConstContainerResponse) GetEmptySet() []ConstContainerResponseEmptySet { + return []ConstContainerResponseEmptySet{} +} + func (c *ConstContainerResponse) GetEmptyMap() map[string]string { return map[string]string{} } From 96bb1763d543948aa4a2418a4830ddacb2563f79 Mon Sep 17 00:00:00 2001 From: Ash Godfrey Date: Mon, 2 Nov 2026 13:09:03 +0000 Subject: [PATCH 13/22] fix(terraform): handle const containers nested in list items and template delimiters in const map keys A const array or map declared on a property of a list item's object schema made Terraform generation fail: the list-item field loop in the TF-to-SDK builder matched hidden const fields positionally against the Terraform type, hit the wrong field and raised "Unexpected type detected". The loop now skips const fields, as the object-level loop already did; the SDK model injects the value. A const map whose key contains `{{` broke template parsing when rendering the Go literal for the field's getter. Keys are now escaped the same way string values are. The review fixture gains a list-of-objects property with a nested const array and a map const with a `{{` key; the lifecycle test asserts both reach the request body and round-trip through a read. --- templates/templates/common/go/sanitization.ts | 7 ++- .../terraform/includes/generateTFToSDK.ts | 3 ++ tests/specs/review-terraform.yaml | 54 +++++++++++++++++++ .../.speakeasy/gen.lock | 26 +++++---- .../.speakeasy/logs/naming.log | 11 ++++ zSDKs/terraform-provider-testing/README.md | 2 +- .../docs/data-sources/const_container.md | 10 ++++ .../docs/resources/const_container.md | 19 +++++++ .../testing_const_container/resource.tf | 5 ++ .../provider/constcontainer_data_source.go | 19 ++++++- .../constcontainer_data_source_sdk.go | 10 ++++ .../provider/constcontainer_resource.go | 44 ++++++++++++++- .../provider/constcontainer_resource_sdk.go | 25 ++++++++- .../provider/constcontainer_resource_test.go | 13 ++++- .../main.tf | 1 + .../const_container_request_nested_list.go | 11 ++++ .../const_container_response_nested_list.go | 11 ++++ .../models/shared/constcontainerrequest.go | 49 +++++++++++++++++ .../models/shared/constcontainerresponse.go | 49 +++++++++++++++++ 19 files changed, 349 insertions(+), 20 deletions(-) create mode 100644 zSDKs/terraform-provider-testing/internal/provider/types/const_container_request_nested_list.go create mode 100644 zSDKs/terraform-provider-testing/internal/provider/types/const_container_response_nested_list.go diff --git a/templates/templates/common/go/sanitization.ts b/templates/templates/common/go/sanitization.ts index aa4cd270a..850a04f49 100644 --- a/templates/templates/common/go/sanitization.ts +++ b/templates/templates/common/go/sanitization.ts @@ -771,7 +771,12 @@ function templateConstContainerValue( if (fieldDef.Type.Type.toString() === "map") { const entries = Object.entries( withSortedKeys(fieldDef.Const.Value ?? {}), - ).map(([key, value]) => `${JSON.stringify(key)}: ${renderItem(value)}`); + ).map( + ([key, value]) => + `${JSON.stringify(key).replaceAll("{{", `{{"{{"}}`)}: ${renderItem( + value, + )}`, + ); return `${containerType}{${entries.join(", ")}}`; } diff --git a/templates/templates/terraform/includes/generateTFToSDK.ts b/templates/templates/terraform/includes/generateTFToSDK.ts index bd8617737..0c3f4ccb4 100644 --- a/templates/templates/terraform/includes/generateTFToSDK.ts +++ b/templates/templates/terraform/includes/generateTFToSDK.ts @@ -1145,6 +1145,9 @@ function generateModelToSDKMethodBody( tfAccessor = `${tfAccessor}[${iterVariable}]`; for (let i = 0; i < targetTypeDef.ItemType.Fields.length; i++) { const field = targetTypeDef.ItemType.Fields[i]; + if (field.Const) { + continue; + } const equivalent = fromTypeDef.ItemType?.Fields.find( (f) => sanitizeFieldName(field.Name) == sanitizeFieldName(f.Name), diff --git a/tests/specs/review-terraform.yaml b/tests/specs/review-terraform.yaml index b21fdd521..1858bece0 100644 --- a/tests/specs/review-terraform.yaml +++ b/tests/specs/review-terraform.yaml @@ -6010,6 +6010,33 @@ components: const: max: 10 min: 1 + templated_map: + description: | + Map const whose key contains template delimiters. The generated + Go literal and struct tag must escape them. + type: object + additionalProperties: + type: string + const: + '{{key}}': value + nested_list: + description: | + List of objects whose item schema declares a const array. The + nested const must be hidden from the Terraform schema and sent + for every item. + type: array + items: + type: object + additionalProperties: false + properties: + label: + type: string + tags: + type: array + items: + type: string + const: + - fixed required: - name - empty_list @@ -6062,6 +6089,33 @@ components: const: max: 10 min: 1 + templated_map: + description: | + Map const whose key contains template delimiters. The generated + Go literal and struct tag must escape them. + type: object + additionalProperties: + type: string + const: + '{{key}}': value + nested_list: + description: | + List of objects whose item schema declares a const array. The + nested const must be hidden from the Terraform schema and sent + for every item. + type: array + items: + type: object + additionalProperties: false + properties: + label: + type: string + tags: + type: array + items: + type: string + const: + - fixed DiscriminatedUnionCreateRequest: x-speakeasy-entity: DiscriminatedUnion type: object diff --git a/zSDKs/terraform-provider-testing/.speakeasy/gen.lock b/zSDKs/terraform-provider-testing/.speakeasy/gen.lock index e9060f782..3c80ff1f0 100644 --- a/zSDKs/terraform-provider-testing/.speakeasy/gen.lock +++ b/zSDKs/terraform-provider-testing/.speakeasy/gen.lock @@ -1,7 +1,7 @@ lockVersion: 2.0.0 id: review-sdk-test-id management: - docChecksum: f8647c8985caf59cadd9e2438073ca25 + docChecksum: a0a27db9e77dc544c3bf600ce831af52 docVersion: 0.0.1 speakeasyVersion: internal generationVersion: internal @@ -284,7 +284,7 @@ trackedFiles: examples/resources/testing_const_container/import.sh: last_write_checksum: sha1:dc82e240078029b62b56bb695067d4c5e9cb4264 examples/resources/testing_const_container/resource.tf: - last_write_checksum: sha1:73c7ef301934066294a6aa619b7a7e4268581b95 + last_write_checksum: sha1:e99fed339d5e89b5fd901103358d29986496d02a examples/resources/testing_discriminated_union/import-by-string-id.tf: last_write_checksum: sha1:61473f31485ac280bfa6943e7580d1bdd1e43413 examples/resources/testing_discriminated_union/import.sh: @@ -774,13 +774,13 @@ trackedFiles: internal/provider/basic_resource_sdk.go: last_write_checksum: sha1:c7327b7ec6b530ccb4ba940c83953e7b58b092a4 internal/provider/constcontainer_data_source.go: - last_write_checksum: sha1:3af6b6a8ec4bc9b019d8c83c297577266be2cb05 + last_write_checksum: sha1:a6dc05d0e18d792fe568ae34a06528de71e0e82b internal/provider/constcontainer_data_source_sdk.go: - last_write_checksum: sha1:a3d2f26a22da0b68da7f73523f16dec043d43c59 + last_write_checksum: sha1:11bd69185d0dd245e66a897fec5da3a6bbacb62a internal/provider/constcontainer_resource.go: - last_write_checksum: sha1:1c82779f3e4d07d9145f3c49abc8ecbf21b390af + last_write_checksum: sha1:65ef61f51490dba8ecc6d5d0f3428fb632f1d76d internal/provider/constcontainer_resource_sdk.go: - last_write_checksum: sha1:e8e60887a5d623a9cdaef5a5d0f38884b3cc56a5 + last_write_checksum: sha1:1742253997f1ad0e00600193af22ec233d4c9016 internal/provider/discriminatedunion_data_source.go: last_write_checksum: sha1:dd97963488cb1994321bf5e3f813917c80a7d7b5 internal/provider/discriminatedunion_data_source_sdk.go: @@ -1233,6 +1233,10 @@ trackedFiles: last_write_checksum: sha1:a2a20e6785f1e12c3f94c016cbc106e54942e981 internal/provider/typeconvert/int.go: last_write_checksum: sha1:c28123f17006dc96a233f916a17c38408e37b71f + internal/provider/types/const_container_request_nested_list.go: + last_write_checksum: sha1:458f9b9dd282edcdd630ceea677772735874d669 + internal/provider/types/const_container_response_nested_list.go: + last_write_checksum: sha1:7090951d7f68ab5f6994376600b38b2470079383 internal/provider/types/credential.go: last_write_checksum: sha1:0f481ec7276acf4c15b64e3a7453e4bddc2dfa1c internal/provider/types/credential1.go: @@ -3098,9 +3102,9 @@ trackedFiles: internal/sdk/models/shared/basicsearch.go: last_write_checksum: sha1:ebc8943a31148f7623c5f8ff940dd81c1b52f23d internal/sdk/models/shared/constcontainerrequest.go: - last_write_checksum: sha1:040d3355c429964b952a6bb74e7fcb40971c3ebc + last_write_checksum: sha1:ddd4ad7779260d9e7a9ac96c5918c4e5345c66d2 internal/sdk/models/shared/constcontainerresponse.go: - last_write_checksum: sha1:b1dab8efea26ccee13f869bb633e5c918032ee3e + last_write_checksum: sha1:4d97877805a1493c13e7d36ad58fc1ed13c8293d internal/sdk/models/shared/discriminatedobject.go: last_write_checksum: sha1:9bb5641a1bcb27ec59c1f16d82d8a251ec733286 internal/sdk/models/shared/discriminatedunionarraycreaterequest.go: @@ -6051,10 +6055,10 @@ examples: create-const-container: speakeasy-default-create-const-container: requestBody: - application/json: {"name": "", "empty_list": [], "fixed_list": ["read", "write"], "empty_set": [], "empty_map": {}, "fixed_map": {"max": 10, "min": 1}} + application/json: {"name": "", "empty_list": [], "fixed_list": ["read", "write"], "empty_set": [], "empty_map": {}, "fixed_map": {"max": 10, "min": 1}, "templated_map": {"{{key}}": "value"}} responses: "200": - application/json: {"empty_list": [], "fixed_list": ["read", "write"], "empty_set": [], "empty_map": {}, "fixed_map": {"max": 10, "min": 1}} + application/json: {"empty_list": [], "fixed_list": ["read", "write"], "empty_set": [], "empty_map": {}, "fixed_map": {"max": 10, "min": 1}, "templated_map": {"{{key}}": "value"}} get-const-container: speakeasy-default-get-const-container: parameters: @@ -6062,7 +6066,7 @@ examples: id: "" responses: "200": - application/json: {"empty_list": [], "fixed_list": ["read", "write"], "empty_set": [], "empty_map": {}, "fixed_map": {"max": 10, "min": 1}} + application/json: {"empty_list": [], "fixed_list": ["read", "write"], "empty_set": [], "empty_map": {}, "fixed_map": {"max": 10, "min": 1}, "templated_map": {"{{key}}": "value"}} delete-const-container: speakeasy-default-delete-const-container: parameters: diff --git a/zSDKs/terraform-provider-testing/.speakeasy/logs/naming.log b/zSDKs/terraform-provider-testing/.speakeasy/logs/naming.log index 5bf896489..f7abd69db 100644 --- a/zSDKs/terraform-provider-testing/.speakeasy/logs/naming.log +++ b/zSDKs/terraform-provider-testing/.speakeasy/logs/naming.log @@ -2256,6 +2256,15 @@ DEBUG discriminated: Renamed to "ConstContainerResponse_empty_set" registrationID: "scope:shared refType:Schemas refName:ConstContainerResponse originalName:empty_set" DEBUG +--- Renaming 2 types with name "nested_list" --- +DEBUG discriminated: Renamed to "ConstContainerRequest_nested_list" + labels: "original_name:nested_list scope:shared refName:ConstContainerRequest" + registrationID: "scope:shared refType:Schemas refName:ConstContainerRequest originalName:nested_list" +DEBUG discriminated: Renamed to "ConstContainerResponse_nested_list" + labels: "original_name:nested_list scope:shared refName:ConstContainerResponse" + registrationID: "scope:shared refType:Schemas refName:ConstContainerResponse originalName:nested_list" +DEBUG + --- Renaming 3 types with name "tier" --- DEBUG discriminated: Renamed to "create_import_defaulted_id_tier" labels: "original_name:tier operation:create_import_defaulted_id data_type:enum parameter:pathParam" @@ -3834,10 +3843,12 @@ DeleteOasContentMediaTypeResponse (ContentType: string, StatusCode: int32, RawRe ConstContainerRequest (name: string, empty_list: array, fixed_list: array ...) ConstContainerRequestFixedList (enum: read, write, admin) ConstContainerRequestEmptySet (key: string) + ConstContainerRequestNestedList (label: string, tags: array) CreateConstContainerResponse (ContentType: string, StatusCode: int32, RawResponse: response ...) ConstContainerResponse (id: string, name: string, empty_list: array ...) ConstContainerResponseFixedList (enum: read, write, admin) ConstContainerResponseEmptySet (key: string) + ConstContainerResponseNestedList (label: string, tags: array) GetConstContainerRequest (id: string) GetConstContainerResponse (ContentType: string, StatusCode: int32, RawResponse: response ...) DeleteConstContainerRequest (id: string) diff --git a/zSDKs/terraform-provider-testing/README.md b/zSDKs/terraform-provider-testing/README.md index 62129d589..5c26d2b76 100644 --- a/zSDKs/terraform-provider-testing/README.md +++ b/zSDKs/terraform-provider-testing/README.md @@ -56,7 +56,7 @@ terraform { required_providers { testing = { source = "hashicorp/testing" - version = "0.0.1" + version = "0.0.2" } } } diff --git a/zSDKs/terraform-provider-testing/docs/data-sources/const_container.md b/zSDKs/terraform-provider-testing/docs/data-sources/const_container.md index d32d01fab..1d60f693d 100644 --- a/zSDKs/terraform-provider-testing/docs/data-sources/const_container.md +++ b/zSDKs/terraform-provider-testing/docs/data-sources/const_container.md @@ -25,3 +25,13 @@ data "testing_const_container" "my_constcontainer" { - `id` (String) The ID of this resource. - `name` (String) +- `nested_list` (Attributes List) List of objects whose item schema declares a const array. The +nested const must be hidden from the Terraform schema and sent +for every item. (see [below for nested schema](#nestedatt--nested_list)) + + +### Nested Schema for `nested_list` + +Read-Only: + +- `label` (String) diff --git a/zSDKs/terraform-provider-testing/docs/resources/const_container.md b/zSDKs/terraform-provider-testing/docs/resources/const_container.md index 665204c33..0366f4308 100644 --- a/zSDKs/terraform-provider-testing/docs/resources/const_container.md +++ b/zSDKs/terraform-provider-testing/docs/resources/const_container.md @@ -15,6 +15,11 @@ ConstContainer Resource ```terraform resource "testing_const_container" "my_constcontainer" { name = "...my_name..." + nested_list = [ + { + label = "...my_label..." + } + ] } ``` @@ -25,10 +30,24 @@ resource "testing_const_container" "my_constcontainer" { - `name` (String) Requires replacement if changed. +### Optional + +- `nested_list` (Attributes List) List of objects whose item schema declares a const array. The +nested const must be hidden from the Terraform schema and sent +for every item. +Requires replacement if changed. (see [below for nested schema](#nestedatt--nested_list)) + ### Read-Only - `id` (String) The ID of this resource. + +### Nested Schema for `nested_list` + +Optional: + +- `label` (String) Requires replacement if changed. + ## Import Import is supported using the following syntax: diff --git a/zSDKs/terraform-provider-testing/examples/resources/testing_const_container/resource.tf b/zSDKs/terraform-provider-testing/examples/resources/testing_const_container/resource.tf index 871e0d3f3..0b58be5a7 100644 --- a/zSDKs/terraform-provider-testing/examples/resources/testing_const_container/resource.tf +++ b/zSDKs/terraform-provider-testing/examples/resources/testing_const_container/resource.tf @@ -1,3 +1,8 @@ resource "testing_const_container" "my_constcontainer" { name = "...my_name..." + nested_list = [ + { + label = "...my_label..." + } + ] } \ No newline at end of file diff --git a/zSDKs/terraform-provider-testing/internal/provider/constcontainer_data_source.go b/zSDKs/terraform-provider-testing/internal/provider/constcontainer_data_source.go index 4b2b78c30..d9f8f0361 100644 --- a/zSDKs/terraform-provider-testing/internal/provider/constcontainer_data_source.go +++ b/zSDKs/terraform-provider-testing/internal/provider/constcontainer_data_source.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-framework/types/basetypes" + tfTypes "github.com/hashicorp/terraform-provider-testing/internal/provider/types" "github.com/hashicorp/terraform-provider-testing/internal/sdk" ) @@ -28,8 +29,9 @@ type ConstContainerDataSource struct { // ConstContainerDataSourceModel describes the data model. type ConstContainerDataSourceModel struct { - ID types.String `tfsdk:"id"` - Name types.String `tfsdk:"name"` + ID types.String `tfsdk:"id"` + Name types.String `tfsdk:"name"` + NestedList []tfTypes.ConstContainerResponseNestedList `tfsdk:"nested_list"` } // Metadata returns the data source type name. @@ -49,6 +51,19 @@ func (r *ConstContainerDataSource) Schema(ctx context.Context, req datasource.Sc "name": schema.StringAttribute{ Computed: true, }, + "nested_list": schema.ListNestedAttribute{ + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "label": schema.StringAttribute{ + Computed: true, + }, + }, + }, + MarkdownDescription: `List of objects whose item schema declares a const array. The` + "\n" + + `nested const must be hidden from the Terraform schema and sent` + "\n" + + `for every item.`, + }, }, } } diff --git a/zSDKs/terraform-provider-testing/internal/provider/constcontainer_data_source_sdk.go b/zSDKs/terraform-provider-testing/internal/provider/constcontainer_data_source_sdk.go index 0dfce4980..a8194d854 100644 --- a/zSDKs/terraform-provider-testing/internal/provider/constcontainer_data_source_sdk.go +++ b/zSDKs/terraform-provider-testing/internal/provider/constcontainer_data_source_sdk.go @@ -6,6 +6,7 @@ import ( "context" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/types" + tfTypes "github.com/hashicorp/terraform-provider-testing/internal/provider/types" "github.com/hashicorp/terraform-provider-testing/internal/sdk/models/operations" "github.com/hashicorp/terraform-provider-testing/internal/sdk/models/shared" ) @@ -16,6 +17,15 @@ func (r *ConstContainerDataSourceModel) RefreshFromSharedConstContainerResponse( if resp != nil { r.ID = types.StringPointerValue(resp.ID) r.Name = types.StringPointerValue(resp.Name) + r.NestedList = []tfTypes.ConstContainerResponseNestedList{} + + for _, nestedListItem := range resp.NestedList { + var nestedList tfTypes.ConstContainerResponseNestedList + + nestedList.Label = types.StringPointerValue(nestedListItem.Label) + + r.NestedList = append(r.NestedList, nestedList) + } } return diags diff --git a/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource.go b/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource.go index 3cd47c03e..f6a006812 100644 --- a/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource.go +++ b/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource.go @@ -8,12 +8,19 @@ import ( "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/objectplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-framework/types/basetypes" + speakeasy_listplanmodifier "github.com/hashicorp/terraform-provider-testing/internal/planmodifiers/listplanmodifier" + speakeasy_objectplanmodifier "github.com/hashicorp/terraform-provider-testing/internal/planmodifiers/objectplanmodifier" speakeasy_stringplanmodifier "github.com/hashicorp/terraform-provider-testing/internal/planmodifiers/stringplanmodifier" + tfTypes "github.com/hashicorp/terraform-provider-testing/internal/provider/types" "github.com/hashicorp/terraform-provider-testing/internal/sdk" + speakeasy_objectvalidators "github.com/hashicorp/terraform-provider-testing/internal/validators/objectvalidators" ) // Ensure provider defined types fully satisfy framework interfaces. @@ -32,8 +39,9 @@ type ConstContainerResource struct { // ConstContainerResourceModel describes the resource data model. type ConstContainerResourceModel struct { - ID types.String `tfsdk:"id"` - Name types.String `tfsdk:"name"` + ID types.String `tfsdk:"id"` + Name types.String `tfsdk:"name"` + NestedList []tfTypes.ConstContainerRequestNestedList `tfsdk:"nested_list"` } func (r *ConstContainerResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { @@ -55,6 +63,38 @@ func (r *ConstContainerResource) Schema(ctx context.Context, req resource.Schema }, Description: `Requires replacement if changed.`, }, + "nested_list": schema.ListNestedAttribute{ + Computed: true, + Optional: true, + PlanModifiers: []planmodifier.List{ + listplanmodifier.RequiresReplaceIfConfigured(), + speakeasy_listplanmodifier.SuppressDiff(speakeasy_listplanmodifier.ExplicitSuppress), + }, + NestedObject: schema.NestedAttributeObject{ + Validators: []validator.Object{ + speakeasy_objectvalidators.NotNull(), + }, + PlanModifiers: []planmodifier.Object{ + objectplanmodifier.RequiresReplaceIfConfigured(), + speakeasy_objectplanmodifier.SuppressDiff(speakeasy_objectplanmodifier.ExplicitSuppress), + }, + Attributes: map[string]schema.Attribute{ + "label": schema.StringAttribute{ + Computed: true, + Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplaceIfConfigured(), + speakeasy_stringplanmodifier.SuppressDiff(speakeasy_stringplanmodifier.ExplicitSuppress), + }, + Description: `Requires replacement if changed.`, + }, + }, + }, + MarkdownDescription: `List of objects whose item schema declares a const array. The` + "\n" + + `nested const must be hidden from the Terraform schema and sent` + "\n" + + `for every item.` + "\n" + + `Requires replacement if changed.`, + }, }, } } diff --git a/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource_sdk.go b/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource_sdk.go index f6f4a0ed4..a9a774ec0 100644 --- a/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource_sdk.go +++ b/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource_sdk.go @@ -6,6 +6,7 @@ import ( "context" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/types" + tfTypes "github.com/hashicorp/terraform-provider-testing/internal/provider/types" "github.com/hashicorp/terraform-provider-testing/internal/sdk/models/operations" "github.com/hashicorp/terraform-provider-testing/internal/sdk/models/shared" ) @@ -16,6 +17,15 @@ func (r *ConstContainerResourceModel) RefreshFromSharedConstContainerResponse(ct if resp != nil { r.ID = types.StringPointerValue(resp.ID) r.Name = types.StringPointerValue(resp.Name) + r.NestedList = []tfTypes.ConstContainerRequestNestedList{} + + for _, nestedListItem := range resp.NestedList { + var nestedList tfTypes.ConstContainerRequestNestedList + + nestedList.Label = types.StringPointerValue(nestedListItem.Label) + + r.NestedList = append(r.NestedList, nestedList) + } } return diags @@ -53,8 +63,21 @@ func (r *ConstContainerResourceModel) ToSharedConstContainerRequest(ctx context. var name string name = r.Name.ValueString() + nestedList := make([]shared.ConstContainerRequestNestedList, 0, len(r.NestedList)) + for nestedListIndex := range r.NestedList { + label := new(string) + if !r.NestedList[nestedListIndex].Label.IsUnknown() && !r.NestedList[nestedListIndex].Label.IsNull() { + *label = r.NestedList[nestedListIndex].Label.ValueString() + } else { + label = nil + } + nestedList = append(nestedList, shared.ConstContainerRequestNestedList{ + Label: label, + }) + } out := shared.ConstContainerRequest{ - Name: name, + Name: name, + NestedList: nestedList, } return &out, diags diff --git a/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource_test.go b/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource_test.go index b8e04f623..e0a9bf119 100644 --- a/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource_test.go +++ b/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource_test.go @@ -41,7 +41,9 @@ func TestConstContainerResourceLifecycle(t *testing.T) { "fixed_list": [ "read" , "write" ], "empty_map": { }, "empty_set": [ ], - "fixed_map": { "min" : 1, "max" : 1e1 } + "fixed_map": { "min" : 1, "max" : 1e1 }, + "templated_map": { "{{key}}": "value" }, + "nested_list": [ { "tags": [ "fixed" ], "label": "first" } ] }`)) }, }, @@ -77,6 +79,11 @@ func TestConstContainerResourceLifecycle(t *testing.T) { tfjsonpath.New("name"), knownvalue.StringExact("test-const-container"), ), + statecheck.ExpectKnownValue( + resourceAddress, + tfjsonpath.New("nested_list").AtSliceIndex(0).AtMapKey("label"), + knownvalue.StringExact("first"), + ), }, }, { @@ -102,5 +109,7 @@ func TestConstContainerResourceLifecycle(t *testing.T) { tfmockserver.AssertRequestBodyField(t, body, "empty_map", map[string]any{}) tfmockserver.AssertRequestBodyFieldEmptyArray(t, body, "empty_set") tfmockserver.AssertRequestBodyField(t, body, "fixed_map", map[string]any{"max": float64(10), "min": float64(1)}) - require.Len(t, body, 6, "request body carries only name and the five const fields: %v", body) + tfmockserver.AssertRequestBodyField(t, body, "templated_map", map[string]any{"{{key}}": "value"}) + tfmockserver.AssertRequestBodyField(t, body, "nested_list", []any{map[string]any{"label": "first", "tags": []any{"fixed"}}}) + require.Len(t, body, 8, "request body carries only name, nested_list and the six const fields: %v", body) } diff --git a/zSDKs/terraform-provider-testing/internal/provider/testdata/TestConstContainerResourceLifecycle/main.tf b/zSDKs/terraform-provider-testing/internal/provider/testdata/TestConstContainerResourceLifecycle/main.tf index c8a2e559a..56216538d 100644 --- a/zSDKs/terraform-provider-testing/internal/provider/testdata/TestConstContainerResourceLifecycle/main.tf +++ b/zSDKs/terraform-provider-testing/internal/provider/testdata/TestConstContainerResourceLifecycle/main.tf @@ -8,4 +8,5 @@ provider "testing" { resource "testing_const_container" "test" { name = "test-const-container" + nested_list = [{ label = "first" }] } diff --git a/zSDKs/terraform-provider-testing/internal/provider/types/const_container_request_nested_list.go b/zSDKs/terraform-provider-testing/internal/provider/types/const_container_request_nested_list.go new file mode 100644 index 000000000..19dfdb317 --- /dev/null +++ b/zSDKs/terraform-provider-testing/internal/provider/types/const_container_request_nested_list.go @@ -0,0 +1,11 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package types + +import ( + "github.com/hashicorp/terraform-plugin-framework/types" +) + +type ConstContainerRequestNestedList struct { + Label types.String `tfsdk:"label"` +} diff --git a/zSDKs/terraform-provider-testing/internal/provider/types/const_container_response_nested_list.go b/zSDKs/terraform-provider-testing/internal/provider/types/const_container_response_nested_list.go new file mode 100644 index 000000000..9cc58e19b --- /dev/null +++ b/zSDKs/terraform-provider-testing/internal/provider/types/const_container_response_nested_list.go @@ -0,0 +1,11 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package types + +import ( + "github.com/hashicorp/terraform-plugin-framework/types" +) + +type ConstContainerResponseNestedList struct { + Label types.String `tfsdk:"label"` +} diff --git a/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerrequest.go b/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerrequest.go index 0dea978da..989a516af 100644 --- a/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerrequest.go +++ b/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerrequest.go @@ -48,6 +48,34 @@ func (c *ConstContainerRequestEmptySet) GetKey() *string { return c.Key } +type ConstContainerRequestNestedList struct { + Label *string `json:"label,omitempty"` + //lint:ignore U1000 accessed via reflection for JSON marshaling + tags []string `const:"[\"fixed\"]" json:"tags,omitempty"` +} + +func (c ConstContainerRequestNestedList) MarshalJSON() ([]byte, error) { + return utils.MarshalJSON(c, "", false) +} + +func (c *ConstContainerRequestNestedList) UnmarshalJSON(data []byte) error { + if err := utils.UnmarshalJSON(data, &c, "", false, nil); err != nil { + return err + } + return nil +} + +func (c *ConstContainerRequestNestedList) GetLabel() *string { + if c == nil { + return nil + } + return c.Label +} + +func (c *ConstContainerRequestNestedList) GetTags() []string { + return []string{"fixed"} +} + type ConstContainerRequest struct { Name string `json:"name"` //lint:ignore U1000 accessed via reflection for JSON marshaling @@ -60,6 +88,16 @@ type ConstContainerRequest struct { emptyMap map[string]string `const:"{}" json:"empty_map"` //lint:ignore U1000 accessed via reflection for JSON marshaling fixedMap map[string]int64 `const:"{\"max\":10,\"min\":1}" json:"fixed_map,omitempty"` + // Map const whose key contains template delimiters. The generated + // Go literal and struct tag must escape them. + // + //lint:ignore U1000 accessed via reflection for JSON marshaling + templatedMap map[string]string `const:"{\"{{key}}\":\"value\"}" json:"templated_map,omitempty"` + // List of objects whose item schema declares a const array. The + // nested const must be hidden from the Terraform schema and sent + // for every item. + // + NestedList []ConstContainerRequestNestedList `json:"nested_list,omitempty"` } func (c ConstContainerRequest) MarshalJSON() ([]byte, error) { @@ -99,3 +137,14 @@ func (c *ConstContainerRequest) GetEmptyMap() map[string]string { func (c *ConstContainerRequest) GetFixedMap() map[string]int64 { return map[string]int64{"max": 10, "min": 1} } + +func (c *ConstContainerRequest) GetTemplatedMap() map[string]string { + return map[string]string{"{{key}}": "value"} +} + +func (c *ConstContainerRequest) GetNestedList() []ConstContainerRequestNestedList { + if c == nil { + return nil + } + return c.NestedList +} diff --git a/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerresponse.go b/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerresponse.go index ea9e7727d..7365f02e6 100644 --- a/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerresponse.go +++ b/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerresponse.go @@ -48,6 +48,34 @@ func (c *ConstContainerResponseEmptySet) GetKey() *string { return c.Key } +type ConstContainerResponseNestedList struct { + Label *string `json:"label,omitempty"` + //lint:ignore U1000 accessed via reflection for JSON marshaling + tags []string `const:"[\"fixed\"]" json:"tags,omitempty"` +} + +func (c ConstContainerResponseNestedList) MarshalJSON() ([]byte, error) { + return utils.MarshalJSON(c, "", false) +} + +func (c *ConstContainerResponseNestedList) UnmarshalJSON(data []byte) error { + if err := utils.UnmarshalJSON(data, &c, "", false, nil); err != nil { + return err + } + return nil +} + +func (c *ConstContainerResponseNestedList) GetLabel() *string { + if c == nil { + return nil + } + return c.Label +} + +func (c *ConstContainerResponseNestedList) GetTags() []string { + return []string{"fixed"} +} + type ConstContainerResponse struct { ID *string `json:"id,omitempty"` Name *string `json:"name,omitempty"` @@ -61,6 +89,16 @@ type ConstContainerResponse struct { emptyMap map[string]string `const:"{}" json:"empty_map,omitempty"` //lint:ignore U1000 accessed via reflection for JSON marshaling fixedMap map[string]int64 `const:"{\"max\":10,\"min\":1}" json:"fixed_map,omitempty"` + // Map const whose key contains template delimiters. The generated + // Go literal and struct tag must escape them. + // + //lint:ignore U1000 accessed via reflection for JSON marshaling + templatedMap map[string]string `const:"{\"{{key}}\":\"value\"}" json:"templated_map,omitempty"` + // List of objects whose item schema declares a const array. The + // nested const must be hidden from the Terraform schema and sent + // for every item. + // + NestedList []ConstContainerResponseNestedList `json:"nested_list,omitempty"` } func (c ConstContainerResponse) MarshalJSON() ([]byte, error) { @@ -107,3 +145,14 @@ func (c *ConstContainerResponse) GetEmptyMap() map[string]string { func (c *ConstContainerResponse) GetFixedMap() map[string]int64 { return map[string]int64{"max": 10, "min": 1} } + +func (c *ConstContainerResponse) GetTemplatedMap() map[string]string { + return map[string]string{"{{key}}": "value"} +} + +func (c *ConstContainerResponse) GetNestedList() []ConstContainerResponseNestedList { + if c == nil { + return nil + } + return c.NestedList +} From 8362a45b3ecab5bfb4f9c46eab41b657cb8cc40c Mon Sep 17 00:00:00 2001 From: Ash Godfrey Date: Mon, 2 Nov 2026 13:20:52 +0000 Subject: [PATCH 14/22] test(terraform): cover a const empty set on a delete body across API prefixes The review fixture gains a ConstEmptySetDelete entity shaped like an API whose desired state is a set of objects: one PUT serves create and update, and delete is a separate PUT under another API version prefix whose body declares the same set with `format: set` and `const: []`. The response carries a readOnly const array. The acceptance test drives create, a no-op plan, an update and destroy against the mock server and asserts the replace bodies carry the configured group while the teardown body carries `scope_id` and an empty `groups` array, never the groups held in state. The readOnly const never appears in a request body and decodes from every response. The mock server's delete handler now captures a JSON request body when one is sent, so tests can assert delete bodies like create and update bodies. --- tests/specs/review-terraform.yaml | 137 ++++++ .../.speakeasy/gen.lock | 52 ++- .../.speakeasy/logs/naming.log | 14 + zSDKs/terraform-provider-testing/README.md | 3 +- .../docs/resources/const_empty_set_delete.md | 66 +++ .../import-by-string-id.tf | 4 + .../testing_const_empty_set_delete/import.sh | 1 + .../resource.tf | 10 + .../provider/constemptysetdelete_resource.go | 331 ++++++++++++++ .../constemptysetdelete_resource_sdk.go | 94 ++++ .../constemptysetdelete_resource_test.go | 124 ++++++ .../internal/provider/provider.go | 1 + .../main.tf | 20 + .../types/const_empty_set_delete_group.go | 13 + .../operations/createconstemptysetdelete.go | 47 ++ .../operations/deleteconstemptysetdelete.go | 76 ++++ .../operations/getconstemptysetdelete.go | 58 +++ .../models/shared/constemptysetdeletegroup.go | 30 ++ .../shared/constemptysetdeleterequest.go | 22 + .../shared/constemptysetdeleteresponse.go | 55 +++ .../internal/sdk/sdk.go | 412 ++++++++++++++++++ .../internal/tfmockserver/server.go | 11 +- 22 files changed, 1576 insertions(+), 5 deletions(-) create mode 100644 zSDKs/terraform-provider-testing/docs/resources/const_empty_set_delete.md create mode 100644 zSDKs/terraform-provider-testing/examples/resources/testing_const_empty_set_delete/import-by-string-id.tf create mode 100644 zSDKs/terraform-provider-testing/examples/resources/testing_const_empty_set_delete/import.sh create mode 100644 zSDKs/terraform-provider-testing/examples/resources/testing_const_empty_set_delete/resource.tf create mode 100644 zSDKs/terraform-provider-testing/internal/provider/constemptysetdelete_resource.go create mode 100644 zSDKs/terraform-provider-testing/internal/provider/constemptysetdelete_resource_sdk.go create mode 100644 zSDKs/terraform-provider-testing/internal/provider/constemptysetdelete_resource_test.go create mode 100644 zSDKs/terraform-provider-testing/internal/provider/testdata/TestConstEmptySetDeleteResourceLifecycle/main.tf create mode 100644 zSDKs/terraform-provider-testing/internal/provider/types/const_empty_set_delete_group.go create mode 100644 zSDKs/terraform-provider-testing/internal/sdk/models/operations/createconstemptysetdelete.go create mode 100644 zSDKs/terraform-provider-testing/internal/sdk/models/operations/deleteconstemptysetdelete.go create mode 100644 zSDKs/terraform-provider-testing/internal/sdk/models/operations/getconstemptysetdelete.go create mode 100644 zSDKs/terraform-provider-testing/internal/sdk/models/shared/constemptysetdeletegroup.go create mode 100644 zSDKs/terraform-provider-testing/internal/sdk/models/shared/constemptysetdeleterequest.go create mode 100644 zSDKs/terraform-provider-testing/internal/sdk/models/shared/constemptysetdeleteresponse.go diff --git a/tests/specs/review-terraform.yaml b/tests/specs/review-terraform.yaml index 1858bece0..e31fd1e66 100644 --- a/tests/specs/review-terraform.yaml +++ b/tests/specs/review-terraform.yaml @@ -5745,6 +5745,86 @@ paths: responses: '200': description: OK + /v0/constemptysetdelete: + put: + x-speakeasy-entity-operation: ConstEmptySetDelete#create,update + description: | + Create or replace a resource whose desired state is a set of objects. + One operation serves create and update; deletion goes through a + separate operation whose request body declares the same set with an + empty const value. + operationId: create-const-empty-set-delete + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/ConstEmptySetDeleteRequest' + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/ConstEmptySetDeleteResponse' + /v0/constemptysetdelete/{id}: + parameters: + - name: id + in: path + required: true + schema: + type: string + get: + x-speakeasy-entity-operation: + terraform-datasource: null + terraform-resource: ConstEmptySetDelete#read + description: Get a const empty set delete resource + operationId: get-const-empty-set-delete + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/ConstEmptySetDeleteResponse' + '404': + description: Not Found + /v1/constemptysetdelete/teardown: + put: + x-speakeasy-entity-operation: ConstEmptySetDelete#delete + description: | + Delete the resource by replacing its group set with an empty set. The + request body declares the set property with `format: set` and + `const: []`, so Terraform must hide it and send an empty array instead + of the groups held in state. The operation lives under a different + API version prefix from the entity's other operations. + operationId: delete-const-empty-set-delete + requestBody: + required: true + content: + application/json: + schema: + type: object + additionalProperties: false + properties: + scope_id: + type: string + groups: + type: array + format: set + items: + $ref: '#/components/schemas/ConstEmptySetDeleteGroup' + const: [] + required: + - scope_id + - groups + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/ConstEmptySetDeleteResponse' components: parameters: GlobalBoolean: @@ -6116,6 +6196,63 @@ components: type: string const: - fixed + ConstEmptySetDeleteGroup: + type: object + additionalProperties: false + properties: + provider: + type: string + region: + type: string + replicas: + type: integer + required: + - provider + - region + ConstEmptySetDeleteRequest: + type: object + additionalProperties: false + x-speakeasy-entity: ConstEmptySetDelete + properties: + scope_id: + type: string + groups: + type: array + format: set + items: + $ref: '#/components/schemas/ConstEmptySetDeleteGroup' + required: + - scope_id + - groups + ConstEmptySetDeleteResponse: + type: object + additionalProperties: false + x-speakeasy-entity: ConstEmptySetDelete + properties: + id: + type: string + scope_id: + type: string + groups: + type: array + format: set + items: + $ref: '#/components/schemas/ConstEmptySetDeleteGroup' + supported_actions: + description: | + Response-only const array. It must stay off the request model, + be hidden from the Terraform schema, and be checked when the + response is decoded. + type: array + items: + type: string + readOnly: true + const: + - replace + required: + - id + - scope_id + - groups DiscriminatedUnionCreateRequest: x-speakeasy-entity: DiscriminatedUnion type: object diff --git a/zSDKs/terraform-provider-testing/.speakeasy/gen.lock b/zSDKs/terraform-provider-testing/.speakeasy/gen.lock index 3c80ff1f0..6f6068591 100644 --- a/zSDKs/terraform-provider-testing/.speakeasy/gen.lock +++ b/zSDKs/terraform-provider-testing/.speakeasy/gen.lock @@ -1,7 +1,7 @@ lockVersion: 2.0.0 id: review-sdk-test-id management: - docChecksum: a0a27db9e77dc544c3bf600ce831af52 + docChecksum: 645a6255443dd07cc5e84f7ec7134634 docVersion: 0.0.1 speakeasyVersion: internal generationVersion: internal @@ -285,6 +285,12 @@ trackedFiles: last_write_checksum: sha1:dc82e240078029b62b56bb695067d4c5e9cb4264 examples/resources/testing_const_container/resource.tf: last_write_checksum: sha1:e99fed339d5e89b5fd901103358d29986496d02a + examples/resources/testing_const_empty_set_delete/import-by-string-id.tf: + last_write_checksum: sha1:5e2fa4d90023d6fd8023b8df472dc294c2610004 + examples/resources/testing_const_empty_set_delete/import.sh: + last_write_checksum: sha1:7f1db4230b8685d1674c91ab6d0834483d1388d7 + examples/resources/testing_const_empty_set_delete/resource.tf: + last_write_checksum: sha1:3f758caa89921c6e250892c31cc357ee5b137c10 examples/resources/testing_discriminated_union/import-by-string-id.tf: last_write_checksum: sha1:61473f31485ac280bfa6943e7580d1bdd1e43413 examples/resources/testing_discriminated_union/import.sh: @@ -781,6 +787,10 @@ trackedFiles: last_write_checksum: sha1:65ef61f51490dba8ecc6d5d0f3428fb632f1d76d internal/provider/constcontainer_resource_sdk.go: last_write_checksum: sha1:1742253997f1ad0e00600193af22ec233d4c9016 + internal/provider/constemptysetdelete_resource.go: + last_write_checksum: sha1:c3fafc720d57f71f6b2cf165b9e96e347711c078 + internal/provider/constemptysetdelete_resource_sdk.go: + last_write_checksum: sha1:e4011063b10ba78613522aab7b958a801a850764 internal/provider/discriminatedunion_data_source.go: last_write_checksum: sha1:dd97963488cb1994321bf5e3f813917c80a7d7b5 internal/provider/discriminatedunion_data_source_sdk.go: @@ -1084,7 +1094,7 @@ trackedFiles: internal/provider/patch_resource_sdk.go: last_write_checksum: sha1:9b583e2ac47191350373ce5a86408c118bd606b1 internal/provider/provider.go: - last_write_checksum: sha1:8b1723df0915047021b8fd1b267f93dc19808e67 + last_write_checksum: sha1:61dd2f3795c80f9758d2788d91afc2b1dda4a885 internal/provider/reflect/diags.go: last_write_checksum: sha1:ace8bc53054bb1d8ee8689acf3e4323de75a6297 internal/provider/reflect/doc.go: @@ -1237,6 +1247,8 @@ trackedFiles: last_write_checksum: sha1:458f9b9dd282edcdd630ceea677772735874d669 internal/provider/types/const_container_response_nested_list.go: last_write_checksum: sha1:7090951d7f68ab5f6994376600b38b2470079383 + internal/provider/types/const_empty_set_delete_group.go: + last_write_checksum: sha1:cd350a23a4944c1d3dcbca450daa9d4b799bfeae internal/provider/types/credential.go: last_write_checksum: sha1:0f481ec7276acf4c15b64e3a7453e4bddc2dfa1c internal/provider/types/credential1.go: @@ -2463,6 +2475,8 @@ trackedFiles: last_write_checksum: sha1:0fdbac8d615b203c4f6054f9f44176e1c4ce564a internal/sdk/models/operations/createconstcontainer.go: last_write_checksum: sha1:892a2934f9b5cc0d5e40335502d20c3750702b95 + internal/sdk/models/operations/createconstemptysetdelete.go: + last_write_checksum: sha1:a0fae74d349d3ea63d3df50ba944230a3379e0a3 internal/sdk/models/operations/creatediscriminatedunion.go: last_write_checksum: sha1:68d916f8c709a15e2a564066dbc9317502aecf13 internal/sdk/models/operations/creatediscriminatedunionarray.go: @@ -2613,6 +2627,8 @@ trackedFiles: last_write_checksum: sha1:2d991f9ce3b49547f88d3ed69a9a4e01ccc135a8 internal/sdk/models/operations/deleteconstcontainer.go: last_write_checksum: sha1:443d6380ef9a4f9405c655078371ab2c13e633fa + internal/sdk/models/operations/deleteconstemptysetdelete.go: + last_write_checksum: sha1:67e766f608bf87fb1c06b22916fce98ed38d048c internal/sdk/models/operations/deletecustomplanmodifiers.go: last_write_checksum: sha1:8bcb2a4f56d57265de023e41d21617f5b88a7bc6 internal/sdk/models/operations/deletediscriminatedunion.go: @@ -2755,6 +2771,8 @@ trackedFiles: last_write_checksum: sha1:73ada8ac1a2cec3987eb5b93f78f815934067b9d internal/sdk/models/operations/getconstcontainer.go: last_write_checksum: sha1:c4ac02b538bdf08901d302a4d4c07a6a18cb2536 + internal/sdk/models/operations/getconstemptysetdelete.go: + last_write_checksum: sha1:0fd0c404cc7659c8ee1f1453adf5be9a55443f03 internal/sdk/models/operations/getcustomplanmodifiers.go: last_write_checksum: sha1:c6f5938cb6330969450186336a3085558bcd6d1c internal/sdk/models/operations/getdiscriminatedunion.go: @@ -3105,6 +3123,12 @@ trackedFiles: last_write_checksum: sha1:ddd4ad7779260d9e7a9ac96c5918c4e5345c66d2 internal/sdk/models/shared/constcontainerresponse.go: last_write_checksum: sha1:4d97877805a1493c13e7d36ad58fc1ed13c8293d + internal/sdk/models/shared/constemptysetdeletegroup.go: + last_write_checksum: sha1:d33860be5d32e993a1907c5f4a9b85f849357a8e + internal/sdk/models/shared/constemptysetdeleterequest.go: + last_write_checksum: sha1:1823ce955c667bf3702f098e162b9fa0bac9d8a4 + internal/sdk/models/shared/constemptysetdeleteresponse.go: + last_write_checksum: sha1:49ba49af13fb530bb278d8559e23e0b191c8b1ed internal/sdk/models/shared/discriminatedobject.go: last_write_checksum: sha1:9bb5641a1bcb27ec59c1f16d82d8a251ec733286 internal/sdk/models/shared/discriminatedunionarraycreaterequest.go: @@ -3610,7 +3634,7 @@ trackedFiles: internal/sdk/retry/config.go: last_write_checksum: sha1:102d1953fbd7e9f312c4442c71ccca2eaaeaa27d internal/sdk/sdk.go: - last_write_checksum: sha1:f390c541016ad47b4744f87a396fc36e8590d9f4 + last_write_checksum: sha1:d2ae7d2c0b4faa1fa52da3725944f1fc12be1c6d internal/sdk/types/bigint.go: last_write_checksum: sha1:49b004005d0461fb04b846eca062b070b0360b31 internal/sdk/types/date.go: @@ -6072,4 +6096,26 @@ examples: parameters: path: id: "" + create-const-empty-set-delete: + speakeasy-default-create-const-empty-set-delete: + requestBody: + application/json: {"scope_id": "", "groups": []} + responses: + "200": + application/json: {"id": "", "scope_id": "", "groups": [{"provider": "", "region": ""}], "supported_actions": ["replace"]} + get-const-empty-set-delete: + speakeasy-default-get-const-empty-set-delete: + parameters: + path: + id: "" + responses: + "200": + application/json: {"id": "", "scope_id": "", "groups": [], "supported_actions": ["replace"]} + delete-const-empty-set-delete: + speakeasy-default-delete-const-empty-set-delete: + requestBody: + application/json: {"scope_id": "", "groups": []} + responses: + "200": + application/json: {"id": "", "scope_id": "", "groups": [], "supported_actions": ["replace"]} examplesVersion: 1.0.2 diff --git a/zSDKs/terraform-provider-testing/.speakeasy/logs/naming.log b/zSDKs/terraform-provider-testing/.speakeasy/logs/naming.log index f7abd69db..6f878db69 100644 --- a/zSDKs/terraform-provider-testing/.speakeasy/logs/naming.log +++ b/zSDKs/terraform-provider-testing/.speakeasy/logs/naming.log @@ -175,6 +175,9 @@ DEBUG prepend_op_id: Renamed to "list_x_client_filter_ResponseBody" DEBUG prepend_op_id: Renamed to "list_x_client_filter_array_ResponseBody" labels: "original_name:ResponseBody operation:list_x_client_filter_array requestResponse:response" registrationID: "scope:operations operation:list-x-client-filter-array requestResponse:response responseStatusCode:200 responseMediaType:application/json originalName:ResponseBody" +DEBUG prepend_op_id: Renamed to "delete_const_empty_set_delete_request" + labels: "original_name:request operation:delete_const_empty_set_delete" + registrationID: "scope:operations operation:delete-const-empty-set-delete requestResponse:request originalName:RequestBody" DEBUG --- Renaming 2 types with name "Transformed" --- @@ -2413,6 +2416,9 @@ DEBUG prepend_op_id: N/A rename "list_x_client_filter_ResponseBody" DEBUG prepend_op_id: N/A rename "list_x_client_filter_array_ResponseBody" labels: "original_name:ResponseBody operation:list_x_client_filter_array requestResponse:response" registrationID: "scope:operations operation:list-x-client-filter-array requestResponse:response responseStatusCode:200 responseMediaType:application/json originalName:ResponseBody" +DEBUG prepend_op_id: N/A rename "delete_const_empty_set_delete_request" + labels: "original_name:request operation:delete_const_empty_set_delete" + registrationID: "scope:operations operation:delete-const-empty-set-delete requestResponse:request originalName:RequestBody" DEBUG Sdk (SDK empty) @@ -3853,6 +3859,14 @@ GetConstContainerRequest (id: string) GetConstContainerResponse (ContentType: string, StatusCode: int32, RawResponse: response ...) DeleteConstContainerRequest (id: string) DeleteConstContainerResponse (ContentType: string, StatusCode: int32, RawResponse: response) +ConstEmptySetDeleteRequest (scope_id: string, groups: set) + ConstEmptySetDeleteGroup (provider: string, region: string, replicas: integer) +CreateConstEmptySetDeleteResponse (ContentType: string, StatusCode: int32, RawResponse: response ...) + ConstEmptySetDeleteResponse (id: string, scope_id: string, groups: set ...) +GetConstEmptySetDeleteRequest (id: string) +GetConstEmptySetDeleteResponse (ContentType: string, StatusCode: int32, RawResponse: response ...) +DeleteConstEmptySetDeleteRequest (scope_id: string, groups: set) +DeleteConstEmptySetDeleteResponse (ContentType: string, StatusCode: int32, RawResponse: response ...) Globals (globalBoolean: boolean, globalBooleanWithDefault: boolean, globalEnumFloat32: float32 ...) UpdateXGlobalsGlobals (globalBoolean: boolean, globalBooleanWithDefault: boolean, globalEnumFloat32: float32 ...) diff --git a/zSDKs/terraform-provider-testing/README.md b/zSDKs/terraform-provider-testing/README.md index 5c26d2b76..2250ea672 100644 --- a/zSDKs/terraform-provider-testing/README.md +++ b/zSDKs/terraform-provider-testing/README.md @@ -56,7 +56,7 @@ terraform { required_providers { testing = { source = "hashicorp/testing" - version = "0.0.2" + version = "0.0.1" } } } @@ -103,6 +103,7 @@ Available configuration: * [testing_api_create_and_update](docs/resources/api_create_and_update.md) * [testing_basic](docs/resources/basic.md) * [testing_const_container](docs/resources/const_container.md) +* [testing_const_empty_set_delete](docs/resources/const_empty_set_delete.md) * [testing_discriminated_union](docs/resources/discriminated_union.md) * [testing_discriminated_union_array](docs/resources/discriminated_union_array.md) * [testing_framework_type](docs/resources/framework_type.md) diff --git a/zSDKs/terraform-provider-testing/docs/resources/const_empty_set_delete.md b/zSDKs/terraform-provider-testing/docs/resources/const_empty_set_delete.md new file mode 100644 index 000000000..64387f3e2 --- /dev/null +++ b/zSDKs/terraform-provider-testing/docs/resources/const_empty_set_delete.md @@ -0,0 +1,66 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "testing_const_empty_set_delete Resource - terraform-provider-testing" +subcategory: "" +description: |- + ConstEmptySetDelete Resource +--- + +# testing_const_empty_set_delete (Resource) + +ConstEmptySetDelete Resource + +## Example Usage + +```terraform +resource "testing_const_empty_set_delete" "my_constemptysetdelete" { + groups = [ + { + provider = "...my_provider..." + region = "...my_region..." + replicas = 10 + } + ] + scope_id = "...my_scope_id..." +} +``` + + +## Schema + +### Required + +- `groups` (Attributes Set) (see [below for nested schema](#nestedatt--groups)) +- `scope_id` (String) + +### Read-Only + +- `id` (String) The ID of this resource. + + +### Nested Schema for `groups` + +Optional: + +- `provider` (String) Not Null +- `region` (String) Not Null +- `replicas` (Number) + +## Import + +Import is supported using the following syntax: + +In Terraform v1.5.0 and later, the [`import` block](https://developer.hashicorp.com/terraform/language/import) can be used with the `id` attribute, for example: + +```terraform +import { + to = testing_const_empty_set_delete.my_testing_const_empty_set_delete + id = "..." +} +``` + +The [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import) can be used, for example: + +```shell +terraform import testing_const_empty_set_delete.my_testing_const_empty_set_delete "..." +``` diff --git a/zSDKs/terraform-provider-testing/examples/resources/testing_const_empty_set_delete/import-by-string-id.tf b/zSDKs/terraform-provider-testing/examples/resources/testing_const_empty_set_delete/import-by-string-id.tf new file mode 100644 index 000000000..6d1e48dc5 --- /dev/null +++ b/zSDKs/terraform-provider-testing/examples/resources/testing_const_empty_set_delete/import-by-string-id.tf @@ -0,0 +1,4 @@ +import { + to = testing_const_empty_set_delete.my_testing_const_empty_set_delete + id = "..." +} diff --git a/zSDKs/terraform-provider-testing/examples/resources/testing_const_empty_set_delete/import.sh b/zSDKs/terraform-provider-testing/examples/resources/testing_const_empty_set_delete/import.sh new file mode 100644 index 000000000..3445ab4e8 --- /dev/null +++ b/zSDKs/terraform-provider-testing/examples/resources/testing_const_empty_set_delete/import.sh @@ -0,0 +1 @@ +terraform import testing_const_empty_set_delete.my_testing_const_empty_set_delete "..." diff --git a/zSDKs/terraform-provider-testing/examples/resources/testing_const_empty_set_delete/resource.tf b/zSDKs/terraform-provider-testing/examples/resources/testing_const_empty_set_delete/resource.tf new file mode 100644 index 000000000..584e6f099 --- /dev/null +++ b/zSDKs/terraform-provider-testing/examples/resources/testing_const_empty_set_delete/resource.tf @@ -0,0 +1,10 @@ +resource "testing_const_empty_set_delete" "my_constemptysetdelete" { + groups = [ + { + provider = "...my_provider..." + region = "...my_region..." + replicas = 10 + } + ] + scope_id = "...my_scope_id..." +} \ No newline at end of file diff --git a/zSDKs/terraform-provider-testing/internal/provider/constemptysetdelete_resource.go b/zSDKs/terraform-provider-testing/internal/provider/constemptysetdelete_resource.go new file mode 100644 index 000000000..fcc501ec0 --- /dev/null +++ b/zSDKs/terraform-provider-testing/internal/provider/constemptysetdelete_resource.go @@ -0,0 +1,331 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package provider + +import ( + "context" + "fmt" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-framework/types/basetypes" + tfTypes "github.com/hashicorp/terraform-provider-testing/internal/provider/types" + "github.com/hashicorp/terraform-provider-testing/internal/sdk" + speakeasy_objectvalidators "github.com/hashicorp/terraform-provider-testing/internal/validators/objectvalidators" + speakeasy_stringvalidators "github.com/hashicorp/terraform-provider-testing/internal/validators/stringvalidators" +) + +// Ensure provider defined types fully satisfy framework interfaces. +var _ resource.Resource = &ConstEmptySetDeleteResource{} +var _ resource.ResourceWithImportState = &ConstEmptySetDeleteResource{} + +func NewConstEmptySetDeleteResource() resource.Resource { + return &ConstEmptySetDeleteResource{} +} + +// ConstEmptySetDeleteResource defines the resource implementation. +type ConstEmptySetDeleteResource struct { + // Provider configured SDK client. + client *sdk.SDK +} + +// ConstEmptySetDeleteResourceModel describes the resource data model. +type ConstEmptySetDeleteResourceModel struct { + Groups []tfTypes.ConstEmptySetDeleteGroup `tfsdk:"groups"` + ID types.String `tfsdk:"id"` + ScopeID types.String `tfsdk:"scope_id"` +} + +func (r *ConstEmptySetDeleteResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_const_empty_set_delete" +} + +func (r *ConstEmptySetDeleteResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { + resp.Schema = schema.Schema{ + MarkdownDescription: "ConstEmptySetDelete Resource", + Attributes: map[string]schema.Attribute{ + "groups": schema.SetNestedAttribute{ + Required: true, + NestedObject: schema.NestedAttributeObject{ + Validators: []validator.Object{ + speakeasy_objectvalidators.NotNull(), + }, + Attributes: map[string]schema.Attribute{ + "provider": schema.StringAttribute{ + Computed: true, + Optional: true, + Description: `Not Null`, + Validators: []validator.String{ + speakeasy_stringvalidators.NotNull(), + }, + }, + "region": schema.StringAttribute{ + Computed: true, + Optional: true, + Description: `Not Null`, + Validators: []validator.String{ + speakeasy_stringvalidators.NotNull(), + }, + }, + "replicas": schema.Int64Attribute{ + Computed: true, + Optional: true, + }, + }, + }, + }, + "id": schema.StringAttribute{ + Computed: true, + }, + "scope_id": schema.StringAttribute{ + Required: true, + }, + }, + } +} + +func (r *ConstEmptySetDeleteResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { + // Prevent panic if the provider has not been configured. + if req.ProviderData == nil { + return + } + + providerData, ok := req.ProviderData.(*TestingProviderConfigureData) + + if !ok { + resp.Diagnostics.AddError( + "Unexpected Resource Configure Type", + fmt.Sprintf("Expected *TestingProviderConfigureData, got: %T. Please report this issue to the provider developers.", req.ProviderData), + ) + + return + } + + r.client = providerData.SDKClient +} + +func (r *ConstEmptySetDeleteResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var data *ConstEmptySetDeleteResourceModel + var plan types.Object + + resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) + if resp.Diagnostics.HasError() { + return + } + + resp.Diagnostics.Append(plan.As(ctx, &data, basetypes.ObjectAsOptions{ + UnhandledNullAsEmpty: true, + UnhandledUnknownAsEmpty: true, + })...) + + if resp.Diagnostics.HasError() { + return + } + + request, requestDiags := data.ToSharedConstEmptySetDeleteRequest(ctx) + resp.Diagnostics.Append(requestDiags...) + + if resp.Diagnostics.HasError() { + return + } + res, err := r.client.CreateConstEmptySetDelete(ctx, *request) + if err != nil { + resp.Diagnostics.AddError("failure to invoke API", redactSensitiveValues(ctx, err.Error())) + if res != nil && res.RawResponse != nil { + resp.Diagnostics.AddError("unexpected http request/response", debugResponse(res.RawResponse)) + } + return + } + if res == nil { + resp.Diagnostics.AddError("unexpected response from API", fmt.Sprintf("%v", res)) + return + } + if res.StatusCode != 200 { + resp.Diagnostics.AddError(fmt.Sprintf("unexpected response from API. Got an unexpected response code %v", res.StatusCode), debugResponse(res.RawResponse)) + return + } + if !(res.ConstEmptySetDeleteResponse != nil) { + resp.Diagnostics.AddError("unexpected response from API. Got an unexpected response body", debugResponse(res.RawResponse)) + return + } + resp.Diagnostics.Append(data.RefreshFromSharedConstEmptySetDeleteResponse(ctx, res.ConstEmptySetDeleteResponse)...) + + if resp.Diagnostics.HasError() { + return + } + + resp.Diagnostics.Append(refreshPlan(ctx, plan, &data)...) + + if resp.Diagnostics.HasError() { + return + } + + // Save updated data into Terraform state + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) +} + +func (r *ConstEmptySetDeleteResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var data *ConstEmptySetDeleteResourceModel + var item types.Object + + resp.Diagnostics.Append(req.State.Get(ctx, &item)...) + if resp.Diagnostics.HasError() { + return + } + + resp.Diagnostics.Append(item.As(ctx, &data, basetypes.ObjectAsOptions{ + UnhandledNullAsEmpty: true, + UnhandledUnknownAsEmpty: true, + })...) + + if resp.Diagnostics.HasError() { + return + } + + request, requestDiags := data.ToOperationsGetConstEmptySetDeleteRequest(ctx) + resp.Diagnostics.Append(requestDiags...) + + if resp.Diagnostics.HasError() { + return + } + res, err := r.client.GetConstEmptySetDelete(ctx, *request) + if err != nil { + resp.Diagnostics.AddError("failure to invoke API", redactSensitiveValues(ctx, err.Error())) + if res != nil && res.RawResponse != nil { + resp.Diagnostics.AddError("unexpected http request/response", debugResponse(res.RawResponse)) + } + return + } + if res == nil { + resp.Diagnostics.AddError("unexpected response from API", fmt.Sprintf("%v", res)) + return + } + if res.StatusCode == 404 { + resp.State.RemoveResource(ctx) + return + } + if res.StatusCode != 200 { + resp.Diagnostics.AddError(fmt.Sprintf("unexpected response from API. Got an unexpected response code %v", res.StatusCode), debugResponse(res.RawResponse)) + return + } + if !(res.ConstEmptySetDeleteResponse != nil) { + resp.Diagnostics.AddError("unexpected response from API. Got an unexpected response body", debugResponse(res.RawResponse)) + return + } + resp.Diagnostics.Append(data.RefreshFromSharedConstEmptySetDeleteResponse(ctx, res.ConstEmptySetDeleteResponse)...) + + if resp.Diagnostics.HasError() { + return + } + + // Save updated data into Terraform state + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) +} + +func (r *ConstEmptySetDeleteResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var data *ConstEmptySetDeleteResourceModel + var plan types.Object + + resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) + if resp.Diagnostics.HasError() { + return + } + + merge(ctx, req, resp, &data) + if resp.Diagnostics.HasError() { + return + } + + request, requestDiags := data.ToSharedConstEmptySetDeleteRequest(ctx) + resp.Diagnostics.Append(requestDiags...) + + if resp.Diagnostics.HasError() { + return + } + res, err := r.client.CreateConstEmptySetDelete(ctx, *request) + if err != nil { + resp.Diagnostics.AddError("failure to invoke API", redactSensitiveValues(ctx, err.Error())) + if res != nil && res.RawResponse != nil { + resp.Diagnostics.AddError("unexpected http request/response", debugResponse(res.RawResponse)) + } + return + } + if res == nil { + resp.Diagnostics.AddError("unexpected response from API", fmt.Sprintf("%v", res)) + return + } + if res.StatusCode != 200 { + resp.Diagnostics.AddError(fmt.Sprintf("unexpected response from API. Got an unexpected response code %v", res.StatusCode), debugResponse(res.RawResponse)) + return + } + if !(res.ConstEmptySetDeleteResponse != nil) { + resp.Diagnostics.AddError("unexpected response from API. Got an unexpected response body", debugResponse(res.RawResponse)) + return + } + resp.Diagnostics.Append(data.RefreshFromSharedConstEmptySetDeleteResponse(ctx, res.ConstEmptySetDeleteResponse)...) + + if resp.Diagnostics.HasError() { + return + } + + resp.Diagnostics.Append(refreshPlan(ctx, plan, &data)...) + + if resp.Diagnostics.HasError() { + return + } + + // Save updated data into Terraform state + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) +} + +func (r *ConstEmptySetDeleteResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var data *ConstEmptySetDeleteResourceModel + var item types.Object + + resp.Diagnostics.Append(req.State.Get(ctx, &item)...) + if resp.Diagnostics.HasError() { + return + } + + resp.Diagnostics.Append(item.As(ctx, &data, basetypes.ObjectAsOptions{ + UnhandledNullAsEmpty: true, + UnhandledUnknownAsEmpty: true, + })...) + + if resp.Diagnostics.HasError() { + return + } + + request, requestDiags := data.ToOperationsDeleteConstEmptySetDeleteRequest(ctx) + resp.Diagnostics.Append(requestDiags...) + + if resp.Diagnostics.HasError() { + return + } + res, err := r.client.DeleteConstEmptySetDelete(ctx, *request) + if err != nil { + resp.Diagnostics.AddError("failure to invoke API", redactSensitiveValues(ctx, err.Error())) + if res != nil && res.RawResponse != nil { + resp.Diagnostics.AddError("unexpected http request/response", debugResponse(res.RawResponse)) + } + return + } + if res == nil { + resp.Diagnostics.AddError("unexpected response from API", fmt.Sprintf("%v", res)) + return + } + switch res.StatusCode { + case 200, 404: + break + default: + resp.Diagnostics.AddError(fmt.Sprintf("unexpected response from API. Got an unexpected response code %v", res.StatusCode), debugResponse(res.RawResponse)) + return + } + +} + +func (r *ConstEmptySetDeleteResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), req.ID)...) +} diff --git a/zSDKs/terraform-provider-testing/internal/provider/constemptysetdelete_resource_sdk.go b/zSDKs/terraform-provider-testing/internal/provider/constemptysetdelete_resource_sdk.go new file mode 100644 index 000000000..449a22a55 --- /dev/null +++ b/zSDKs/terraform-provider-testing/internal/provider/constemptysetdelete_resource_sdk.go @@ -0,0 +1,94 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package provider + +import ( + "context" + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/types" + tfTypes "github.com/hashicorp/terraform-provider-testing/internal/provider/types" + "github.com/hashicorp/terraform-provider-testing/internal/sdk/models/operations" + "github.com/hashicorp/terraform-provider-testing/internal/sdk/models/shared" +) + +func (r *ConstEmptySetDeleteResourceModel) RefreshFromSharedConstEmptySetDeleteResponse(ctx context.Context, resp *shared.ConstEmptySetDeleteResponse) diag.Diagnostics { + var diags diag.Diagnostics + + if resp != nil { + r.Groups = []tfTypes.ConstEmptySetDeleteGroup{} + + for _, groupsItem := range resp.Groups { + var groups tfTypes.ConstEmptySetDeleteGroup + + groups.Provider = types.StringValue(groupsItem.Provider) + groups.Region = types.StringValue(groupsItem.Region) + groups.Replicas = types.Int64PointerValue(groupsItem.Replicas) + + r.Groups = append(r.Groups, groups) + } + r.ID = types.StringValue(resp.ID) + r.ScopeID = types.StringValue(resp.ScopeID) + } + + return diags +} + +func (r *ConstEmptySetDeleteResourceModel) ToOperationsDeleteConstEmptySetDeleteRequest(ctx context.Context) (*operations.DeleteConstEmptySetDeleteRequest, diag.Diagnostics) { + var diags diag.Diagnostics + + var scopeID string + scopeID = r.ScopeID.ValueString() + + out := operations.DeleteConstEmptySetDeleteRequest{ + ScopeID: scopeID, + } + + return &out, diags +} + +func (r *ConstEmptySetDeleteResourceModel) ToOperationsGetConstEmptySetDeleteRequest(ctx context.Context) (*operations.GetConstEmptySetDeleteRequest, diag.Diagnostics) { + var diags diag.Diagnostics + + var id string + id = r.ID.ValueString() + + out := operations.GetConstEmptySetDeleteRequest{ + ID: id, + } + + return &out, diags +} + +func (r *ConstEmptySetDeleteResourceModel) ToSharedConstEmptySetDeleteRequest(ctx context.Context) (*shared.ConstEmptySetDeleteRequest, diag.Diagnostics) { + var diags diag.Diagnostics + + var scopeID string + scopeID = r.ScopeID.ValueString() + + groups := make([]shared.ConstEmptySetDeleteGroup, 0, len(r.Groups)) + for groupsIndex := range r.Groups { + var provider string + provider = r.Groups[groupsIndex].Provider.ValueString() + + var region string + region = r.Groups[groupsIndex].Region.ValueString() + + replicas := new(int64) + if !r.Groups[groupsIndex].Replicas.IsUnknown() && !r.Groups[groupsIndex].Replicas.IsNull() { + *replicas = r.Groups[groupsIndex].Replicas.ValueInt64() + } else { + replicas = nil + } + groups = append(groups, shared.ConstEmptySetDeleteGroup{ + Provider: provider, + Region: region, + Replicas: replicas, + }) + } + out := shared.ConstEmptySetDeleteRequest{ + ScopeID: scopeID, + Groups: groups, + } + + return &out, diags +} diff --git a/zSDKs/terraform-provider-testing/internal/provider/constemptysetdelete_resource_test.go b/zSDKs/terraform-provider-testing/internal/provider/constemptysetdelete_resource_test.go new file mode 100644 index 000000000..d8beee83a --- /dev/null +++ b/zSDKs/terraform-provider-testing/internal/provider/constemptysetdelete_resource_test.go @@ -0,0 +1,124 @@ +package provider_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-testing/config" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/knownvalue" + "github.com/hashicorp/terraform-plugin-testing/statecheck" + "github.com/hashicorp/terraform-plugin-testing/tfjsonpath" + "github.com/hashicorp/terraform-provider-testing/internal/provider" + "github.com/hashicorp/terraform-provider-testing/internal/tfmockserver" + "github.com/stretchr/testify/require" +) + +// Create and update replace the whole group set through one operation. Delete +// is a separate operation, under another API prefix, whose body declares the +// same set with an empty const: the provider must send [] there, not the +// groups held in state. The response carries a readOnly const array that must +// never reach a request body. +func TestConstEmptySetDeleteResourceLifecycle(t *testing.T) { + t.Parallel() + + supportedActions := map[string]any{"supported_actions": []any{"replace"}} + endpoints := tfmockserver.ResourceEndpoints{ + Create: tfmockserver.Endpoints{ + { + Endpoint: "PUT /v0/constemptysetdelete", + ResponseOverlay: supportedActions, + }, + }, + Get: tfmockserver.Endpoints{ + { + Endpoint: "GET /v0/constemptysetdelete/{id}", + ResponseOverlay: supportedActions, + }, + }, + Delete: tfmockserver.Endpoints{ + { + Endpoint: "PUT /v1/constemptysetdelete/teardown", + ResponseOverlay: map[string]any{ + "id": tfmockserver.StoreKey, + "scope_id": "scope-1", + "groups": []any{}, + "supported_actions": []any{"replace"}, + }, + }, + }, + } + + mockServer := tfmockserver.StartServer(endpoints, t) + defer mockServer.Close() + + resourceAddress := "testing_const_empty_set_delete.test" + variables := func(replicas int64) config.Variables { + return config.Variables{ + "server_url": config.StringVariable(mockServer.URL), + "replicas": config.IntegerVariable(replicas), + } + } + + resource.Test(t, resource.TestCase{ + Steps: []resource.TestStep{ + { + ConfigDirectory: config.TestNameDirectory(), + ProtoV6ProviderFactories: provider.GetTestProviders(), + ConfigVariables: variables(2), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue( + resourceAddress, + tfjsonpath.New("id"), + knownvalue.StringExact(tfmockserver.StoreKey), + ), + statecheck.ExpectKnownValue( + resourceAddress, + tfjsonpath.New("groups"), + knownvalue.SetExact([]knownvalue.Check{ + knownvalue.ObjectExact(map[string]knownvalue.Check{ + "provider": knownvalue.StringExact("aws"), + "region": knownvalue.StringExact("eu-west-1"), + "replicas": knownvalue.Int64Exact(2), + }), + }), + ), + }, + }, + { + ConfigDirectory: config.TestNameDirectory(), + ProtoV6ProviderFactories: provider.GetTestProviders(), + ConfigVariables: variables(2), + PlanOnly: true, + }, + { + ConfigDirectory: config.TestNameDirectory(), + ProtoV6ProviderFactories: provider.GetTestProviders(), + ConfigVariables: variables(3), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue( + resourceAddress, + tfjsonpath.New("groups").AtSliceIndex(0).AtMapKey("replicas"), + knownvalue.Int64Exact(3), + ), + }, + }, + }, + }) + + group := func(replicas float64) map[string]any { + return map[string]any{"provider": "aws", "region": "eu-west-1", "replicas": replicas} + } + upserts := endpoints.Create[0].Requests.Bodies() + require.Len(t, upserts, 2, "create and update both go through the replace operation") + for i, replicas := range []float64{2, 3} { + tfmockserver.AssertRequestBodyField(t, upserts[i], "scope_id", "scope-1") + tfmockserver.AssertRequestBodyFieldArray(t, upserts[i], "groups", []any{group(replicas)}) + tfmockserver.AssertRequestBodyFieldOmitted(t, upserts[i], "supported_actions") + } + + deletes := endpoints.Delete[0].Requests.Bodies() + require.Len(t, deletes, 1) + tfmockserver.AssertRequestBodyField(t, deletes[0], "scope_id", "scope-1") + tfmockserver.AssertRequestBodyFieldEmptyArray(t, deletes[0], "groups") + require.Len(t, deletes[0], 2, "delete body carries only scope_id and the const empty set: %v", deletes[0]) +} diff --git a/zSDKs/terraform-provider-testing/internal/provider/provider.go b/zSDKs/terraform-provider-testing/internal/provider/provider.go index 06585ae95..e37055a94 100644 --- a/zSDKs/terraform-provider-testing/internal/provider/provider.go +++ b/zSDKs/terraform-provider-testing/internal/provider/provider.go @@ -809,6 +809,7 @@ func (p *TestingProvider) Resources(ctx context.Context) []func() resource.Resou NewAPICreateAndUpdateResource, NewBasicResource, NewConstContainerResource, + NewConstEmptySetDeleteResource, NewDiscriminatedUnionResource, NewDiscriminatedUnionArrayResource, NewFrameworkTypeResource, diff --git a/zSDKs/terraform-provider-testing/internal/provider/testdata/TestConstEmptySetDeleteResourceLifecycle/main.tf b/zSDKs/terraform-provider-testing/internal/provider/testdata/TestConstEmptySetDeleteResourceLifecycle/main.tf new file mode 100644 index 000000000..3c0e0aeb5 --- /dev/null +++ b/zSDKs/terraform-provider-testing/internal/provider/testdata/TestConstEmptySetDeleteResourceLifecycle/main.tf @@ -0,0 +1,20 @@ +variable "server_url" { + type = string +} + +variable "replicas" { + type = number +} + +provider "testing" { + server_url = var.server_url +} + +resource "testing_const_empty_set_delete" "test" { + scope_id = "scope-1" + groups = [{ + provider = "aws" + region = "eu-west-1" + replicas = var.replicas + }] +} diff --git a/zSDKs/terraform-provider-testing/internal/provider/types/const_empty_set_delete_group.go b/zSDKs/terraform-provider-testing/internal/provider/types/const_empty_set_delete_group.go new file mode 100644 index 000000000..fae799d80 --- /dev/null +++ b/zSDKs/terraform-provider-testing/internal/provider/types/const_empty_set_delete_group.go @@ -0,0 +1,13 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package types + +import ( + "github.com/hashicorp/terraform-plugin-framework/types" +) + +type ConstEmptySetDeleteGroup struct { + Provider types.String `tfsdk:"provider"` + Region types.String `tfsdk:"region"` + Replicas types.Int64 `tfsdk:"replicas"` +} diff --git a/zSDKs/terraform-provider-testing/internal/sdk/models/operations/createconstemptysetdelete.go b/zSDKs/terraform-provider-testing/internal/sdk/models/operations/createconstemptysetdelete.go new file mode 100644 index 000000000..87b017d05 --- /dev/null +++ b/zSDKs/terraform-provider-testing/internal/sdk/models/operations/createconstemptysetdelete.go @@ -0,0 +1,47 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package operations + +import ( + "github.com/hashicorp/terraform-provider-testing/internal/sdk/models/shared" + "net/http" +) + +type CreateConstEmptySetDeleteResponse struct { + // HTTP response content type for this operation + ContentType string + // HTTP response status code for this operation + StatusCode int + // Raw HTTP response; suitable for custom response parsing + RawResponse *http.Response + // OK + ConstEmptySetDeleteResponse *shared.ConstEmptySetDeleteResponse +} + +func (c *CreateConstEmptySetDeleteResponse) GetContentType() string { + if c == nil { + return "" + } + return c.ContentType +} + +func (c *CreateConstEmptySetDeleteResponse) GetStatusCode() int { + if c == nil { + return 0 + } + return c.StatusCode +} + +func (c *CreateConstEmptySetDeleteResponse) GetRawResponse() *http.Response { + if c == nil { + return nil + } + return c.RawResponse +} + +func (c *CreateConstEmptySetDeleteResponse) GetConstEmptySetDeleteResponse() *shared.ConstEmptySetDeleteResponse { + if c == nil { + return nil + } + return c.ConstEmptySetDeleteResponse +} diff --git a/zSDKs/terraform-provider-testing/internal/sdk/models/operations/deleteconstemptysetdelete.go b/zSDKs/terraform-provider-testing/internal/sdk/models/operations/deleteconstemptysetdelete.go new file mode 100644 index 000000000..4e222c35b --- /dev/null +++ b/zSDKs/terraform-provider-testing/internal/sdk/models/operations/deleteconstemptysetdelete.go @@ -0,0 +1,76 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package operations + +import ( + "github.com/hashicorp/terraform-provider-testing/internal/sdk/internal/utils" + "github.com/hashicorp/terraform-provider-testing/internal/sdk/models/shared" + "net/http" +) + +type DeleteConstEmptySetDeleteRequest struct { + ScopeID string `json:"scope_id"` + //lint:ignore U1000 accessed via reflection for JSON marshaling + groups []shared.ConstEmptySetDeleteGroup `const:"[]" json:"groups"` +} + +func (d DeleteConstEmptySetDeleteRequest) MarshalJSON() ([]byte, error) { + return utils.MarshalJSON(d, "", false) +} + +func (d *DeleteConstEmptySetDeleteRequest) UnmarshalJSON(data []byte) error { + if err := utils.UnmarshalJSON(data, &d, "", false, nil); err != nil { + return err + } + return nil +} + +func (d *DeleteConstEmptySetDeleteRequest) GetScopeID() string { + if d == nil { + return "" + } + return d.ScopeID +} + +func (d *DeleteConstEmptySetDeleteRequest) GetGroups() []shared.ConstEmptySetDeleteGroup { + return []shared.ConstEmptySetDeleteGroup{} +} + +type DeleteConstEmptySetDeleteResponse struct { + // HTTP response content type for this operation + ContentType string + // HTTP response status code for this operation + StatusCode int + // Raw HTTP response; suitable for custom response parsing + RawResponse *http.Response + // OK + ConstEmptySetDeleteResponse *shared.ConstEmptySetDeleteResponse +} + +func (d *DeleteConstEmptySetDeleteResponse) GetContentType() string { + if d == nil { + return "" + } + return d.ContentType +} + +func (d *DeleteConstEmptySetDeleteResponse) GetStatusCode() int { + if d == nil { + return 0 + } + return d.StatusCode +} + +func (d *DeleteConstEmptySetDeleteResponse) GetRawResponse() *http.Response { + if d == nil { + return nil + } + return d.RawResponse +} + +func (d *DeleteConstEmptySetDeleteResponse) GetConstEmptySetDeleteResponse() *shared.ConstEmptySetDeleteResponse { + if d == nil { + return nil + } + return d.ConstEmptySetDeleteResponse +} diff --git a/zSDKs/terraform-provider-testing/internal/sdk/models/operations/getconstemptysetdelete.go b/zSDKs/terraform-provider-testing/internal/sdk/models/operations/getconstemptysetdelete.go new file mode 100644 index 000000000..b3283830e --- /dev/null +++ b/zSDKs/terraform-provider-testing/internal/sdk/models/operations/getconstemptysetdelete.go @@ -0,0 +1,58 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package operations + +import ( + "github.com/hashicorp/terraform-provider-testing/internal/sdk/models/shared" + "net/http" +) + +type GetConstEmptySetDeleteRequest struct { + ID string `pathParam:"style=simple,explode=false,name=id"` +} + +func (g *GetConstEmptySetDeleteRequest) GetID() string { + if g == nil { + return "" + } + return g.ID +} + +type GetConstEmptySetDeleteResponse struct { + // HTTP response content type for this operation + ContentType string + // HTTP response status code for this operation + StatusCode int + // Raw HTTP response; suitable for custom response parsing + RawResponse *http.Response + // OK + ConstEmptySetDeleteResponse *shared.ConstEmptySetDeleteResponse +} + +func (g *GetConstEmptySetDeleteResponse) GetContentType() string { + if g == nil { + return "" + } + return g.ContentType +} + +func (g *GetConstEmptySetDeleteResponse) GetStatusCode() int { + if g == nil { + return 0 + } + return g.StatusCode +} + +func (g *GetConstEmptySetDeleteResponse) GetRawResponse() *http.Response { + if g == nil { + return nil + } + return g.RawResponse +} + +func (g *GetConstEmptySetDeleteResponse) GetConstEmptySetDeleteResponse() *shared.ConstEmptySetDeleteResponse { + if g == nil { + return nil + } + return g.ConstEmptySetDeleteResponse +} diff --git a/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constemptysetdeletegroup.go b/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constemptysetdeletegroup.go new file mode 100644 index 000000000..2eff13840 --- /dev/null +++ b/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constemptysetdeletegroup.go @@ -0,0 +1,30 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package shared + +type ConstEmptySetDeleteGroup struct { + Provider string `json:"provider"` + Region string `json:"region"` + Replicas *int64 `json:"replicas,omitempty"` +} + +func (c *ConstEmptySetDeleteGroup) GetProvider() string { + if c == nil { + return "" + } + return c.Provider +} + +func (c *ConstEmptySetDeleteGroup) GetRegion() string { + if c == nil { + return "" + } + return c.Region +} + +func (c *ConstEmptySetDeleteGroup) GetReplicas() *int64 { + if c == nil { + return nil + } + return c.Replicas +} diff --git a/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constemptysetdeleterequest.go b/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constemptysetdeleterequest.go new file mode 100644 index 000000000..05eb8bc54 --- /dev/null +++ b/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constemptysetdeleterequest.go @@ -0,0 +1,22 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package shared + +type ConstEmptySetDeleteRequest struct { + ScopeID string `json:"scope_id"` + Groups []ConstEmptySetDeleteGroup `json:"groups"` +} + +func (c *ConstEmptySetDeleteRequest) GetScopeID() string { + if c == nil { + return "" + } + return c.ScopeID +} + +func (c *ConstEmptySetDeleteRequest) GetGroups() []ConstEmptySetDeleteGroup { + if c == nil { + return []ConstEmptySetDeleteGroup{} + } + return c.Groups +} diff --git a/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constemptysetdeleteresponse.go b/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constemptysetdeleteresponse.go new file mode 100644 index 000000000..ba0be2163 --- /dev/null +++ b/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constemptysetdeleteresponse.go @@ -0,0 +1,55 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package shared + +import ( + "github.com/hashicorp/terraform-provider-testing/internal/sdk/internal/utils" +) + +type ConstEmptySetDeleteResponse struct { + ID string `json:"id"` + ScopeID string `json:"scope_id"` + Groups []ConstEmptySetDeleteGroup `json:"groups"` + // Response-only const array. It must stay off the request model, + // be hidden from the Terraform schema, and be checked when the + // response is decoded. + // + //lint:ignore U1000 accessed via reflection for JSON marshaling + supportedActions []string `const:"[\"replace\"]" json:"supported_actions,omitempty"` +} + +func (c ConstEmptySetDeleteResponse) MarshalJSON() ([]byte, error) { + return utils.MarshalJSON(c, "", false) +} + +func (c *ConstEmptySetDeleteResponse) UnmarshalJSON(data []byte) error { + if err := utils.UnmarshalJSON(data, &c, "", false, nil); err != nil { + return err + } + return nil +} + +func (c *ConstEmptySetDeleteResponse) GetID() string { + if c == nil { + return "" + } + return c.ID +} + +func (c *ConstEmptySetDeleteResponse) GetScopeID() string { + if c == nil { + return "" + } + return c.ScopeID +} + +func (c *ConstEmptySetDeleteResponse) GetGroups() []ConstEmptySetDeleteGroup { + if c == nil { + return []ConstEmptySetDeleteGroup{} + } + return c.Groups +} + +func (c *ConstEmptySetDeleteResponse) GetSupportedActions() []string { + return []string{"replace"} +} diff --git a/zSDKs/terraform-provider-testing/internal/sdk/sdk.go b/zSDKs/terraform-provider-testing/internal/sdk/sdk.go index a31c2eb1d..24d7c837d 100644 --- a/zSDKs/terraform-provider-testing/internal/sdk/sdk.go +++ b/zSDKs/terraform-provider-testing/internal/sdk/sdk.go @@ -42573,3 +42573,415 @@ func (s *SDK) DeleteConstContainer(ctx context.Context, request operations.Delet return res, nil } + +// CreateConstEmptySetDelete - Create or replace a resource whose desired state is a set of objects. +// One operation serves create and update; deletion goes through a +// separate operation whose request body declares the same set with an +// empty const value. +func (s *SDK) CreateConstEmptySetDelete(ctx context.Context, request shared.ConstEmptySetDeleteRequest, opts ...operations.Option) (*operations.CreateConstEmptySetDeleteResponse, error) { + o := operations.Options{} + supportedOptions := []string{ + operations.SupportedOptionTimeout, + } + + for _, opt := range opts { + if err := opt(&o, supportedOptions...); err != nil { + return nil, fmt.Errorf("error applying option: %w", err) + } + } + + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } + opURL, err := url.JoinPath(baseURL, "/v0/constemptysetdelete") + if err != nil { + return nil, fmt.Errorf("error generating URL: %w", err) + } + + hookCtx := hooks.HookContext{ + SDK: s, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "create-const-empty-set-delete", + OAuth2Scopes: []string{}, + SecuritySource: s.sdkConfiguration.Security, + } + bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, false, false, "Request", "json", `request:"mediaType=application/json"`) + if err != nil { + return nil, err + } + + timeout := o.Timeout + if timeout == nil { + timeout = s.sdkConfiguration.Timeout + } + + if timeout != nil { + var cancel context.CancelFunc + ctx, cancel = context.WithTimeout(ctx, *timeout) + defer cancel() + } + + req, err := http.NewRequestWithContext(ctx, "PUT", opURL, bodyReader) + if err != nil { + return nil, fmt.Errorf("error creating request: %w", err) + } + req.Header.Set("Accept", "application/json") + req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) + if reqContentType != "" { + req.Header.Set("Content-Type", reqContentType) + } + + if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil { + return nil, err + } + + for k, v := range o.SetHeaders { + req.Header.Set(k, v) + } + + req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + if err != nil { + return nil, err + } + + httpRes, err := s.sdkConfiguration.Client.Do(req) + if err != nil || httpRes == nil { + if err != nil { + err = fmt.Errorf("error sending request: %w", err) + } else { + err = fmt.Errorf("error sending request: no response") + } + + _, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + return nil, err + } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { + _httpRes, err := s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) + if err != nil { + return nil, err + } else if _httpRes != nil { + httpRes = _httpRes + } + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { + return nil, err + } + } + + res := &operations.CreateConstEmptySetDeleteResponse{ + StatusCode: httpRes.StatusCode, + ContentType: httpRes.Header.Get("Content-Type"), + RawResponse: httpRes, + } + + switch { + case httpRes.StatusCode == 200: + switch { + case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + + var out shared.ConstEmptySetDeleteResponse + if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { + return nil, err + } + + res.ConstEmptySetDeleteResponse = &out + default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + return nil, errors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) + } + default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + return nil, errors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) + } + + return res, nil + +} + +// GetConstEmptySetDelete - Get a const empty set delete resource +func (s *SDK) GetConstEmptySetDelete(ctx context.Context, request operations.GetConstEmptySetDeleteRequest, opts ...operations.Option) (*operations.GetConstEmptySetDeleteResponse, error) { + o := operations.Options{} + supportedOptions := []string{ + operations.SupportedOptionTimeout, + } + + for _, opt := range opts { + if err := opt(&o, supportedOptions...); err != nil { + return nil, fmt.Errorf("error applying option: %w", err) + } + } + + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } + opURL, err := utils.GenerateURL(ctx, baseURL, "/v0/constemptysetdelete/{id}", request, nil) + if err != nil { + return nil, fmt.Errorf("error generating URL: %w", err) + } + + hookCtx := hooks.HookContext{ + SDK: s, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "get-const-empty-set-delete", + OAuth2Scopes: []string{}, + SecuritySource: s.sdkConfiguration.Security, + } + + timeout := o.Timeout + if timeout == nil { + timeout = s.sdkConfiguration.Timeout + } + + if timeout != nil { + var cancel context.CancelFunc + ctx, cancel = context.WithTimeout(ctx, *timeout) + defer cancel() + } + + req, err := http.NewRequestWithContext(ctx, "GET", opURL, nil) + if err != nil { + return nil, fmt.Errorf("error creating request: %w", err) + } + req.Header.Set("Accept", "application/json") + req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) + + if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil { + return nil, err + } + + for k, v := range o.SetHeaders { + req.Header.Set(k, v) + } + + req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + if err != nil { + return nil, err + } + + httpRes, err := s.sdkConfiguration.Client.Do(req) + if err != nil || httpRes == nil { + if err != nil { + err = fmt.Errorf("error sending request: %w", err) + } else { + err = fmt.Errorf("error sending request: no response") + } + + _, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + return nil, err + } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { + _httpRes, err := s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) + if err != nil { + return nil, err + } else if _httpRes != nil { + httpRes = _httpRes + } + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { + return nil, err + } + } + + res := &operations.GetConstEmptySetDeleteResponse{ + StatusCode: httpRes.StatusCode, + ContentType: httpRes.Header.Get("Content-Type"), + RawResponse: httpRes, + } + + switch { + case httpRes.StatusCode == 200: + switch { + case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + + var out shared.ConstEmptySetDeleteResponse + if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { + return nil, err + } + + res.ConstEmptySetDeleteResponse = &out + default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + return nil, errors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) + } + case httpRes.StatusCode == 404: + utils.DrainBody(httpRes) + default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + return nil, errors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) + } + + return res, nil + +} + +// DeleteConstEmptySetDelete - Delete the resource by replacing its group set with an empty set. The +// request body declares the set property with `format: set` and +// `const: []`, so Terraform must hide it and send an empty array instead +// of the groups held in state. The operation lives under a different +// API version prefix from the entity's other operations. +func (s *SDK) DeleteConstEmptySetDelete(ctx context.Context, request operations.DeleteConstEmptySetDeleteRequest, opts ...operations.Option) (*operations.DeleteConstEmptySetDeleteResponse, error) { + o := operations.Options{} + supportedOptions := []string{ + operations.SupportedOptionTimeout, + } + + for _, opt := range opts { + if err := opt(&o, supportedOptions...); err != nil { + return nil, fmt.Errorf("error applying option: %w", err) + } + } + + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } + opURL, err := url.JoinPath(baseURL, "/v1/constemptysetdelete/teardown") + if err != nil { + return nil, fmt.Errorf("error generating URL: %w", err) + } + + hookCtx := hooks.HookContext{ + SDK: s, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "delete-const-empty-set-delete", + OAuth2Scopes: []string{}, + SecuritySource: s.sdkConfiguration.Security, + } + bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, false, false, "Request", "json", `request:"mediaType=application/json"`) + if err != nil { + return nil, err + } + + timeout := o.Timeout + if timeout == nil { + timeout = s.sdkConfiguration.Timeout + } + + if timeout != nil { + var cancel context.CancelFunc + ctx, cancel = context.WithTimeout(ctx, *timeout) + defer cancel() + } + + req, err := http.NewRequestWithContext(ctx, "PUT", opURL, bodyReader) + if err != nil { + return nil, fmt.Errorf("error creating request: %w", err) + } + req.Header.Set("Accept", "application/json") + req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) + if reqContentType != "" { + req.Header.Set("Content-Type", reqContentType) + } + + if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil { + return nil, err + } + + for k, v := range o.SetHeaders { + req.Header.Set(k, v) + } + + req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + if err != nil { + return nil, err + } + + httpRes, err := s.sdkConfiguration.Client.Do(req) + if err != nil || httpRes == nil { + if err != nil { + err = fmt.Errorf("error sending request: %w", err) + } else { + err = fmt.Errorf("error sending request: no response") + } + + _, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + return nil, err + } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { + _httpRes, err := s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) + if err != nil { + return nil, err + } else if _httpRes != nil { + httpRes = _httpRes + } + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { + return nil, err + } + } + + res := &operations.DeleteConstEmptySetDeleteResponse{ + StatusCode: httpRes.StatusCode, + ContentType: httpRes.Header.Get("Content-Type"), + RawResponse: httpRes, + } + + switch { + case httpRes.StatusCode == 200: + switch { + case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + + var out shared.ConstEmptySetDeleteResponse + if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { + return nil, err + } + + res.ConstEmptySetDeleteResponse = &out + default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + return nil, errors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) + } + case httpRes.StatusCode == 404: + utils.DrainBody(httpRes) + default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + return nil, errors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) + } + + return res, nil + +} diff --git a/zSDKs/terraform-provider-testing/internal/tfmockserver/server.go b/zSDKs/terraform-provider-testing/internal/tfmockserver/server.go index 6a6800809..dc67c9903 100644 --- a/zSDKs/terraform-provider-testing/internal/tfmockserver/server.go +++ b/zSDKs/terraform-provider-testing/internal/tfmockserver/server.go @@ -586,11 +586,20 @@ func (h *ResourceHandler) handleDeleteWithConfig(w http.ResponseWriter, r *http. for _, p := range config.params { pathParams[p] = r.PathValue(p) } + var requestData map[string]interface{} + if r.ContentLength != 0 { + if err := json.NewDecoder(r.Body).Decode(&requestData); err != nil { + h.testingContext.Logf("🔴 [MOCK SERVER] DELETE - Failed to decode JSON: %v\n", err) + h.writeError(w, 400, "Invalid JSON data", "VALIDATION_ERROR") + return + } + h.testingContext.Logf("🔵 [MOCK SERVER] DELETE - Request body: %+v\n", requestData) + } config.Requests.Append(CapturedRequest{ Method: r.Method, Path: r.URL.Path, PathParams: pathParams, - Body: nil, // DELETE requests typically don't have a body + Body: requestData, }) h.testingContext.Logf("🔵 [MOCK SERVER] DELETE - Id: %s,\n", StoreKey) From 90088f889d101846c2127585da9b027d7ad77555 Mon Sep 17 00:00:00 2001 From: Ash Godfrey Date: Mon, 2 Nov 2026 13:29:49 +0000 Subject: [PATCH 15/22] test(terraform): assert a wrong response const fails decoding and harden mock delete body capture A new acceptance case returns a wrong value for the response-only const array and asserts the apply fails with the const mismatch error, so the lifecycle test's claim that the const is checked on decode is exercised. The mock server's delete handler reads the whole body and decodes it only when non-empty, so a chunked request without a body is not rejected, and a malformed body is still recorded in the request log before the 400, as the create and update handlers do. --- .../constemptysetdelete_resource_test.go | 31 +++++++++++++++++++ .../internal/tfmockserver/server.go | 12 +++++-- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/zSDKs/terraform-provider-testing/internal/provider/constemptysetdelete_resource_test.go b/zSDKs/terraform-provider-testing/internal/provider/constemptysetdelete_resource_test.go index d8beee83a..069ccd7ff 100644 --- a/zSDKs/terraform-provider-testing/internal/provider/constemptysetdelete_resource_test.go +++ b/zSDKs/terraform-provider-testing/internal/provider/constemptysetdelete_resource_test.go @@ -1,6 +1,7 @@ package provider_test import ( + "regexp" "testing" "github.com/hashicorp/terraform-plugin-testing/config" @@ -122,3 +123,33 @@ func TestConstEmptySetDeleteResourceLifecycle(t *testing.T) { tfmockserver.AssertRequestBodyFieldEmptyArray(t, deletes[0], "groups") require.Len(t, deletes[0], 2, "delete body carries only scope_id and the const empty set: %v", deletes[0]) } + +func TestConstEmptySetDeleteResourceRejectsWrongResponseConst(t *testing.T) { + t.Parallel() + + endpoints := tfmockserver.ResourceEndpoints{ + Create: tfmockserver.Endpoints{ + { + Endpoint: "PUT /v0/constemptysetdelete", + ResponseOverlay: map[string]any{"supported_actions": []any{"delete"}}, + }, + }, + } + + mockServer := tfmockserver.StartServer(endpoints, t) + defer mockServer.Close() + + resource.Test(t, resource.TestCase{ + Steps: []resource.TestStep{ + { + ConfigDirectory: config.StaticDirectory("testdata/TestConstEmptySetDeleteResourceLifecycle"), + ProtoV6ProviderFactories: provider.GetTestProviders(), + ConfigVariables: config.Variables{ + "server_url": config.StringVariable(mockServer.URL), + "replicas": config.IntegerVariable(2), + }, + ExpectError: regexp.MustCompile(`(?s)const field.*supported_actions.*does\s+not match`), + }, + }, + }) +} diff --git a/zSDKs/terraform-provider-testing/internal/tfmockserver/server.go b/zSDKs/terraform-provider-testing/internal/tfmockserver/server.go index dc67c9903..e07586501 100644 --- a/zSDKs/terraform-provider-testing/internal/tfmockserver/server.go +++ b/zSDKs/terraform-provider-testing/internal/tfmockserver/server.go @@ -4,6 +4,7 @@ import ( "encoding/json" "errors" "fmt" + "io" "net/http" "net/http/httptest" "regexp" @@ -587,9 +588,16 @@ func (h *ResourceHandler) handleDeleteWithConfig(w http.ResponseWriter, r *http. pathParams[p] = r.PathValue(p) } var requestData map[string]interface{} - if r.ContentLength != 0 { - if err := json.NewDecoder(r.Body).Decode(&requestData); err != nil { + rawBody, _ := io.ReadAll(r.Body) + if len(rawBody) > 0 { + if err := json.Unmarshal(rawBody, &requestData); err != nil { h.testingContext.Logf("🔴 [MOCK SERVER] DELETE - Failed to decode JSON: %v\n", err) + config.Requests.Append(CapturedRequest{ + Method: r.Method, + Path: r.URL.Path, + PathParams: pathParams, + Body: nil, + }) h.writeError(w, 400, "Invalid JSON data", "VALIDATION_ERROR") return } From 100b3a64050a50c36862ea9e25008bf42c40985d Mon Sep 17 00:00:00 2001 From: Ash Godfrey Date: Mon, 2 Nov 2026 13:41:38 +0000 Subject: [PATCH 16/22] test(terraform): reject a delete request whose body cannot be read The mock server's delete handler ignored the body read error, so a failed or partial read could still delete the stored resource. A read error is now handled like a decode error: the request is logged with a nil body and answered with 400 before the store changes. --- .../internal/tfmockserver/server.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/zSDKs/terraform-provider-testing/internal/tfmockserver/server.go b/zSDKs/terraform-provider-testing/internal/tfmockserver/server.go index e07586501..f2efe7dc9 100644 --- a/zSDKs/terraform-provider-testing/internal/tfmockserver/server.go +++ b/zSDKs/terraform-provider-testing/internal/tfmockserver/server.go @@ -588,10 +588,13 @@ func (h *ResourceHandler) handleDeleteWithConfig(w http.ResponseWriter, r *http. pathParams[p] = r.PathValue(p) } var requestData map[string]interface{} - rawBody, _ := io.ReadAll(r.Body) - if len(rawBody) > 0 { - if err := json.Unmarshal(rawBody, &requestData); err != nil { - h.testingContext.Logf("🔴 [MOCK SERVER] DELETE - Failed to decode JSON: %v\n", err) + rawBody, readErr := io.ReadAll(r.Body) + if readErr != nil || len(rawBody) > 0 { + if readErr == nil { + readErr = json.Unmarshal(rawBody, &requestData) + } + if readErr != nil { + h.testingContext.Logf("🔴 [MOCK SERVER] DELETE - Failed to read or decode body: %v\n", readErr) config.Requests.Append(CapturedRequest{ Method: r.Method, Path: r.URL.Path, From a70e3ed33b01aa355bd753becf97c95939ec687f Mon Sep 17 00:00:00 2001 From: Ash Godfrey Date: Mon, 2 Nov 2026 13:45:14 +0000 Subject: [PATCH 17/22] fix: drop an empty container const when minItems is positive An array with `const: []` and `minItems: 1` cannot be satisfied by any value, so the const is now dropped with a validation warning like the other unsupported container const shapes, instead of being emitted on the model. --- internal/schemas/handle_array_test.go | 30 +++++++++++++++++++++++++++ internal/schemas/schemas.go | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/internal/schemas/handle_array_test.go b/internal/schemas/handle_array_test.go index fe749b48e..c69771620 100644 --- a/internal/schemas/handle_array_test.go +++ b/internal/schemas/handle_array_test.go @@ -246,6 +246,36 @@ func TestHandleArray(t *testing.T) { WithConst(&ast.AnyValue{Value: []interface{}{}}). Build(), }, + { + name: "UniqueItemsArrayWithEmptyConstAndMinItems", + schemasYAML: `TestSchema: + type: array + items: + type: string + uniqueItems: true + minItems: 1 + 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{ + UniqueItems: pointer.From(true), + MinItems: pointer.From[int64](1), + }). + Build()). + Build(), + expectedWarning: "only arrays without uniqueItems and maps of scalar values are supported, omitting const", + }, { name: "SetFormatWithEmptyConst", schemasYAML: `TestSchema: diff --git a/internal/schemas/schemas.go b/internal/schemas/schemas.go index a7e5365c5..fa0d627b9 100644 --- a/internal/schemas/schemas.go +++ b/internal/schemas/schemas.go @@ -1701,7 +1701,7 @@ func constContainerValueSupported(val any, typ *ast.TypeDef) bool { return false } if len(items) == 0 { - return true + return typ.Validations == nil || typ.Validations.MinItems == nil || *typ.Validations.MinItems <= 0 } if typ.Type == ast.DataTypeSet || (typ.Validations != nil && typ.Validations.UniqueItems != nil && *typ.Validations.UniqueItems) { return false From a2f81d9369a115e99d3b0335a67429940787a205 Mon Sep 17 00:00:00 2001 From: Ash Godfrey Date: Mon, 2 Nov 2026 14:16:33 +0000 Subject: [PATCH 18/22] fix: bound container consts by minItems and maxItems and accept null for optional container consts A non-empty array const that falls outside the schema's own minItems or maxItems is dropped with a validation warning instead of being baked into every request. JSON unmarshaling treats null as absent for a container const field that is optional or nullable, so a response that sends null for such a field no longer fails to decode. --- .changesets/1792662097-2435dcc7.yaml | 2 +- internal/schemas/handle_array_test.go | 59 +++++++++++++++++++ internal/schemas/schemas.go | 13 +++- .../{{getUtilsLocation}}/json.go.stmpl | 4 ++ .../internal/sdk/utils/json.go.stmpl | 4 ++ .../mockserver/internal/sdk/utils/json.go | 4 ++ .../internal/sdk/sdkinternal/utils/json.go | 4 ++ .../mockserver/internal/sdk/utils/json.go | 4 ++ .../mockserver/internal/sdk/utils/json.go | 4 ++ zSDKs/sdk-go/internal/utils/json.go | 4 ++ .../mockserver/internal/sdk/utils/json.go | 4 ++ .../mockserver/internal/sdk/utils/json.go | 4 ++ .../mockserver/internal/sdk/utils/json.go | 4 ++ .../mockserver/internal/sdk/utils/json.go | 4 ++ .../mockserver/internal/sdk/utils/json.go | 4 ++ .../mockserver/internal/sdk/utils/json.go | 4 ++ .../.speakeasy/gen.lock | 2 +- .../provider/constcontainer_resource_test.go | 5 +- .../internal/sdk/internal/utils/json.go | 4 ++ 19 files changed, 131 insertions(+), 6 deletions(-) diff --git a/.changesets/1792662097-2435dcc7.yaml b/.changesets/1792662097-2435dcc7.yaml index d5028978c..81352685c 100644 --- a/.changesets/1792662097-2435dcc7.yaml +++ b/.changesets/1792662097-2435dcc7.yaml @@ -6,6 +6,6 @@ targets: - cli type: fix bump: patch -description: JSON unmarshaling compares array and map const values structurally instead of by exact text +description: JSON unmarshaling compares array and map const values structurally instead of by exact text and accepts null for an optional container const author: AshGodfrey date: "2026-10-22" diff --git a/internal/schemas/handle_array_test.go b/internal/schemas/handle_array_test.go index c69771620..22aa605ce 100644 --- a/internal/schemas/handle_array_test.go +++ b/internal/schemas/handle_array_test.go @@ -276,6 +276,65 @@ func TestHandleArray(t *testing.T) { Build(), expectedWarning: "only arrays without uniqueItems and maps of scalar values are supported, omitting const", }, + { + name: "ArrayWithConstBelowMinItems", + schemasYAML: `TestSchema: + type: array + items: + type: string + minItems: 2 + 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()). + WithLocation(&yaml.Node{Line: 9, Column: 7}). + WithValidations(&ast.Validations{ + MinItems: pointer.From[int64](2), + }). + Build()). + Build(), + expectedWarning: "only arrays without uniqueItems and maps of scalar values are supported, omitting const", + }, + { + name: "ArrayWithConstAboveMaxItems", + schemasYAML: `TestSchema: + type: array + items: + type: string + maxItems: 1 + 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{ + MaxItems: pointer.From[int64](1), + }). + Build()). + Build(), + expectedWarning: "only arrays without uniqueItems and maps of scalar values are supported, omitting const", + }, { name: "SetFormatWithEmptyConst", schemasYAML: `TestSchema: diff --git a/internal/schemas/schemas.go b/internal/schemas/schemas.go index fa0d627b9..c89f1ca8c 100644 --- a/internal/schemas/schemas.go +++ b/internal/schemas/schemas.go @@ -1700,8 +1700,17 @@ func constContainerValueSupported(val any, typ *ast.TypeDef) bool { if !ok { return false } - if len(items) == 0 { - return typ.Validations == nil || typ.Validations.MinItems == nil || *typ.Validations.MinItems <= 0 + count := int64(len(items)) + if typ.Validations != nil { + if typ.Validations.MinItems != nil && count < *typ.Validations.MinItems { + return false + } + if typ.Validations.MaxItems != nil && count > *typ.Validations.MaxItems { + return false + } + } + if count == 0 { + return true } if typ.Type == ast.DataTypeSet || (typ.Validations != nil && typ.Validations.UniqueItems != nil && *typ.Validations.UniqueItems) { return false diff --git a/templates/templates/go/auxiliary/{{getUtilsLocation}}/json.go.stmpl b/templates/templates/go/auxiliary/{{getUtilsLocation}}/json.go.stmpl index a5ad54c12..196015bf5 100644 --- a/templates/templates/go/auxiliary/{{getUtilsLocation}}/json.go.stmpl +++ b/templates/templates/go/auxiliary/{{getUtilsLocation}}/json.go.stmpl @@ -205,6 +205,10 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (field.Type.Kind() == reflect.Ptr || strings.Contains(jsonTag, "omitempty")) { + delete(unmarshaled, fieldName) + continue + } val := string(r) if strings.HasPrefix(val, `"`) && strings.HasSuffix(val, `"`) { diff --git a/templates/templates/mockserver/auxiliary/internal/sdk/utils/json.go.stmpl b/templates/templates/mockserver/auxiliary/internal/sdk/utils/json.go.stmpl index 95b5e6ad8..9aeea6503 100644 --- a/templates/templates/mockserver/auxiliary/internal/sdk/utils/json.go.stmpl +++ b/templates/templates/mockserver/auxiliary/internal/sdk/utils/json.go.stmpl @@ -189,6 +189,10 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (field.Type.Kind() == reflect.Ptr || strings.Contains(jsonTag, "omitempty")) { + delete(unmarshaled, fieldName) + continue + } val := string(r) if strings.HasPrefix(val, `"`) && strings.HasSuffix(val, `"`) { diff --git a/zSDKs/mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go b/zSDKs/mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go index d59d5e51c..21f2afa80 100644 --- a/zSDKs/mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go @@ -191,6 +191,10 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (field.Type.Kind() == reflect.Ptr || strings.Contains(jsonTag, "omitempty")) { + delete(unmarshaled, fieldName) + continue + } val := string(r) if strings.HasPrefix(val, `"`) && strings.HasSuffix(val, `"`) { diff --git a/zSDKs/sdk-cli/internal/sdk/sdkinternal/utils/json.go b/zSDKs/sdk-cli/internal/sdk/sdkinternal/utils/json.go index b7b564a01..e63f20a28 100644 --- a/zSDKs/sdk-cli/internal/sdk/sdkinternal/utils/json.go +++ b/zSDKs/sdk-cli/internal/sdk/sdkinternal/utils/json.go @@ -206,6 +206,10 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (field.Type.Kind() == reflect.Ptr || strings.Contains(jsonTag, "omitempty")) { + delete(unmarshaled, fieldName) + continue + } val := string(r) if strings.HasPrefix(val, `"`) && strings.HasSuffix(val, `"`) { diff --git a/zSDKs/sdk-cli/tests/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-cli/tests/mockserver/internal/sdk/utils/json.go index d59d5e51c..21f2afa80 100644 --- a/zSDKs/sdk-cli/tests/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-cli/tests/mockserver/internal/sdk/utils/json.go @@ -191,6 +191,10 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (field.Type.Kind() == reflect.Ptr || strings.Contains(jsonTag, "omitempty")) { + delete(unmarshaled, fieldName) + continue + } val := string(r) if strings.HasPrefix(val, `"`) && strings.HasSuffix(val, `"`) { diff --git a/zSDKs/sdk-csharp/Tests/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-csharp/Tests/mockserver/internal/sdk/utils/json.go index d59d5e51c..21f2afa80 100644 --- a/zSDKs/sdk-csharp/Tests/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-csharp/Tests/mockserver/internal/sdk/utils/json.go @@ -191,6 +191,10 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (field.Type.Kind() == reflect.Ptr || strings.Contains(jsonTag, "omitempty")) { + delete(unmarshaled, fieldName) + continue + } val := string(r) if strings.HasPrefix(val, `"`) && strings.HasSuffix(val, `"`) { diff --git a/zSDKs/sdk-go/internal/utils/json.go b/zSDKs/sdk-go/internal/utils/json.go index a245cbee6..d281b3360 100644 --- a/zSDKs/sdk-go/internal/utils/json.go +++ b/zSDKs/sdk-go/internal/utils/json.go @@ -206,6 +206,10 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (field.Type.Kind() == reflect.Ptr || strings.Contains(jsonTag, "omitempty")) { + delete(unmarshaled, fieldName) + continue + } val := string(r) if strings.HasPrefix(val, `"`) && strings.HasSuffix(val, `"`) { diff --git a/zSDKs/sdk-go/tests/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-go/tests/mockserver/internal/sdk/utils/json.go index d59d5e51c..21f2afa80 100644 --- a/zSDKs/sdk-go/tests/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-go/tests/mockserver/internal/sdk/utils/json.go @@ -191,6 +191,10 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (field.Type.Kind() == reflect.Ptr || strings.Contains(jsonTag, "omitempty")) { + delete(unmarshaled, fieldName) + continue + } val := string(r) if strings.HasPrefix(val, `"`) && strings.HasSuffix(val, `"`) { diff --git a/zSDKs/sdk-javav2/tests/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-javav2/tests/mockserver/internal/sdk/utils/json.go index d59d5e51c..21f2afa80 100644 --- a/zSDKs/sdk-javav2/tests/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-javav2/tests/mockserver/internal/sdk/utils/json.go @@ -191,6 +191,10 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (field.Type.Kind() == reflect.Ptr || strings.Contains(jsonTag, "omitempty")) { + delete(unmarshaled, fieldName) + continue + } val := string(r) if strings.HasPrefix(val, `"`) && strings.HasSuffix(val, `"`) { diff --git a/zSDKs/sdk-mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go index d59d5e51c..21f2afa80 100644 --- a/zSDKs/sdk-mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go @@ -191,6 +191,10 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (field.Type.Kind() == reflect.Ptr || strings.Contains(jsonTag, "omitempty")) { + delete(unmarshaled, fieldName) + continue + } val := string(r) if strings.HasPrefix(val, `"`) && strings.HasSuffix(val, `"`) { diff --git a/zSDKs/sdk-pythonv2/tests/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-pythonv2/tests/mockserver/internal/sdk/utils/json.go index d59d5e51c..21f2afa80 100644 --- a/zSDKs/sdk-pythonv2/tests/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-pythonv2/tests/mockserver/internal/sdk/utils/json.go @@ -191,6 +191,10 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (field.Type.Kind() == reflect.Ptr || strings.Contains(jsonTag, "omitempty")) { + delete(unmarshaled, fieldName) + continue + } val := string(r) if strings.HasPrefix(val, `"`) && strings.HasSuffix(val, `"`) { diff --git a/zSDKs/sdk-ruby/test/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-ruby/test/mockserver/internal/sdk/utils/json.go index d59d5e51c..21f2afa80 100644 --- a/zSDKs/sdk-ruby/test/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-ruby/test/mockserver/internal/sdk/utils/json.go @@ -191,6 +191,10 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (field.Type.Kind() == reflect.Ptr || strings.Contains(jsonTag, "omitempty")) { + delete(unmarshaled, fieldName) + continue + } val := string(r) if strings.HasPrefix(val, `"`) && strings.HasSuffix(val, `"`) { diff --git a/zSDKs/sdk-typescriptv2/src/__tests__/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-typescriptv2/src/__tests__/mockserver/internal/sdk/utils/json.go index d59d5e51c..21f2afa80 100644 --- a/zSDKs/sdk-typescriptv2/src/__tests__/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-typescriptv2/src/__tests__/mockserver/internal/sdk/utils/json.go @@ -191,6 +191,10 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (field.Type.Kind() == reflect.Ptr || strings.Contains(jsonTag, "omitempty")) { + delete(unmarshaled, fieldName) + continue + } val := string(r) if strings.HasPrefix(val, `"`) && strings.HasSuffix(val, `"`) { diff --git a/zSDKs/terraform-provider-testing/.speakeasy/gen.lock b/zSDKs/terraform-provider-testing/.speakeasy/gen.lock index 6f6068591..2e93f74af 100644 --- a/zSDKs/terraform-provider-testing/.speakeasy/gen.lock +++ b/zSDKs/terraform-provider-testing/.speakeasy/gen.lock @@ -2438,7 +2438,7 @@ trackedFiles: internal/sdk/internal/utils/jq.go: last_write_checksum: sha1:2e75ed7a7db1f91e97dac1ac4ca7801b2beb69b5 internal/sdk/internal/utils/json.go: - last_write_checksum: sha1:1c9d6f7c612b8041b7ef3098eae1b145f6260e54 + last_write_checksum: sha1:d24c3552f50a1c14aad60e16bd6ca345236b6433 internal/sdk/internal/utils/oauth2_credentials.go: last_write_checksum: sha1:f9218b6b3dbd11494cc353bf22eb37f0ca654a7d internal/sdk/internal/utils/oauth2_sessions.go: diff --git a/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource_test.go b/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource_test.go index e0a9bf119..b1800be1f 100644 --- a/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource_test.go +++ b/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource_test.go @@ -30,7 +30,8 @@ func TestConstContainerResourceLifecycle(t *testing.T) { { Endpoint: "GET /v0/constcontainer/{id}", // Return the const values with whitespace, map key order and - // number formatting the client did not send. + // number formatting the client did not send, and null for an + // optional const container. ResponseFuncWithStore: func(r *http.Request, w http.ResponseWriter, storedData map[string]any) { w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) @@ -38,7 +39,7 @@ func TestConstContainerResourceLifecycle(t *testing.T) { "id": "` + tfmockserver.StoreKey + `", "name": "` + storedData["name"].(string) + `", "empty_list": [ ], - "fixed_list": [ "read" , "write" ], + "fixed_list": null, "empty_map": { }, "empty_set": [ ], "fixed_map": { "min" : 1, "max" : 1e1 }, diff --git a/zSDKs/terraform-provider-testing/internal/sdk/internal/utils/json.go b/zSDKs/terraform-provider-testing/internal/sdk/internal/utils/json.go index 84fbf1af1..5be50d78f 100644 --- a/zSDKs/terraform-provider-testing/internal/sdk/internal/utils/json.go +++ b/zSDKs/terraform-provider-testing/internal/sdk/internal/utils/json.go @@ -204,6 +204,10 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (field.Type.Kind() == reflect.Ptr || strings.Contains(jsonTag, "omitempty")) { + delete(unmarshaled, fieldName) + continue + } val := string(r) if strings.HasPrefix(val, `"`) && strings.HasSuffix(val, `"`) { From 356dfe271c66e0184763ff02c706b16b70720163 Mon Sep 17 00:00:00 2001 From: Ash Godfrey Date: Mon, 2 Nov 2026 14:26:52 +0000 Subject: [PATCH 19/22] fix: decide container const optionality from parsed JSON tag options Match omitempty and omitzero as exact comma-separated options rather than a substring of the tag, so a property whose name contains omitempty is not treated as optional and omitzero fields accept null. --- .../go/auxiliary/{{getUtilsLocation}}/json.go.stmpl | 7 +++++-- .../mockserver/auxiliary/internal/sdk/utils/json.go.stmpl | 7 +++++-- zSDKs/mcp-typescript/.speakeasy/gen.lock | 2 +- .../src/__tests__/mockserver/internal/sdk/utils/json.go | 7 +++++-- zSDKs/sdk-cli/.speakeasy/gen.lock | 4 ++-- zSDKs/sdk-cli/internal/sdk/sdkinternal/utils/json.go | 7 +++++-- zSDKs/sdk-cli/tests/mockserver/internal/sdk/utils/json.go | 7 +++++-- zSDKs/sdk-csharp/.speakeasy/gen.lock | 2 +- .../sdk-csharp/Tests/mockserver/internal/sdk/utils/json.go | 7 +++++-- zSDKs/sdk-go/.speakeasy/gen.lock | 4 ++-- zSDKs/sdk-go/internal/utils/json.go | 7 +++++-- zSDKs/sdk-go/tests/mockserver/internal/sdk/utils/json.go | 7 +++++-- zSDKs/sdk-javav2/.speakeasy/gen.lock | 2 +- .../sdk-javav2/tests/mockserver/internal/sdk/utils/json.go | 7 +++++-- zSDKs/sdk-mcp-typescript/.speakeasy/gen.lock | 2 +- .../src/__tests__/mockserver/internal/sdk/utils/json.go | 7 +++++-- zSDKs/sdk-pythonv2/.speakeasy/gen.lock | 2 +- .../tests/mockserver/internal/sdk/utils/json.go | 7 +++++-- zSDKs/sdk-ruby/.speakeasy/gen.lock | 2 +- zSDKs/sdk-ruby/test/mockserver/internal/sdk/utils/json.go | 7 +++++-- zSDKs/sdk-typescriptv2/.speakeasy/gen.lock | 2 +- .../src/__tests__/mockserver/internal/sdk/utils/json.go | 7 +++++-- zSDKs/terraform-provider-testing/.speakeasy/gen.lock | 2 +- .../internal/sdk/internal/utils/json.go | 7 +++++-- 24 files changed, 82 insertions(+), 40 deletions(-) diff --git a/templates/templates/go/auxiliary/{{getUtilsLocation}}/json.go.stmpl b/templates/templates/go/auxiliary/{{getUtilsLocation}}/json.go.stmpl index 196015bf5..457b079ff 100644 --- a/templates/templates/go/auxiliary/{{getUtilsLocation}}/json.go.stmpl +++ b/templates/templates/go/auxiliary/{{getUtilsLocation}}/json.go.stmpl @@ -186,11 +186,14 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool fieldVal := val.Field(i) fieldName := field.Name + optional := false jsonTag := field.Tag.Get("json") if jsonTag != "" { for _, tag := range strings.Split(jsonTag, ",") { - if tag != "omitempty" && tag != "omitzero" { + if tag == "omitempty" || tag == "omitzero" { + optional = true + } else { fieldName = tag } } @@ -205,7 +208,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (field.Type.Kind() == reflect.Ptr || strings.Contains(jsonTag, "omitempty")) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr) { delete(unmarshaled, fieldName) continue } diff --git a/templates/templates/mockserver/auxiliary/internal/sdk/utils/json.go.stmpl b/templates/templates/mockserver/auxiliary/internal/sdk/utils/json.go.stmpl index 9aeea6503..1dbcf5322 100644 --- a/templates/templates/mockserver/auxiliary/internal/sdk/utils/json.go.stmpl +++ b/templates/templates/mockserver/auxiliary/internal/sdk/utils/json.go.stmpl @@ -170,11 +170,14 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool fieldVal := val.Field(i) fieldName := field.Name + optional := false jsonTag := field.Tag.Get("json") if jsonTag != "" { for _, tag := range strings.Split(jsonTag, ",") { - if tag != "omitempty" && tag != "omitzero" { + if tag == "omitempty" || tag == "omitzero" { + optional = true + } else { fieldName = tag } } @@ -189,7 +192,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (field.Type.Kind() == reflect.Ptr || strings.Contains(jsonTag, "omitempty")) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr) { delete(unmarshaled, fieldName) continue } diff --git a/zSDKs/mcp-typescript/.speakeasy/gen.lock b/zSDKs/mcp-typescript/.speakeasy/gen.lock index acc0fbc8c..e4d569997 100644 --- a/zSDKs/mcp-typescript/.speakeasy/gen.lock +++ b/zSDKs/mcp-typescript/.speakeasy/gen.lock @@ -412,7 +412,7 @@ trackedFiles: src/__tests__/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd src/__tests__/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:642159c8ddd0e1d4f69146b64af207f6a7c0cd76 + last_write_checksum: sha1:9c5fde148723a2f12ecefa1d2708cb55fded894f src/__tests__/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 src/__tests__/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go b/zSDKs/mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go index 21f2afa80..10962bc00 100644 --- a/zSDKs/mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go @@ -172,11 +172,14 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool fieldVal := val.Field(i) fieldName := field.Name + optional := false jsonTag := field.Tag.Get("json") if jsonTag != "" { for _, tag := range strings.Split(jsonTag, ",") { - if tag != "omitempty" && tag != "omitzero" { + if tag == "omitempty" || tag == "omitzero" { + optional = true + } else { fieldName = tag } } @@ -191,7 +194,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (field.Type.Kind() == reflect.Ptr || strings.Contains(jsonTag, "omitempty")) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr) { delete(unmarshaled, fieldName) continue } diff --git a/zSDKs/sdk-cli/.speakeasy/gen.lock b/zSDKs/sdk-cli/.speakeasy/gen.lock index 9ab7799cc..83feb8cec 100644 --- a/zSDKs/sdk-cli/.speakeasy/gen.lock +++ b/zSDKs/sdk-cli/.speakeasy/gen.lock @@ -602,7 +602,7 @@ trackedFiles: internal/sdk/sdkinternal/utils/headers.go: last_write_checksum: sha1:1b0bd68e1ea0bce8c5a42b5de9fd020fede7aecc internal/sdk/sdkinternal/utils/json.go: - last_write_checksum: sha1:019b03979496abc305273aa8a995adce357bcc1a + last_write_checksum: sha1:443ad5894efdfa2de36e9f5c67895b3ee0279bdd internal/sdk/sdkinternal/utils/oauth2_credentials.go: last_write_checksum: sha1:f9218b6b3dbd11494cc353bf22eb37f0ca654a7d internal/sdk/sdkinternal/utils/oauth2_sessions.go: @@ -1076,7 +1076,7 @@ trackedFiles: tests/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd tests/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:642159c8ddd0e1d4f69146b64af207f6a7c0cd76 + last_write_checksum: sha1:9c5fde148723a2f12ecefa1d2708cb55fded894f tests/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 tests/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-cli/internal/sdk/sdkinternal/utils/json.go b/zSDKs/sdk-cli/internal/sdk/sdkinternal/utils/json.go index e63f20a28..a0fafa04c 100644 --- a/zSDKs/sdk-cli/internal/sdk/sdkinternal/utils/json.go +++ b/zSDKs/sdk-cli/internal/sdk/sdkinternal/utils/json.go @@ -187,11 +187,14 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool fieldVal := val.Field(i) fieldName := field.Name + optional := false jsonTag := field.Tag.Get("json") if jsonTag != "" { for _, tag := range strings.Split(jsonTag, ",") { - if tag != "omitempty" && tag != "omitzero" { + if tag == "omitempty" || tag == "omitzero" { + optional = true + } else { fieldName = tag } } @@ -206,7 +209,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (field.Type.Kind() == reflect.Ptr || strings.Contains(jsonTag, "omitempty")) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr) { delete(unmarshaled, fieldName) continue } diff --git a/zSDKs/sdk-cli/tests/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-cli/tests/mockserver/internal/sdk/utils/json.go index 21f2afa80..10962bc00 100644 --- a/zSDKs/sdk-cli/tests/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-cli/tests/mockserver/internal/sdk/utils/json.go @@ -172,11 +172,14 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool fieldVal := val.Field(i) fieldName := field.Name + optional := false jsonTag := field.Tag.Get("json") if jsonTag != "" { for _, tag := range strings.Split(jsonTag, ",") { - if tag != "omitempty" && tag != "omitzero" { + if tag == "omitempty" || tag == "omitzero" { + optional = true + } else { fieldName = tag } } @@ -191,7 +194,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (field.Type.Kind() == reflect.Ptr || strings.Contains(jsonTag, "omitempty")) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr) { delete(unmarshaled, fieldName) continue } diff --git a/zSDKs/sdk-csharp/.speakeasy/gen.lock b/zSDKs/sdk-csharp/.speakeasy/gen.lock index 651faf679..3bf348f7d 100644 --- a/zSDKs/sdk-csharp/.speakeasy/gen.lock +++ b/zSDKs/sdk-csharp/.speakeasy/gen.lock @@ -458,7 +458,7 @@ trackedFiles: Tests/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd Tests/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:642159c8ddd0e1d4f69146b64af207f6a7c0cd76 + last_write_checksum: sha1:9c5fde148723a2f12ecefa1d2708cb55fded894f Tests/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 Tests/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-csharp/Tests/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-csharp/Tests/mockserver/internal/sdk/utils/json.go index 21f2afa80..10962bc00 100644 --- a/zSDKs/sdk-csharp/Tests/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-csharp/Tests/mockserver/internal/sdk/utils/json.go @@ -172,11 +172,14 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool fieldVal := val.Field(i) fieldName := field.Name + optional := false jsonTag := field.Tag.Get("json") if jsonTag != "" { for _, tag := range strings.Split(jsonTag, ",") { - if tag != "omitempty" && tag != "omitzero" { + if tag == "omitempty" || tag == "omitzero" { + optional = true + } else { fieldName = tag } } @@ -191,7 +194,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (field.Type.Kind() == reflect.Ptr || strings.Contains(jsonTag, "omitempty")) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr) { delete(unmarshaled, fieldName) continue } diff --git a/zSDKs/sdk-go/.speakeasy/gen.lock b/zSDKs/sdk-go/.speakeasy/gen.lock index 7f80c5259..025636906 100644 --- a/zSDKs/sdk-go/.speakeasy/gen.lock +++ b/zSDKs/sdk-go/.speakeasy/gen.lock @@ -713,7 +713,7 @@ trackedFiles: internal/utils/headers.go: last_write_checksum: sha1:e529ca3d7ab96a091021bcd471ba2cbef50286b3 internal/utils/json.go: - last_write_checksum: sha1:c3b8298dcb759309db7e312f3d04993cfd41643a + last_write_checksum: sha1:a57614614bc82e69e2b49092e60cdfbe2c3f5818 internal/utils/pathparams.go: last_write_checksum: sha1:a092fc31b7c8fac29c359ddfa8bf2e02763fa097 internal/utils/queryparams.go: @@ -1233,7 +1233,7 @@ trackedFiles: tests/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd tests/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:642159c8ddd0e1d4f69146b64af207f6a7c0cd76 + last_write_checksum: sha1:9c5fde148723a2f12ecefa1d2708cb55fded894f tests/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 tests/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-go/internal/utils/json.go b/zSDKs/sdk-go/internal/utils/json.go index d281b3360..ac0843fa1 100644 --- a/zSDKs/sdk-go/internal/utils/json.go +++ b/zSDKs/sdk-go/internal/utils/json.go @@ -187,11 +187,14 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool fieldVal := val.Field(i) fieldName := field.Name + optional := false jsonTag := field.Tag.Get("json") if jsonTag != "" { for _, tag := range strings.Split(jsonTag, ",") { - if tag != "omitempty" && tag != "omitzero" { + if tag == "omitempty" || tag == "omitzero" { + optional = true + } else { fieldName = tag } } @@ -206,7 +209,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (field.Type.Kind() == reflect.Ptr || strings.Contains(jsonTag, "omitempty")) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr) { delete(unmarshaled, fieldName) continue } diff --git a/zSDKs/sdk-go/tests/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-go/tests/mockserver/internal/sdk/utils/json.go index 21f2afa80..10962bc00 100644 --- a/zSDKs/sdk-go/tests/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-go/tests/mockserver/internal/sdk/utils/json.go @@ -172,11 +172,14 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool fieldVal := val.Field(i) fieldName := field.Name + optional := false jsonTag := field.Tag.Get("json") if jsonTag != "" { for _, tag := range strings.Split(jsonTag, ",") { - if tag != "omitempty" && tag != "omitzero" { + if tag == "omitempty" || tag == "omitzero" { + optional = true + } else { fieldName = tag } } @@ -191,7 +194,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (field.Type.Kind() == reflect.Ptr || strings.Contains(jsonTag, "omitempty")) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr) { delete(unmarshaled, fieldName) continue } diff --git a/zSDKs/sdk-javav2/.speakeasy/gen.lock b/zSDKs/sdk-javav2/.speakeasy/gen.lock index 25cb31c21..6280400a5 100644 --- a/zSDKs/sdk-javav2/.speakeasy/gen.lock +++ b/zSDKs/sdk-javav2/.speakeasy/gen.lock @@ -1983,7 +1983,7 @@ trackedFiles: tests/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd tests/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:642159c8ddd0e1d4f69146b64af207f6a7c0cd76 + last_write_checksum: sha1:9c5fde148723a2f12ecefa1d2708cb55fded894f tests/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 tests/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-javav2/tests/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-javav2/tests/mockserver/internal/sdk/utils/json.go index 21f2afa80..10962bc00 100644 --- a/zSDKs/sdk-javav2/tests/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-javav2/tests/mockserver/internal/sdk/utils/json.go @@ -172,11 +172,14 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool fieldVal := val.Field(i) fieldName := field.Name + optional := false jsonTag := field.Tag.Get("json") if jsonTag != "" { for _, tag := range strings.Split(jsonTag, ",") { - if tag != "omitempty" && tag != "omitzero" { + if tag == "omitempty" || tag == "omitzero" { + optional = true + } else { fieldName = tag } } @@ -191,7 +194,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (field.Type.Kind() == reflect.Ptr || strings.Contains(jsonTag, "omitempty")) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr) { delete(unmarshaled, fieldName) continue } diff --git a/zSDKs/sdk-mcp-typescript/.speakeasy/gen.lock b/zSDKs/sdk-mcp-typescript/.speakeasy/gen.lock index 974b45e02..371e97413 100644 --- a/zSDKs/sdk-mcp-typescript/.speakeasy/gen.lock +++ b/zSDKs/sdk-mcp-typescript/.speakeasy/gen.lock @@ -370,7 +370,7 @@ trackedFiles: src/__tests__/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd src/__tests__/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:642159c8ddd0e1d4f69146b64af207f6a7c0cd76 + last_write_checksum: sha1:9c5fde148723a2f12ecefa1d2708cb55fded894f src/__tests__/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 src/__tests__/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go index 21f2afa80..10962bc00 100644 --- a/zSDKs/sdk-mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go @@ -172,11 +172,14 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool fieldVal := val.Field(i) fieldName := field.Name + optional := false jsonTag := field.Tag.Get("json") if jsonTag != "" { for _, tag := range strings.Split(jsonTag, ",") { - if tag != "omitempty" && tag != "omitzero" { + if tag == "omitempty" || tag == "omitzero" { + optional = true + } else { fieldName = tag } } @@ -191,7 +194,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (field.Type.Kind() == reflect.Ptr || strings.Contains(jsonTag, "omitempty")) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr) { delete(unmarshaled, fieldName) continue } diff --git a/zSDKs/sdk-pythonv2/.speakeasy/gen.lock b/zSDKs/sdk-pythonv2/.speakeasy/gen.lock index 0344f6a25..5bbcb8476 100644 --- a/zSDKs/sdk-pythonv2/.speakeasy/gen.lock +++ b/zSDKs/sdk-pythonv2/.speakeasy/gen.lock @@ -1176,7 +1176,7 @@ trackedFiles: tests/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd tests/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:642159c8ddd0e1d4f69146b64af207f6a7c0cd76 + last_write_checksum: sha1:9c5fde148723a2f12ecefa1d2708cb55fded894f tests/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 tests/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-pythonv2/tests/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-pythonv2/tests/mockserver/internal/sdk/utils/json.go index 21f2afa80..10962bc00 100644 --- a/zSDKs/sdk-pythonv2/tests/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-pythonv2/tests/mockserver/internal/sdk/utils/json.go @@ -172,11 +172,14 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool fieldVal := val.Field(i) fieldName := field.Name + optional := false jsonTag := field.Tag.Get("json") if jsonTag != "" { for _, tag := range strings.Split(jsonTag, ",") { - if tag != "omitempty" && tag != "omitzero" { + if tag == "omitempty" || tag == "omitzero" { + optional = true + } else { fieldName = tag } } @@ -191,7 +194,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (field.Type.Kind() == reflect.Ptr || strings.Contains(jsonTag, "omitempty")) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr) { delete(unmarshaled, fieldName) continue } diff --git a/zSDKs/sdk-ruby/.speakeasy/gen.lock b/zSDKs/sdk-ruby/.speakeasy/gen.lock index 5bf7a29a2..421933f0d 100644 --- a/zSDKs/sdk-ruby/.speakeasy/gen.lock +++ b/zSDKs/sdk-ruby/.speakeasy/gen.lock @@ -1835,7 +1835,7 @@ trackedFiles: test/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd test/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:642159c8ddd0e1d4f69146b64af207f6a7c0cd76 + last_write_checksum: sha1:9c5fde148723a2f12ecefa1d2708cb55fded894f test/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 test/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-ruby/test/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-ruby/test/mockserver/internal/sdk/utils/json.go index 21f2afa80..10962bc00 100644 --- a/zSDKs/sdk-ruby/test/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-ruby/test/mockserver/internal/sdk/utils/json.go @@ -172,11 +172,14 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool fieldVal := val.Field(i) fieldName := field.Name + optional := false jsonTag := field.Tag.Get("json") if jsonTag != "" { for _, tag := range strings.Split(jsonTag, ",") { - if tag != "omitempty" && tag != "omitzero" { + if tag == "omitempty" || tag == "omitzero" { + optional = true + } else { fieldName = tag } } @@ -191,7 +194,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (field.Type.Kind() == reflect.Ptr || strings.Contains(jsonTag, "omitempty")) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr) { delete(unmarshaled, fieldName) continue } diff --git a/zSDKs/sdk-typescriptv2/.speakeasy/gen.lock b/zSDKs/sdk-typescriptv2/.speakeasy/gen.lock index 1fcbdf6fb..0ce2d6cf3 100644 --- a/zSDKs/sdk-typescriptv2/.speakeasy/gen.lock +++ b/zSDKs/sdk-typescriptv2/.speakeasy/gen.lock @@ -867,7 +867,7 @@ trackedFiles: src/__tests__/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd src/__tests__/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:642159c8ddd0e1d4f69146b64af207f6a7c0cd76 + last_write_checksum: sha1:9c5fde148723a2f12ecefa1d2708cb55fded894f src/__tests__/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 src/__tests__/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-typescriptv2/src/__tests__/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-typescriptv2/src/__tests__/mockserver/internal/sdk/utils/json.go index 21f2afa80..10962bc00 100644 --- a/zSDKs/sdk-typescriptv2/src/__tests__/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-typescriptv2/src/__tests__/mockserver/internal/sdk/utils/json.go @@ -172,11 +172,14 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool fieldVal := val.Field(i) fieldName := field.Name + optional := false jsonTag := field.Tag.Get("json") if jsonTag != "" { for _, tag := range strings.Split(jsonTag, ",") { - if tag != "omitempty" && tag != "omitzero" { + if tag == "omitempty" || tag == "omitzero" { + optional = true + } else { fieldName = tag } } @@ -191,7 +194,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (field.Type.Kind() == reflect.Ptr || strings.Contains(jsonTag, "omitempty")) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr) { delete(unmarshaled, fieldName) continue } diff --git a/zSDKs/terraform-provider-testing/.speakeasy/gen.lock b/zSDKs/terraform-provider-testing/.speakeasy/gen.lock index 2e93f74af..ce677e51c 100644 --- a/zSDKs/terraform-provider-testing/.speakeasy/gen.lock +++ b/zSDKs/terraform-provider-testing/.speakeasy/gen.lock @@ -2438,7 +2438,7 @@ trackedFiles: internal/sdk/internal/utils/jq.go: last_write_checksum: sha1:2e75ed7a7db1f91e97dac1ac4ca7801b2beb69b5 internal/sdk/internal/utils/json.go: - last_write_checksum: sha1:d24c3552f50a1c14aad60e16bd6ca345236b6433 + last_write_checksum: sha1:ae79611ccaa6b6302717f8ba368dda6e91e88496 internal/sdk/internal/utils/oauth2_credentials.go: last_write_checksum: sha1:f9218b6b3dbd11494cc353bf22eb37f0ca654a7d internal/sdk/internal/utils/oauth2_sessions.go: diff --git a/zSDKs/terraform-provider-testing/internal/sdk/internal/utils/json.go b/zSDKs/terraform-provider-testing/internal/sdk/internal/utils/json.go index 5be50d78f..d86ce2f11 100644 --- a/zSDKs/terraform-provider-testing/internal/sdk/internal/utils/json.go +++ b/zSDKs/terraform-provider-testing/internal/sdk/internal/utils/json.go @@ -185,11 +185,14 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool fieldVal := val.Field(i) fieldName := field.Name + optional := false jsonTag := field.Tag.Get("json") if jsonTag != "" { for _, tag := range strings.Split(jsonTag, ",") { - if tag != "omitempty" && tag != "omitzero" { + if tag == "omitempty" || tag == "omitzero" { + optional = true + } else { fieldName = tag } } @@ -204,7 +207,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (field.Type.Kind() == reflect.Ptr || strings.Contains(jsonTag, "omitempty")) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr) { delete(unmarshaled, fieldName) continue } From ff9eedd60d61aaa47cbe776ab9fa803c5f0247d5 Mon Sep 17 00:00:00 2001 From: Ash Godfrey Date: Mon, 2 Nov 2026 14:35:06 +0000 Subject: [PATCH 20/22] fix: unwrap OptionalNullable when classifying and null-checking container consts OptionalNullable[T] is a map kind, so a wrapped scalar const was compared structurally and a wrapped container const rejected null. Classify by the wrapped type and treat the wrapper as nullable. --- .../go/auxiliary/{{getUtilsLocation}}/json.go.stmpl | 8 ++++++-- .../mockserver/auxiliary/internal/sdk/utils/json.go.stmpl | 8 ++++++-- zSDKs/mcp-typescript/.speakeasy/gen.lock | 2 +- .../src/__tests__/mockserver/internal/sdk/utils/json.go | 8 ++++++-- zSDKs/sdk-cli/.speakeasy/gen.lock | 4 ++-- zSDKs/sdk-cli/internal/sdk/sdkinternal/utils/json.go | 8 ++++++-- zSDKs/sdk-cli/tests/mockserver/internal/sdk/utils/json.go | 8 ++++++-- zSDKs/sdk-csharp/.speakeasy/gen.lock | 2 +- .../Tests/mockserver/internal/sdk/utils/json.go | 8 ++++++-- zSDKs/sdk-go/.speakeasy/gen.lock | 4 ++-- zSDKs/sdk-go/internal/utils/json.go | 8 ++++++-- zSDKs/sdk-go/tests/mockserver/internal/sdk/utils/json.go | 8 ++++++-- zSDKs/sdk-javav2/.speakeasy/gen.lock | 2 +- .../tests/mockserver/internal/sdk/utils/json.go | 8 ++++++-- zSDKs/sdk-mcp-typescript/.speakeasy/gen.lock | 2 +- .../src/__tests__/mockserver/internal/sdk/utils/json.go | 8 ++++++-- zSDKs/sdk-pythonv2/.speakeasy/gen.lock | 2 +- .../tests/mockserver/internal/sdk/utils/json.go | 8 ++++++-- zSDKs/sdk-ruby/.speakeasy/gen.lock | 2 +- zSDKs/sdk-ruby/test/mockserver/internal/sdk/utils/json.go | 8 ++++++-- zSDKs/sdk-typescriptv2/.speakeasy/gen.lock | 2 +- .../src/__tests__/mockserver/internal/sdk/utils/json.go | 8 ++++++-- zSDKs/terraform-provider-testing/.speakeasy/gen.lock | 2 +- .../internal/sdk/internal/utils/json.go | 8 ++++++-- 24 files changed, 96 insertions(+), 40 deletions(-) diff --git a/templates/templates/go/auxiliary/{{getUtilsLocation}}/json.go.stmpl b/templates/templates/go/auxiliary/{{getUtilsLocation}}/json.go.stmpl index 457b079ff..ba18b3995 100644 --- a/templates/templates/go/auxiliary/{{getUtilsLocation}}/json.go.stmpl +++ b/templates/templates/go/auxiliary/{{getUtilsLocation}}/json.go.stmpl @@ -208,7 +208,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr || optionalnullable.IsOptionalNullableType(field.Type)) { delete(unmarshaled, fieldName) continue } @@ -459,7 +459,11 @@ func implementsJSONMarshaler(v interface{}) bool { } func isContainerKind(typ reflect.Type) bool { - switch dereferenceTypePointer(typ).Kind() { + typ = dereferenceTypePointer(typ) + if optionalnullable.IsOptionalNullableType(typ) { + typ = dereferenceTypePointer(typ.Elem()) + } + switch typ.Kind() { case reflect.Slice, reflect.Map: return true default: diff --git a/templates/templates/mockserver/auxiliary/internal/sdk/utils/json.go.stmpl b/templates/templates/mockserver/auxiliary/internal/sdk/utils/json.go.stmpl index 1dbcf5322..bb6c25b07 100644 --- a/templates/templates/mockserver/auxiliary/internal/sdk/utils/json.go.stmpl +++ b/templates/templates/mockserver/auxiliary/internal/sdk/utils/json.go.stmpl @@ -192,7 +192,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr || optionalnullable.IsOptionalNullableType(field.Type)) { delete(unmarshaled, fieldName) continue } @@ -434,7 +434,11 @@ func implementsJSONMarshaler(v interface{}) bool { } func isContainerKind(typ reflect.Type) bool { - switch dereferenceTypePointer(typ).Kind() { + typ = dereferenceTypePointer(typ) + if optionalnullable.IsOptionalNullableType(typ) { + typ = dereferenceTypePointer(typ.Elem()) + } + switch typ.Kind() { case reflect.Slice, reflect.Map: return true default: diff --git a/zSDKs/mcp-typescript/.speakeasy/gen.lock b/zSDKs/mcp-typescript/.speakeasy/gen.lock index e4d569997..88db7f256 100644 --- a/zSDKs/mcp-typescript/.speakeasy/gen.lock +++ b/zSDKs/mcp-typescript/.speakeasy/gen.lock @@ -412,7 +412,7 @@ trackedFiles: src/__tests__/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd src/__tests__/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:9c5fde148723a2f12ecefa1d2708cb55fded894f + last_write_checksum: sha1:4fed9401b417236d862fb7245abef44b3c11fda4 src/__tests__/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 src/__tests__/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go b/zSDKs/mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go index 10962bc00..0f8c3b353 100644 --- a/zSDKs/mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go @@ -194,7 +194,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr || optionalnullable.IsOptionalNullableType(field.Type)) { delete(unmarshaled, fieldName) continue } @@ -436,7 +436,11 @@ func implementsJSONMarshaler(v interface{}) bool { } func isContainerKind(typ reflect.Type) bool { - switch dereferenceTypePointer(typ).Kind() { + typ = dereferenceTypePointer(typ) + if optionalnullable.IsOptionalNullableType(typ) { + typ = dereferenceTypePointer(typ.Elem()) + } + switch typ.Kind() { case reflect.Slice, reflect.Map: return true default: diff --git a/zSDKs/sdk-cli/.speakeasy/gen.lock b/zSDKs/sdk-cli/.speakeasy/gen.lock index 83feb8cec..1356fc4f0 100644 --- a/zSDKs/sdk-cli/.speakeasy/gen.lock +++ b/zSDKs/sdk-cli/.speakeasy/gen.lock @@ -602,7 +602,7 @@ trackedFiles: internal/sdk/sdkinternal/utils/headers.go: last_write_checksum: sha1:1b0bd68e1ea0bce8c5a42b5de9fd020fede7aecc internal/sdk/sdkinternal/utils/json.go: - last_write_checksum: sha1:443ad5894efdfa2de36e9f5c67895b3ee0279bdd + last_write_checksum: sha1:714c96a6f5558c1cf8ac1cf25e170b6591e33bba internal/sdk/sdkinternal/utils/oauth2_credentials.go: last_write_checksum: sha1:f9218b6b3dbd11494cc353bf22eb37f0ca654a7d internal/sdk/sdkinternal/utils/oauth2_sessions.go: @@ -1076,7 +1076,7 @@ trackedFiles: tests/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd tests/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:9c5fde148723a2f12ecefa1d2708cb55fded894f + last_write_checksum: sha1:4fed9401b417236d862fb7245abef44b3c11fda4 tests/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 tests/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-cli/internal/sdk/sdkinternal/utils/json.go b/zSDKs/sdk-cli/internal/sdk/sdkinternal/utils/json.go index a0fafa04c..1f8817ad9 100644 --- a/zSDKs/sdk-cli/internal/sdk/sdkinternal/utils/json.go +++ b/zSDKs/sdk-cli/internal/sdk/sdkinternal/utils/json.go @@ -209,7 +209,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr || optionalnullable.IsOptionalNullableType(field.Type)) { delete(unmarshaled, fieldName) continue } @@ -458,7 +458,11 @@ func implementsJSONMarshaler(v interface{}) bool { } func isContainerKind(typ reflect.Type) bool { - switch dereferenceTypePointer(typ).Kind() { + typ = dereferenceTypePointer(typ) + if optionalnullable.IsOptionalNullableType(typ) { + typ = dereferenceTypePointer(typ.Elem()) + } + switch typ.Kind() { case reflect.Slice, reflect.Map: return true default: diff --git a/zSDKs/sdk-cli/tests/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-cli/tests/mockserver/internal/sdk/utils/json.go index 10962bc00..0f8c3b353 100644 --- a/zSDKs/sdk-cli/tests/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-cli/tests/mockserver/internal/sdk/utils/json.go @@ -194,7 +194,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr || optionalnullable.IsOptionalNullableType(field.Type)) { delete(unmarshaled, fieldName) continue } @@ -436,7 +436,11 @@ func implementsJSONMarshaler(v interface{}) bool { } func isContainerKind(typ reflect.Type) bool { - switch dereferenceTypePointer(typ).Kind() { + typ = dereferenceTypePointer(typ) + if optionalnullable.IsOptionalNullableType(typ) { + typ = dereferenceTypePointer(typ.Elem()) + } + switch typ.Kind() { case reflect.Slice, reflect.Map: return true default: diff --git a/zSDKs/sdk-csharp/.speakeasy/gen.lock b/zSDKs/sdk-csharp/.speakeasy/gen.lock index 3bf348f7d..21c343a55 100644 --- a/zSDKs/sdk-csharp/.speakeasy/gen.lock +++ b/zSDKs/sdk-csharp/.speakeasy/gen.lock @@ -458,7 +458,7 @@ trackedFiles: Tests/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd Tests/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:9c5fde148723a2f12ecefa1d2708cb55fded894f + last_write_checksum: sha1:4fed9401b417236d862fb7245abef44b3c11fda4 Tests/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 Tests/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-csharp/Tests/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-csharp/Tests/mockserver/internal/sdk/utils/json.go index 10962bc00..0f8c3b353 100644 --- a/zSDKs/sdk-csharp/Tests/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-csharp/Tests/mockserver/internal/sdk/utils/json.go @@ -194,7 +194,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr || optionalnullable.IsOptionalNullableType(field.Type)) { delete(unmarshaled, fieldName) continue } @@ -436,7 +436,11 @@ func implementsJSONMarshaler(v interface{}) bool { } func isContainerKind(typ reflect.Type) bool { - switch dereferenceTypePointer(typ).Kind() { + typ = dereferenceTypePointer(typ) + if optionalnullable.IsOptionalNullableType(typ) { + typ = dereferenceTypePointer(typ.Elem()) + } + switch typ.Kind() { case reflect.Slice, reflect.Map: return true default: diff --git a/zSDKs/sdk-go/.speakeasy/gen.lock b/zSDKs/sdk-go/.speakeasy/gen.lock index 025636906..6cc048d9e 100644 --- a/zSDKs/sdk-go/.speakeasy/gen.lock +++ b/zSDKs/sdk-go/.speakeasy/gen.lock @@ -713,7 +713,7 @@ trackedFiles: internal/utils/headers.go: last_write_checksum: sha1:e529ca3d7ab96a091021bcd471ba2cbef50286b3 internal/utils/json.go: - last_write_checksum: sha1:a57614614bc82e69e2b49092e60cdfbe2c3f5818 + last_write_checksum: sha1:2bf1c063f236075eef751fa644e2e854f4b4d27f internal/utils/pathparams.go: last_write_checksum: sha1:a092fc31b7c8fac29c359ddfa8bf2e02763fa097 internal/utils/queryparams.go: @@ -1233,7 +1233,7 @@ trackedFiles: tests/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd tests/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:9c5fde148723a2f12ecefa1d2708cb55fded894f + last_write_checksum: sha1:4fed9401b417236d862fb7245abef44b3c11fda4 tests/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 tests/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-go/internal/utils/json.go b/zSDKs/sdk-go/internal/utils/json.go index ac0843fa1..68a28ed95 100644 --- a/zSDKs/sdk-go/internal/utils/json.go +++ b/zSDKs/sdk-go/internal/utils/json.go @@ -209,7 +209,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr || optionalnullable.IsOptionalNullableType(field.Type)) { delete(unmarshaled, fieldName) continue } @@ -458,7 +458,11 @@ func implementsJSONMarshaler(v interface{}) bool { } func isContainerKind(typ reflect.Type) bool { - switch dereferenceTypePointer(typ).Kind() { + typ = dereferenceTypePointer(typ) + if optionalnullable.IsOptionalNullableType(typ) { + typ = dereferenceTypePointer(typ.Elem()) + } + switch typ.Kind() { case reflect.Slice, reflect.Map: return true default: diff --git a/zSDKs/sdk-go/tests/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-go/tests/mockserver/internal/sdk/utils/json.go index 10962bc00..0f8c3b353 100644 --- a/zSDKs/sdk-go/tests/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-go/tests/mockserver/internal/sdk/utils/json.go @@ -194,7 +194,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr || optionalnullable.IsOptionalNullableType(field.Type)) { delete(unmarshaled, fieldName) continue } @@ -436,7 +436,11 @@ func implementsJSONMarshaler(v interface{}) bool { } func isContainerKind(typ reflect.Type) bool { - switch dereferenceTypePointer(typ).Kind() { + typ = dereferenceTypePointer(typ) + if optionalnullable.IsOptionalNullableType(typ) { + typ = dereferenceTypePointer(typ.Elem()) + } + switch typ.Kind() { case reflect.Slice, reflect.Map: return true default: diff --git a/zSDKs/sdk-javav2/.speakeasy/gen.lock b/zSDKs/sdk-javav2/.speakeasy/gen.lock index 6280400a5..de27a020b 100644 --- a/zSDKs/sdk-javav2/.speakeasy/gen.lock +++ b/zSDKs/sdk-javav2/.speakeasy/gen.lock @@ -1983,7 +1983,7 @@ trackedFiles: tests/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd tests/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:9c5fde148723a2f12ecefa1d2708cb55fded894f + last_write_checksum: sha1:4fed9401b417236d862fb7245abef44b3c11fda4 tests/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 tests/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-javav2/tests/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-javav2/tests/mockserver/internal/sdk/utils/json.go index 10962bc00..0f8c3b353 100644 --- a/zSDKs/sdk-javav2/tests/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-javav2/tests/mockserver/internal/sdk/utils/json.go @@ -194,7 +194,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr || optionalnullable.IsOptionalNullableType(field.Type)) { delete(unmarshaled, fieldName) continue } @@ -436,7 +436,11 @@ func implementsJSONMarshaler(v interface{}) bool { } func isContainerKind(typ reflect.Type) bool { - switch dereferenceTypePointer(typ).Kind() { + typ = dereferenceTypePointer(typ) + if optionalnullable.IsOptionalNullableType(typ) { + typ = dereferenceTypePointer(typ.Elem()) + } + switch typ.Kind() { case reflect.Slice, reflect.Map: return true default: diff --git a/zSDKs/sdk-mcp-typescript/.speakeasy/gen.lock b/zSDKs/sdk-mcp-typescript/.speakeasy/gen.lock index 371e97413..36b0a5efa 100644 --- a/zSDKs/sdk-mcp-typescript/.speakeasy/gen.lock +++ b/zSDKs/sdk-mcp-typescript/.speakeasy/gen.lock @@ -370,7 +370,7 @@ trackedFiles: src/__tests__/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd src/__tests__/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:9c5fde148723a2f12ecefa1d2708cb55fded894f + last_write_checksum: sha1:4fed9401b417236d862fb7245abef44b3c11fda4 src/__tests__/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 src/__tests__/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go index 10962bc00..0f8c3b353 100644 --- a/zSDKs/sdk-mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go @@ -194,7 +194,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr || optionalnullable.IsOptionalNullableType(field.Type)) { delete(unmarshaled, fieldName) continue } @@ -436,7 +436,11 @@ func implementsJSONMarshaler(v interface{}) bool { } func isContainerKind(typ reflect.Type) bool { - switch dereferenceTypePointer(typ).Kind() { + typ = dereferenceTypePointer(typ) + if optionalnullable.IsOptionalNullableType(typ) { + typ = dereferenceTypePointer(typ.Elem()) + } + switch typ.Kind() { case reflect.Slice, reflect.Map: return true default: diff --git a/zSDKs/sdk-pythonv2/.speakeasy/gen.lock b/zSDKs/sdk-pythonv2/.speakeasy/gen.lock index 5bbcb8476..65711a48e 100644 --- a/zSDKs/sdk-pythonv2/.speakeasy/gen.lock +++ b/zSDKs/sdk-pythonv2/.speakeasy/gen.lock @@ -1176,7 +1176,7 @@ trackedFiles: tests/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd tests/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:9c5fde148723a2f12ecefa1d2708cb55fded894f + last_write_checksum: sha1:4fed9401b417236d862fb7245abef44b3c11fda4 tests/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 tests/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-pythonv2/tests/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-pythonv2/tests/mockserver/internal/sdk/utils/json.go index 10962bc00..0f8c3b353 100644 --- a/zSDKs/sdk-pythonv2/tests/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-pythonv2/tests/mockserver/internal/sdk/utils/json.go @@ -194,7 +194,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr || optionalnullable.IsOptionalNullableType(field.Type)) { delete(unmarshaled, fieldName) continue } @@ -436,7 +436,11 @@ func implementsJSONMarshaler(v interface{}) bool { } func isContainerKind(typ reflect.Type) bool { - switch dereferenceTypePointer(typ).Kind() { + typ = dereferenceTypePointer(typ) + if optionalnullable.IsOptionalNullableType(typ) { + typ = dereferenceTypePointer(typ.Elem()) + } + switch typ.Kind() { case reflect.Slice, reflect.Map: return true default: diff --git a/zSDKs/sdk-ruby/.speakeasy/gen.lock b/zSDKs/sdk-ruby/.speakeasy/gen.lock index 421933f0d..37d366d4c 100644 --- a/zSDKs/sdk-ruby/.speakeasy/gen.lock +++ b/zSDKs/sdk-ruby/.speakeasy/gen.lock @@ -1835,7 +1835,7 @@ trackedFiles: test/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd test/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:9c5fde148723a2f12ecefa1d2708cb55fded894f + last_write_checksum: sha1:4fed9401b417236d862fb7245abef44b3c11fda4 test/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 test/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-ruby/test/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-ruby/test/mockserver/internal/sdk/utils/json.go index 10962bc00..0f8c3b353 100644 --- a/zSDKs/sdk-ruby/test/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-ruby/test/mockserver/internal/sdk/utils/json.go @@ -194,7 +194,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr || optionalnullable.IsOptionalNullableType(field.Type)) { delete(unmarshaled, fieldName) continue } @@ -436,7 +436,11 @@ func implementsJSONMarshaler(v interface{}) bool { } func isContainerKind(typ reflect.Type) bool { - switch dereferenceTypePointer(typ).Kind() { + typ = dereferenceTypePointer(typ) + if optionalnullable.IsOptionalNullableType(typ) { + typ = dereferenceTypePointer(typ.Elem()) + } + switch typ.Kind() { case reflect.Slice, reflect.Map: return true default: diff --git a/zSDKs/sdk-typescriptv2/.speakeasy/gen.lock b/zSDKs/sdk-typescriptv2/.speakeasy/gen.lock index 0ce2d6cf3..c64b740be 100644 --- a/zSDKs/sdk-typescriptv2/.speakeasy/gen.lock +++ b/zSDKs/sdk-typescriptv2/.speakeasy/gen.lock @@ -867,7 +867,7 @@ trackedFiles: src/__tests__/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd src/__tests__/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:9c5fde148723a2f12ecefa1d2708cb55fded894f + last_write_checksum: sha1:4fed9401b417236d862fb7245abef44b3c11fda4 src/__tests__/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 src/__tests__/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-typescriptv2/src/__tests__/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-typescriptv2/src/__tests__/mockserver/internal/sdk/utils/json.go index 10962bc00..0f8c3b353 100644 --- a/zSDKs/sdk-typescriptv2/src/__tests__/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-typescriptv2/src/__tests__/mockserver/internal/sdk/utils/json.go @@ -194,7 +194,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr || optionalnullable.IsOptionalNullableType(field.Type)) { delete(unmarshaled, fieldName) continue } @@ -436,7 +436,11 @@ func implementsJSONMarshaler(v interface{}) bool { } func isContainerKind(typ reflect.Type) bool { - switch dereferenceTypePointer(typ).Kind() { + typ = dereferenceTypePointer(typ) + if optionalnullable.IsOptionalNullableType(typ) { + typ = dereferenceTypePointer(typ.Elem()) + } + switch typ.Kind() { case reflect.Slice, reflect.Map: return true default: diff --git a/zSDKs/terraform-provider-testing/.speakeasy/gen.lock b/zSDKs/terraform-provider-testing/.speakeasy/gen.lock index ce677e51c..09a9bef19 100644 --- a/zSDKs/terraform-provider-testing/.speakeasy/gen.lock +++ b/zSDKs/terraform-provider-testing/.speakeasy/gen.lock @@ -2438,7 +2438,7 @@ trackedFiles: internal/sdk/internal/utils/jq.go: last_write_checksum: sha1:2e75ed7a7db1f91e97dac1ac4ca7801b2beb69b5 internal/sdk/internal/utils/json.go: - last_write_checksum: sha1:ae79611ccaa6b6302717f8ba368dda6e91e88496 + last_write_checksum: sha1:ebb6408cfb986bea1aaf510ff1b830b7d7b4a1bb internal/sdk/internal/utils/oauth2_credentials.go: last_write_checksum: sha1:f9218b6b3dbd11494cc353bf22eb37f0ca654a7d internal/sdk/internal/utils/oauth2_sessions.go: diff --git a/zSDKs/terraform-provider-testing/internal/sdk/internal/utils/json.go b/zSDKs/terraform-provider-testing/internal/sdk/internal/utils/json.go index d86ce2f11..48a5311db 100644 --- a/zSDKs/terraform-provider-testing/internal/sdk/internal/utils/json.go +++ b/zSDKs/terraform-provider-testing/internal/sdk/internal/utils/json.go @@ -207,7 +207,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr || optionalnullable.IsOptionalNullableType(field.Type)) { delete(unmarshaled, fieldName) continue } @@ -445,7 +445,11 @@ func implementsJSONMarshaler(v interface{}) bool { } func isContainerKind(typ reflect.Type) bool { - switch dereferenceTypePointer(typ).Kind() { + typ = dereferenceTypePointer(typ) + if optionalnullable.IsOptionalNullableType(typ) { + typ = dereferenceTypePointer(typ.Elem()) + } + switch typ.Kind() { case reflect.Slice, reflect.Map: return true default: From 17e61596b17ef8fcd1d2420c172be266d3854c79 Mon Sep 17 00:00:00 2001 From: Ash Godfrey Date: Mon, 2 Nov 2026 16:31:34 +0000 Subject: [PATCH 21/22] test(terraform): cover nullable, escaped and parameter container consts A required nullable const list returned as null now decodes as absent, so null is treated as absent for every container const rather than only optional ones. Map const keys and values with quotes, backslashes and newlines round-trip through the struct tag and the Go literal. A const array on a query parameter is dropped with a validation warning instead of being serialized as its JSON text, keeping container consts to body properties. --- .changesets/1792662097-2435dcc7.yaml | 2 +- internal/schemas/handle_array_test.go | 29 ++++++++++++ internal/schemas/schemas.go | 17 +++++-- .../{{getUtilsLocation}}/json.go.stmpl | 7 +-- .../internal/sdk/utils/json.go.stmpl | 7 +-- tests/specs/review-terraform.yaml | 47 +++++++++++++++++-- zSDKs/mcp-typescript/.speakeasy/gen.lock | 2 +- .../mockserver/internal/sdk/utils/json.go | 7 +-- zSDKs/sdk-cli/.speakeasy/gen.lock | 4 +- .../internal/sdk/sdkinternal/utils/json.go | 7 +-- .../mockserver/internal/sdk/utils/json.go | 7 +-- zSDKs/sdk-csharp/.speakeasy/gen.lock | 2 +- .../mockserver/internal/sdk/utils/json.go | 7 +-- zSDKs/sdk-go/.speakeasy/gen.lock | 4 +- zSDKs/sdk-go/internal/utils/json.go | 7 +-- .../mockserver/internal/sdk/utils/json.go | 7 +-- zSDKs/sdk-javav2/.speakeasy/gen.lock | 2 +- .../mockserver/internal/sdk/utils/json.go | 7 +-- zSDKs/sdk-mcp-typescript/.speakeasy/gen.lock | 2 +- .../mockserver/internal/sdk/utils/json.go | 7 +-- zSDKs/sdk-pythonv2/.speakeasy/gen.lock | 2 +- .../mockserver/internal/sdk/utils/json.go | 7 +-- zSDKs/sdk-ruby/.speakeasy/gen.lock | 2 +- .../mockserver/internal/sdk/utils/json.go | 7 +-- zSDKs/sdk-typescriptv2/.speakeasy/gen.lock | 2 +- .../mockserver/internal/sdk/utils/json.go | 7 +-- .../.speakeasy/gen.lock | 28 ++++++----- .../.speakeasy/logs/naming.log | 2 +- .../docs/data-sources/const_container.md | 7 +++ .../testing_const_container/data-source.tf | 3 ++ .../provider/constcontainer_data_source.go | 5 ++ .../constcontainer_data_source_sdk.go | 7 ++- .../provider/constcontainer_resource.go | 37 +++++++++++++++ .../provider/constcontainer_resource_test.go | 18 +++++-- .../internal/sdk/internal/utils/json.go | 7 +-- .../models/operations/getconstcontainer.go | 10 +++- .../models/shared/constcontainerrequest.go | 18 +++++-- .../models/shared/constcontainerresponse.go | 18 +++++-- .../internal/sdk/sdk.go | 8 +++- .../internal/tfmockserver/server.go | 3 ++ 40 files changed, 258 insertions(+), 121 deletions(-) diff --git a/.changesets/1792662097-2435dcc7.yaml b/.changesets/1792662097-2435dcc7.yaml index 81352685c..85ab04639 100644 --- a/.changesets/1792662097-2435dcc7.yaml +++ b/.changesets/1792662097-2435dcc7.yaml @@ -6,6 +6,6 @@ targets: - cli type: fix bump: patch -description: JSON unmarshaling compares array and map const values structurally instead of by exact text and accepts null for an optional container const +description: JSON unmarshaling compares array and map const values structurally instead of by exact text and treats null as absent for a container const author: AshGodfrey date: "2026-10-22" diff --git a/internal/schemas/handle_array_test.go b/internal/schemas/handle_array_test.go index 22aa605ce..39f1dff33 100644 --- a/internal/schemas/handle_array_test.go +++ b/internal/schemas/handle_array_test.go @@ -41,6 +41,7 @@ func TestHandleArray(t *testing.T) { fixes *config.Fixes // nil means use default mockFeatures func() *testutils.MockFeaturesConfig // nil means use default (all features supported) isRequest *bool // nil means use default (false), otherwise use specified value + paramType ParamType // empty means a body property expected *ast.FieldDef // expectedWarning, when set, must match exactly one logged validation warning expectedWarning string @@ -335,6 +336,33 @@ func TestHandleArray(t *testing.T) { Build(), expectedWarning: "only arrays without uniqueItems and maps of scalar values are supported, omitting const", }, + { + name: "QueryParameterArrayWithConst", + schemasYAML: `TestSchema: + type: array + items: + type: string + const: + - all`, + schemaName: "TestSchema", + paramType: ParamTypeQuery, + 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(), + expectedWarning: "only request and response body properties honor container const values, omitting const", + }, { name: "SetFormatWithEmptyConst", schemasYAML: `TestSchema: @@ -864,6 +892,7 @@ TestSchema: // Create test parameters params := CreateTestParams(testSchema, common.DocInfo) + params.ParamType = tt.paramType if tt.isRequest != nil { params.IsRequest = *tt.isRequest } diff --git a/internal/schemas/schemas.go b/internal/schemas/schemas.go index c89f1ca8c..6a9411a7e 100644 --- a/internal/schemas/schemas.go +++ b/internal/schemas/schemas.go @@ -562,7 +562,7 @@ func (s *Schemas) handleArray(ctx context.Context, params Params, nullable bool) Optional: nullable, Nullable: nullable, } - fieldDef = s.handleContainerMetaData(ctx, fieldDef, nullable, schema, s.Subsystem.Features.IsFeatureSupported(ctx, features.FeatureDefaultArrays), features.FeatureConstArrays) + fieldDef = s.handleContainerMetaData(ctx, params, fieldDef, nullable, schema, s.Subsystem.Features.IsFeatureSupported(ctx, features.FeatureDefaultArrays), features.FeatureConstArrays) // We need to inherit the multipart annotations if itemField != nil { @@ -816,7 +816,7 @@ func (s *Schemas) handleObject(ctx context.Context, params Params, nullable bool typeDef.Extensions = extensions - return s.handleContainerMetaData(ctx, &ast.FieldDef{ + return s.handleContainerMetaData(ctx, params, &ast.FieldDef{ Name: fieldName, Type: ast.NewType(typeDef, nil), Optional: nullable, @@ -889,7 +889,7 @@ func (s *Schemas) handleObject(ctx context.Context, params Params, nullable bool typeDef.Extensions = extensions - return s.handleContainerMetaData(ctx, &ast.FieldDef{ + return s.handleContainerMetaData(ctx, params, &ast.FieldDef{ Name: fieldName, Type: ast.NewType(typeDef, nil), Optional: nullable, @@ -1296,7 +1296,7 @@ func (s *Schemas) handleObject(ctx context.Context, params Params, nullable bool Nullable: nullable, } - fieldDef = s.handleContainerMetaData(ctx, fieldDef, nullable, schema, s.Subsystem.Features.IsFeatureSupported(ctx, features.FeatureDefaultObjects), features.FeatureConstObjects) + fieldDef = s.handleContainerMetaData(ctx, params, fieldDef, nullable, schema, s.Subsystem.Features.IsFeatureSupported(ctx, features.FeatureDefaultObjects), features.FeatureConstObjects) s.setCachedType(fieldType, ¶ms) @@ -2828,9 +2828,16 @@ func (s *Schemas) handleFieldDefMetaData(ctx context.Context, fieldDef *ast.Fiel return fieldDef } -func (s *Schemas) handleContainerMetaData(ctx context.Context, fieldDef *ast.FieldDef, nullable bool, schema *oas3.Schema, defaultSupported bool, constFeature features.Feature) *ast.FieldDef { +func (s *Schemas) handleContainerMetaData(ctx context.Context, params Params, fieldDef *ast.FieldDef, nullable bool, schema *oas3.Schema, defaultSupported bool, constFeature features.Feature) *ast.FieldDef { applyDefault := schema.Default != nil && defaultSupported applyConst := schema.Const != nil && s.Subsystem.Features.IsFeatureSupported(ctx, constFeature) + if applyConst && params.ParamType != "" { + logging.LogWarning(ctx, "validation warning", errors.NewValidationWarning( + fmt.Sprintf("const on a %s parameter of type %q is not supported, only request and response body properties honor container const values, omitting const", params.ParamType, fieldDef.Type.Type), + schema.GetPropertyNode("Const"), nil, + )) + applyConst = false + } if !applyDefault && !applyConst { return fieldDef } diff --git a/templates/templates/go/auxiliary/{{getUtilsLocation}}/json.go.stmpl b/templates/templates/go/auxiliary/{{getUtilsLocation}}/json.go.stmpl index ba18b3995..712d8ab93 100644 --- a/templates/templates/go/auxiliary/{{getUtilsLocation}}/json.go.stmpl +++ b/templates/templates/go/auxiliary/{{getUtilsLocation}}/json.go.stmpl @@ -186,14 +186,11 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool fieldVal := val.Field(i) fieldName := field.Name - optional := false jsonTag := field.Tag.Get("json") if jsonTag != "" { for _, tag := range strings.Split(jsonTag, ",") { - if tag == "omitempty" || tag == "omitzero" { - optional = true - } else { + if tag != "omitempty" && tag != "omitzero" { fieldName = tag } } @@ -208,7 +205,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr || optionalnullable.IsOptionalNullableType(field.Type)) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) { delete(unmarshaled, fieldName) continue } diff --git a/templates/templates/mockserver/auxiliary/internal/sdk/utils/json.go.stmpl b/templates/templates/mockserver/auxiliary/internal/sdk/utils/json.go.stmpl index bb6c25b07..8fec8c27e 100644 --- a/templates/templates/mockserver/auxiliary/internal/sdk/utils/json.go.stmpl +++ b/templates/templates/mockserver/auxiliary/internal/sdk/utils/json.go.stmpl @@ -170,14 +170,11 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool fieldVal := val.Field(i) fieldName := field.Name - optional := false jsonTag := field.Tag.Get("json") if jsonTag != "" { for _, tag := range strings.Split(jsonTag, ",") { - if tag == "omitempty" || tag == "omitzero" { - optional = true - } else { + if tag != "omitempty" && tag != "omitzero" { fieldName = tag } } @@ -192,7 +189,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr || optionalnullable.IsOptionalNullableType(field.Type)) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) { delete(unmarshaled, fieldName) continue } diff --git a/tests/specs/review-terraform.yaml b/tests/specs/review-terraform.yaml index e31fd1e66..ed177ece5 100644 --- a/tests/specs/review-terraform.yaml +++ b/tests/specs/review-terraform.yaml @@ -5727,8 +5727,20 @@ paths: type: string get: x-speakeasy-entity-operation: ConstContainer#read - description: Get a const container resource + description: | + Get a const container resource. The query parameter declares an + array const, which lives on the parameter path rather than a request + body property, to pin how container consts on parameters surface. operationId: get-const-container + parameters: + - name: scope + in: query + schema: + type: array + items: + type: string + const: + - all responses: '200': description: OK @@ -6092,13 +6104,24 @@ components: min: 1 templated_map: description: | - Map const whose key contains template delimiters. The generated - Go literal and struct tag must escape them. + Map const whose keys and values contain template delimiters, + quotes, backslashes and a newline. The generated Go literal and + struct tag must escape them and round-trip them on the wire. type: object additionalProperties: type: string const: '{{key}}': value + 'quo"te\back': "line\nbreak" + nullable_list: + description: | + Nullable array with an empty const. A response may carry null for + it, which must decode as absent rather than a const mismatch. + type: array + nullable: true + items: + type: string + const: [] nested_list: description: | List of objects whose item schema declares a const array. The @@ -6122,6 +6145,7 @@ components: - empty_list - empty_map - empty_set + - nullable_list ConstContainerResponse: type: object additionalProperties: false @@ -6171,13 +6195,24 @@ components: min: 1 templated_map: description: | - Map const whose key contains template delimiters. The generated - Go literal and struct tag must escape them. + Map const whose keys and values contain template delimiters, + quotes, backslashes and a newline. The generated Go literal and + struct tag must escape them and round-trip them on the wire. type: object additionalProperties: type: string const: '{{key}}': value + 'quo"te\back': "line\nbreak" + nullable_list: + description: | + Nullable array with an empty const. A response may carry null for + it, which must decode as absent rather than a const mismatch. + type: array + nullable: true + items: + type: string + const: [] nested_list: description: | List of objects whose item schema declares a const array. The @@ -6196,6 +6231,8 @@ components: type: string const: - fixed + required: + - nullable_list ConstEmptySetDeleteGroup: type: object additionalProperties: false diff --git a/zSDKs/mcp-typescript/.speakeasy/gen.lock b/zSDKs/mcp-typescript/.speakeasy/gen.lock index 88db7f256..15c7afcd8 100644 --- a/zSDKs/mcp-typescript/.speakeasy/gen.lock +++ b/zSDKs/mcp-typescript/.speakeasy/gen.lock @@ -412,7 +412,7 @@ trackedFiles: src/__tests__/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd src/__tests__/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:4fed9401b417236d862fb7245abef44b3c11fda4 + last_write_checksum: sha1:22904cb9788737f288acdab97255bc78d37531bc src/__tests__/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 src/__tests__/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go b/zSDKs/mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go index 0f8c3b353..05f85d049 100644 --- a/zSDKs/mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go @@ -172,14 +172,11 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool fieldVal := val.Field(i) fieldName := field.Name - optional := false jsonTag := field.Tag.Get("json") if jsonTag != "" { for _, tag := range strings.Split(jsonTag, ",") { - if tag == "omitempty" || tag == "omitzero" { - optional = true - } else { + if tag != "omitempty" && tag != "omitzero" { fieldName = tag } } @@ -194,7 +191,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr || optionalnullable.IsOptionalNullableType(field.Type)) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) { delete(unmarshaled, fieldName) continue } diff --git a/zSDKs/sdk-cli/.speakeasy/gen.lock b/zSDKs/sdk-cli/.speakeasy/gen.lock index 1356fc4f0..4376e17d8 100644 --- a/zSDKs/sdk-cli/.speakeasy/gen.lock +++ b/zSDKs/sdk-cli/.speakeasy/gen.lock @@ -602,7 +602,7 @@ trackedFiles: internal/sdk/sdkinternal/utils/headers.go: last_write_checksum: sha1:1b0bd68e1ea0bce8c5a42b5de9fd020fede7aecc internal/sdk/sdkinternal/utils/json.go: - last_write_checksum: sha1:714c96a6f5558c1cf8ac1cf25e170b6591e33bba + last_write_checksum: sha1:7076ce967d2e68ed410fe56aa5a09d89c6432d6e internal/sdk/sdkinternal/utils/oauth2_credentials.go: last_write_checksum: sha1:f9218b6b3dbd11494cc353bf22eb37f0ca654a7d internal/sdk/sdkinternal/utils/oauth2_sessions.go: @@ -1076,7 +1076,7 @@ trackedFiles: tests/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd tests/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:4fed9401b417236d862fb7245abef44b3c11fda4 + last_write_checksum: sha1:22904cb9788737f288acdab97255bc78d37531bc tests/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 tests/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-cli/internal/sdk/sdkinternal/utils/json.go b/zSDKs/sdk-cli/internal/sdk/sdkinternal/utils/json.go index 1f8817ad9..f3e5ca68d 100644 --- a/zSDKs/sdk-cli/internal/sdk/sdkinternal/utils/json.go +++ b/zSDKs/sdk-cli/internal/sdk/sdkinternal/utils/json.go @@ -187,14 +187,11 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool fieldVal := val.Field(i) fieldName := field.Name - optional := false jsonTag := field.Tag.Get("json") if jsonTag != "" { for _, tag := range strings.Split(jsonTag, ",") { - if tag == "omitempty" || tag == "omitzero" { - optional = true - } else { + if tag != "omitempty" && tag != "omitzero" { fieldName = tag } } @@ -209,7 +206,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr || optionalnullable.IsOptionalNullableType(field.Type)) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) { delete(unmarshaled, fieldName) continue } diff --git a/zSDKs/sdk-cli/tests/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-cli/tests/mockserver/internal/sdk/utils/json.go index 0f8c3b353..05f85d049 100644 --- a/zSDKs/sdk-cli/tests/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-cli/tests/mockserver/internal/sdk/utils/json.go @@ -172,14 +172,11 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool fieldVal := val.Field(i) fieldName := field.Name - optional := false jsonTag := field.Tag.Get("json") if jsonTag != "" { for _, tag := range strings.Split(jsonTag, ",") { - if tag == "omitempty" || tag == "omitzero" { - optional = true - } else { + if tag != "omitempty" && tag != "omitzero" { fieldName = tag } } @@ -194,7 +191,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr || optionalnullable.IsOptionalNullableType(field.Type)) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) { delete(unmarshaled, fieldName) continue } diff --git a/zSDKs/sdk-csharp/.speakeasy/gen.lock b/zSDKs/sdk-csharp/.speakeasy/gen.lock index 21c343a55..a4b24a8fd 100644 --- a/zSDKs/sdk-csharp/.speakeasy/gen.lock +++ b/zSDKs/sdk-csharp/.speakeasy/gen.lock @@ -458,7 +458,7 @@ trackedFiles: Tests/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd Tests/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:4fed9401b417236d862fb7245abef44b3c11fda4 + last_write_checksum: sha1:22904cb9788737f288acdab97255bc78d37531bc Tests/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 Tests/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-csharp/Tests/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-csharp/Tests/mockserver/internal/sdk/utils/json.go index 0f8c3b353..05f85d049 100644 --- a/zSDKs/sdk-csharp/Tests/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-csharp/Tests/mockserver/internal/sdk/utils/json.go @@ -172,14 +172,11 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool fieldVal := val.Field(i) fieldName := field.Name - optional := false jsonTag := field.Tag.Get("json") if jsonTag != "" { for _, tag := range strings.Split(jsonTag, ",") { - if tag == "omitempty" || tag == "omitzero" { - optional = true - } else { + if tag != "omitempty" && tag != "omitzero" { fieldName = tag } } @@ -194,7 +191,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr || optionalnullable.IsOptionalNullableType(field.Type)) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) { delete(unmarshaled, fieldName) continue } diff --git a/zSDKs/sdk-go/.speakeasy/gen.lock b/zSDKs/sdk-go/.speakeasy/gen.lock index 6cc048d9e..8654ed510 100644 --- a/zSDKs/sdk-go/.speakeasy/gen.lock +++ b/zSDKs/sdk-go/.speakeasy/gen.lock @@ -713,7 +713,7 @@ trackedFiles: internal/utils/headers.go: last_write_checksum: sha1:e529ca3d7ab96a091021bcd471ba2cbef50286b3 internal/utils/json.go: - last_write_checksum: sha1:2bf1c063f236075eef751fa644e2e854f4b4d27f + last_write_checksum: sha1:a85097f13cf5aafe7e9f72fa3d14cd38b22efb02 internal/utils/pathparams.go: last_write_checksum: sha1:a092fc31b7c8fac29c359ddfa8bf2e02763fa097 internal/utils/queryparams.go: @@ -1233,7 +1233,7 @@ trackedFiles: tests/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd tests/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:4fed9401b417236d862fb7245abef44b3c11fda4 + last_write_checksum: sha1:22904cb9788737f288acdab97255bc78d37531bc tests/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 tests/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-go/internal/utils/json.go b/zSDKs/sdk-go/internal/utils/json.go index 68a28ed95..9014f69a1 100644 --- a/zSDKs/sdk-go/internal/utils/json.go +++ b/zSDKs/sdk-go/internal/utils/json.go @@ -187,14 +187,11 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool fieldVal := val.Field(i) fieldName := field.Name - optional := false jsonTag := field.Tag.Get("json") if jsonTag != "" { for _, tag := range strings.Split(jsonTag, ",") { - if tag == "omitempty" || tag == "omitzero" { - optional = true - } else { + if tag != "omitempty" && tag != "omitzero" { fieldName = tag } } @@ -209,7 +206,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr || optionalnullable.IsOptionalNullableType(field.Type)) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) { delete(unmarshaled, fieldName) continue } diff --git a/zSDKs/sdk-go/tests/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-go/tests/mockserver/internal/sdk/utils/json.go index 0f8c3b353..05f85d049 100644 --- a/zSDKs/sdk-go/tests/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-go/tests/mockserver/internal/sdk/utils/json.go @@ -172,14 +172,11 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool fieldVal := val.Field(i) fieldName := field.Name - optional := false jsonTag := field.Tag.Get("json") if jsonTag != "" { for _, tag := range strings.Split(jsonTag, ",") { - if tag == "omitempty" || tag == "omitzero" { - optional = true - } else { + if tag != "omitempty" && tag != "omitzero" { fieldName = tag } } @@ -194,7 +191,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr || optionalnullable.IsOptionalNullableType(field.Type)) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) { delete(unmarshaled, fieldName) continue } diff --git a/zSDKs/sdk-javav2/.speakeasy/gen.lock b/zSDKs/sdk-javav2/.speakeasy/gen.lock index de27a020b..60fba223e 100644 --- a/zSDKs/sdk-javav2/.speakeasy/gen.lock +++ b/zSDKs/sdk-javav2/.speakeasy/gen.lock @@ -1983,7 +1983,7 @@ trackedFiles: tests/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd tests/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:4fed9401b417236d862fb7245abef44b3c11fda4 + last_write_checksum: sha1:22904cb9788737f288acdab97255bc78d37531bc tests/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 tests/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-javav2/tests/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-javav2/tests/mockserver/internal/sdk/utils/json.go index 0f8c3b353..05f85d049 100644 --- a/zSDKs/sdk-javav2/tests/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-javav2/tests/mockserver/internal/sdk/utils/json.go @@ -172,14 +172,11 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool fieldVal := val.Field(i) fieldName := field.Name - optional := false jsonTag := field.Tag.Get("json") if jsonTag != "" { for _, tag := range strings.Split(jsonTag, ",") { - if tag == "omitempty" || tag == "omitzero" { - optional = true - } else { + if tag != "omitempty" && tag != "omitzero" { fieldName = tag } } @@ -194,7 +191,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr || optionalnullable.IsOptionalNullableType(field.Type)) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) { delete(unmarshaled, fieldName) continue } diff --git a/zSDKs/sdk-mcp-typescript/.speakeasy/gen.lock b/zSDKs/sdk-mcp-typescript/.speakeasy/gen.lock index 36b0a5efa..ef94d2c55 100644 --- a/zSDKs/sdk-mcp-typescript/.speakeasy/gen.lock +++ b/zSDKs/sdk-mcp-typescript/.speakeasy/gen.lock @@ -370,7 +370,7 @@ trackedFiles: src/__tests__/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd src/__tests__/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:4fed9401b417236d862fb7245abef44b3c11fda4 + last_write_checksum: sha1:22904cb9788737f288acdab97255bc78d37531bc src/__tests__/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 src/__tests__/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go index 0f8c3b353..05f85d049 100644 --- a/zSDKs/sdk-mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-mcp-typescript/src/__tests__/mockserver/internal/sdk/utils/json.go @@ -172,14 +172,11 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool fieldVal := val.Field(i) fieldName := field.Name - optional := false jsonTag := field.Tag.Get("json") if jsonTag != "" { for _, tag := range strings.Split(jsonTag, ",") { - if tag == "omitempty" || tag == "omitzero" { - optional = true - } else { + if tag != "omitempty" && tag != "omitzero" { fieldName = tag } } @@ -194,7 +191,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr || optionalnullable.IsOptionalNullableType(field.Type)) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) { delete(unmarshaled, fieldName) continue } diff --git a/zSDKs/sdk-pythonv2/.speakeasy/gen.lock b/zSDKs/sdk-pythonv2/.speakeasy/gen.lock index 65711a48e..4ae0501ef 100644 --- a/zSDKs/sdk-pythonv2/.speakeasy/gen.lock +++ b/zSDKs/sdk-pythonv2/.speakeasy/gen.lock @@ -1176,7 +1176,7 @@ trackedFiles: tests/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd tests/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:4fed9401b417236d862fb7245abef44b3c11fda4 + last_write_checksum: sha1:22904cb9788737f288acdab97255bc78d37531bc tests/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 tests/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-pythonv2/tests/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-pythonv2/tests/mockserver/internal/sdk/utils/json.go index 0f8c3b353..05f85d049 100644 --- a/zSDKs/sdk-pythonv2/tests/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-pythonv2/tests/mockserver/internal/sdk/utils/json.go @@ -172,14 +172,11 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool fieldVal := val.Field(i) fieldName := field.Name - optional := false jsonTag := field.Tag.Get("json") if jsonTag != "" { for _, tag := range strings.Split(jsonTag, ",") { - if tag == "omitempty" || tag == "omitzero" { - optional = true - } else { + if tag != "omitempty" && tag != "omitzero" { fieldName = tag } } @@ -194,7 +191,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr || optionalnullable.IsOptionalNullableType(field.Type)) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) { delete(unmarshaled, fieldName) continue } diff --git a/zSDKs/sdk-ruby/.speakeasy/gen.lock b/zSDKs/sdk-ruby/.speakeasy/gen.lock index 37d366d4c..de45e8f4d 100644 --- a/zSDKs/sdk-ruby/.speakeasy/gen.lock +++ b/zSDKs/sdk-ruby/.speakeasy/gen.lock @@ -1835,7 +1835,7 @@ trackedFiles: test/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd test/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:4fed9401b417236d862fb7245abef44b3c11fda4 + last_write_checksum: sha1:22904cb9788737f288acdab97255bc78d37531bc test/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 test/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-ruby/test/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-ruby/test/mockserver/internal/sdk/utils/json.go index 0f8c3b353..05f85d049 100644 --- a/zSDKs/sdk-ruby/test/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-ruby/test/mockserver/internal/sdk/utils/json.go @@ -172,14 +172,11 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool fieldVal := val.Field(i) fieldName := field.Name - optional := false jsonTag := field.Tag.Get("json") if jsonTag != "" { for _, tag := range strings.Split(jsonTag, ",") { - if tag == "omitempty" || tag == "omitzero" { - optional = true - } else { + if tag != "omitempty" && tag != "omitzero" { fieldName = tag } } @@ -194,7 +191,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr || optionalnullable.IsOptionalNullableType(field.Type)) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) { delete(unmarshaled, fieldName) continue } diff --git a/zSDKs/sdk-typescriptv2/.speakeasy/gen.lock b/zSDKs/sdk-typescriptv2/.speakeasy/gen.lock index c64b740be..ac25cfad4 100644 --- a/zSDKs/sdk-typescriptv2/.speakeasy/gen.lock +++ b/zSDKs/sdk-typescriptv2/.speakeasy/gen.lock @@ -867,7 +867,7 @@ trackedFiles: src/__tests__/mockserver/internal/sdk/types/stream/stream.go: last_write_checksum: sha1:c48811a5243fa7f9e23c67966b140c52614b58bd src/__tests__/mockserver/internal/sdk/utils/json.go: - last_write_checksum: sha1:4fed9401b417236d862fb7245abef44b3c11fda4 + last_write_checksum: sha1:22904cb9788737f288acdab97255bc78d37531bc src/__tests__/mockserver/internal/sdk/utils/reflect.go: last_write_checksum: sha1:1e3a0ca0387685b6b21c0a6a75650b8611c76ee3 src/__tests__/mockserver/internal/sdk/utils/sort.go: diff --git a/zSDKs/sdk-typescriptv2/src/__tests__/mockserver/internal/sdk/utils/json.go b/zSDKs/sdk-typescriptv2/src/__tests__/mockserver/internal/sdk/utils/json.go index 0f8c3b353..05f85d049 100644 --- a/zSDKs/sdk-typescriptv2/src/__tests__/mockserver/internal/sdk/utils/json.go +++ b/zSDKs/sdk-typescriptv2/src/__tests__/mockserver/internal/sdk/utils/json.go @@ -172,14 +172,11 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool fieldVal := val.Field(i) fieldName := field.Name - optional := false jsonTag := field.Tag.Get("json") if jsonTag != "" { for _, tag := range strings.Split(jsonTag, ",") { - if tag == "omitempty" || tag == "omitzero" { - optional = true - } else { + if tag != "omitempty" && tag != "omitzero" { fieldName = tag } } @@ -194,7 +191,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr || optionalnullable.IsOptionalNullableType(field.Type)) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) { delete(unmarshaled, fieldName) continue } diff --git a/zSDKs/terraform-provider-testing/.speakeasy/gen.lock b/zSDKs/terraform-provider-testing/.speakeasy/gen.lock index 09a9bef19..c59d2b041 100644 --- a/zSDKs/terraform-provider-testing/.speakeasy/gen.lock +++ b/zSDKs/terraform-provider-testing/.speakeasy/gen.lock @@ -1,7 +1,7 @@ lockVersion: 2.0.0 id: review-sdk-test-id management: - docChecksum: 645a6255443dd07cc5e84f7ec7134634 + docChecksum: 52db7940c5b8f2e1032a13a3f84626ae docVersion: 0.0.1 speakeasyVersion: internal generationVersion: internal @@ -54,7 +54,7 @@ trackedFiles: examples/data-sources/testing_basic/data-source.tf: last_write_checksum: sha1:02bc159abd38449bcddcff2ed9eb7daf0b5cf5b4 examples/data-sources/testing_const_container/data-source.tf: - last_write_checksum: sha1:a45dc527c9b2b2404f3ce3797f8a0c3009de47dd + last_write_checksum: sha1:c9d73d56cf6105882eaea310da3bba6b1b60c82a examples/data-sources/testing_discriminated_union/data-source.tf: last_write_checksum: sha1:a21b63c90ce67e7b78e103fb57e8b55ba8ab4073 examples/data-sources/testing_framework_type/data-source.tf: @@ -780,11 +780,11 @@ trackedFiles: internal/provider/basic_resource_sdk.go: last_write_checksum: sha1:c7327b7ec6b530ccb4ba940c83953e7b58b092a4 internal/provider/constcontainer_data_source.go: - last_write_checksum: sha1:a6dc05d0e18d792fe568ae34a06528de71e0e82b + last_write_checksum: sha1:adf9e08cf64bc77225f07361d4c8201b6d355b1c internal/provider/constcontainer_data_source_sdk.go: - last_write_checksum: sha1:11bd69185d0dd245e66a897fec5da3a6bbacb62a + last_write_checksum: sha1:e025e23a41dc09acbaad5fa4f1f805bd15dd55df internal/provider/constcontainer_resource.go: - last_write_checksum: sha1:65ef61f51490dba8ecc6d5d0f3428fb632f1d76d + last_write_checksum: sha1:c84b662f5167a29ae64dcde0a01652e661d44357 internal/provider/constcontainer_resource_sdk.go: last_write_checksum: sha1:1742253997f1ad0e00600193af22ec233d4c9016 internal/provider/constemptysetdelete_resource.go: @@ -2438,7 +2438,7 @@ trackedFiles: internal/sdk/internal/utils/jq.go: last_write_checksum: sha1:2e75ed7a7db1f91e97dac1ac4ca7801b2beb69b5 internal/sdk/internal/utils/json.go: - last_write_checksum: sha1:ebb6408cfb986bea1aaf510ff1b830b7d7b4a1bb + last_write_checksum: sha1:ad8147f0769042e18fc1e9f1bfab2db8ecac713f internal/sdk/internal/utils/oauth2_credentials.go: last_write_checksum: sha1:f9218b6b3dbd11494cc353bf22eb37f0ca654a7d internal/sdk/internal/utils/oauth2_sessions.go: @@ -2770,7 +2770,7 @@ trackedFiles: internal/sdk/models/operations/getbasic.go: last_write_checksum: sha1:73ada8ac1a2cec3987eb5b93f78f815934067b9d internal/sdk/models/operations/getconstcontainer.go: - last_write_checksum: sha1:c4ac02b538bdf08901d302a4d4c07a6a18cb2536 + last_write_checksum: sha1:558633acfdf5a314fc1fdc4a580949f6ab6a90e0 internal/sdk/models/operations/getconstemptysetdelete.go: last_write_checksum: sha1:0fd0c404cc7659c8ee1f1453adf5be9a55443f03 internal/sdk/models/operations/getcustomplanmodifiers.go: @@ -3120,9 +3120,9 @@ trackedFiles: internal/sdk/models/shared/basicsearch.go: last_write_checksum: sha1:ebc8943a31148f7623c5f8ff940dd81c1b52f23d internal/sdk/models/shared/constcontainerrequest.go: - last_write_checksum: sha1:ddd4ad7779260d9e7a9ac96c5918c4e5345c66d2 + last_write_checksum: sha1:1cf8e117d1b1a8ce9fe2a7e36bcb59eb6052a12e internal/sdk/models/shared/constcontainerresponse.go: - last_write_checksum: sha1:4d97877805a1493c13e7d36ad58fc1ed13c8293d + last_write_checksum: sha1:ab518fe68f26a5fc1ee473a2fc1d47ffa571efd3 internal/sdk/models/shared/constemptysetdeletegroup.go: last_write_checksum: sha1:d33860be5d32e993a1907c5f4a9b85f849357a8e internal/sdk/models/shared/constemptysetdeleterequest.go: @@ -3634,7 +3634,7 @@ trackedFiles: internal/sdk/retry/config.go: last_write_checksum: sha1:102d1953fbd7e9f312c4442c71ccca2eaaeaa27d internal/sdk/sdk.go: - last_write_checksum: sha1:d2ae7d2c0b4faa1fa52da3725944f1fc12be1c6d + last_write_checksum: sha1:cb8f4e761171f2f355a69d1cb043075c79f9fa20 internal/sdk/types/bigint.go: last_write_checksum: sha1:49b004005d0461fb04b846eca062b070b0360b31 internal/sdk/types/date.go: @@ -6079,18 +6079,20 @@ examples: create-const-container: speakeasy-default-create-const-container: requestBody: - application/json: {"name": "", "empty_list": [], "fixed_list": ["read", "write"], "empty_set": [], "empty_map": {}, "fixed_map": {"max": 10, "min": 1}, "templated_map": {"{{key}}": "value"}} + application/json: {"name": "", "empty_list": [], "fixed_list": ["read", "write"], "empty_set": [], "empty_map": {}, "fixed_map": {"max": 10, "min": 1}, "templated_map": {"quo\"te\\back": "line\nbreak", "{{key}}": "value"}, "nullable_list": []} responses: "200": - application/json: {"empty_list": [], "fixed_list": ["read", "write"], "empty_set": [], "empty_map": {}, "fixed_map": {"max": 10, "min": 1}, "templated_map": {"{{key}}": "value"}} + application/json: {"empty_list": [], "fixed_list": ["read", "write"], "empty_set": [], "empty_map": {}, "fixed_map": {"max": 10, "min": 1}, "templated_map": {"quo\"te\\back": "line\nbreak", "{{key}}": "value"}, "nullable_list": []} get-const-container: speakeasy-default-get-const-container: parameters: path: id: "" + query: + scope: ["all"] responses: "200": - application/json: {"empty_list": [], "fixed_list": ["read", "write"], "empty_set": [], "empty_map": {}, "fixed_map": {"max": 10, "min": 1}, "templated_map": {"{{key}}": "value"}} + application/json: {"empty_list": [], "fixed_list": ["read", "write"], "empty_set": [], "empty_map": {}, "fixed_map": {"max": 10, "min": 1}, "templated_map": {"quo\"te\\back": "line\nbreak", "{{key}}": "value"}, "nullable_list": []} delete-const-container: speakeasy-default-delete-const-container: parameters: diff --git a/zSDKs/terraform-provider-testing/.speakeasy/logs/naming.log b/zSDKs/terraform-provider-testing/.speakeasy/logs/naming.log index 6f878db69..b97827cb7 100644 --- a/zSDKs/terraform-provider-testing/.speakeasy/logs/naming.log +++ b/zSDKs/terraform-provider-testing/.speakeasy/logs/naming.log @@ -3855,7 +3855,7 @@ CreateConstContainerResponse (ContentType: string, StatusCode: int32, RawRespons ConstContainerResponseFixedList (enum: read, write, admin) ConstContainerResponseEmptySet (key: string) ConstContainerResponseNestedList (label: string, tags: array) -GetConstContainerRequest (id: string) +GetConstContainerRequest (id: string, scope: array) GetConstContainerResponse (ContentType: string, StatusCode: int32, RawResponse: response ...) DeleteConstContainerRequest (id: string) DeleteConstContainerResponse (ContentType: string, StatusCode: int32, RawResponse: response) diff --git a/zSDKs/terraform-provider-testing/docs/data-sources/const_container.md b/zSDKs/terraform-provider-testing/docs/data-sources/const_container.md index 1d60f693d..4217c912b 100644 --- a/zSDKs/terraform-provider-testing/docs/data-sources/const_container.md +++ b/zSDKs/terraform-provider-testing/docs/data-sources/const_container.md @@ -15,12 +15,19 @@ ConstContainer DataSource ```terraform data "testing_const_container" "my_constcontainer" { id = "...my_id..." + scope = [ + "..." + ] } ``` ## Schema +### Optional + +- `scope` (List of String) + ### Read-Only - `id` (String) The ID of this resource. diff --git a/zSDKs/terraform-provider-testing/examples/data-sources/testing_const_container/data-source.tf b/zSDKs/terraform-provider-testing/examples/data-sources/testing_const_container/data-source.tf index 96013b05a..ce2f98db4 100644 --- a/zSDKs/terraform-provider-testing/examples/data-sources/testing_const_container/data-source.tf +++ b/zSDKs/terraform-provider-testing/examples/data-sources/testing_const_container/data-source.tf @@ -1,3 +1,6 @@ data "testing_const_container" "my_constcontainer" { id = "...my_id..." + scope = [ + "..." + ] } \ No newline at end of file diff --git a/zSDKs/terraform-provider-testing/internal/provider/constcontainer_data_source.go b/zSDKs/terraform-provider-testing/internal/provider/constcontainer_data_source.go index d9f8f0361..b1b43e845 100644 --- a/zSDKs/terraform-provider-testing/internal/provider/constcontainer_data_source.go +++ b/zSDKs/terraform-provider-testing/internal/provider/constcontainer_data_source.go @@ -32,6 +32,7 @@ type ConstContainerDataSourceModel struct { ID types.String `tfsdk:"id"` Name types.String `tfsdk:"name"` NestedList []tfTypes.ConstContainerResponseNestedList `tfsdk:"nested_list"` + Scope []types.String `queryParam:"style=form,explode=true,name=scope" tfsdk:"scope"` } // Metadata returns the data source type name. @@ -64,6 +65,10 @@ func (r *ConstContainerDataSource) Schema(ctx context.Context, req datasource.Sc `nested const must be hidden from the Terraform schema and sent` + "\n" + `for every item.`, }, + "scope": schema.ListAttribute{ + Optional: true, + ElementType: types.StringType, + }, }, } } diff --git a/zSDKs/terraform-provider-testing/internal/provider/constcontainer_data_source_sdk.go b/zSDKs/terraform-provider-testing/internal/provider/constcontainer_data_source_sdk.go index a8194d854..29303bce9 100644 --- a/zSDKs/terraform-provider-testing/internal/provider/constcontainer_data_source_sdk.go +++ b/zSDKs/terraform-provider-testing/internal/provider/constcontainer_data_source_sdk.go @@ -37,8 +37,13 @@ func (r *ConstContainerDataSourceModel) ToOperationsGetConstContainerRequest(ctx var id string id = r.ID.ValueString() + scope := make([]string, 0, len(r.Scope)) + for scopeIndex := range r.Scope { + scope = append(scope, r.Scope[scopeIndex].ValueString()) + } out := operations.GetConstContainerRequest{ - ID: id, + ID: id, + Scope: scope, } return &out, diags diff --git a/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource.go b/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource.go index f6a006812..5fc187efe 100644 --- a/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource.go +++ b/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource.go @@ -171,6 +171,43 @@ func (r *ConstContainerResource) Create(ctx context.Context, req resource.Create resp.Diagnostics.Append(refreshPlan(ctx, plan, &data)...) + if resp.Diagnostics.HasError() { + return + } + request1, request1Diags := data.ToOperationsGetConstContainerRequest(ctx) + resp.Diagnostics.Append(request1Diags...) + + if resp.Diagnostics.HasError() { + return + } + res1, err := r.client.GetConstContainer(ctx, *request1) + if err != nil { + resp.Diagnostics.AddError("failure to invoke API", redactSensitiveValues(ctx, err.Error())) + if res1 != nil && res1.RawResponse != nil { + resp.Diagnostics.AddError("unexpected http request/response", debugResponse(res1.RawResponse)) + } + return + } + if res1 == nil { + resp.Diagnostics.AddError("unexpected response from API", fmt.Sprintf("%v", res1)) + return + } + if res1.StatusCode != 200 { + resp.Diagnostics.AddError(fmt.Sprintf("unexpected response from API. Got an unexpected response code %v", res1.StatusCode), debugResponse(res1.RawResponse)) + return + } + if !(res1.ConstContainerResponse != nil) { + resp.Diagnostics.AddError("unexpected response from API. Got an unexpected response body", debugResponse(res1.RawResponse)) + return + } + resp.Diagnostics.Append(data.RefreshFromSharedConstContainerResponse(ctx, res1.ConstContainerResponse)...) + + if resp.Diagnostics.HasError() { + return + } + + resp.Diagnostics.Append(refreshPlan(ctx, plan, &data)...) + if resp.Diagnostics.HasError() { return } diff --git a/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource_test.go b/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource_test.go index b1800be1f..4e4367e18 100644 --- a/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource_test.go +++ b/zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource_test.go @@ -16,7 +16,9 @@ import ( // The request schema declares const values on array and map properties. The // provider must hide them from the resource schema and send them verbatim, -// and a read must accept the const values however the server formats them. +// and a read must accept the const values however the server formats them, +// including null for a nullable one. The read operation's const array query +// parameter is not injected: container consts apply to body properties only. func TestConstContainerResourceLifecycle(t *testing.T) { t.Parallel() @@ -43,7 +45,8 @@ func TestConstContainerResourceLifecycle(t *testing.T) { "empty_map": { }, "empty_set": [ ], "fixed_map": { "min" : 1, "max" : 1e1 }, - "templated_map": { "{{key}}": "value" }, + "templated_map": { "{{key}}": "value", "quo\"te\\back": "line\nbreak" }, + "nullable_list": null, "nested_list": [ { "tags": [ "fixed" ], "label": "first" } ] }`)) }, @@ -110,7 +113,14 @@ func TestConstContainerResourceLifecycle(t *testing.T) { tfmockserver.AssertRequestBodyField(t, body, "empty_map", map[string]any{}) tfmockserver.AssertRequestBodyFieldEmptyArray(t, body, "empty_set") tfmockserver.AssertRequestBodyField(t, body, "fixed_map", map[string]any{"max": float64(10), "min": float64(1)}) - tfmockserver.AssertRequestBodyField(t, body, "templated_map", map[string]any{"{{key}}": "value"}) + tfmockserver.AssertRequestBodyField(t, body, "templated_map", map[string]any{"{{key}}": "value", "quo\"te\\back": "line\nbreak"}) + tfmockserver.AssertRequestBodyFieldEmptyArray(t, body, "nullable_list") tfmockserver.AssertRequestBodyField(t, body, "nested_list", []any{map[string]any{"label": "first", "tags": []any{"fixed"}}}) - require.Len(t, body, 8, "request body carries only name, nested_list and the six const fields: %v", body) + require.Len(t, body, 9, "request body carries only name, nested_list and the seven const fields: %v", body) + + gets := endpoints.Get[0].Requests.All() + require.NotEmpty(t, gets) + for _, get := range gets { + require.Empty(t, get.Query, "read sends no query parameters: %v", get.Query) + } } diff --git a/zSDKs/terraform-provider-testing/internal/sdk/internal/utils/json.go b/zSDKs/terraform-provider-testing/internal/sdk/internal/utils/json.go index 48a5311db..7aa52b5e8 100644 --- a/zSDKs/terraform-provider-testing/internal/sdk/internal/utils/json.go +++ b/zSDKs/terraform-provider-testing/internal/sdk/internal/utils/json.go @@ -185,14 +185,11 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool fieldVal := val.Field(i) fieldName := field.Name - optional := false jsonTag := field.Tag.Get("json") if jsonTag != "" { for _, tag := range strings.Split(jsonTag, ",") { - if tag == "omitempty" || tag == "omitzero" { - optional = true - } else { + if tag != "omitempty" && tag != "omitzero" { fieldName = tag } } @@ -207,7 +204,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { if r, ok := unmarshaled[fieldName]; ok { - if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) && (optional || field.Type.Kind() == reflect.Ptr || optionalnullable.IsOptionalNullableType(field.Type)) { + if isContainerKind(field.Type) && bytes.Equal(bytes.TrimSpace(r), []byte("null")) { delete(unmarshaled, fieldName) continue } diff --git a/zSDKs/terraform-provider-testing/internal/sdk/models/operations/getconstcontainer.go b/zSDKs/terraform-provider-testing/internal/sdk/models/operations/getconstcontainer.go index b9d5e2846..bf11033d3 100644 --- a/zSDKs/terraform-provider-testing/internal/sdk/models/operations/getconstcontainer.go +++ b/zSDKs/terraform-provider-testing/internal/sdk/models/operations/getconstcontainer.go @@ -8,7 +8,8 @@ import ( ) type GetConstContainerRequest struct { - ID string `pathParam:"style=simple,explode=false,name=id"` + ID string `pathParam:"style=simple,explode=false,name=id"` + Scope []string `queryParam:"style=form,explode=true,name=scope"` } func (g *GetConstContainerRequest) GetID() string { @@ -18,6 +19,13 @@ func (g *GetConstContainerRequest) GetID() string { return g.ID } +func (g *GetConstContainerRequest) GetScope() []string { + if g == nil { + return nil + } + return g.Scope +} + type GetConstContainerResponse struct { // HTTP response content type for this operation ContentType string diff --git a/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerrequest.go b/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerrequest.go index 989a516af..bafd010c4 100644 --- a/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerrequest.go +++ b/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerrequest.go @@ -88,11 +88,17 @@ type ConstContainerRequest struct { emptyMap map[string]string `const:"{}" json:"empty_map"` //lint:ignore U1000 accessed via reflection for JSON marshaling fixedMap map[string]int64 `const:"{\"max\":10,\"min\":1}" json:"fixed_map,omitempty"` - // Map const whose key contains template delimiters. The generated - // Go literal and struct tag must escape them. + // Map const whose keys and values contain template delimiters, + // quotes, backslashes and a newline. The generated Go literal and + // struct tag must escape them and round-trip them on the wire. // //lint:ignore U1000 accessed via reflection for JSON marshaling - templatedMap map[string]string `const:"{\"{{key}}\":\"value\"}" json:"templated_map,omitempty"` + templatedMap map[string]string `const:"{\"quo\\\"te\\\\back\":\"line\\nbreak\",\"{{key}}\":\"value\"}" json:"templated_map,omitempty"` + // Nullable array with an empty const. A response may carry null for + // it, which must decode as absent rather than a const mismatch. + // + //lint:ignore U1000 accessed via reflection for JSON marshaling + nullableList []string `const:"[]" json:"nullable_list"` // List of objects whose item schema declares a const array. The // nested const must be hidden from the Terraform schema and sent // for every item. @@ -139,7 +145,11 @@ func (c *ConstContainerRequest) GetFixedMap() map[string]int64 { } func (c *ConstContainerRequest) GetTemplatedMap() map[string]string { - return map[string]string{"{{key}}": "value"} + return map[string]string{"quo\"te\\back": "line\nbreak", "{{key}}": "value"} +} + +func (c *ConstContainerRequest) GetNullableList() []string { + return []string{} } func (c *ConstContainerRequest) GetNestedList() []ConstContainerRequestNestedList { diff --git a/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerresponse.go b/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerresponse.go index 7365f02e6..e5dffde43 100644 --- a/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerresponse.go +++ b/zSDKs/terraform-provider-testing/internal/sdk/models/shared/constcontainerresponse.go @@ -89,11 +89,17 @@ type ConstContainerResponse struct { emptyMap map[string]string `const:"{}" json:"empty_map,omitempty"` //lint:ignore U1000 accessed via reflection for JSON marshaling fixedMap map[string]int64 `const:"{\"max\":10,\"min\":1}" json:"fixed_map,omitempty"` - // Map const whose key contains template delimiters. The generated - // Go literal and struct tag must escape them. + // Map const whose keys and values contain template delimiters, + // quotes, backslashes and a newline. The generated Go literal and + // struct tag must escape them and round-trip them on the wire. // //lint:ignore U1000 accessed via reflection for JSON marshaling - templatedMap map[string]string `const:"{\"{{key}}\":\"value\"}" json:"templated_map,omitempty"` + templatedMap map[string]string `const:"{\"quo\\\"te\\\\back\":\"line\\nbreak\",\"{{key}}\":\"value\"}" json:"templated_map,omitempty"` + // Nullable array with an empty const. A response may carry null for + // it, which must decode as absent rather than a const mismatch. + // + //lint:ignore U1000 accessed via reflection for JSON marshaling + nullableList []string `const:"[]" json:"nullable_list"` // List of objects whose item schema declares a const array. The // nested const must be hidden from the Terraform schema and sent // for every item. @@ -147,7 +153,11 @@ func (c *ConstContainerResponse) GetFixedMap() map[string]int64 { } func (c *ConstContainerResponse) GetTemplatedMap() map[string]string { - return map[string]string{"{{key}}": "value"} + return map[string]string{"quo\"te\\back": "line\nbreak", "{{key}}": "value"} +} + +func (c *ConstContainerResponse) GetNullableList() []string { + return []string{} } func (c *ConstContainerResponse) GetNestedList() []ConstContainerResponseNestedList { diff --git a/zSDKs/terraform-provider-testing/internal/sdk/sdk.go b/zSDKs/terraform-provider-testing/internal/sdk/sdk.go index 24d7c837d..f30e72d66 100644 --- a/zSDKs/terraform-provider-testing/internal/sdk/sdk.go +++ b/zSDKs/terraform-provider-testing/internal/sdk/sdk.go @@ -42331,7 +42331,9 @@ func (s *SDK) CreateConstContainer(ctx context.Context, request shared.ConstCont } -// GetConstContainer - Get a const container resource +// GetConstContainer - Get a const container resource. The query parameter declares an +// array const, which lives on the parameter path rather than a request +// body property, to pin how container consts on parameters surface. func (s *SDK) GetConstContainer(ctx context.Context, request operations.GetConstContainerRequest, opts ...operations.Option) (*operations.GetConstContainerResponse, error) { o := operations.Options{} supportedOptions := []string{ @@ -42383,6 +42385,10 @@ func (s *SDK) GetConstContainer(ctx context.Context, request operations.GetConst req.Header.Set("Accept", "application/json") req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) + if err := utils.PopulateQueryParams(ctx, req, request, nil, nil); err != nil { + return nil, fmt.Errorf("error populating query params: %w", err) + } + if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil { return nil, err } diff --git a/zSDKs/terraform-provider-testing/internal/tfmockserver/server.go b/zSDKs/terraform-provider-testing/internal/tfmockserver/server.go index f2efe7dc9..e17f72dc4 100644 --- a/zSDKs/terraform-provider-testing/internal/tfmockserver/server.go +++ b/zSDKs/terraform-provider-testing/internal/tfmockserver/server.go @@ -7,6 +7,7 @@ import ( "io" "net/http" "net/http/httptest" + "net/url" "regexp" "strings" "sync" @@ -33,6 +34,7 @@ type CapturedRequest struct { Method string Path string PathParams map[string]string + Query url.Values Body map[string]any } @@ -515,6 +517,7 @@ func (h *ResourceHandler) handleGetWithConfig(w http.ResponseWriter, r *http.Req Method: r.Method, Path: r.URL.Path, PathParams: pathParams, + Query: r.URL.Query(), Body: nil, // GET requests typically don't have a body }) From 898b1c75c988250d91b77867f50c29ead9a56929 Mon Sep 17 00:00:00 2001 From: Ash Godfrey Date: Mon, 2 Nov 2026 16:41:42 +0000 Subject: [PATCH 22/22] fix: omit container consts on content-based parameters too Content-based path and query parameters now carry the parameter type into the schema parser, so an array or map const on them is dropped with the same validation warning as on plain parameters. --- pkg/generate/parameters.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/generate/parameters.go b/pkg/generate/parameters.go index 48f6b4a4f..ad7e9f7e7 100644 --- a/pkg/generate/parameters.go +++ b/pkg/generate/parameters.go @@ -508,6 +508,19 @@ func (g *Generator) handleQueryParameters(ctx context.Context, opts handleSpecif return queryParams, globalParams, nil } +func schemaParamType(paramType string) schemas.ParamType { + switch paramType { + case ast.ParamTypePathParam: + return schemas.ParamTypePath + case ast.ParamTypeQueryParam: + return schemas.ParamTypeQuery + case ast.ParamTypeHeader: + return schemas.ParamTypeHeader + default: + return "" + } +} + func (g *Generator) handleContentParameter(ctx context.Context, paramType string, contextStack ast.ContextStack, rp *oas.ReferencedParameter, globalNameOverrides []*extensions.NameOverride, scope ast.Scope, docInfo *document.DocumentInfo) (*param, error) { p := rp.MustGetObject() @@ -539,6 +552,7 @@ func (g *Generator) handleContentParameter(ctx context.Context, paramType string paramField, err := g.schemas.HandleSchema(ctx, schemas.Params{ ContextStack: addPropScope(contextStack, rp), SerializationMethod: ast.SerializationMethodJSON, + ParamType: schemaParamType(paramType), Schema: schema, Scope: s, IsRequest: true,