-
Notifications
You must be signed in to change notification settings - Fork 209
chore: Support dynamic json values which Map type #3860
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2a2eedf
7c7d1b1
36a4d77
f112f9d
686b6fa
b3f5460
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -720,6 +720,77 @@ func TestConvertToProviderSpec_typeOverride(t *testing.T) { | |
| runTestCase(t, tc) | ||
| } | ||
|
|
||
| func TestConvertToProviderSpec_dynamicJSONProperties(t *testing.T) { | ||
| tc := convertToSpecTestCase{ | ||
| inputOpenAPISpecPath: testDataAPISpecPath, | ||
| inputConfigPath: testDataConfigPath, | ||
| inputResourceName: "test_dynamic_json_properties", | ||
|
|
||
| expectedResult: &codespec.Model{ | ||
| Resources: []codespec.Resource{{ | ||
| Schema: &codespec.Schema{ | ||
| Description: conversion.StringPtr(testResourceDesc), | ||
| Attributes: codespec.Attributes{ | ||
| { | ||
| TFSchemaName: "array_of_dynamic_values", | ||
| TFModelName: "ArrayOfDynamicValues", | ||
| ComputedOptionalRequired: codespec.Optional, | ||
| CustomType: codespec.NewCustomListType(codespec.CustomTypeJSON), | ||
| List: &codespec.ListAttribute{ | ||
| ElementType: codespec.CustomTypeJSON, | ||
| }, | ||
| Description: conversion.StringPtr("Array of dynamic values."), | ||
| ReqBodyUsage: codespec.AllRequestBodies, | ||
| }, | ||
| { | ||
| TFSchemaName: "dynamic_value", | ||
| TFModelName: "DynamicValue", | ||
| ComputedOptionalRequired: codespec.Optional, | ||
| String: &codespec.StringAttribute{}, | ||
| CustomType: &codespec.CustomTypeJSONVar, | ||
| Description: conversion.StringPtr("Dynamic value."), | ||
| ReqBodyUsage: codespec.AllRequestBodies, | ||
| }, | ||
| { | ||
| TFSchemaName: "object_of_dynamic_values", | ||
| TFModelName: "ObjectOfDynamicValues", | ||
| ComputedOptionalRequired: codespec.Optional, | ||
| CustomType: codespec.NewCustomMapType(codespec.CustomTypeJSON), | ||
| Map: &codespec.MapAttribute{ | ||
| ElementType: codespec.CustomTypeJSON, | ||
| }, | ||
| Description: conversion.StringPtr("Object of dynamic values."), | ||
| ReqBodyUsage: codespec.AllRequestBodies, | ||
| }, | ||
| }, | ||
| }, | ||
| Name: "test_dynamic_json_properties", | ||
| PackageName: "testdynamicjsonproperties", | ||
| Operations: codespec.APIOperations{ | ||
| Create: codespec.APIOperation{ | ||
| Path: "/api/atlas/v2/dynamicJsonProperties", | ||
| HTTPMethod: "POST", | ||
| }, | ||
| Read: codespec.APIOperation{ | ||
| Path: "/api/atlas/v2/dynamicJsonProperties", | ||
| HTTPMethod: "GET", | ||
| }, | ||
| Update: codespec.APIOperation{ | ||
| Path: "/api/atlas/v2/dynamicJsonProperties", | ||
| HTTPMethod: "PATCH", | ||
| }, | ||
| Delete: &codespec.APIOperation{ | ||
| Path: "/api/atlas/v2/dynamicJsonProperties", | ||
| HTTPMethod: "DELETE", | ||
| }, | ||
| VersionHeader: "application/vnd.atlas.2024-05-30+json", | ||
| }, | ||
| }}, | ||
| }, | ||
| } | ||
| runTestCase(t, tc) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: i know it's not only from this PR but don't see the need to extract
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah agree |
||
| } | ||
|
|
||
| func runTestCase(t *testing.T, tc convertToSpecTestCase) { | ||
| t.Helper() | ||
| result, err := codespec.ToCodeSpecModel(tc.inputOpenAPISpecPath, tc.inputConfigPath, &tc.inputResourceName) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no changes to marshal/unmarshal logic needed, adding testing to ensure coverage