diff --git a/.gitignore b/.gitignore index 7a8a44a..758e7d5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,10 @@ +**/.speakeasy/temp/ +**/.speakeasy/logs/ +.env +.env.local .terraform .terraform* *.tfstate* .DS_Store - original.yaml original_modified.yaml diff --git a/.speakeasy/gen.lock b/.speakeasy/gen.lock index bd71cff..93476d4 100644 --- a/.speakeasy/gen.lock +++ b/.speakeasy/gen.lock @@ -1,34 +1,32 @@ lockVersion: 2.0.0 id: 45f3018a-30de-4d91-ab55-1ad3f43bb6de management: - docChecksum: 3cac38273733de79e2a8196e211ae08a + docChecksum: c8095104c8d4c23ee6b9e02488aa8c27 docVersion: 1.0.0 - speakeasyVersion: 1.453.0 - generationVersion: 2.472.1 - releaseVersion: 1.2.0 - configChecksum: 5f95423ff24fb9f1ed01acda96dda1c1 + speakeasyVersion: 1.645.2 + generationVersion: 2.735.1 + releaseVersion: 1.3.0 + configChecksum: a80b98297dc1cfbe5a95a8ce13060fbd + repoURL: https://github.com/epilot-dev/terraform-provider-epilot-custom-variable.git features: terraform: additionalDependencies: 0.1.0 - constsAndDefaults: 0.2.0 - core: 3.27.0 - envVarSecurityUsage: 0.1.0 - globalSecurity: 2.81.9 - globalServerURLs: 2.82.1 + constsAndDefaults: 0.3.0 + core: 3.46.5 + globalSecurity: 2.82.1 + globalServerURLs: 2.83.0 + inputOutputModels: 2.83.0 nullables: 0.0.0 - retries: 2.81.2 generatedFiles: - .gitattributes - USAGE.md - - examples/README.md - - examples/data-sources/epilot-custom-variable_custom_variable/data-source.tf - examples/provider/provider.tf - - examples/resources/epilot-custom-variable_custom_variable/import.sh - - examples/resources/epilot-custom-variable_custom_variable/resource.tf - go.mod - go.sum - internal/planmodifiers/boolplanmodifier/suppress_diff.go + - internal/planmodifiers/float32planmodifier/suppress_diff.go - internal/planmodifiers/float64planmodifier/suppress_diff.go + - internal/planmodifiers/int32planmodifier/suppress_diff.go - internal/planmodifiers/int64planmodifier/suppress_diff.go - internal/planmodifiers/listplanmodifier/suppress_diff.go - internal/planmodifiers/mapplanmodifier/suppress_diff.go @@ -37,10 +35,6 @@ generatedFiles: - internal/planmodifiers/setplanmodifier/suppress_diff.go - internal/planmodifiers/stringplanmodifier/suppress_diff.go - internal/planmodifiers/utils/state_check.go - - internal/provider/customvariable_data_source.go - - internal/provider/customvariable_data_source_sdk.go - - internal/provider/customvariable_resource.go - - internal/provider/customvariable_resource_sdk.go - internal/provider/provider.go - internal/provider/reflect/diags.go - internal/provider/reflect/doc.go @@ -56,11 +50,13 @@ generatedFiles: - internal/provider/reflect/primitive.go - internal/provider/reflect/slice.go - internal/provider/reflect/struct.go + - internal/provider/typeconvert/date.go + - internal/provider/typeconvert/datetime.go + - internal/provider/typeconvert/int.go - internal/provider/utils.go - internal/sdk/.gitattributes - - internal/sdk/.gitignore - - internal/sdk/CONTRIBUTING.md - internal/sdk/customvariables.go + - internal/sdk/internal/config/sdkconfiguration.go - internal/sdk/internal/hooks/hooks.go - internal/sdk/internal/utils/contenttype.go - internal/sdk/internal/utils/env.go @@ -95,12 +91,13 @@ generatedFiles: - internal/sdk/models/shared/variablecontext.go - internal/sdk/models/shared/variableparameters.go - internal/sdk/models/shared/variableresult.go + - internal/sdk/optionalnullable/optionalnullable.go + - internal/sdk/optionalnullable/optionalnullable_test.go - internal/sdk/retry/config.go - internal/sdk/sdk.go - internal/sdk/types/bigint.go - internal/sdk/types/date.go - internal/sdk/types/datetime.go - - internal/sdk/types/decimal.go - internal/sdk/types/pointers.go - internal/sdk/variables.go - internal/validators/DateValidator.go @@ -108,7 +105,9 @@ generatedFiles: - internal/validators/JSONParseValidator.go - internal/validators/RFC3339Validator.go - internal/validators/boolvalidators/not_null.go + - internal/validators/float32validators/not_null.go - internal/validators/float64validators/not_null.go + - internal/validators/int32validators/not_null.go - internal/validators/int64validators/not_null.go - internal/validators/listvalidators/not_null.go - internal/validators/mapvalidators/not_null.go @@ -123,12 +122,12 @@ examples: createCustomVariable: speakeasy-default-create-custom-variable: requestBody: - application/json: {"created_at": "2022-04-19T12:41:43.662Z", "created_by": "100042", "helper_logic": "return param1 * param2;", "helper_params": ["param1", "param2"], "id": "rbse777b-3cf8-4bff-bb0c-253fd1123250", "key": "my_custom_table", "name": "My Custom table", "template": "\n \n \n {{#each table_config.header.columns as |column|}}\n {{#if column.enable}}\n \n {{/if}}\n {{/each}}\n \n \n \n \n {{#each order.products as |product|}}\n {{#if @last}}\n \n {{else}}\n \n {{/if}}\n {{#each @root.table_config.header.columns as |column|}}\n {{#if column.enable}}\n {{#if (eq column.id 'item')}}\n \n \n {{/if}}\n {{#if (eq column.id 'quantity')}}\n \n \n {{/if}}\n {{#if (eq column.id 'tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'unit_amount')}}\n \n \n {{/if}}\n {{#if (eq column.id 'net_total')}}\n \n \n {{/if}}\n {{#if (eq column.id 'amount_tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'gross_total')}}\n \n \n {{/if}}\n {{/if}}\n {{/each}}\n \n {{/each}}\n \n {{#if table_config.footer.gross_total.enable}}\n {{#each order.total_details.recurrences as |item|}}\n \n \n {{#if @root.table_config.footer.payment_type.enable}}\n \n {{/if}}\n {{#if (isColumnEnabled @root.table_config 'net_total')}}\n {{#if @root.table_config.footer.net_total.enable}}\n \n {{/if}}\n {{/if}}\n \n \n {{/each}}\n {{/if}}\n \n \n
{{column._label}}
\n {{#if @root.table_config.body.product_name.enable}}\n {{product.name}}\n {{/if}}\n {{#if @root.table_config.body.price_description.enable}}\n
\n {{product.price.description}}\n {{/if}}\n {{#if @root.table_config.body.product_description.enable}}\n
\n {{product.description}}\n {{/if}}\n
{{product.price.quantity}}\n \n {{product.price.tax_rate}}\n \n {{product.price.unit_amount_net}}\n \n {{product.price.amount_subtotal}}\n \n {{product.price.amount_tax}}\n \n {{product.price.amount_total}}\n {{#if @root.table_config.body.payment_type.enable}}\n {{#if (eq product.price.type 'recurring')}}\n
\n {{product.price.billing_period}}\n {{/if}}\n {{/if}}\n
{{item.billing_period}}{{item.amount_subtotal}}{{item.amount_total}}\n {{#if @root.table_config.footer.amount_tax.enable}}\n
\n {{item.full_amount_tax}}\n {{/if}}\n
\n", "type": "custom", "updated_at": "2022-04-20T12:41:43.662Z", "updated_by": "100042"} + application/json: {"config": {}, "helper_logic": "return param1 * param2;", "helper_params": ["param1", "param2"], "id": "rbse777b-3cf8-4bff-bb0c-253fd1123250", "key": "my_custom_table", "name": "My Custom table", "template": "\n \n \n {{#each table_config.header.columns as |column|}}\n {{#if column.enable}}\n \n {{/if}}\n {{/each}}\n \n \n \n \n {{#each order.products as |product|}}\n {{#if @last}}\n \n {{else}}\n \n {{/if}}\n {{#each @root.table_config.header.columns as |column|}}\n {{#if column.enable}}\n {{#if (eq column.id 'item')}}\n \n \n {{/if}}\n {{#if (eq column.id 'quantity')}}\n \n \n {{/if}}\n {{#if (eq column.id 'tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'unit_amount')}}\n \n \n {{/if}}\n {{#if (eq column.id 'net_total')}}\n \n \n {{/if}}\n {{#if (eq column.id 'amount_tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'gross_total')}}\n \n \n {{/if}}\n {{/if}}\n {{/each}}\n \n {{/each}}\n \n {{#if table_config.footer.gross_total.enable}}\n {{#each order.total_details.recurrences as |item|}}\n \n \n {{#if @root.table_config.footer.payment_type.enable}}\n \n {{/if}}\n {{#if (isColumnEnabled @root.table_config 'net_total')}}\n {{#if @root.table_config.footer.net_total.enable}}\n \n {{/if}}\n {{/if}}\n \n \n {{/each}}\n {{/if}}\n \n \n
{{column._label}}
\n {{#if @root.table_config.body.product_name.enable}}\n {{product.name}}\n {{/if}}\n {{#if @root.table_config.body.price_description.enable}}\n
\n {{product.price.description}}\n {{/if}}\n {{#if @root.table_config.body.product_description.enable}}\n
\n {{product.description}}\n {{/if}}\n
{{product.price.quantity}}\n \n {{product.price.tax_rate}}\n \n {{product.price.unit_amount_net}}\n \n {{product.price.amount_subtotal}}\n \n {{product.price.amount_tax}}\n \n {{product.price.amount_total}}\n {{#if @root.table_config.body.payment_type.enable}}\n {{#if (eq product.price.type 'recurring')}}\n
\n {{product.price.billing_period}}\n {{/if}}\n {{/if}}\n
{{item.billing_period}}{{item.amount_subtotal}}{{item.amount_total}}\n {{#if @root.table_config.footer.amount_tax.enable}}\n
\n {{item.full_amount_tax}}\n {{/if}}\n
\n"} responses: "201": - application/json: {"created_at": "2022-04-19T12:41:43.662Z", "created_by": "100042", "helper_logic": "return param1 * param2;", "helper_params": ["param1", "param2"], "id": "rbse777b-3cf8-4bff-bb0c-253fd1123250", "key": "my_custom_table", "name": "My Custom table", "template": "\n \n \n {{#each table_config.header.columns as |column|}}\n {{#if column.enable}}\n \n {{/if}}\n {{/each}}\n \n \n \n \n {{#each order.products as |product|}}\n {{#if @last}}\n \n {{else}}\n \n {{/if}}\n {{#each @root.table_config.header.columns as |column|}}\n {{#if column.enable}}\n {{#if (eq column.id 'item')}}\n \n \n {{/if}}\n {{#if (eq column.id 'quantity')}}\n \n \n {{/if}}\n {{#if (eq column.id 'tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'unit_amount')}}\n \n \n {{/if}}\n {{#if (eq column.id 'net_total')}}\n \n \n {{/if}}\n {{#if (eq column.id 'amount_tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'gross_total')}}\n \n \n {{/if}}\n {{/if}}\n {{/each}}\n \n {{/each}}\n \n {{#if table_config.footer.gross_total.enable}}\n {{#each order.total_details.recurrences as |item|}}\n \n \n {{#if @root.table_config.footer.payment_type.enable}}\n \n {{/if}}\n {{#if (isColumnEnabled @root.table_config 'net_total')}}\n {{#if @root.table_config.footer.net_total.enable}}\n \n {{/if}}\n {{/if}}\n \n \n {{/each}}\n {{/if}}\n \n \n
{{column._label}}
\n {{#if @root.table_config.body.product_name.enable}}\n {{product.name}}\n {{/if}}\n {{#if @root.table_config.body.price_description.enable}}\n
\n {{product.price.description}}\n {{/if}}\n {{#if @root.table_config.body.product_description.enable}}\n
\n {{product.description}}\n {{/if}}\n
{{product.price.quantity}}\n \n {{product.price.tax_rate}}\n \n {{product.price.unit_amount_net}}\n \n {{product.price.amount_subtotal}}\n \n {{product.price.amount_tax}}\n \n {{product.price.amount_total}}\n {{#if @root.table_config.body.payment_type.enable}}\n {{#if (eq product.price.type 'recurring')}}\n
\n {{product.price.billing_period}}\n {{/if}}\n {{/if}}\n
{{item.billing_period}}{{item.amount_subtotal}}{{item.amount_total}}\n {{#if @root.table_config.footer.amount_tax.enable}}\n
\n {{item.full_amount_tax}}\n {{/if}}\n
\n", "updated_at": "2022-04-20T12:41:43.662Z", "updated_by": "100042"} + application/json: {"config": {}, "created_at": "2022-04-19T12:41:43.662Z", "created_by": "100042", "helper_logic": "return param1 * param2;", "helper_params": ["param1", "param2"], "id": "rbse777b-3cf8-4bff-bb0c-253fd1123250", "key": "my_custom_table", "name": "My Custom table", "template": "\n \n \n {{#each table_config.header.columns as |column|}}\n {{#if column.enable}}\n \n {{/if}}\n {{/each}}\n \n \n \n \n {{#each order.products as |product|}}\n {{#if @last}}\n \n {{else}}\n \n {{/if}}\n {{#each @root.table_config.header.columns as |column|}}\n {{#if column.enable}}\n {{#if (eq column.id 'item')}}\n \n \n {{/if}}\n {{#if (eq column.id 'quantity')}}\n \n \n {{/if}}\n {{#if (eq column.id 'tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'unit_amount')}}\n \n \n {{/if}}\n {{#if (eq column.id 'net_total')}}\n \n \n {{/if}}\n {{#if (eq column.id 'amount_tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'gross_total')}}\n \n \n {{/if}}\n {{/if}}\n {{/each}}\n \n {{/each}}\n \n {{#if table_config.footer.gross_total.enable}}\n {{#each order.total_details.recurrences as |item|}}\n \n \n {{#if @root.table_config.footer.payment_type.enable}}\n \n {{/if}}\n {{#if (isColumnEnabled @root.table_config 'net_total')}}\n {{#if @root.table_config.footer.net_total.enable}}\n \n {{/if}}\n {{/if}}\n \n \n {{/each}}\n {{/if}}\n \n \n
{{column._label}}
\n {{#if @root.table_config.body.product_name.enable}}\n {{product.name}}\n {{/if}}\n {{#if @root.table_config.body.price_description.enable}}\n
\n {{product.price.description}}\n {{/if}}\n {{#if @root.table_config.body.product_description.enable}}\n
\n {{product.description}}\n {{/if}}\n
{{product.price.quantity}}\n \n {{product.price.tax_rate}}\n \n {{product.price.unit_amount_net}}\n \n {{product.price.amount_subtotal}}\n \n {{product.price.amount_tax}}\n \n {{product.price.amount_total}}\n {{#if @root.table_config.body.payment_type.enable}}\n {{#if (eq product.price.type 'recurring')}}\n
\n {{product.price.billing_period}}\n {{/if}}\n {{/if}}\n
{{item.billing_period}}{{item.amount_subtotal}}{{item.amount_total}}\n {{#if @root.table_config.footer.amount_tax.enable}}\n
\n {{item.full_amount_tax}}\n {{/if}}\n
\n", "updated_at": "2022-04-20T12:41:43.662Z", "updated_by": "100042"} deleteCustomVariable: - "": + speakeasy-default-delete-custom-variable: parameters: path: id: "rbse777b-3cf8-4bff-bb0c-253fd1123250" @@ -136,61 +135,65 @@ examples: speakeasy-default-get-blue-print-table-config: responses: "200": - application/json: {"created_at": "2022-04-19T12:41:43.662Z", "created_by": "100042", "helper_logic": "return param1 * param2;", "helper_params": ["param1", "param2"], "id": "rbse777b-3cf8-4bff-bb0c-253fd1123250", "key": "my_custom_table", "name": "My Custom table", "template": "\n \n \n {{#each table_config.header.columns as |column|}}\n {{#if column.enable}}\n \n {{/if}}\n {{/each}}\n \n \n \n \n {{#each order.products as |product|}}\n {{#if @last}}\n \n {{else}}\n \n {{/if}}\n {{#each @root.table_config.header.columns as |column|}}\n {{#if column.enable}}\n {{#if (eq column.id 'item')}}\n \n \n {{/if}}\n {{#if (eq column.id 'quantity')}}\n \n \n {{/if}}\n {{#if (eq column.id 'tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'unit_amount')}}\n \n \n {{/if}}\n {{#if (eq column.id 'net_total')}}\n \n \n {{/if}}\n {{#if (eq column.id 'amount_tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'gross_total')}}\n \n \n {{/if}}\n {{/if}}\n {{/each}}\n \n {{/each}}\n \n {{#if table_config.footer.gross_total.enable}}\n {{#each order.total_details.recurrences as |item|}}\n \n \n {{#if @root.table_config.footer.payment_type.enable}}\n \n {{/if}}\n {{#if (isColumnEnabled @root.table_config 'net_total')}}\n {{#if @root.table_config.footer.net_total.enable}}\n \n {{/if}}\n {{/if}}\n \n \n {{/each}}\n {{/if}}\n \n \n
{{column._label}}
\n {{#if @root.table_config.body.product_name.enable}}\n {{product.name}}\n {{/if}}\n {{#if @root.table_config.body.price_description.enable}}\n
\n {{product.price.description}}\n {{/if}}\n {{#if @root.table_config.body.product_description.enable}}\n
\n {{product.description}}\n {{/if}}\n
{{product.price.quantity}}\n \n {{product.price.tax_rate}}\n \n {{product.price.unit_amount_net}}\n \n {{product.price.amount_subtotal}}\n \n {{product.price.amount_tax}}\n \n {{product.price.amount_total}}\n {{#if @root.table_config.body.payment_type.enable}}\n {{#if (eq product.price.type 'recurring')}}\n
\n {{product.price.billing_period}}\n {{/if}}\n {{/if}}\n
{{item.billing_period}}{{item.amount_subtotal}}{{item.amount_total}}\n {{#if @root.table_config.footer.amount_tax.enable}}\n
\n {{item.full_amount_tax}}\n {{/if}}\n
\n", "type": "custom", "updated_at": "2022-04-20T12:41:43.662Z", "updated_by": "100042"} - getCategories: - "": - responses: - "200": - application/json: [{"category": "contact", "description": "Contact"}, {"category": "account", "description": "Account"}, {"category": "organization", "description": "Organization"}] + application/json: {"config": {}, "created_at": "2022-04-19T12:41:43.662Z", "created_by": "100042", "helper_logic": "return param1 * param2;", "helper_params": ["param1", "param2"], "id": "rbse777b-3cf8-4bff-bb0c-253fd1123250", "key": "my_custom_table", "name": "My Custom table", "template": "\n \n \n {{#each table_config.header.columns as |column|}}\n {{#if column.enable}}\n \n {{/if}}\n {{/each}}\n \n \n \n \n {{#each order.products as |product|}}\n {{#if @last}}\n \n {{else}}\n \n {{/if}}\n {{#each @root.table_config.header.columns as |column|}}\n {{#if column.enable}}\n {{#if (eq column.id 'item')}}\n \n \n {{/if}}\n {{#if (eq column.id 'quantity')}}\n \n \n {{/if}}\n {{#if (eq column.id 'tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'unit_amount')}}\n \n \n {{/if}}\n {{#if (eq column.id 'net_total')}}\n \n \n {{/if}}\n {{#if (eq column.id 'amount_tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'gross_total')}}\n \n \n {{/if}}\n {{/if}}\n {{/each}}\n \n {{/each}}\n \n {{#if table_config.footer.gross_total.enable}}\n {{#each order.total_details.recurrences as |item|}}\n \n \n {{#if @root.table_config.footer.payment_type.enable}}\n \n {{/if}}\n {{#if (isColumnEnabled @root.table_config 'net_total')}}\n {{#if @root.table_config.footer.net_total.enable}}\n \n {{/if}}\n {{/if}}\n \n \n {{/each}}\n {{/if}}\n \n \n
{{column._label}}
\n {{#if @root.table_config.body.product_name.enable}}\n {{product.name}}\n {{/if}}\n {{#if @root.table_config.body.price_description.enable}}\n
\n {{product.price.description}}\n {{/if}}\n {{#if @root.table_config.body.product_description.enable}}\n
\n {{product.description}}\n {{/if}}\n
{{product.price.quantity}}\n \n {{product.price.tax_rate}}\n \n {{product.price.unit_amount_net}}\n \n {{product.price.amount_subtotal}}\n \n {{product.price.amount_tax}}\n \n {{product.price.amount_total}}\n {{#if @root.table_config.body.payment_type.enable}}\n {{#if (eq product.price.type 'recurring')}}\n
\n {{product.price.billing_period}}\n {{/if}}\n {{/if}}\n
{{item.billing_period}}{{item.amount_subtotal}}{{item.amount_total}}\n {{#if @root.table_config.footer.amount_tax.enable}}\n
\n {{item.full_amount_tax}}\n {{/if}}\n
\n", "updated_at": "2022-04-20T12:41:43.662Z", "updated_by": "100042"} getCustomVariable: - "": + speakeasy-default-get-custom-variable: parameters: path: id: "rbse777b-3cf8-4bff-bb0c-253fd1123250" responses: "200": - application/json: {"created_at": "2022-04-19T12:41:43.662Z", "created_by": "100042", "helper_logic": "return param1 * param2;", "helper_params": ["param1", "param2"], "id": "rbse777b-3cf8-4bff-bb0c-253fd1123250", "key": "my_custom_table", "name": "My Custom table", "template": "\n \n \n {{#each table_config.header.columns as |column|}}\n {{#if column.enable}}\n \n {{/if}}\n {{/each}}\n \n \n \n \n {{#each order.products as |product|}}\n {{#if @last}}\n \n {{else}}\n \n {{/if}}\n {{#each @root.table_config.header.columns as |column|}}\n {{#if column.enable}}\n {{#if (eq column.id 'item')}}\n \n \n {{/if}}\n {{#if (eq column.id 'quantity')}}\n \n \n {{/if}}\n {{#if (eq column.id 'tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'unit_amount')}}\n \n \n {{/if}}\n {{#if (eq column.id 'net_total')}}\n \n \n {{/if}}\n {{#if (eq column.id 'amount_tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'gross_total')}}\n \n \n {{/if}}\n {{/if}}\n {{/each}}\n \n {{/each}}\n \n {{#if table_config.footer.gross_total.enable}}\n {{#each order.total_details.recurrences as |item|}}\n \n \n {{#if @root.table_config.footer.payment_type.enable}}\n \n {{/if}}\n {{#if (isColumnEnabled @root.table_config 'net_total')}}\n {{#if @root.table_config.footer.net_total.enable}}\n \n {{/if}}\n {{/if}}\n \n \n {{/each}}\n {{/if}}\n \n \n
{{column._label}}
\n {{#if @root.table_config.body.product_name.enable}}\n {{product.name}}\n {{/if}}\n {{#if @root.table_config.body.price_description.enable}}\n
\n {{product.price.description}}\n {{/if}}\n {{#if @root.table_config.body.product_description.enable}}\n
\n {{product.description}}\n {{/if}}\n
{{product.price.quantity}}\n \n {{product.price.tax_rate}}\n \n {{product.price.unit_amount_net}}\n \n {{product.price.amount_subtotal}}\n \n {{product.price.amount_tax}}\n \n {{product.price.amount_total}}\n {{#if @root.table_config.body.payment_type.enable}}\n {{#if (eq product.price.type 'recurring')}}\n
\n {{product.price.billing_period}}\n {{/if}}\n {{/if}}\n
{{item.billing_period}}{{item.amount_subtotal}}{{item.amount_total}}\n {{#if @root.table_config.footer.amount_tax.enable}}\n
\n {{item.full_amount_tax}}\n {{/if}}\n
\n", "type": "order_table", "updated_at": "2022-04-20T12:41:43.662Z", "updated_by": "100042"} + application/json: {"config": {}, "created_at": "2022-04-19T12:41:43.662Z", "created_by": "100042", "helper_logic": "return param1 * param2;", "helper_params": ["param1", "param2"], "id": "rbse777b-3cf8-4bff-bb0c-253fd1123250", "key": "my_custom_table", "name": "My Custom table", "template": "\n \n \n {{#each table_config.header.columns as |column|}}\n {{#if column.enable}}\n \n {{/if}}\n {{/each}}\n \n \n \n \n {{#each order.products as |product|}}\n {{#if @last}}\n \n {{else}}\n \n {{/if}}\n {{#each @root.table_config.header.columns as |column|}}\n {{#if column.enable}}\n {{#if (eq column.id 'item')}}\n \n \n {{/if}}\n {{#if (eq column.id 'quantity')}}\n \n \n {{/if}}\n {{#if (eq column.id 'tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'unit_amount')}}\n \n \n {{/if}}\n {{#if (eq column.id 'net_total')}}\n \n \n {{/if}}\n {{#if (eq column.id 'amount_tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'gross_total')}}\n \n \n {{/if}}\n {{/if}}\n {{/each}}\n \n {{/each}}\n \n {{#if table_config.footer.gross_total.enable}}\n {{#each order.total_details.recurrences as |item|}}\n \n \n {{#if @root.table_config.footer.payment_type.enable}}\n \n {{/if}}\n {{#if (isColumnEnabled @root.table_config 'net_total')}}\n {{#if @root.table_config.footer.net_total.enable}}\n \n {{/if}}\n {{/if}}\n \n \n {{/each}}\n {{/if}}\n \n \n
{{column._label}}
\n {{#if @root.table_config.body.product_name.enable}}\n {{product.name}}\n {{/if}}\n {{#if @root.table_config.body.price_description.enable}}\n
\n {{product.price.description}}\n {{/if}}\n {{#if @root.table_config.body.product_description.enable}}\n
\n {{product.description}}\n {{/if}}\n
{{product.price.quantity}}\n \n {{product.price.tax_rate}}\n \n {{product.price.unit_amount_net}}\n \n {{product.price.amount_subtotal}}\n \n {{product.price.amount_tax}}\n \n {{product.price.amount_total}}\n {{#if @root.table_config.body.payment_type.enable}}\n {{#if (eq product.price.type 'recurring')}}\n
\n {{product.price.billing_period}}\n {{/if}}\n {{/if}}\n
{{item.billing_period}}{{item.amount_subtotal}}{{item.amount_total}}\n {{#if @root.table_config.footer.amount_tax.enable}}\n
\n {{item.full_amount_tax}}\n {{/if}}\n
\n", "updated_at": "2022-04-20T12:41:43.662Z", "updated_by": "100042"} getCustomVariables: speakeasy-default-get-custom-variables: responses: "200": - application/json: [{"created_at": "2022-04-19T12:41:43.662Z", "created_by": "100042", "helper_logic": "return param1 * param2;", "helper_params": ["param1", "param2"], "id": "rbse777b-3cf8-4bff-bb0c-253fd1123250", "key": "my_custom_table", "name": "My Custom table", "template": "\n \n \n {{#each table_config.header.columns as |column|}}\n {{#if column.enable}}\n \n {{/if}}\n {{/each}}\n \n \n \n \n {{#each order.products as |product|}}\n {{#if @last}}\n \n {{else}}\n \n {{/if}}\n {{#each @root.table_config.header.columns as |column|}}\n {{#if column.enable}}\n {{#if (eq column.id 'item')}}\n \n \n {{/if}}\n {{#if (eq column.id 'quantity')}}\n \n \n {{/if}}\n {{#if (eq column.id 'tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'unit_amount')}}\n \n \n {{/if}}\n {{#if (eq column.id 'net_total')}}\n \n \n {{/if}}\n {{#if (eq column.id 'amount_tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'gross_total')}}\n \n \n {{/if}}\n {{/if}}\n {{/each}}\n \n {{/each}}\n \n {{#if table_config.footer.gross_total.enable}}\n {{#each order.total_details.recurrences as |item|}}\n \n \n {{#if @root.table_config.footer.payment_type.enable}}\n \n {{/if}}\n {{#if (isColumnEnabled @root.table_config 'net_total')}}\n {{#if @root.table_config.footer.net_total.enable}}\n \n {{/if}}\n {{/if}}\n \n \n {{/each}}\n {{/if}}\n \n \n
{{column._label}}
\n {{#if @root.table_config.body.product_name.enable}}\n {{product.name}}\n {{/if}}\n {{#if @root.table_config.body.price_description.enable}}\n
\n {{product.price.description}}\n {{/if}}\n {{#if @root.table_config.body.product_description.enable}}\n
\n {{product.description}}\n {{/if}}\n
{{product.price.quantity}}\n \n {{product.price.tax_rate}}\n \n {{product.price.unit_amount_net}}\n \n {{product.price.amount_subtotal}}\n \n {{product.price.amount_tax}}\n \n {{product.price.amount_total}}\n {{#if @root.table_config.body.payment_type.enable}}\n {{#if (eq product.price.type 'recurring')}}\n
\n {{product.price.billing_period}}\n {{/if}}\n {{/if}}\n
{{item.billing_period}}{{item.amount_subtotal}}{{item.amount_total}}\n {{#if @root.table_config.footer.amount_tax.enable}}\n
\n {{item.full_amount_tax}}\n {{/if}}\n
\n", "type": "custom", "updated_at": "2022-04-20T12:41:43.662Z", "updated_by": "100042"}, {"created_at": "2022-04-19T12:41:43.662Z", "created_by": "100042", "helper_logic": "return param1 * param2;", "helper_params": ["param1", "param2"], "id": "rbse777b-3cf8-4bff-bb0c-253fd1123250", "key": "my_custom_table", "name": "My Custom table", "template": "\n \n \n {{#each table_config.header.columns as |column|}}\n {{#if column.enable}}\n \n {{/if}}\n {{/each}}\n \n \n \n \n {{#each order.products as |product|}}\n {{#if @last}}\n \n {{else}}\n \n {{/if}}\n {{#each @root.table_config.header.columns as |column|}}\n {{#if column.enable}}\n {{#if (eq column.id 'item')}}\n \n \n {{/if}}\n {{#if (eq column.id 'quantity')}}\n \n \n {{/if}}\n {{#if (eq column.id 'tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'unit_amount')}}\n \n \n {{/if}}\n {{#if (eq column.id 'net_total')}}\n \n \n {{/if}}\n {{#if (eq column.id 'amount_tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'gross_total')}}\n \n \n {{/if}}\n {{/if}}\n {{/each}}\n \n {{/each}}\n \n {{#if table_config.footer.gross_total.enable}}\n {{#each order.total_details.recurrences as |item|}}\n \n \n {{#if @root.table_config.footer.payment_type.enable}}\n \n {{/if}}\n {{#if (isColumnEnabled @root.table_config 'net_total')}}\n {{#if @root.table_config.footer.net_total.enable}}\n \n {{/if}}\n {{/if}}\n \n \n {{/each}}\n {{/if}}\n \n \n
{{column._label}}
\n {{#if @root.table_config.body.product_name.enable}}\n {{product.name}}\n {{/if}}\n {{#if @root.table_config.body.price_description.enable}}\n
\n {{product.price.description}}\n {{/if}}\n {{#if @root.table_config.body.product_description.enable}}\n
\n {{product.description}}\n {{/if}}\n
{{product.price.quantity}}\n \n {{product.price.tax_rate}}\n \n {{product.price.unit_amount_net}}\n \n {{product.price.amount_subtotal}}\n \n {{product.price.amount_tax}}\n \n {{product.price.amount_total}}\n {{#if @root.table_config.body.payment_type.enable}}\n {{#if (eq product.price.type 'recurring')}}\n
\n {{product.price.billing_period}}\n {{/if}}\n {{/if}}\n
{{item.billing_period}}{{item.amount_subtotal}}{{item.amount_total}}\n {{#if @root.table_config.footer.amount_tax.enable}}\n
\n {{item.full_amount_tax}}\n {{/if}}\n
\n", "type": "order_table", "updated_at": "2022-04-20T12:41:43.662Z", "updated_by": "100042"}, {"created_at": "2022-04-19T12:41:43.662Z", "created_by": "100042", "helper_logic": "return param1 * param2;", "helper_params": ["param1", "param2"], "id": "rbse777b-3cf8-4bff-bb0c-253fd1123250", "key": "my_custom_table", "name": "My Custom table", "template": "\n \n \n {{#each table_config.header.columns as |column|}}\n {{#if column.enable}}\n \n {{/if}}\n {{/each}}\n \n \n \n \n {{#each order.products as |product|}}\n {{#if @last}}\n \n {{else}}\n \n {{/if}}\n {{#each @root.table_config.header.columns as |column|}}\n {{#if column.enable}}\n {{#if (eq column.id 'item')}}\n \n \n {{/if}}\n {{#if (eq column.id 'quantity')}}\n \n \n {{/if}}\n {{#if (eq column.id 'tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'unit_amount')}}\n \n \n {{/if}}\n {{#if (eq column.id 'net_total')}}\n \n \n {{/if}}\n {{#if (eq column.id 'amount_tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'gross_total')}}\n \n \n {{/if}}\n {{/if}}\n {{/each}}\n \n {{/each}}\n \n {{#if table_config.footer.gross_total.enable}}\n {{#each order.total_details.recurrences as |item|}}\n \n \n {{#if @root.table_config.footer.payment_type.enable}}\n \n {{/if}}\n {{#if (isColumnEnabled @root.table_config 'net_total')}}\n {{#if @root.table_config.footer.net_total.enable}}\n \n {{/if}}\n {{/if}}\n \n \n {{/each}}\n {{/if}}\n \n \n
{{column._label}}
\n {{#if @root.table_config.body.product_name.enable}}\n {{product.name}}\n {{/if}}\n {{#if @root.table_config.body.price_description.enable}}\n
\n {{product.price.description}}\n {{/if}}\n {{#if @root.table_config.body.product_description.enable}}\n
\n {{product.description}}\n {{/if}}\n
{{product.price.quantity}}\n \n {{product.price.tax_rate}}\n \n {{product.price.unit_amount_net}}\n \n {{product.price.amount_subtotal}}\n \n {{product.price.amount_tax}}\n \n {{product.price.amount_total}}\n {{#if @root.table_config.body.payment_type.enable}}\n {{#if (eq product.price.type 'recurring')}}\n
\n {{product.price.billing_period}}\n {{/if}}\n {{/if}}\n
{{item.billing_period}}{{item.amount_subtotal}}{{item.amount_total}}\n {{#if @root.table_config.footer.amount_tax.enable}}\n
\n {{item.full_amount_tax}}\n {{/if}}\n
\n", "type": "order_table", "updated_at": "2022-04-20T12:41:43.662Z", "updated_by": "100042"}] - getVariableContext: - speakeasy-default-get-variable-context: + application/json: [{"config": {}, "created_at": "2022-04-19T12:41:43.662Z", "created_by": "100042", "helper_logic": "return param1 * param2;", "helper_params": ["param1", "param2"], "id": "rbse777b-3cf8-4bff-bb0c-253fd1123250", "key": "my_custom_table", "name": "My Custom table", "template": "\n \n \n {{#each table_config.header.columns as |column|}}\n {{#if column.enable}}\n \n {{/if}}\n {{/each}}\n \n \n \n \n {{#each order.products as |product|}}\n {{#if @last}}\n \n {{else}}\n \n {{/if}}\n {{#each @root.table_config.header.columns as |column|}}\n {{#if column.enable}}\n {{#if (eq column.id 'item')}}\n \n \n {{/if}}\n {{#if (eq column.id 'quantity')}}\n \n \n {{/if}}\n {{#if (eq column.id 'tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'unit_amount')}}\n \n \n {{/if}}\n {{#if (eq column.id 'net_total')}}\n \n \n {{/if}}\n {{#if (eq column.id 'amount_tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'gross_total')}}\n \n \n {{/if}}\n {{/if}}\n {{/each}}\n \n {{/each}}\n \n {{#if table_config.footer.gross_total.enable}}\n {{#each order.total_details.recurrences as |item|}}\n \n \n {{#if @root.table_config.footer.payment_type.enable}}\n \n {{/if}}\n {{#if (isColumnEnabled @root.table_config 'net_total')}}\n {{#if @root.table_config.footer.net_total.enable}}\n \n {{/if}}\n {{/if}}\n \n \n {{/each}}\n {{/if}}\n \n \n
{{column._label}}
\n {{#if @root.table_config.body.product_name.enable}}\n {{product.name}}\n {{/if}}\n {{#if @root.table_config.body.price_description.enable}}\n
\n {{product.price.description}}\n {{/if}}\n {{#if @root.table_config.body.product_description.enable}}\n
\n {{product.description}}\n {{/if}}\n
{{product.price.quantity}}\n \n {{product.price.tax_rate}}\n \n {{product.price.unit_amount_net}}\n \n {{product.price.amount_subtotal}}\n \n {{product.price.amount_tax}}\n \n {{product.price.amount_total}}\n {{#if @root.table_config.body.payment_type.enable}}\n {{#if (eq product.price.type 'recurring')}}\n
\n {{product.price.billing_period}}\n {{/if}}\n {{/if}}\n
{{item.billing_period}}{{item.amount_subtotal}}{{item.amount_total}}\n {{#if @root.table_config.footer.amount_tax.enable}}\n
\n {{item.full_amount_tax}}\n {{/if}}\n
\n", "updated_at": "2022-04-20T12:41:43.662Z", "updated_by": "100042"}] + searchCustomVariables: + speakeasy-default-search-custom-variables: requestBody: - application/json: {"parameters": {"brand_id": 123451, "custom_variables": [{"value": "https://partner.epilot.cloud/activate-account?user_name=htny.pct%2Btet%40gmail.com&confirmation_code=EdXPRW19", "variable": "{{craftsmen.invitation_link}}"}, {"value": "https://partner.epilot.cloud/activate-account?user_name=htny.pct%2Btet%40gmail.com&confirmation_code=EdXPRW19", "variable": "{{craftsmen.invitation_link}}"}], "main_entity_id": "63753437-c9e2-4e83-82bb-b1c666514561", "template_type": "email", "user_id": "50001", "user_org_id": "729224", "variables_version": "2"}} + application/json: {"from": 0, "query": "logo", "size": 25, "sort_by": "created_at, name, key"} responses: "200": - application/json: {"brand": {"$ref": "#/components/examples/ExampleBrand/value"}, "contact": {"$ref": "#/components/examples/ExampleContactEntity/value"}, "main": {"$ref": "#/components/examples/ExampleMain/value"}, "unsubscribe_url": "https://consent.sls.epilot.io/v1/unsubscribe?token=abc123"} - replaceTemplates: - speakeasy-default-replace-templates: + application/json: {"hits": 100, "results": [{"config": {}, "created_at": "2022-04-19T12:41:43.662Z", "created_by": "100042", "helper_logic": "return param1 * param2;", "helper_params": ["param1", "param2"], "id": "rbse777b-3cf8-4bff-bb0c-253fd1123250", "key": "my_custom_table", "name": "My Custom table", "template": "\n \n \n {{#each table_config.header.columns as |column|}}\n {{#if column.enable}}\n \n {{/if}}\n {{/each}}\n \n \n \n \n {{#each order.products as |product|}}\n {{#if @last}}\n \n {{else}}\n \n {{/if}}\n {{#each @root.table_config.header.columns as |column|}}\n {{#if column.enable}}\n {{#if (eq column.id 'item')}}\n \n \n {{/if}}\n {{#if (eq column.id 'quantity')}}\n \n \n {{/if}}\n {{#if (eq column.id 'tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'unit_amount')}}\n \n \n {{/if}}\n {{#if (eq column.id 'net_total')}}\n \n \n {{/if}}\n {{#if (eq column.id 'amount_tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'gross_total')}}\n \n \n {{/if}}\n {{/if}}\n {{/each}}\n \n {{/each}}\n \n {{#if table_config.footer.gross_total.enable}}\n {{#each order.total_details.recurrences as |item|}}\n \n \n {{#if @root.table_config.footer.payment_type.enable}}\n \n {{/if}}\n {{#if (isColumnEnabled @root.table_config 'net_total')}}\n {{#if @root.table_config.footer.net_total.enable}}\n \n {{/if}}\n {{/if}}\n \n \n {{/each}}\n {{/if}}\n \n \n
{{column._label}}
\n {{#if @root.table_config.body.product_name.enable}}\n {{product.name}}\n {{/if}}\n {{#if @root.table_config.body.price_description.enable}}\n
\n {{product.price.description}}\n {{/if}}\n {{#if @root.table_config.body.product_description.enable}}\n
\n {{product.description}}\n {{/if}}\n
{{product.price.quantity}}\n \n {{product.price.tax_rate}}\n \n {{product.price.unit_amount_net}}\n \n {{product.price.amount_subtotal}}\n \n {{product.price.amount_tax}}\n \n {{product.price.amount_total}}\n {{#if @root.table_config.body.payment_type.enable}}\n {{#if (eq product.price.type 'recurring')}}\n
\n {{product.price.billing_period}}\n {{/if}}\n {{/if}}\n
{{item.billing_period}}{{item.amount_subtotal}}{{item.amount_total}}\n {{#if @root.table_config.footer.amount_tax.enable}}\n
\n {{item.full_amount_tax}}\n {{/if}}\n
\n", "updated_at": "2022-04-20T12:41:43.662Z", "updated_by": "100042"}]} + updateCustomVariable: + speakeasy-default-update-custom-variable: + parameters: + path: + id: "rbse777b-3cf8-4bff-bb0c-253fd1123250" requestBody: - application/json: {"inputs": ["Hello, {{contact.first_name}}!\n\n{{{brand.signature}}}\n"], "parameters": {"brand_id": 123451, "custom_variables": [{"value": "https://partner.epilot.cloud/activate-account?user_name=htny.pct%2Btet%40gmail.com&confirmation_code=EdXPRW19", "variable": "{{craftsmen.invitation_link}}"}], "main_entity_id": "63753437-c9e2-4e83-82bb-b1c666514561", "template_type": "email", "user_id": "50001", "user_org_id": "729224", "variables_version": "2"}} + application/json: {"config": {}, "helper_logic": "return param1 * param2;", "helper_params": ["param1", "param2"], "id": "rbse777b-3cf8-4bff-bb0c-253fd1123250", "key": "my_custom_table", "name": "My Custom table", "template": "\n \n \n {{#each table_config.header.columns as |column|}}\n {{#if column.enable}}\n \n {{/if}}\n {{/each}}\n \n \n \n \n {{#each order.products as |product|}}\n {{#if @last}}\n \n {{else}}\n \n {{/if}}\n {{#each @root.table_config.header.columns as |column|}}\n {{#if column.enable}}\n {{#if (eq column.id 'item')}}\n \n \n {{/if}}\n {{#if (eq column.id 'quantity')}}\n \n \n {{/if}}\n {{#if (eq column.id 'tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'unit_amount')}}\n \n \n {{/if}}\n {{#if (eq column.id 'net_total')}}\n \n \n {{/if}}\n {{#if (eq column.id 'amount_tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'gross_total')}}\n \n \n {{/if}}\n {{/if}}\n {{/each}}\n \n {{/each}}\n \n {{#if table_config.footer.gross_total.enable}}\n {{#each order.total_details.recurrences as |item|}}\n \n \n {{#if @root.table_config.footer.payment_type.enable}}\n \n {{/if}}\n {{#if (isColumnEnabled @root.table_config 'net_total')}}\n {{#if @root.table_config.footer.net_total.enable}}\n \n {{/if}}\n {{/if}}\n \n \n {{/each}}\n {{/if}}\n \n \n
{{column._label}}
\n {{#if @root.table_config.body.product_name.enable}}\n {{product.name}}\n {{/if}}\n {{#if @root.table_config.body.price_description.enable}}\n
\n {{product.price.description}}\n {{/if}}\n {{#if @root.table_config.body.product_description.enable}}\n
\n {{product.description}}\n {{/if}}\n
{{product.price.quantity}}\n \n {{product.price.tax_rate}}\n \n {{product.price.unit_amount_net}}\n \n {{product.price.amount_subtotal}}\n \n {{product.price.amount_tax}}\n \n {{product.price.amount_total}}\n {{#if @root.table_config.body.payment_type.enable}}\n {{#if (eq product.price.type 'recurring')}}\n
\n {{product.price.billing_period}}\n {{/if}}\n {{/if}}\n
{{item.billing_period}}{{item.amount_subtotal}}{{item.amount_total}}\n {{#if @root.table_config.footer.amount_tax.enable}}\n
\n {{item.full_amount_tax}}\n {{/if}}\n
\n"} responses: "200": - application/json: {"outputs": ["\"[Brand Name GmbH] Order confirmation\",\n\"Hello Customer Name\n\nBrand Name GmbH\n\"Brand\nimprint\n\"]\n"]} - searchCustomVariables: - speakeasy-default-search-custom-variables: + application/json: {"config": {}, "created_at": "2022-04-19T12:41:43.662Z", "created_by": "100042", "helper_logic": "return param1 * param2;", "helper_params": ["param1", "param2"], "id": "rbse777b-3cf8-4bff-bb0c-253fd1123250", "key": "my_custom_table", "name": "My Custom table", "template": "\n \n \n {{#each table_config.header.columns as |column|}}\n {{#if column.enable}}\n \n {{/if}}\n {{/each}}\n \n \n \n \n {{#each order.products as |product|}}\n {{#if @last}}\n \n {{else}}\n \n {{/if}}\n {{#each @root.table_config.header.columns as |column|}}\n {{#if column.enable}}\n {{#if (eq column.id 'item')}}\n \n \n {{/if}}\n {{#if (eq column.id 'quantity')}}\n \n \n {{/if}}\n {{#if (eq column.id 'tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'unit_amount')}}\n \n \n {{/if}}\n {{#if (eq column.id 'net_total')}}\n \n \n {{/if}}\n {{#if (eq column.id 'amount_tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'gross_total')}}\n \n \n {{/if}}\n {{/if}}\n {{/each}}\n \n {{/each}}\n \n {{#if table_config.footer.gross_total.enable}}\n {{#each order.total_details.recurrences as |item|}}\n \n \n {{#if @root.table_config.footer.payment_type.enable}}\n \n {{/if}}\n {{#if (isColumnEnabled @root.table_config 'net_total')}}\n {{#if @root.table_config.footer.net_total.enable}}\n \n {{/if}}\n {{/if}}\n \n \n {{/each}}\n {{/if}}\n \n \n
{{column._label}}
\n {{#if @root.table_config.body.product_name.enable}}\n {{product.name}}\n {{/if}}\n {{#if @root.table_config.body.price_description.enable}}\n
\n {{product.price.description}}\n {{/if}}\n {{#if @root.table_config.body.product_description.enable}}\n
\n {{product.description}}\n {{/if}}\n
{{product.price.quantity}}\n \n {{product.price.tax_rate}}\n \n {{product.price.unit_amount_net}}\n \n {{product.price.amount_subtotal}}\n \n {{product.price.amount_tax}}\n \n {{product.price.amount_total}}\n {{#if @root.table_config.body.payment_type.enable}}\n {{#if (eq product.price.type 'recurring')}}\n
\n {{product.price.billing_period}}\n {{/if}}\n {{/if}}\n
{{item.billing_period}}{{item.amount_subtotal}}{{item.amount_total}}\n {{#if @root.table_config.footer.amount_tax.enable}}\n
\n {{item.full_amount_tax}}\n {{/if}}\n
\n", "updated_at": "2022-04-20T12:41:43.662Z", "updated_by": "100042"} + getCategories: + speakeasy-default-get-categories: + parameters: + query: + lang: "de" + responses: + "200": + application/json: [{"category": "contact", "description": "Contact"}] + getVariableContext: + speakeasy-default-get-variable-context: requestBody: - application/json: {"query": "logo", "sort_by": "[\"created_at\",\"created_at:desc\",\"name\",\"name:desc\",\"key\"]"} + application/json: {"parameters": {"brand_id": 123451, "custom_variables": [{"value": "https://partner.epilot.cloud/activate-account?user_name=htny.pct%2Btet%40gmail.com&confirmation_code=EdXPRW19", "variable": "{{craftsmen.invitation_link}}"}], "language": "de", "main_entity_id": "63753437-c9e2-4e83-82bb-b1c666514561", "template_type": "document", "user_id": "50001", "user_org_id": "729224", "variables_version": "2"}} responses: "200": - application/json: {"hits": 100, "results": [{"created_at": "2022-04-19T12:41:43.662Z", "created_by": "100042", "helper_logic": "return param1 * param2;", "helper_params": ["param1", "param2"], "id": "rbse777b-3cf8-4bff-bb0c-253fd1123250", "key": "my_custom_table", "name": "My Custom table", "template": "\n \n \n {{#each table_config.header.columns as |column|}}\n {{#if column.enable}}\n \n {{/if}}\n {{/each}}\n \n \n \n \n {{#each order.products as |product|}}\n {{#if @last}}\n \n {{else}}\n \n {{/if}}\n {{#each @root.table_config.header.columns as |column|}}\n {{#if column.enable}}\n {{#if (eq column.id 'item')}}\n \n \n {{/if}}\n {{#if (eq column.id 'quantity')}}\n \n \n {{/if}}\n {{#if (eq column.id 'tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'unit_amount')}}\n \n \n {{/if}}\n {{#if (eq column.id 'net_total')}}\n \n \n {{/if}}\n {{#if (eq column.id 'amount_tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'gross_total')}}\n \n \n {{/if}}\n {{/if}}\n {{/each}}\n \n {{/each}}\n \n {{#if table_config.footer.gross_total.enable}}\n {{#each order.total_details.recurrences as |item|}}\n \n \n {{#if @root.table_config.footer.payment_type.enable}}\n \n {{/if}}\n {{#if (isColumnEnabled @root.table_config 'net_total')}}\n {{#if @root.table_config.footer.net_total.enable}}\n \n {{/if}}\n {{/if}}\n \n \n {{/each}}\n {{/if}}\n \n \n
{{column._label}}
\n {{#if @root.table_config.body.product_name.enable}}\n {{product.name}}\n {{/if}}\n {{#if @root.table_config.body.price_description.enable}}\n
\n {{product.price.description}}\n {{/if}}\n {{#if @root.table_config.body.product_description.enable}}\n
\n {{product.description}}\n {{/if}}\n
{{product.price.quantity}}\n \n {{product.price.tax_rate}}\n \n {{product.price.unit_amount_net}}\n \n {{product.price.amount_subtotal}}\n \n {{product.price.amount_tax}}\n \n {{product.price.amount_total}}\n {{#if @root.table_config.body.payment_type.enable}}\n {{#if (eq product.price.type 'recurring')}}\n
\n {{product.price.billing_period}}\n {{/if}}\n {{/if}}\n
{{item.billing_period}}{{item.amount_subtotal}}{{item.amount_total}}\n {{#if @root.table_config.footer.amount_tax.enable}}\n
\n {{item.full_amount_tax}}\n {{/if}}\n
\n", "type": "custom", "updated_at": "2022-04-20T12:41:43.662Z", "updated_by": "100042"}, {"created_at": "2022-04-19T12:41:43.662Z", "created_by": "100042", "helper_logic": "return param1 * param2;", "helper_params": ["param1", "param2"], "id": "rbse777b-3cf8-4bff-bb0c-253fd1123250", "key": "my_custom_table", "name": "My Custom table", "template": "\n \n \n {{#each table_config.header.columns as |column|}}\n {{#if column.enable}}\n \n {{/if}}\n {{/each}}\n \n \n \n \n {{#each order.products as |product|}}\n {{#if @last}}\n \n {{else}}\n \n {{/if}}\n {{#each @root.table_config.header.columns as |column|}}\n {{#if column.enable}}\n {{#if (eq column.id 'item')}}\n \n \n {{/if}}\n {{#if (eq column.id 'quantity')}}\n \n \n {{/if}}\n {{#if (eq column.id 'tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'unit_amount')}}\n \n \n {{/if}}\n {{#if (eq column.id 'net_total')}}\n \n \n {{/if}}\n {{#if (eq column.id 'amount_tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'gross_total')}}\n \n \n {{/if}}\n {{/if}}\n {{/each}}\n \n {{/each}}\n \n {{#if table_config.footer.gross_total.enable}}\n {{#each order.total_details.recurrences as |item|}}\n \n \n {{#if @root.table_config.footer.payment_type.enable}}\n \n {{/if}}\n {{#if (isColumnEnabled @root.table_config 'net_total')}}\n {{#if @root.table_config.footer.net_total.enable}}\n \n {{/if}}\n {{/if}}\n \n \n {{/each}}\n {{/if}}\n \n \n
{{column._label}}
\n {{#if @root.table_config.body.product_name.enable}}\n {{product.name}}\n {{/if}}\n {{#if @root.table_config.body.price_description.enable}}\n
\n {{product.price.description}}\n {{/if}}\n {{#if @root.table_config.body.product_description.enable}}\n
\n {{product.description}}\n {{/if}}\n
{{product.price.quantity}}\n \n {{product.price.tax_rate}}\n \n {{product.price.unit_amount_net}}\n \n {{product.price.amount_subtotal}}\n \n {{product.price.amount_tax}}\n \n {{product.price.amount_total}}\n {{#if @root.table_config.body.payment_type.enable}}\n {{#if (eq product.price.type 'recurring')}}\n
\n {{product.price.billing_period}}\n {{/if}}\n {{/if}}\n
{{item.billing_period}}{{item.amount_subtotal}}{{item.amount_total}}\n {{#if @root.table_config.footer.amount_tax.enable}}\n
\n {{item.full_amount_tax}}\n {{/if}}\n
\n", "type": "custom", "updated_at": "2022-04-20T12:41:43.662Z", "updated_by": "100042"}]} - searchVariables: - "": + application/json: {"brand": {"id": 123453, "name": "Brand name", "signature": "Signature"}, "contact": {"_id": "03be777b-3cf8-4bff-bb0c-253fd1128479", "_title": "Example Customer", "customer_number": 123, "first_name": "Example", "last_name": "Customer", "title": "Prof.", "salutation": "Ms. / Mrs.", "birthdate": "2018-03-03", "email": [{"email": "contact.primary@domain.com", "_tags": ["primary"]}, {"email": "sale@domain.com"}], "phone": [{"phone": "+49123456789", "_tags": ["primary", "support"]}, {"phone": "+49504305025"}], "address": [{"_tags": ["primary", "delivery"], "country": "Germany", "city": "Köln", "postal_code": "50825", "street": "Im Mediapark", "street_number": "8a", "additional_info": "11th floor"}, {"_tags": ["billing"], "country": "Finland", "city": "Köln", "postal_code": "50670", "street": "Im Mediapark", "street_number": "8a", "additional_info": ""}], "account": [{"status": "Active", "_id": "c8d20ff6-df7a-465a-a26e-e5d28c2a3f79", "tax_id": "123abc", "name": "name", "email": [{"email": "account.primary@domain.com", "_tags": ["primary"]}, {"email": "account.sale@domain.com"}], "phone": [{"phone": "+49123456789", "_tags": ["primary", "support"]}, {"phone": "+49504305025"}], "address": [{"_tags": ["primary", "delivery"], "country": "Germany", "city": "KölnSS", "postal_code": "50825", "street": "Im Mediapark", "street_number": "8a", "additional_info": "11th floor"}]}]}, "main": {"_id": "03be777b-3cf8-4bff-bb0c-253fd1128479", "_title": "Example Customer", "customer_number": 123, "first_name": "Example", "last_name": "Customer", "title": "Prof.", "salutation": "Ms. / Mrs.", "birthdate": "2018-03-03", "email": [{"email": "contact.primary@domain.com", "_tags": ["primary"]}, {"email": "sale@domain.com"}], "phone": [{"phone": "+49123456789", "_tags": ["primary", "support"]}, {"phone": "+49504305025"}], "address": [{"_tags": ["primary", "delivery"], "country": "Germany", "city": "Köln", "postal_code": "50825", "street": "Im Mediapark", "street_number": "8a", "additional_info": "11th floor"}, {"_tags": ["billing"], "country": "Finland", "city": "Köln", "postal_code": "50670", "street": "Im Mediapark", "street_number": "8a", "additional_info": ""}], "account": [{"status": "Active", "_id": "c8d20ff6-df7a-465a-a26e-e5d28c2a3f79", "tax_id": "123abc", "name": "name", "email": [{"email": "account.primary@domain.com", "_tags": ["primary"]}, {"email": "account.sale@domain.com"}], "phone": [{"phone": "+49123456789", "_tags": ["primary", "support"]}, {"phone": "+49504305025"}], "address": [{"_tags": ["primary", "delivery"], "country": "Germany", "city": "Köln", "postal_code": "50825", "street": "Im Mediapark", "street_number": "8a", "additional_info": "11th floor"}]}]}, "unsubscribe_url": "https://consent.sls.epilot.io/v1/unsubscribe?token=abc123"} + replaceTemplates: + speakeasy-default-replace-templates: requestBody: - application/json: {"entity_schemas": ["contact"], "query": "logo", "template_type": "document"} + application/json: {"inputs": ["Hello, {{contact.first_name}}!\n\n{{{brand.signature}}}\n"], "parameters": {"brand_id": 123451, "custom_variables": [{"value": "https://partner.epilot.cloud/activate-account?user_name=htny.pct%2Btet%40gmail.com&confirmation_code=EdXPRW19", "variable": "{{craftsmen.invitation_link}}"}], "language": "de", "main_entity_id": "63753437-c9e2-4e83-82bb-b1c666514561", "template_type": "email", "user_id": "50001", "user_org_id": "729224", "variables_version": "2"}} responses: "200": - application/json: [{"description": "Company name", "group": "Personal Details", "insert": "{{account.name}}", "type": "simple"}, {"description": "Tax ID", "group": "Personal Details", "insert": "{{account.tax_id}}", "type": "simple"}, {"description": "Address Details", "group": "Address details", "qrdata": "{{account.address_details}}", "type": "partial"}, {"description": "Address - Street name", "group": "Address Details", "insert": "{{account.address.street}}", "type": "simple"}, {"description": "Address - Street number", "group": "Address Details", "insert": "{{account.address.street_number}}", "type": "simple"}, {"description": "Address - Postal code", "group": "Address Details", "insert": "{{account.address.postal_code}}", "type": "simple"}, {"description": "Address - City", "group": "Address Details", "insert": "{{account.address.city}}", "type": "simple"}] - updateCustomVariable: - "": - parameters: - path: - id: "rbse777b-3cf8-4bff-bb0c-253fd1123250" + application/json: {"outputs": ["[Brand Name GmbH] Order confirmation\nHello Customer Name\n\nBrand Name GmbH\n\"Brand\nimprint\n"]} + searchVariables: + speakeasy-default-search-variables: requestBody: - application/json: {"created_at": "2022-04-19T12:41:43.662Z", "created_by": "100042", "helper_logic": "return param1 * param2;", "helper_params": ["param1", "param2"], "id": "rbse777b-3cf8-4bff-bb0c-253fd1123250", "key": "my_custom_table", "name": "My Custom table", "template": "\n \n \n {{#each table_config.header.columns as |column|}}\n {{#if column.enable}}\n \n {{/if}}\n {{/each}}\n \n \n \n \n {{#each order.products as |product|}}\n {{#if @last}}\n \n {{else}}\n \n {{/if}}\n {{#each @root.table_config.header.columns as |column|}}\n {{#if column.enable}}\n {{#if (eq column.id 'item')}}\n \n \n {{/if}}\n {{#if (eq column.id 'quantity')}}\n \n \n {{/if}}\n {{#if (eq column.id 'tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'unit_amount')}}\n \n \n {{/if}}\n {{#if (eq column.id 'net_total')}}\n \n \n {{/if}}\n {{#if (eq column.id 'amount_tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'gross_total')}}\n \n \n {{/if}}\n {{/if}}\n {{/each}}\n \n {{/each}}\n \n {{#if table_config.footer.gross_total.enable}}\n {{#each order.total_details.recurrences as |item|}}\n \n \n {{#if @root.table_config.footer.payment_type.enable}}\n \n {{/if}}\n {{#if (isColumnEnabled @root.table_config 'net_total')}}\n {{#if @root.table_config.footer.net_total.enable}}\n \n {{/if}}\n {{/if}}\n \n \n {{/each}}\n {{/if}}\n \n \n
{{column._label}}
\n {{#if @root.table_config.body.product_name.enable}}\n {{product.name}}\n {{/if}}\n {{#if @root.table_config.body.price_description.enable}}\n
\n {{product.price.description}}\n {{/if}}\n {{#if @root.table_config.body.product_description.enable}}\n
\n {{product.description}}\n {{/if}}\n
{{product.price.quantity}}\n \n {{product.price.tax_rate}}\n \n {{product.price.unit_amount_net}}\n \n {{product.price.amount_subtotal}}\n \n {{product.price.amount_tax}}\n \n {{product.price.amount_total}}\n {{#if @root.table_config.body.payment_type.enable}}\n {{#if (eq product.price.type 'recurring')}}\n
\n {{product.price.billing_period}}\n {{/if}}\n {{/if}}\n
{{item.billing_period}}{{item.amount_subtotal}}{{item.amount_total}}\n {{#if @root.table_config.footer.amount_tax.enable}}\n
\n {{item.full_amount_tax}}\n {{/if}}\n
\n", "type": "custom", "updated_at": "2022-04-20T12:41:43.662Z", "updated_by": "100042"} + application/json: {"entity_schemas": ["contact"], "from": 0, "lang": "de", "query": "logo", "size": 25, "template_type": "document"} responses: "200": - application/json: {"created_at": "2022-04-19T12:41:43.662Z", "created_by": "100042", "helper_logic": "return param1 * param2;", "helper_params": ["param1", "param2"], "id": "rbse777b-3cf8-4bff-bb0c-253fd1123250", "key": "my_custom_table", "name": "My Custom table", "template": "\n \n \n {{#each table_config.header.columns as |column|}}\n {{#if column.enable}}\n \n {{/if}}\n {{/each}}\n \n \n \n \n {{#each order.products as |product|}}\n {{#if @last}}\n \n {{else}}\n \n {{/if}}\n {{#each @root.table_config.header.columns as |column|}}\n {{#if column.enable}}\n {{#if (eq column.id 'item')}}\n \n \n {{/if}}\n {{#if (eq column.id 'quantity')}}\n \n \n {{/if}}\n {{#if (eq column.id 'tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'unit_amount')}}\n \n \n {{/if}}\n {{#if (eq column.id 'net_total')}}\n \n \n {{/if}}\n {{#if (eq column.id 'amount_tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'gross_total')}}\n \n \n {{/if}}\n {{/if}}\n {{/each}}\n \n {{/each}}\n \n {{#if table_config.footer.gross_total.enable}}\n {{#each order.total_details.recurrences as |item|}}\n \n \n {{#if @root.table_config.footer.payment_type.enable}}\n \n {{/if}}\n {{#if (isColumnEnabled @root.table_config 'net_total')}}\n {{#if @root.table_config.footer.net_total.enable}}\n \n {{/if}}\n {{/if}}\n \n \n {{/each}}\n {{/if}}\n \n \n
{{column._label}}
\n {{#if @root.table_config.body.product_name.enable}}\n {{product.name}}\n {{/if}}\n {{#if @root.table_config.body.price_description.enable}}\n
\n {{product.price.description}}\n {{/if}}\n {{#if @root.table_config.body.product_description.enable}}\n
\n {{product.description}}\n {{/if}}\n
{{product.price.quantity}}\n \n {{product.price.tax_rate}}\n \n {{product.price.unit_amount_net}}\n \n {{product.price.amount_subtotal}}\n \n {{product.price.amount_tax}}\n \n {{product.price.amount_total}}\n {{#if @root.table_config.body.payment_type.enable}}\n {{#if (eq product.price.type 'recurring')}}\n
\n {{product.price.billing_period}}\n {{/if}}\n {{/if}}\n
{{item.billing_period}}{{item.amount_subtotal}}{{item.amount_total}}\n {{#if @root.table_config.footer.amount_tax.enable}}\n
\n {{item.full_amount_tax}}\n {{/if}}\n
\n", "updated_at": "2022-04-20T12:41:43.662Z", "updated_by": "100042"} + application/json: [{}] +examplesVersion: 1.0.2 generatedTests: {} diff --git a/.speakeasy/workflow.lock b/.speakeasy/workflow.lock new file mode 100644 index 0000000..2334d2d --- /dev/null +++ b/.speakeasy/workflow.lock @@ -0,0 +1,29 @@ +speakeasyVersion: 1.645.2 +sources: + my-source: + sourceNamespace: my-source + sourceRevisionDigest: sha256:c1120ccdc94f03b3d3a7368ac6d99fdd6130e9583fb365c6958e28f565f586bd + sourceBlobDigest: sha256:73eb5dc30fe708b6736df3fba0f0a4560d0fba349e723028483bb16c8f4c4dc4 + tags: + - latest + - speakeasy-sdk-regen-1758760432 + - 1.0.0 +targets: + terraform: + source: my-source + sourceNamespace: my-source + sourceRevisionDigest: sha256:c1120ccdc94f03b3d3a7368ac6d99fdd6130e9583fb365c6958e28f565f586bd + sourceBlobDigest: sha256:73eb5dc30fe708b6736df3fba0f0a4560d0fba349e723028483bb16c8f4c4dc4 +workflow: + workflowVersion: 1.0.0 + speakeasyVersion: latest + sources: + my-source: + inputs: + - location: https://docs.api.epilot.io/template-variables.yaml + registry: + location: registry.speakeasyapi.dev/epilot/epilot/my-source + targets: + terraform: + target: terraform + source: my-source diff --git a/.speakeasy/workflow.yaml b/.speakeasy/workflow.yaml index 00162b9..3e7820a 100644 --- a/.speakeasy/workflow.yaml +++ b/.speakeasy/workflow.yaml @@ -1,8 +1,11 @@ workflowVersion: 1.0.0 +speakeasyVersion: latest sources: my-source: inputs: - location: https://docs.api.epilot.io/template-variables.yaml + registry: + location: registry.speakeasyapi.dev/epilot/epilot/my-source targets: terraform: target: terraform diff --git a/README.md b/README.md index 7b83e59..32cd49a 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ Template Variables API: API to provide variables for email and document template * [epilot-custom-variable](#epilot-custom-variable) * [🏗 **Welcome to your new Terraform Provider!** 🏗](#welcome-to-your-new-terraform-provider) * [Installation](#installation) + * [Authentication](#authentication) * [Available Resources and Data Sources](#available-resources-and-data-sources) * [Testing the provider locally](#testing-the-provider-locally) * [Development](#development) @@ -47,7 +48,7 @@ terraform { required_providers { epilot-custom-variable = { source = "epilot-dev/epilot-custom-variable" - version = "1.2.0" + version = "1.3.0" } } } @@ -58,15 +59,25 @@ provider "epilot-custom-variable" { ``` + +## Authentication + +This provider supports authentication configuration via provider configuration. + +Available configuration: + +| Provider Attribute | Description | +|---|---| +| `epilot_auth` | Authorization header with epilot OAuth2 bearer token. | +| `epilot_org` | Overrides the target organization. | + + ## Available Resources and Data Sources ### Resources -* [epilot-custom-variable_custom_variable](docs/resources/custom_variable.md) ### Data Sources - -* [epilot-custom-variable_custom_variable](docs/data-sources/custom_variable.md) diff --git a/RELEASES.md b/RELEASES.md index f4a2be8..f13e4c2 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -14,4 +14,14 @@ Based on: - OpenAPI Doc 1.0.0 - Speakeasy CLI 1.147.0 (2.237.2) https://github.com/speakeasy-api/speakeasy ### Generated -- [terraform v0.4.4] . \ No newline at end of file +- [terraform v0.4.4] . + +## 2025-11-03 00:36:40 +### Changes +Based on: +- OpenAPI Doc +- Speakeasy CLI 1.645.2 (2.735.1) https://github.com/speakeasy-api/speakeasy +### Generated +- [terraform v1.3.0] . +### Releases +- [Terraform v1.3.0] https://registry.terraform.io/providers/epilot-dev/epilot-custom-variable/1.3.0 - . \ No newline at end of file diff --git a/docs/data-sources/custom_variable.md b/docs/data-sources/custom_variable.md deleted file mode 100644 index 9b1db09..0000000 --- a/docs/data-sources/custom_variable.md +++ /dev/null @@ -1,41 +0,0 @@ ---- -# generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "epilot-custom-variable_custom_variable Data Source - terraform-provider-epilot-custom-variable" -subcategory: "" -description: |- - CustomVariable DataSource ---- - -# epilot-custom-variable_custom_variable (Data Source) - -CustomVariable DataSource - -## Example Usage - -```terraform -data "epilot-custom-variable_custom_variable" "my_customvariable" { - id = "rbse777b-3cf8-4bff-bb0c-253fd1123250" -} -``` - - -## Schema - -### Required - -- `id` (String) Custom vairable ID - -### Read-Only - -- `config` (String) Parsed as JSON. -- `created_at` (String) Creation time -- `created_by` (String) Created by -- `helper_logic` (String) The helper function logic -- `helper_params` (List of String) The helper function parameter's names -- `key` (String) The key which is used for Handlebar variable syntax {{"{{"}}key{{"}}"}} -- `name` (String) Custom variable name -- `tags` (List of String) The tags of custom variable -- `template` (String) Handlebar template that used to generate the variable content -- `type` (String) Custom variable type -- `updated_at` (String) Last update time -- `updated_by` (String) Updated by diff --git a/docs/index.md b/docs/index.md index d37ad7a..15d66eb 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,7 +1,6 @@ --- # generated by https://github.com/hashicorp/terraform-plugin-docs page_title: "epilot-custom-variable Provider" -subcategory: "" description: |- Template Variables API: API to provide variables for email and document templates. --- @@ -17,7 +16,7 @@ terraform { required_providers { epilot-custom-variable = { source = "epilot-dev/epilot-custom-variable" - version = "1.2.0" + version = "1.3.0" } } } @@ -32,6 +31,6 @@ provider "epilot-custom-variable" { ### Optional -- `epilot_auth` (String, Sensitive) -- `epilot_org` (String, Sensitive) +- `epilot_auth` (String, Sensitive) Authorization header with epilot OAuth2 bearer token. +- `epilot_org` (String, Sensitive) Overrides the target organization. - `server_url` (String) Server URL (defaults to https://template-variables-api.sls.epilot.io) diff --git a/docs/resources/custom_variable.md b/docs/resources/custom_variable.md deleted file mode 100644 index b5b7f09..0000000 --- a/docs/resources/custom_variable.md +++ /dev/null @@ -1,62 +0,0 @@ ---- -# generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "epilot-custom-variable_custom_variable Resource - terraform-provider-epilot-custom-variable" -subcategory: "" -description: |- - CustomVariable Resource ---- - -# epilot-custom-variable_custom_variable (Resource) - -CustomVariable Resource - -## Example Usage - -```terraform -resource "epilot-custom-variable_custom_variable" "my_customvariable" { - config = "{ \"see\": \"documentation\" }" - created_at = "2022-04-19T12:41:43.662Z" - created_by = 100042 - helper_logic = "return param1 * param2;" - helper_params = [ - "..." - ] - id = "rbse777b-3cf8-4bff-bb0c-253fd1123250" - key = "my_custom_table" - name = "My Custom table" - tags = [ - "..." - ] - template = "\n \n \n {{#each table_config.header.columns as |column|}}\n {{#if column.enable}}\n \n {{/if}}\n {{/each}}\n \n \n \n \n {{#each order.products as |product|}}\n {{#if @last}}\n \n {{else}}\n \n {{/if}}\n {{#each @root.table_config.header.columns as |column|}}\n {{#if column.enable}}\n {{#if (eq column.id 'item')}}\n \n \n {{/if}}\n {{#if (eq column.id 'quantity')}}\n \n \n {{/if}}\n {{#if (eq column.id 'tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'unit_amount')}}\n \n \n {{/if}}\n {{#if (eq column.id 'net_total')}}\n \n \n {{/if}}\n {{#if (eq column.id 'amount_tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'gross_total')}}\n \n \n {{/if}}\n {{/if}}\n {{/each}}\n \n {{/each}}\n \n {{#if table_config.footer.gross_total.enable}}\n {{#each order.total_details.recurrences as |item|}}\n \n \n {{#if @root.table_config.footer.payment_type.enable}}\n \n {{/if}}\n {{#if (isColumnEnabled @root.table_config 'net_total')}}\n {{#if @root.table_config.footer.net_total.enable}}\n \n {{/if}}\n {{/if}}\n \n \n {{/each}}\n {{/if}}\n \n \n
{{column._label}}
\n {{#if @root.table_config.body.product_name.enable}}\n {{product.name}}\n {{/if}}\n {{#if @root.table_config.body.price_description.enable}}\n
\n {{product.price.description}}\n {{/if}}\n {{#if @root.table_config.body.product_description.enable}}\n
\n {{product.description}}\n {{/if}}\n
{{product.price.quantity}}\n \n {{product.price.tax_rate}}\n \n {{product.price.unit_amount_net}}\n \n {{product.price.amount_subtotal}}\n \n {{product.price.amount_tax}}\n \n {{product.price.amount_total}}\n {{#if @root.table_config.body.payment_type.enable}}\n {{#if (eq product.price.type 'recurring')}}\n
\n {{product.price.billing_period}}\n {{/if}}\n {{/if}}\n
{{item.billing_period}}{{item.amount_subtotal}}{{item.amount_total}}\n {{#if @root.table_config.footer.amount_tax.enable}}\n
\n {{item.full_amount_tax}}\n {{/if}}\n
\n" - type = "custom" - updated_at = "2022-04-20T12:41:43.662Z" - updated_by = 100042 -} -``` - - -## Schema - -### Optional - -- `config` (String) Parsed as JSON. -- `created_at` (String) Creation time -- `created_by` (String) Created by -- `helper_logic` (String) The helper function logic -- `helper_params` (List of String) The helper function parameter's names -- `id` (String) ID -- `key` (String) The key which is used for Handlebar variable syntax {{"{{"}}key{{"}}"}} -- `name` (String) Custom variable name -- `tags` (List of String) The tags of custom variable -- `template` (String) Handlebar template that used to generate the variable content -- `type` (String) Custom variable type. must be one of ["order_table", "custom", "journey_link"] -- `updated_at` (String) Last update time -- `updated_by` (String) Updated by - -## Import - -Import is supported using the following syntax: - -```shell -terraform import epilot-custom-variable_custom_variable.my_epilot-custom-variable_custom_variable "rbse777b-3cf8-4bff-bb0c-253fd1123250" -``` diff --git a/examples/README.md b/examples/README.md deleted file mode 100644 index f87f5c1..0000000 --- a/examples/README.md +++ /dev/null @@ -1 +0,0 @@ -# TODO \ No newline at end of file diff --git a/examples/data-sources/epilot-custom-variable_custom_variable/data-source.tf b/examples/data-sources/epilot-custom-variable_custom_variable/data-source.tf deleted file mode 100644 index 0289a55..0000000 --- a/examples/data-sources/epilot-custom-variable_custom_variable/data-source.tf +++ /dev/null @@ -1,3 +0,0 @@ -data "epilot-custom-variable_custom_variable" "my_customvariable" { - id = "rbse777b-3cf8-4bff-bb0c-253fd1123250" -} \ No newline at end of file diff --git a/examples/provider/provider.tf b/examples/provider/provider.tf index b1774a6..b00335c 100644 --- a/examples/provider/provider.tf +++ b/examples/provider/provider.tf @@ -2,7 +2,7 @@ terraform { required_providers { epilot-custom-variable = { source = "epilot-dev/epilot-custom-variable" - version = "1.2.0" + version = "1.3.0" } } } diff --git a/examples/resources/epilot-custom-variable_custom_variable/import.sh b/examples/resources/epilot-custom-variable_custom_variable/import.sh deleted file mode 100644 index cc2311a..0000000 --- a/examples/resources/epilot-custom-variable_custom_variable/import.sh +++ /dev/null @@ -1 +0,0 @@ -terraform import epilot-custom-variable_custom_variable.my_epilot-custom-variable_custom_variable "rbse777b-3cf8-4bff-bb0c-253fd1123250" diff --git a/examples/resources/epilot-custom-variable_custom_variable/resource.tf b/examples/resources/epilot-custom-variable_custom_variable/resource.tf deleted file mode 100644 index b3f9b01..0000000 --- a/examples/resources/epilot-custom-variable_custom_variable/resource.tf +++ /dev/null @@ -1,19 +0,0 @@ -resource "epilot-custom-variable_custom_variable" "my_customvariable" { - config = "{ \"see\": \"documentation\" }" - created_at = "2022-04-19T12:41:43.662Z" - created_by = 100042 - helper_logic = "return param1 * param2;" - helper_params = [ - "..." - ] - id = "rbse777b-3cf8-4bff-bb0c-253fd1123250" - key = "my_custom_table" - name = "My Custom table" - tags = [ - "..." - ] - template = "\n \n \n {{#each table_config.header.columns as |column|}}\n {{#if column.enable}}\n \n {{/if}}\n {{/each}}\n \n \n \n \n {{#each order.products as |product|}}\n {{#if @last}}\n \n {{else}}\n \n {{/if}}\n {{#each @root.table_config.header.columns as |column|}}\n {{#if column.enable}}\n {{#if (eq column.id 'item')}}\n \n \n {{/if}}\n {{#if (eq column.id 'quantity')}}\n \n \n {{/if}}\n {{#if (eq column.id 'tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'unit_amount')}}\n \n \n {{/if}}\n {{#if (eq column.id 'net_total')}}\n \n \n {{/if}}\n {{#if (eq column.id 'amount_tax')}}\n \n \n {{/if}}\n {{#if (eq column.id 'gross_total')}}\n \n \n {{/if}}\n {{/if}}\n {{/each}}\n \n {{/each}}\n \n {{#if table_config.footer.gross_total.enable}}\n {{#each order.total_details.recurrences as |item|}}\n \n \n {{#if @root.table_config.footer.payment_type.enable}}\n \n {{/if}}\n {{#if (isColumnEnabled @root.table_config 'net_total')}}\n {{#if @root.table_config.footer.net_total.enable}}\n \n {{/if}}\n {{/if}}\n \n \n {{/each}}\n {{/if}}\n \n \n
{{column._label}}
\n {{#if @root.table_config.body.product_name.enable}}\n {{product.name}}\n {{/if}}\n {{#if @root.table_config.body.price_description.enable}}\n
\n {{product.price.description}}\n {{/if}}\n {{#if @root.table_config.body.product_description.enable}}\n
\n {{product.description}}\n {{/if}}\n
{{product.price.quantity}}\n \n {{product.price.tax_rate}}\n \n {{product.price.unit_amount_net}}\n \n {{product.price.amount_subtotal}}\n \n {{product.price.amount_tax}}\n \n {{product.price.amount_total}}\n {{#if @root.table_config.body.payment_type.enable}}\n {{#if (eq product.price.type 'recurring')}}\n
\n {{product.price.billing_period}}\n {{/if}}\n {{/if}}\n
{{item.billing_period}}{{item.amount_subtotal}}{{item.amount_total}}\n {{#if @root.table_config.footer.amount_tax.enable}}\n
\n {{item.full_amount_tax}}\n {{/if}}\n
\n" - type = "custom" - updated_at = "2022-04-20T12:41:43.662Z" - updated_by = 100042 -} \ No newline at end of file diff --git a/gen.yaml b/gen.yaml index decfeea..3694d0f 100644 --- a/gen.yaml +++ b/gen.yaml @@ -4,22 +4,37 @@ generation: sdkClassName: SDK usageSnippets: optionalPropertyRendering: withExample + sdkInitStyle: constructor fixes: - nameResolutionDec2023: false + nameResolutionFeb2025: false parameterOrderingFeb2024: false requestResponseComponentNamesFeb2024: false + securityFeb2025: false + sharedErrorComponentsApr2025: false auth: oAuth2ClientCredentialsEnabled: false oAuth2PasswordEnabled: false + hoistGlobalSecurity: true + schemas: + allOfMergeStrategy: shallowMerge + tests: + generateTests: true + generateNewTests: false + skipResponseBodyAssertions: false sdkFlattening: true telemetryEnabled: false terraform: - version: 1.2.0 + version: 1.3.0 additionalDataSources: [] additionalDependencies: {} + additionalEphemeralResources: [] + additionalProviderAttributes: + httpHeaders: "" + tlsSkipVerify: "" additionalResources: [] allowUnknownFieldsInWeakUnions: false author: epilot-dev + baseErrorName: SDKBaseError defaultErrorName: SDKError enableTypeDeduplication: true environmentVariables: [] @@ -31,6 +46,8 @@ terraform: operations: operations shared: shared webhooks: webhooks + includeEmptyObjects: false inputModelSuffix: input outputModelSuffix: output packageName: epilot-custom-variable + unionDeserializationStrategy: populated-fields diff --git a/go.mod b/go.mod index 9298687..297ad57 100644 --- a/go.mod +++ b/go.mod @@ -1,15 +1,15 @@ module github.com/epilot-dev/terraform-provider-epilot-custom-variable -go 1.22.0 +go 1.23.7 require ( - github.com/ericlagergren/decimal v0.0.0-20221120152707-495c53812d05 github.com/hashicorp/go-uuid v1.0.3 - github.com/hashicorp/terraform-plugin-docs v0.19.4 - github.com/hashicorp/terraform-plugin-framework v1.12.0 - github.com/hashicorp/terraform-plugin-framework-validators v0.13.0 - github.com/hashicorp/terraform-plugin-go v0.24.0 + github.com/hashicorp/terraform-plugin-docs v0.22.0 + github.com/hashicorp/terraform-plugin-framework v1.15.1 + github.com/hashicorp/terraform-plugin-framework-validators v0.18.0 + github.com/hashicorp/terraform-plugin-go v0.28.0 github.com/hashicorp/terraform-plugin-log v0.9.0 + github.com/stretchr/testify v1.8.3 ) require ( @@ -18,56 +18,59 @@ require ( github.com/Masterminds/goutils v1.1.1 // indirect github.com/Masterminds/semver/v3 v3.2.0 // indirect github.com/Masterminds/sprig/v3 v3.2.3 // indirect - github.com/ProtonMail/go-crypto v1.1.0-alpha.2 // indirect + github.com/ProtonMail/go-crypto v1.1.6 // indirect github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect github.com/armon/go-radix v1.0.0 // indirect github.com/bgentry/speakeasy v0.1.0 // indirect - github.com/bmatcuk/doublestar/v4 v4.6.1 // indirect - github.com/cloudflare/circl v1.3.7 // indirect + github.com/bmatcuk/doublestar/v4 v4.8.1 // indirect + github.com/cloudflare/circl v1.6.1 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect github.com/fatih/color v1.16.0 // indirect github.com/golang/protobuf v1.5.4 // indirect github.com/google/uuid v1.6.0 // indirect - github.com/hashicorp/cli v1.1.6 // indirect + github.com/hashicorp/cli v1.1.7 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-checkpoint v0.5.0 // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect - github.com/hashicorp/go-hclog v1.5.0 // indirect + github.com/hashicorp/go-hclog v1.6.3 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect - github.com/hashicorp/go-plugin v1.6.1 // indirect + github.com/hashicorp/go-plugin v1.6.3 // indirect + github.com/hashicorp/go-retryablehttp v0.7.7 // indirect github.com/hashicorp/go-version v1.7.0 // indirect - github.com/hashicorp/hc-install v0.7.0 // indirect - github.com/hashicorp/terraform-exec v0.21.0 // indirect - github.com/hashicorp/terraform-json v0.22.1 // indirect - github.com/hashicorp/terraform-registry-address v0.2.3 // indirect + github.com/hashicorp/hc-install v0.9.2 // indirect + github.com/hashicorp/terraform-exec v0.23.0 // indirect + github.com/hashicorp/terraform-json v0.25.0 // indirect + github.com/hashicorp/terraform-registry-address v0.2.5 // indirect github.com/hashicorp/terraform-svchost v0.1.1 // indirect github.com/hashicorp/yamux v0.1.1 // indirect github.com/huandu/xstrings v1.3.3 // indirect github.com/imdario/mergo v0.3.15 // indirect - github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.9 // indirect github.com/mitchellh/copystructure v1.2.0 // indirect github.com/mitchellh/go-testing-interface v1.14.1 // indirect github.com/mitchellh/reflectwalk v1.0.2 // indirect github.com/oklog/run v1.0.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect github.com/posener/complete v1.2.3 // indirect github.com/shopspring/decimal v1.3.1 // indirect github.com/spf13/cast v1.5.0 // indirect github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect - github.com/yuin/goldmark v1.7.1 // indirect + github.com/yuin/goldmark v1.7.7 // indirect github.com/yuin/goldmark-meta v1.1.0 // indirect - github.com/zclconf/go-cty v1.14.4 // indirect + github.com/zclconf/go-cty v1.16.3 // indirect go.abhg.dev/goldmark/frontmatter v0.2.0 // indirect - golang.org/x/crypto v0.24.0 // indirect + golang.org/x/crypto v0.38.0 // indirect golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect - golang.org/x/mod v0.17.0 // indirect - golang.org/x/net v0.26.0 // indirect - golang.org/x/sys v0.21.0 // indirect - golang.org/x/text v0.16.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 // indirect - google.golang.org/grpc v1.66.2 // indirect - google.golang.org/protobuf v1.34.2 // indirect + golang.org/x/mod v0.25.0 // indirect + golang.org/x/net v0.39.0 // indirect + golang.org/x/sys v0.33.0 // indirect + golang.org/x/text v0.26.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20250218202821-56aae31c358a // indirect + google.golang.org/grpc v1.72.1 // indirect + google.golang.org/protobuf v1.36.6 // indirect gopkg.in/yaml.v2 v2.3.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 762ad5a..e91839d 100644 --- a/go.sum +++ b/go.sum @@ -10,31 +10,29 @@ github.com/Masterminds/semver/v3 v3.2.0 h1:3MEsd0SM6jqZojhjLWWeBY+Kcjy9i6MQAeY7Y github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= github.com/Masterminds/sprig/v3 v3.2.3 h1:eL2fZNezLomi0uOLqjQoN6BfsDD+fyLtgbJMAj9n6YA= github.com/Masterminds/sprig/v3 v3.2.3/go.mod h1:rXcFaZ2zZbLRJv/xSysmlgIM1u11eBaRMhvYXJNkGuM= -github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= -github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= -github.com/ProtonMail/go-crypto v1.1.0-alpha.2 h1:bkyFVUP+ROOARdgCiJzNQo2V2kiB97LyUpzH9P6Hrlg= -github.com/ProtonMail/go-crypto v1.1.0-alpha.2/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE= +github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= +github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= +github.com/ProtonMail/go-crypto v1.1.6 h1:ZcV+Ropw6Qn0AX9brlQLAUXfqLBc7Bl+f/DmNxpLfdw= +github.com/ProtonMail/go-crypto v1.1.6/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE= github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY= github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4= github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI= github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= -github.com/bmatcuk/doublestar/v4 v4.6.1 h1:FH9SifrbvJhnlQpztAx++wlkk70QBf0iBWDwNy7PA4I= -github.com/bmatcuk/doublestar/v4 v4.6.1/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc= +github.com/bmatcuk/doublestar/v4 v4.8.1 h1:54Bopc5c2cAvhLRAzqOGCYHYyhcDHsFF4wWIR5wKP38= +github.com/bmatcuk/doublestar/v4 v4.8.1/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc= github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA= github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8= -github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU= -github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA= -github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg= -github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= +github.com/cloudflare/circl v1.6.1 h1:zqIqSPIndyBh1bjLVVDHMPpVKqp8Su/V+6MeDzzQBQ0= +github.com/cloudflare/circl v1.6.1/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs= +github.com/cyphar/filepath-securejoin v0.4.1 h1:JyxxyPEaktOD+GAnqIqTf9A8tHyAG22rowi7HkoSU1s= +github.com/cyphar/filepath-securejoin v0.4.1/go.mod h1:Sdj7gXlvMcPZsbhwhQ33GguGLDGQL7h7bg04C/+u9jI= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= -github.com/ericlagergren/decimal v0.0.0-20221120152707-495c53812d05 h1:S92OBrGuLLZsyM5ybUzgc/mPjIYk2AZqufieooe98uw= -github.com/ericlagergren/decimal v0.0.0-20221120152707-495c53812d05/go.mod h1:M9R1FoZ3y//hwwnJtO51ypFGwm8ZfpxPT/ZLtO1mcgQ= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM= github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE= @@ -42,21 +40,25 @@ github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3 github.com/frankban/quicktest v1.14.3/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps= github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI= github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic= -github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU= -github.com/go-git/go-billy/v5 v5.5.0/go.mod h1:hmexnoNsr2SJU1Ju67OaNz5ASJY3+sHgFRpCtpDCKow= -github.com/go-git/go-git/v5 v5.12.0 h1:7Md+ndsjrzZxbddRDZjF14qK+NN56sy6wkqaVrjZtys= -github.com/go-git/go-git/v5 v5.12.0/go.mod h1:FTM9VKtnI2m65hNI/TenDDDnUf2Q9FHnXYjuz9i5OEY= -github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= -github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/go-git/go-billy/v5 v5.6.2 h1:6Q86EsPXMa7c3YZ3aLAQsMA0VlWmy43r6FHqa/UNbRM= +github.com/go-git/go-billy/v5 v5.6.2/go.mod h1:rcFC2rAsp/erv7CMz9GczHcuD0D32fWzH+MJAU+jaUU= +github.com/go-git/go-git/v5 v5.14.0 h1:/MD3lCrGjCen5WfEAzKg00MJJffKhC8gzS80ycmCi60= +github.com/go-git/go-git/v5 v5.14.0/go.mod h1:Z5Xhoia5PcWA3NF8vRLURn9E5FRhSl7dGj9ItW3Wk5k= +github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= +github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 h1:f+oWsMOmNPc8JmEHVZIycC7hBoQxHH9pNKQORJNozsQ= +github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8/go.mod h1:wcDNUvekVysuuOpQKo3191zZyTpiI6se1N1ULghS0sw= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= -github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= -github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= +github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/hashicorp/cli v1.1.6 h1:CMOV+/LJfL1tXCOKrgAX0uRKnzjj/mpmqNXloRSy2K8= -github.com/hashicorp/cli v1.1.6/go.mod h1:MPon5QYlgjjo0BSoAiN0ESeT5fRzDjVRp+uioJ0piz4= +github.com/hashicorp/cli v1.1.7 h1:/fZJ+hNdwfTSfsxMBa9WWMlfjUZbX8/LnUxgAd7lCVU= +github.com/hashicorp/cli v1.1.7/go.mod h1:e6Mfpga9OCT1vqzFuoGZiiF/KaG9CbUfO5s3ghU3YgU= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -65,36 +67,38 @@ github.com/hashicorp/go-checkpoint v0.5.0/go.mod h1:7nfLNL10NsxqO4iWuW6tWW0HjZuD github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= -github.com/hashicorp/go-hclog v1.5.0 h1:bI2ocEMgcVlz55Oj1xZNBsVi900c7II+fWDyV9o+13c= -github.com/hashicorp/go-hclog v1.5.0/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= +github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k= +github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= -github.com/hashicorp/go-plugin v1.6.1 h1:P7MR2UP6gNKGPp+y7EZw2kOiq4IR9WiqLvp0XOsVdwI= -github.com/hashicorp/go-plugin v1.6.1/go.mod h1:XPHFku2tFo3o3QKFgSYo+cghcUhw1NA1hZyMK0PWAw0= +github.com/hashicorp/go-plugin v1.6.3 h1:xgHB+ZUSYeuJi96WtxEjzi23uh7YQpznjGh0U0UUrwg= +github.com/hashicorp/go-plugin v1.6.3/go.mod h1:MRobyh+Wc/nYy1V4KAXUiYfzxoYhs7V1mlH1Z7iY2h0= +github.com/hashicorp/go-retryablehttp v0.7.7 h1:C8hUCYzor8PIfXHa4UrZkU4VvK8o9ISHxT2Q8+VepXU= +github.com/hashicorp/go-retryablehttp v0.7.7/go.mod h1:pkQpWZeYWskR+D1tR2O5OcBFOxfA7DoAO6xtkuQnHTk= github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8= github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY= github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= -github.com/hashicorp/hc-install v0.7.0 h1:Uu9edVqjKQxxuD28mR5TikkKDd/p55S8vzPC1659aBk= -github.com/hashicorp/hc-install v0.7.0/go.mod h1:ELmmzZlGnEcqoUMKUuykHaPCIR1sYLYX+KSggWSKZuA= -github.com/hashicorp/terraform-exec v0.21.0 h1:uNkLAe95ey5Uux6KJdua6+cv8asgILFVWkd/RG0D2XQ= -github.com/hashicorp/terraform-exec v0.21.0/go.mod h1:1PPeMYou+KDUSSeRE9szMZ/oHf4fYUmB923Wzbq1ICg= -github.com/hashicorp/terraform-json v0.22.1 h1:xft84GZR0QzjPVWs4lRUwvTcPnegqlyS7orfb5Ltvec= -github.com/hashicorp/terraform-json v0.22.1/go.mod h1:JbWSQCLFSXFFhg42T7l9iJwdGXBYV8fmmD6o/ML4p3A= -github.com/hashicorp/terraform-plugin-docs v0.19.4 h1:G3Bgo7J22OMtegIgn8Cd/CaSeyEljqjH3G39w28JK4c= -github.com/hashicorp/terraform-plugin-docs v0.19.4/go.mod h1:4pLASsatTmRynVzsjEhbXZ6s7xBlUw/2Kt0zfrq8HxA= -github.com/hashicorp/terraform-plugin-framework v1.12.0 h1:7HKaueHPaikX5/7cbC1r9d1m12iYHY+FlNZEGxQ42CQ= -github.com/hashicorp/terraform-plugin-framework v1.12.0/go.mod h1:N/IOQ2uYjW60Jp39Cp3mw7I/OpC/GfZ0385R0YibmkE= -github.com/hashicorp/terraform-plugin-framework-validators v0.13.0 h1:bxZfGo9DIUoLLtHMElsu+zwqI4IsMZQBRRy4iLzZJ8E= -github.com/hashicorp/terraform-plugin-framework-validators v0.13.0/go.mod h1:wGeI02gEhj9nPANU62F2jCaHjXulejm/X+af4PdZaNo= -github.com/hashicorp/terraform-plugin-go v0.24.0 h1:2WpHhginCdVhFIrWHxDEg6RBn3YaWzR2o6qUeIEat2U= -github.com/hashicorp/terraform-plugin-go v0.24.0/go.mod h1:tUQ53lAsOyYSckFGEefGC5C8BAaO0ENqzFd3bQeuYQg= +github.com/hashicorp/hc-install v0.9.2 h1:v80EtNX4fCVHqzL9Lg/2xkp62bbvQMnvPQ0G+OmtO24= +github.com/hashicorp/hc-install v0.9.2/go.mod h1:XUqBQNnuT4RsxoxiM9ZaUk0NX8hi2h+Lb6/c0OZnC/I= +github.com/hashicorp/terraform-exec v0.23.0 h1:MUiBM1s0CNlRFsCLJuM5wXZrzA3MnPYEsiXmzATMW/I= +github.com/hashicorp/terraform-exec v0.23.0/go.mod h1:mA+qnx1R8eePycfwKkCRk3Wy65mwInvlpAeOwmA7vlY= +github.com/hashicorp/terraform-json v0.25.0 h1:rmNqc/CIfcWawGiwXmRuiXJKEiJu1ntGoxseG1hLhoQ= +github.com/hashicorp/terraform-json v0.25.0/go.mod h1:sMKS8fiRDX4rVlR6EJUMudg1WcanxCMoWwTLkgZP/vc= +github.com/hashicorp/terraform-plugin-docs v0.22.0 h1:fwIDStbFel1PPNkM+mDPnpB4efHZBdGoMz/zt5FbTDw= +github.com/hashicorp/terraform-plugin-docs v0.22.0/go.mod h1:55DJVyZ7BNK4t/lANcQ1YpemRuS6KsvIO1BbGA+xzGE= +github.com/hashicorp/terraform-plugin-framework v1.15.1 h1:2mKDkwb8rlx/tvJTlIcpw0ykcmvdWv+4gY3SIgk8Pq8= +github.com/hashicorp/terraform-plugin-framework v1.15.1/go.mod h1:hxrNI/GY32KPISpWqlCoTLM9JZsGH3CyYlir09bD/fI= +github.com/hashicorp/terraform-plugin-framework-validators v0.18.0 h1:OQnlOt98ua//rCw+QhBbSqfW3QbwtVrcdWeQN5gI3Hw= +github.com/hashicorp/terraform-plugin-framework-validators v0.18.0/go.mod h1:lZvZvagw5hsJwuY7mAY6KUz45/U6fiDR0CzQAwWD0CA= +github.com/hashicorp/terraform-plugin-go v0.28.0 h1:zJmu2UDwhVN0J+J20RE5huiF3XXlTYVIleaevHZgKPA= +github.com/hashicorp/terraform-plugin-go v0.28.0/go.mod h1:FDa2Bb3uumkTGSkTFpWSOwWJDwA7bf3vdP3ltLDTH6o= github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0= github.com/hashicorp/terraform-plugin-log v0.9.0/go.mod h1:rKL8egZQ/eXSyDqzLUuwUYLVdlYeamldAHSxjUFADow= -github.com/hashicorp/terraform-registry-address v0.2.3 h1:2TAiKJ1A3MAkZlH1YI/aTVcLZRu7JseiXNRHbOAyoTI= -github.com/hashicorp/terraform-registry-address v0.2.3/go.mod h1:lFHA76T8jfQteVfT7caREqguFrW3c4MFSPhZB7HHgUM= +github.com/hashicorp/terraform-registry-address v0.2.5 h1:2GTftHqmUhVOeuu9CW3kwDkRe4pcBDq0uuK5VJngU1M= +github.com/hashicorp/terraform-registry-address v0.2.5/go.mod h1:PpzXWINwB5kuVS5CA7m1+eO2f1jKb5ZDIxrOPfpnGkg= github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S52uzrw4x0jKQ= github.com/hashicorp/terraform-svchost v0.1.1/go.mod h1:mNsjQfZyf/Jhz35v6/0LWcv26+X7JPS+buii2c9/ctc= github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE= @@ -116,11 +120,10 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= -github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= -github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE= +github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= @@ -135,21 +138,21 @@ github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zx github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw= github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= -github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= -github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI= +github.com/pjbgf/sha1cd v0.3.2 h1:a9wb0bp1oC2TGwStyn0Umc/IGKQnEgF0vVaZ8QF8eo4= +github.com/pjbgf/sha1cd v0.3.2/go.mod h1:zQWigSxVmsHEZow5qaLtPYxpcKMMQpa09ixqBxuCS6A= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/posener/complete v1.2.3 h1:NP0eAhjcjImqslEwo/1hq7gpajME0fTLTezBKDqfXqo= github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s= -github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= -github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= +github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= +github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc= github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8= github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4= github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= -github.com/skeema/knownhosts v1.2.2 h1:Iug2P4fLmDw9f41PB6thxUkNUkJzB5i+1/exaj40L3A= -github.com/skeema/knownhosts v1.2.2/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo= +github.com/skeema/knownhosts v1.3.1 h1:X2osQ+RAjK76shCbvhHHHVl3ZlgDm8apHEHFqRjnBY8= +github.com/skeema/knownhosts v1.3.1/go.mod h1:r7KTdC8l4uxWRyK2TpQZ/1o5HaSzh06ePQNxPwTcfiY= github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w= github.com/spf13/cast v1.5.0/go.mod h1:SpXXQ5YoyJw6s3/6cMTQuxvgRl3PCJiyaX9p6b155UU= @@ -158,8 +161,8 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= -github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= -github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY= +github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IUPn0Bjt8= github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok= github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g= @@ -167,34 +170,44 @@ github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -github.com/yuin/goldmark v1.7.1 h1:3bajkSilaCbjdKVsKdZjZCLBNPL9pYzrCakKaf4U49U= -github.com/yuin/goldmark v1.7.1/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E= +github.com/yuin/goldmark v1.7.7 h1:5m9rrB1sW3JUMToKFQfb+FGt1U7r57IHu5GrYrG2nqU= +github.com/yuin/goldmark v1.7.7/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E= github.com/yuin/goldmark-meta v1.1.0 h1:pWw+JLHGZe8Rk0EGsMVssiNb/AaPMHfSRszZeUeiOUc= github.com/yuin/goldmark-meta v1.1.0/go.mod h1:U4spWENafuA7Zyg+Lj5RqK/MF+ovMYtBvXi1lBb2VP0= -github.com/zclconf/go-cty v1.14.4 h1:uXXczd9QDGsgu0i/QFR/hzI5NYCHLf6NQw/atrbnhq8= -github.com/zclconf/go-cty v1.14.4/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= +github.com/zclconf/go-cty v1.16.3 h1:osr++gw2T61A8KVYHoQiFbFd1Lh3JOCXc/jFLJXKTxk= +github.com/zclconf/go-cty v1.16.3/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= go.abhg.dev/goldmark/frontmatter v0.2.0 h1:P8kPG0YkL12+aYk2yU3xHv4tcXzeVnN+gU0tJ5JnxRw= go.abhg.dev/goldmark/frontmatter v0.2.0/go.mod h1:XqrEkZuM57djk7zrlRUB02x8I5J0px76YjkOzhB4YlU= +go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA= +go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A= +go.opentelemetry.io/otel v1.34.0 h1:zRLXxLCgL1WyKsPVrgbSdMN4c0FMkDAskSTQP+0hdUY= +go.opentelemetry.io/otel v1.34.0/go.mod h1:OWFPOQ+h4G8xpyjgqo4SxJYdDQ/qmRH+wivy7zzx9oI= +go.opentelemetry.io/otel/metric v1.34.0 h1:+eTR3U0MyfWjRDhmFMxe2SsW64QrZ84AOhvqS7Y+PoQ= +go.opentelemetry.io/otel/metric v1.34.0/go.mod h1:CEDrp0fy2D0MvkXE+dPV7cMi8tWZwX3dmaIhwPOaqHE= +go.opentelemetry.io/otel/sdk v1.34.0 h1:95zS4k/2GOy069d321O8jWgYsW3MzVV+KuSPKp7Wr1A= +go.opentelemetry.io/otel/sdk v1.34.0/go.mod h1:0e/pNiaMAqaykJGKbi+tSjWfNNHMTxoC9qANsCzbyxU= +go.opentelemetry.io/otel/sdk/metric v1.34.0 h1:5CeK9ujjbFVL5c1PhLuStg1wxA7vQv7ce1EK0Gyvahk= +go.opentelemetry.io/otel/sdk/metric v1.34.0/go.mod h1:jQ/r8Ze28zRKoNRdkjCZxfs6YvBTG1+YIqyFVFYec5w= +go.opentelemetry.io/otel/trace v1.34.0 h1:+ouXS2V8Rd4hp4580a8q23bg0azF2nI8cqLYnC8mh/k= +go.opentelemetry.io/otel/trace v1.34.0/go.mod h1:Svm7lSjQD7kG7KJ/MUHPVXSDGz2OX4h0M2jHBhmSfRE= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= -golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI= -golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM= +golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8= +golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw= golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df h1:UA2aFVmmsIlefxMk29Dp2juaUSth8Pyn3Tq5Y5mJGME= golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= -golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.25.0 h1:n7a+ZbQKQA/Ysbyb0/6IbB1H/X41mKgbhfv7AfG/44w= +golang.org/x/mod v0.25.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= -golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= -golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= +golang.org/x/net v0.39.0 h1:ZCu7HMWDxpXpaiKdhzIfaltL9Lp31x/3fCP11bc6/fY= +golang.org/x/net v0.39.0/go.mod h1:X7NRbYVEA+ewNkCNyJ513WmMdQ3BineSwVtN2zD/d+E= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= -golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -205,11 +218,10 @@ golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= -golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= +golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= @@ -217,20 +229,20 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= -golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= +golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M= +golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= -golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= +golang.org/x/tools v0.33.0 h1:4qz2S3zmRxbGIhDIAgjxvFutSvH5EfnsYrRBj0UI0bc= +golang.org/x/tools v0.33.0/go.mod h1:CIJMaWEY88juyUfo7UbgPqbC8rU2OqfAV1h2Qp0oMYI= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 h1:1GBuWVLM/KMVUv1t1En5Gs+gFZCNd360GGb4sSxtrhU= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0= -google.golang.org/grpc v1.66.2 h1:3QdXkuq3Bkh7w+ywLdLvM56cmGvQHUMZpiCzt6Rqaoo= -google.golang.org/grpc v1.66.2/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y= -google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= -google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= +google.golang.org/genproto/googleapis/rpc v0.0.0-20250218202821-56aae31c358a h1:51aaUVRocpvUOSQKM6Q7VuoaktNIaMCLuhZB6DKksq4= +google.golang.org/genproto/googleapis/rpc v0.0.0-20250218202821-56aae31c358a/go.mod h1:uRxBH1mhmO8PGhU89cMcHaXKZqO+OfakD8QQO0oYwlQ= +google.golang.org/grpc v1.72.1 h1:HR03wO6eyZ7lknl75XlxABNVLLFc2PAb6mHlYh756mA= +google.golang.org/grpc v1.72.1/go.mod h1:wH5Aktxcg25y1I3w7H69nHfXdOG3UiadoBtjh3izSDM= +google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY= +google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= diff --git a/internal/planmodifiers/float32planmodifier/suppress_diff.go b/internal/planmodifiers/float32planmodifier/suppress_diff.go new file mode 100644 index 0000000..a82a09f --- /dev/null +++ b/internal/planmodifiers/float32planmodifier/suppress_diff.go @@ -0,0 +1,56 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package float32planmodifier + +import ( + "context" + "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/planmodifiers/utils" + + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" +) + +const ( + // ExplicitSuppress strategy suppresses "(known after changes)" messages unless we're in the initial creation + ExplicitSuppress = iota +) + +// SuppressDiff returns a plan modifier that propagates a state value into the planned value, when it is Known, and the Plan Value is Unknown +func SuppressDiff(strategy int) planmodifier.Float32 { + return suppressDiff{ + strategy: strategy, + } +} + +// suppressDiff implements the plan modifier. +type suppressDiff struct { + strategy int +} + +// Description returns a human-readable description of the plan modifier. +func (m suppressDiff) Description(_ context.Context) string { + return "Once set, the value of this attribute in state will not change." +} + +// MarkdownDescription returns a markdown description of the plan modifier. +func (m suppressDiff) MarkdownDescription(_ context.Context) string { + return "Once set, the value of this attribute in state will not change." +} + +// PlanModifyFloat32 implements the plan modification logic. +func (m suppressDiff) PlanModifyFloat32(ctx context.Context, req planmodifier.Float32Request, resp *planmodifier.Float32Response) { + // Do nothing if there is a known planned value. + if !req.PlanValue.IsUnknown() { + return + } + + // Do nothing if there is an unknown configuration value + if req.ConfigValue.IsUnknown() { + return + } + + if utils.IsAllStateUnknown(ctx, req.State) { + return + } + + resp.PlanValue = req.StateValue +} diff --git a/internal/planmodifiers/int32planmodifier/suppress_diff.go b/internal/planmodifiers/int32planmodifier/suppress_diff.go new file mode 100644 index 0000000..b2b5e4c --- /dev/null +++ b/internal/planmodifiers/int32planmodifier/suppress_diff.go @@ -0,0 +1,56 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package int32planmodifier + +import ( + "context" + "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/planmodifiers/utils" + + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" +) + +const ( + // ExplicitSuppress strategy suppresses "(known after changes)" messages unless we're in the initial creation + ExplicitSuppress = iota +) + +// SuppressDiff returns a plan modifier that propagates a state value into the planned value, when it is Known, and the Plan Value is Unknown +func SuppressDiff(strategy int) planmodifier.Int32 { + return suppressDiff{ + strategy: strategy, + } +} + +// suppressDiff implements the plan modifier. +type suppressDiff struct { + strategy int +} + +// Description returns a human-readable description of the plan modifier. +func (m suppressDiff) Description(_ context.Context) string { + return "Once set, the value of this attribute in state will not change." +} + +// MarkdownDescription returns a markdown description of the plan modifier. +func (m suppressDiff) MarkdownDescription(_ context.Context) string { + return "Once set, the value of this attribute in state will not change." +} + +// PlanModifyInt32 implements the plan modification logic. +func (m suppressDiff) PlanModifyInt32(ctx context.Context, req planmodifier.Int32Request, resp *planmodifier.Int32Response) { + // Do nothing if there is a known planned value. + if !req.PlanValue.IsUnknown() { + return + } + + // Do nothing if there is an unknown configuration value + if req.ConfigValue.IsUnknown() { + return + } + + if utils.IsAllStateUnknown(ctx, req.State) { + return + } + + resp.PlanValue = req.StateValue +} diff --git a/internal/planmodifiers/utils/state_check.go b/internal/planmodifiers/utils/state_check.go index 51d5362..0ea64fb 100644 --- a/internal/planmodifiers/utils/state_check.go +++ b/internal/planmodifiers/utils/state_check.go @@ -4,6 +4,7 @@ package utils import ( "context" + "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/tfsdk" @@ -12,7 +13,7 @@ import ( func IsAllStateUnknown(ctx context.Context, state tfsdk.State) bool { attrs := state.Schema.GetAttributes() anyFound := false - for k, _ := range attrs { + for k := range attrs { attrValue := new(attr.Value) state.GetAttribute(ctx, path.Root(k), attrValue) if attrValue != nil && !(*attrValue).IsUnknown() && !(*attrValue).IsNull() { diff --git a/internal/provider/customvariable_data_source.go b/internal/provider/customvariable_data_source.go deleted file mode 100644 index a56569c..0000000 --- a/internal/provider/customvariable_data_source.go +++ /dev/null @@ -1,187 +0,0 @@ -// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - -package provider - -import ( - "context" - "fmt" - "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk" - "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/models/operations" - "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" -) - -// Ensure provider defined types fully satisfy framework interfaces. -var _ datasource.DataSource = &CustomVariableDataSource{} -var _ datasource.DataSourceWithConfigure = &CustomVariableDataSource{} - -func NewCustomVariableDataSource() datasource.DataSource { - return &CustomVariableDataSource{} -} - -// CustomVariableDataSource is the data source implementation. -type CustomVariableDataSource struct { - client *sdk.SDK -} - -// CustomVariableDataSourceModel describes the data model. -type CustomVariableDataSourceModel struct { - Config types.String `tfsdk:"config"` - CreatedAt types.String `tfsdk:"created_at"` - CreatedBy types.String `tfsdk:"created_by"` - HelperLogic types.String `tfsdk:"helper_logic"` - HelperParams []types.String `tfsdk:"helper_params"` - ID types.String `tfsdk:"id"` - Key types.String `tfsdk:"key"` - Name types.String `tfsdk:"name"` - Tags []types.String `tfsdk:"tags"` - Template types.String `tfsdk:"template"` - Type types.String `tfsdk:"type"` - UpdatedAt types.String `tfsdk:"updated_at"` - UpdatedBy types.String `tfsdk:"updated_by"` -} - -// Metadata returns the data source type name. -func (r *CustomVariableDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { - resp.TypeName = req.ProviderTypeName + "_custom_variable" -} - -// Schema defines the schema for the data source. -func (r *CustomVariableDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { - resp.Schema = schema.Schema{ - MarkdownDescription: "CustomVariable DataSource", - - Attributes: map[string]schema.Attribute{ - "config": schema.StringAttribute{ - Computed: true, - Description: `Parsed as JSON.`, - }, - "created_at": schema.StringAttribute{ - Computed: true, - Description: `Creation time`, - }, - "created_by": schema.StringAttribute{ - Computed: true, - Description: `Created by`, - }, - "helper_logic": schema.StringAttribute{ - Computed: true, - Description: `The helper function logic`, - }, - "helper_params": schema.ListAttribute{ - Computed: true, - ElementType: types.StringType, - Description: `The helper function parameter's names`, - }, - "id": schema.StringAttribute{ - Required: true, - Description: `Custom vairable ID`, - }, - "key": schema.StringAttribute{ - Computed: true, - Description: `The key which is used for Handlebar variable syntax {{"{{"}}key{{"}}"}}`, - }, - "name": schema.StringAttribute{ - Computed: true, - Description: `Custom variable name`, - }, - "tags": schema.ListAttribute{ - Computed: true, - ElementType: types.StringType, - Description: `The tags of custom variable`, - }, - "template": schema.StringAttribute{ - Computed: true, - Description: `Handlebar template that used to generate the variable content`, - }, - "type": schema.StringAttribute{ - Computed: true, - Description: `Custom variable type`, - }, - "updated_at": schema.StringAttribute{ - Computed: true, - Description: `Last update time`, - }, - "updated_by": schema.StringAttribute{ - Computed: true, - Description: `Updated by`, - }, - }, - } -} - -func (r *CustomVariableDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { - // Prevent panic if the provider has not been configured. - if req.ProviderData == nil { - return - } - - client, ok := req.ProviderData.(*sdk.SDK) - - if !ok { - resp.Diagnostics.AddError( - "Unexpected DataSource Configure Type", - fmt.Sprintf("Expected *sdk.SDK, got: %T. Please report this issue to the provider developers.", req.ProviderData), - ) - - return - } - - r.client = client -} - -func (r *CustomVariableDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { - var data *CustomVariableDataSourceModel - 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 - } - - var id string - id = data.ID.ValueString() - - request := operations.GetCustomVariableRequest{ - ID: id, - } - res, err := r.client.CustomVariables.GetCustomVariable(ctx, request) - if err != nil { - resp.Diagnostics.AddError("failure to invoke API", 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.CustomVariable != nil) { - resp.Diagnostics.AddError("unexpected response from API. Got an unexpected response body", debugResponse(res.RawResponse)) - return - } - data.RefreshFromSharedCustomVariable(res.CustomVariable) - - // Save updated data into Terraform state - resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) -} diff --git a/internal/provider/customvariable_data_source_sdk.go b/internal/provider/customvariable_data_source_sdk.go deleted file mode 100644 index 0fa2ab5..0000000 --- a/internal/provider/customvariable_data_source_sdk.go +++ /dev/null @@ -1,42 +0,0 @@ -// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - -package provider - -import ( - "encoding/json" - "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/models/shared" - "github.com/hashicorp/terraform-plugin-framework/types" -) - -func (r *CustomVariableDataSourceModel) RefreshFromSharedCustomVariable(resp *shared.CustomVariable) { - if resp != nil { - r.Tags = []types.String{} - for _, v := range resp.Tags { - r.Tags = append(r.Tags, types.StringValue(v)) - } - if resp.Config == nil { - r.Config = types.StringNull() - } else { - configResult, _ := json.Marshal(resp.Config) - r.Config = types.StringValue(string(configResult)) - } - r.CreatedAt = types.StringPointerValue(resp.CreatedAt) - r.CreatedBy = types.StringPointerValue(resp.CreatedBy) - r.HelperLogic = types.StringPointerValue(resp.HelperLogic) - r.HelperParams = []types.String{} - for _, v := range resp.HelperParams { - r.HelperParams = append(r.HelperParams, types.StringValue(v)) - } - r.ID = types.StringPointerValue(resp.ID) - r.Key = types.StringPointerValue(resp.Key) - r.Name = types.StringPointerValue(resp.Name) - r.Template = types.StringPointerValue(resp.Template) - if resp.Type != nil { - r.Type = types.StringValue(string(*resp.Type)) - } else { - r.Type = types.StringNull() - } - r.UpdatedAt = types.StringPointerValue(resp.UpdatedAt) - r.UpdatedBy = types.StringPointerValue(resp.UpdatedBy) - } -} diff --git a/internal/provider/customvariable_resource.go b/internal/provider/customvariable_resource.go deleted file mode 100644 index d8dde2b..0000000 --- a/internal/provider/customvariable_resource.go +++ /dev/null @@ -1,353 +0,0 @@ -// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - -package provider - -import ( - "context" - "fmt" - "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk" - "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/models/operations" - "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/validators" - "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" - "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" -) - -// Ensure provider defined types fully satisfy framework interfaces. -var _ resource.Resource = &CustomVariableResource{} -var _ resource.ResourceWithImportState = &CustomVariableResource{} - -func NewCustomVariableResource() resource.Resource { - return &CustomVariableResource{} -} - -// CustomVariableResource defines the resource implementation. -type CustomVariableResource struct { - client *sdk.SDK -} - -// CustomVariableResourceModel describes the resource data model. -type CustomVariableResourceModel struct { - Config types.String `tfsdk:"config"` - CreatedAt types.String `tfsdk:"created_at"` - CreatedBy types.String `tfsdk:"created_by"` - HelperLogic types.String `tfsdk:"helper_logic"` - HelperParams []types.String `tfsdk:"helper_params"` - ID types.String `tfsdk:"id"` - Key types.String `tfsdk:"key"` - Name types.String `tfsdk:"name"` - Tags []types.String `tfsdk:"tags"` - Template types.String `tfsdk:"template"` - Type types.String `tfsdk:"type"` - UpdatedAt types.String `tfsdk:"updated_at"` - UpdatedBy types.String `tfsdk:"updated_by"` -} - -func (r *CustomVariableResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { - resp.TypeName = req.ProviderTypeName + "_custom_variable" -} - -func (r *CustomVariableResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { - resp.Schema = schema.Schema{ - MarkdownDescription: "CustomVariable Resource", - Attributes: map[string]schema.Attribute{ - "config": schema.StringAttribute{ - Computed: true, - Optional: true, - Description: `Parsed as JSON.`, - Validators: []validator.String{ - validators.IsValidJSON(), - }, - }, - "created_at": schema.StringAttribute{ - Computed: true, - Optional: true, - Description: `Creation time`, - }, - "created_by": schema.StringAttribute{ - Computed: true, - Optional: true, - Description: `Created by`, - }, - "helper_logic": schema.StringAttribute{ - Computed: true, - Optional: true, - Description: `The helper function logic`, - }, - "helper_params": schema.ListAttribute{ - Computed: true, - Optional: true, - ElementType: types.StringType, - Description: `The helper function parameter's names`, - }, - "id": schema.StringAttribute{ - Computed: true, - Optional: true, - Description: `ID`, - }, - "key": schema.StringAttribute{ - Computed: true, - Optional: true, - Description: `The key which is used for Handlebar variable syntax {{"{{"}}key{{"}}"}}`, - }, - "name": schema.StringAttribute{ - Computed: true, - Optional: true, - Description: `Custom variable name`, - }, - "tags": schema.ListAttribute{ - Computed: true, - Optional: true, - ElementType: types.StringType, - Description: `The tags of custom variable`, - }, - "template": schema.StringAttribute{ - Computed: true, - Optional: true, - Description: `Handlebar template that used to generate the variable content`, - }, - "type": schema.StringAttribute{ - Computed: true, - Optional: true, - Description: `Custom variable type. must be one of ["order_table", "custom", "journey_link"]`, - Validators: []validator.String{ - stringvalidator.OneOf( - "order_table", - "custom", - "journey_link", - ), - }, - }, - "updated_at": schema.StringAttribute{ - Computed: true, - Optional: true, - Description: `Last update time`, - }, - "updated_by": schema.StringAttribute{ - Computed: true, - Optional: true, - Description: `Updated by`, - }, - }, - } -} - -func (r *CustomVariableResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { - // Prevent panic if the provider has not been configured. - if req.ProviderData == nil { - return - } - - client, ok := req.ProviderData.(*sdk.SDK) - - if !ok { - resp.Diagnostics.AddError( - "Unexpected Resource Configure Type", - fmt.Sprintf("Expected *sdk.SDK, got: %T. Please report this issue to the provider developers.", req.ProviderData), - ) - - return - } - - r.client = client -} - -func (r *CustomVariableResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { - var data *CustomVariableResourceModel - 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 := data.ToSharedCustomVariable() - res, err := r.client.CustomVariables.CreateCustomVariable(ctx, request) - if err != nil { - resp.Diagnostics.AddError("failure to invoke API", 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 != 201 { - resp.Diagnostics.AddError(fmt.Sprintf("unexpected response from API. Got an unexpected response code %v", res.StatusCode), debugResponse(res.RawResponse)) - return - } - if !(res.CustomVariable != nil) { - resp.Diagnostics.AddError("unexpected response from API. Got an unexpected response body", debugResponse(res.RawResponse)) - return - } - data.RefreshFromSharedCustomVariable(res.CustomVariable) - refreshPlan(ctx, plan, &data, resp.Diagnostics) - - // Save updated data into Terraform state - resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) -} - -func (r *CustomVariableResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { - var data *CustomVariableResourceModel - 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 - } - - var id string - id = data.ID.ValueString() - - request := operations.GetCustomVariableRequest{ - ID: id, - } - res, err := r.client.CustomVariables.GetCustomVariable(ctx, request) - if err != nil { - resp.Diagnostics.AddError("failure to invoke API", 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.CustomVariable != nil) { - resp.Diagnostics.AddError("unexpected response from API. Got an unexpected response body", debugResponse(res.RawResponse)) - return - } - data.RefreshFromSharedCustomVariable(res.CustomVariable) - - // Save updated data into Terraform state - resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) -} - -func (r *CustomVariableResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { - var data *CustomVariableResourceModel - 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 - } - - customVariable := data.ToSharedCustomVariable() - var id string - id = data.ID.ValueString() - - request := operations.UpdateCustomVariableRequest{ - CustomVariable: customVariable, - ID: id, - } - res, err := r.client.CustomVariables.UpdateCustomVariable(ctx, request) - if err != nil { - resp.Diagnostics.AddError("failure to invoke API", 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.CustomVariable != nil) { - resp.Diagnostics.AddError("unexpected response from API. Got an unexpected response body", debugResponse(res.RawResponse)) - return - } - data.RefreshFromSharedCustomVariable(res.CustomVariable) - refreshPlan(ctx, plan, &data, resp.Diagnostics) - - // Save updated data into Terraform state - resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) -} - -func (r *CustomVariableResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { - var data *CustomVariableResourceModel - 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 - } - - var id string - id = data.ID.ValueString() - - request := operations.DeleteCustomVariableRequest{ - ID: id, - } - res, err := r.client.CustomVariables.DeleteCustomVariable(ctx, request) - if err != nil { - resp.Diagnostics.AddError("failure to invoke API", 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 != 204 { - resp.Diagnostics.AddError(fmt.Sprintf("unexpected response from API. Got an unexpected response code %v", res.StatusCode), debugResponse(res.RawResponse)) - return - } - -} - -func (r *CustomVariableResource) 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/internal/provider/customvariable_resource_sdk.go b/internal/provider/customvariable_resource_sdk.go deleted file mode 100644 index 36152e0..0000000 --- a/internal/provider/customvariable_resource_sdk.go +++ /dev/null @@ -1,133 +0,0 @@ -// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - -package provider - -import ( - "encoding/json" - "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/models/shared" - "github.com/hashicorp/terraform-plugin-framework/types" -) - -func (r *CustomVariableResourceModel) ToSharedCustomVariable() *shared.CustomVariable { - var tags []string = []string{} - for _, tagsItem := range r.Tags { - tags = append(tags, tagsItem.ValueString()) - } - var config interface{} - if !r.Config.IsUnknown() && !r.Config.IsNull() { - _ = json.Unmarshal([]byte(r.Config.ValueString()), &config) - } - createdAt := new(string) - if !r.CreatedAt.IsUnknown() && !r.CreatedAt.IsNull() { - *createdAt = r.CreatedAt.ValueString() - } else { - createdAt = nil - } - createdBy := new(string) - if !r.CreatedBy.IsUnknown() && !r.CreatedBy.IsNull() { - *createdBy = r.CreatedBy.ValueString() - } else { - createdBy = nil - } - helperLogic := new(string) - if !r.HelperLogic.IsUnknown() && !r.HelperLogic.IsNull() { - *helperLogic = r.HelperLogic.ValueString() - } else { - helperLogic = nil - } - var helperParams []string = []string{} - for _, helperParamsItem := range r.HelperParams { - helperParams = append(helperParams, helperParamsItem.ValueString()) - } - id := new(string) - if !r.ID.IsUnknown() && !r.ID.IsNull() { - *id = r.ID.ValueString() - } else { - id = nil - } - key := new(string) - if !r.Key.IsUnknown() && !r.Key.IsNull() { - *key = r.Key.ValueString() - } else { - key = nil - } - name := new(string) - if !r.Name.IsUnknown() && !r.Name.IsNull() { - *name = r.Name.ValueString() - } else { - name = nil - } - template := new(string) - if !r.Template.IsUnknown() && !r.Template.IsNull() { - *template = r.Template.ValueString() - } else { - template = nil - } - typeVar := new(shared.Type) - if !r.Type.IsUnknown() && !r.Type.IsNull() { - *typeVar = shared.Type(r.Type.ValueString()) - } else { - typeVar = nil - } - updatedAt := new(string) - if !r.UpdatedAt.IsUnknown() && !r.UpdatedAt.IsNull() { - *updatedAt = r.UpdatedAt.ValueString() - } else { - updatedAt = nil - } - updatedBy := new(string) - if !r.UpdatedBy.IsUnknown() && !r.UpdatedBy.IsNull() { - *updatedBy = r.UpdatedBy.ValueString() - } else { - updatedBy = nil - } - out := shared.CustomVariable{ - Tags: tags, - Config: config, - CreatedAt: createdAt, - CreatedBy: createdBy, - HelperLogic: helperLogic, - HelperParams: helperParams, - ID: id, - Key: key, - Name: name, - Template: template, - Type: typeVar, - UpdatedAt: updatedAt, - UpdatedBy: updatedBy, - } - return &out -} - -func (r *CustomVariableResourceModel) RefreshFromSharedCustomVariable(resp *shared.CustomVariable) { - if resp != nil { - r.Tags = []types.String{} - for _, v := range resp.Tags { - r.Tags = append(r.Tags, types.StringValue(v)) - } - if resp.Config == nil { - r.Config = types.StringNull() - } else { - configResult, _ := json.Marshal(resp.Config) - r.Config = types.StringValue(string(configResult)) - } - r.CreatedAt = types.StringPointerValue(resp.CreatedAt) - r.CreatedBy = types.StringPointerValue(resp.CreatedBy) - r.HelperLogic = types.StringPointerValue(resp.HelperLogic) - r.HelperParams = []types.String{} - for _, v := range resp.HelperParams { - r.HelperParams = append(r.HelperParams, types.StringValue(v)) - } - r.ID = types.StringPointerValue(resp.ID) - r.Key = types.StringPointerValue(resp.Key) - r.Name = types.StringPointerValue(resp.Name) - r.Template = types.StringPointerValue(resp.Template) - if resp.Type != nil { - r.Type = types.StringValue(string(*resp.Type)) - } else { - r.Type = types.StringNull() - } - r.UpdatedAt = types.StringPointerValue(resp.UpdatedAt) - r.UpdatedBy = types.StringPointerValue(resp.UpdatedBy) - } -} diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 5ec1bc6..1a31b41 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -7,6 +7,7 @@ import ( "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk" "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/models/shared" "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/ephemeral" "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-framework/provider/schema" "github.com/hashicorp/terraform-plugin-framework/resource" @@ -14,7 +15,8 @@ import ( "net/http" ) -var _ provider.Provider = &EpilotCustomVariableProvider{} +var _ provider.Provider = (*EpilotCustomVariableProvider)(nil) +var _ provider.ProviderWithEphemeralResources = (*EpilotCustomVariableProvider)(nil) type EpilotCustomVariableProvider struct { // version is set to the provider version on release, "dev" when the @@ -25,9 +27,9 @@ type EpilotCustomVariableProvider struct { // EpilotCustomVariableProviderModel describes the provider data model. type EpilotCustomVariableProviderModel struct { - ServerURL types.String `tfsdk:"server_url"` EpilotAuth types.String `tfsdk:"epilot_auth"` EpilotOrg types.String `tfsdk:"epilot_org"` + ServerURL types.String `tfsdk:"server_url"` } func (p *EpilotCustomVariableProvider) Metadata(ctx context.Context, req provider.MetadataRequest, resp *provider.MetadataResponse) { @@ -37,22 +39,23 @@ func (p *EpilotCustomVariableProvider) Metadata(ctx context.Context, req provide func (p *EpilotCustomVariableProvider) Schema(ctx context.Context, req provider.SchemaRequest, resp *provider.SchemaResponse) { resp.Schema = schema.Schema{ - Description: `Template Variables API: API to provide variables for email and document templates.`, Attributes: map[string]schema.Attribute{ - "server_url": schema.StringAttribute{ - MarkdownDescription: "Server URL (defaults to https://template-variables-api.sls.epilot.io)", - Optional: true, - Required: false, - }, "epilot_auth": schema.StringAttribute{ - Sensitive: true, - Optional: true, + MarkdownDescription: `Authorization header with epilot OAuth2 bearer token.`, + Optional: true, + Sensitive: true, }, "epilot_org": schema.StringAttribute{ - Sensitive: true, - Optional: true, + MarkdownDescription: `Overrides the target organization.`, + Optional: true, + Sensitive: true, + }, + "server_url": schema.StringAttribute{ + Description: `Server URL (defaults to https://template-variables-api.sls.epilot.io)`, + Optional: true, }, }, + MarkdownDescription: `Template Variables API: API to provide variables for email and document templates.`, } } @@ -65,53 +68,52 @@ func (p *EpilotCustomVariableProvider) Configure(ctx context.Context, req provid return } - ServerURL := data.ServerURL.ValueString() + serverUrl := data.ServerURL.ValueString() - if ServerURL == "" { - ServerURL = "https://template-variables-api.sls.epilot.io" + if serverUrl == "" { + serverUrl = "https://template-variables-api.sls.epilot.io" } - epilotAuth := new(string) - if !data.EpilotAuth.IsUnknown() && !data.EpilotAuth.IsNull() { - *epilotAuth = data.EpilotAuth.ValueString() - } else { - epilotAuth = nil + security := shared.Security{} + + if !data.EpilotAuth.IsUnknown() { + security.EpilotAuth = data.EpilotAuth.ValueStringPointer() } - epilotOrg := new(string) - if !data.EpilotOrg.IsUnknown() && !data.EpilotOrg.IsNull() { - *epilotOrg = data.EpilotOrg.ValueString() - } else { - epilotOrg = nil + + if !data.EpilotOrg.IsUnknown() { + security.EpilotOrg = data.EpilotOrg.ValueStringPointer() } - security := shared.Security{ - EpilotAuth: epilotAuth, - EpilotOrg: epilotOrg, + + providerHTTPTransportOpts := ProviderHTTPTransportOpts{ + SetHeaders: make(map[string]string), + Transport: http.DefaultTransport, } httpClient := http.DefaultClient - httpClient.Transport = NewLoggingHTTPTransport(http.DefaultTransport) + httpClient.Transport = NewProviderHTTPTransport(providerHTTPTransportOpts) opts := []sdk.SDKOption{ - sdk.WithServerURL(ServerURL), + sdk.WithServerURL(serverUrl), sdk.WithSecurity(security), sdk.WithClient(httpClient), } - client := sdk.New(opts...) + client := sdk.New(opts...) resp.DataSourceData = client + resp.EphemeralResourceData = client resp.ResourceData = client } func (p *EpilotCustomVariableProvider) Resources(ctx context.Context) []func() resource.Resource { - return []func() resource.Resource{ - NewCustomVariableResource, - } + return []func() resource.Resource{} } func (p *EpilotCustomVariableProvider) DataSources(ctx context.Context) []func() datasource.DataSource { - return []func() datasource.DataSource{ - NewCustomVariableDataSource, - } + return []func() datasource.DataSource{} +} + +func (p *EpilotCustomVariableProvider) EphemeralResources(ctx context.Context) []func() ephemeral.EphemeralResource { + return []func() ephemeral.EphemeralResource{} } func New(version string) func() provider.Provider { diff --git a/internal/provider/typeconvert/date.go b/internal/provider/typeconvert/date.go new file mode 100644 index 0000000..563cc03 --- /dev/null +++ b/internal/provider/typeconvert/date.go @@ -0,0 +1,23 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package typeconvert + +import ( + sdkTypes "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/types" +) + +// Converts a date types.Date to string. +func DateToString(value sdkTypes.Date) string { + return value.String() +} + +// Converts a date *types.Date to *string. +func DatePointerToStringPointer(value *sdkTypes.Date) *string { + if value == nil { + return nil + } + + stringValue := DateToString(*value) + + return &stringValue +} diff --git a/internal/provider/typeconvert/datetime.go b/internal/provider/typeconvert/datetime.go new file mode 100644 index 0000000..7bfdc55 --- /dev/null +++ b/internal/provider/typeconvert/datetime.go @@ -0,0 +1,23 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package typeconvert + +import ( + "time" +) + +// Converts a date-time time.Time to string. +func TimeToString(value time.Time) string { + return value.Format(time.RFC3339Nano) +} + +// Converts a date-time *time.Time to *string. +func TimePointerToStringPointer(value *time.Time) *string { + if value == nil { + return nil + } + + stringValue := TimeToString(*value) + + return &stringValue +} diff --git a/internal/provider/typeconvert/int.go b/internal/provider/typeconvert/int.go new file mode 100644 index 0000000..54763e7 --- /dev/null +++ b/internal/provider/typeconvert/int.go @@ -0,0 +1,50 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package typeconvert + +// Converts an *int to *int32. +func IntPointerToInt32Pointer(value *int) *int32 { + if value == nil { + return nil + } + + int32Value := int32(*value) + + return &int32Value +} + +// Converts an *int to *int64. +func IntPointerToInt64Pointer(value *int) *int64 { + if value == nil { + return nil + } + + int64Value := int64(*value) + + return &int64Value +} + +// Converts an *int32 to *int. +func Int32PointerToIntPointer(value *int32) *int { + if value == nil { + return nil + } + + intValue := int(*value) + + return &intValue +} + +// Converts an *int64 to *int32. +func Int64PointerToInt32Pointer(value *int64) *int32 { + if value == nil { + return nil + } + + // This may panic and if it does, represents a schema mismatch between + // response and response types. Request and response types should always + // be consistent with the highest integer size necessary. + int32Value := int32(*value) + + return &int32Value +} diff --git a/internal/provider/utils.go b/internal/provider/utils.go index 1dd5d69..91affe6 100644 --- a/internal/provider/utils.go +++ b/internal/provider/utils.go @@ -6,22 +6,22 @@ import ( "bufio" "bytes" "context" - "encoding/json" "errors" "fmt" - tfReflect "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/provider/reflect" + "io" + "net/http" + "net/http/httputil" + "net/textproto" + "strings" + "github.com/hashicorp/go-uuid" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-log/tflog" - "io" - "net/http" - "net/http/httputil" - "net/textproto" - "reflect" - "strings" + + tfReflect "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/provider/reflect" ) func debugResponse(response *http.Response) string { @@ -48,19 +48,6 @@ func debugResponse(response *http.Response) string { return fmt.Sprintf("**Request**:\n%s\n**Response**:\n%s", string(dumpReq), string(dumpRes)) } -func reflectJSONKey(data any, key string) reflect.Value { - jsonIfied, err := json.Marshal(data) - if err != nil { - panic(fmt.Errorf("failed to marshal data: %w", err)) - } - var jsonMap map[string]interface{} - err = json.Unmarshal(jsonIfied, &jsonMap) - if err != nil { - panic(fmt.Errorf("failed to unmarshal data: %w", err)) - } - return reflect.ValueOf(jsonMap[key]) -} - func merge(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse, target interface{}) { var plan types.Object var state types.Object @@ -86,26 +73,46 @@ func merge(ctx context.Context, req resource.UpdateRequest, resp *resource.Updat return } - refreshPlan(ctx, plan, target, resp.Diagnostics) + resp.Diagnostics.Append(refreshPlan(ctx, plan, target)...) } -func refreshPlan(ctx context.Context, plan types.Object, target interface{}, diagnostics diag.Diagnostics) { +func refreshPlan(ctx context.Context, plan types.Object, target any) diag.Diagnostics { + var diags diag.Diagnostics + obj := types.ObjectType{AttrTypes: plan.AttributeTypes(ctx)} val, err := plan.ToTerraformValue(ctx) if err != nil { - diagnostics.Append(diag.NewErrorDiagnostic("Object Conversion Error", "An unexpected error was encountered trying to convert object. This is always an error in the provider. Please report the following to the provider developer:\n\n"+err.Error())) - return + diags.AddError( + "Object Conversion Error", + "An unexpected error was encountered trying to convert object. This is always an error in the provider. Please report the following to the provider developer:\n\n"+err.Error(), + ) + return diags } - diagnostics.Append(tfReflect.Into(ctx, obj, val, target, tfReflect.Options{ + + diags.Append(tfReflect.Into(ctx, obj, val, target, tfReflect.Options{ UnhandledNullAsEmpty: true, UnhandledUnknownAsEmpty: true, SourceType: tfReflect.SourceTypePlan, }, path.Empty())...) + + return diags +} + +// Configurable options for the provider HTTP transport. +type ProviderHTTPTransportOpts struct { + // HTTP headers to set on all requests. + SetHeaders map[string]string + + // Underlying HTTP transport. + Transport http.RoundTripper } // Note: this is taken as a more minimal/specific version of https://github.com/hashicorp/terraform-plugin-sdk/blob/main/helper/logging/logging_http_transport.go -func NewLoggingHTTPTransport(t http.RoundTripper) *loggingHttpTransport { - return &loggingHttpTransport{t} +func NewProviderHTTPTransport(opts ProviderHTTPTransportOpts) *providerHttpTransport { + return &providerHttpTransport{ + setHeaders: opts.SetHeaders, + transport: opts.Transport, + } } const ( @@ -123,14 +130,18 @@ const ( FieldHttpTransactionId = "tf_http_trans_id" ) -type loggingHttpTransport struct { - transport http.RoundTripper +type providerHttpTransport struct { + setHeaders map[string]string + transport http.RoundTripper } -func (t *loggingHttpTransport) RoundTrip(req *http.Request) (*http.Response, error) { +func (t *providerHttpTransport) RoundTrip(req *http.Request) (*http.Response, error) { ctx := req.Context() ctx = t.addTransactionIdField(ctx) + // Set globally defined HTTP headers in the request + t.setRequestHeaders(req) + // Decompose the request bytes in a message (HTTP body) and fields (HTTP headers), then log it fields, err := decomposeRequestForLogging(req) if err != nil { @@ -160,7 +171,8 @@ func (t *loggingHttpTransport) RoundTrip(req *http.Request) (*http.Response, err return res, nil } -func (t *loggingHttpTransport) addTransactionIdField(ctx context.Context) context.Context { +// Generates UUID and sets it into the tf_http_trans_id logging field. +func (t *providerHttpTransport) addTransactionIdField(ctx context.Context) context.Context { tId, err := uuid.GenerateUUID() if err != nil { @@ -170,6 +182,13 @@ func (t *loggingHttpTransport) addTransactionIdField(ctx context.Context) contex return tflog.SetField(ctx, FieldHttpTransactionId, tId) } +// Sets globally defined HTTP headers in the request. +func (t *providerHttpTransport) setRequestHeaders(req *http.Request) { + for name, value := range t.setHeaders { + req.Header.Set(name, value) + } +} + func decomposeRequestForLogging(req *http.Request) (map[string]interface{}, error) { fields := make(map[string]interface{}, len(req.Header)+4) fields[FieldHttpOperationType] = OperationHttpRequest diff --git a/internal/sdk/.gitignore b/internal/sdk/.gitignore index d3c2f59..4f42473 100644 --- a/internal/sdk/.gitignore +++ b/internal/sdk/.gitignore @@ -1 +1,7 @@ +.DS_Store +**/.speakeasy/temp/ +**/.speakeasy/logs/ +.speakeasy/reports +.env +.env.local # .gitignore diff --git a/internal/sdk/customvariables.go b/internal/sdk/customvariables.go index 5d120c2..b60f49a 100644 --- a/internal/sdk/customvariables.go +++ b/internal/sdk/customvariables.go @@ -6,39 +6,36 @@ import ( "bytes" "context" "fmt" + "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/internal/config" "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/internal/hooks" "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/internal/utils" "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/models/errors" "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/models/operations" "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/models/shared" - "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/retry" "net/http" "net/url" ) +// CustomVariables - Custom variables type CustomVariables struct { - sdkConfiguration sdkConfiguration + rootSDK *SDK + sdkConfiguration config.SDKConfiguration + hooks *hooks.Hooks } -func newCustomVariables(sdkConfig sdkConfiguration) *CustomVariables { +func newCustomVariables(rootSDK *SDK, sdkConfig config.SDKConfiguration, hooks *hooks.Hooks) *CustomVariables { return &CustomVariables{ + rootSDK: rootSDK, sdkConfiguration: sdkConfig, + hooks: hooks, } } // CreateCustomVariable - Create custom variable // Create custom variable -func (s *CustomVariables) CreateCustomVariable(ctx context.Context, request *shared.CustomVariable, opts ...operations.Option) (*operations.CreateCustomVariableResponse, error) { - hookCtx := hooks.HookContext{ - Context: ctx, - OperationID: "createCustomVariable", - OAuth2Scopes: []string{}, - SecuritySource: s.sdkConfiguration.Security, - } - +func (s *CustomVariables) CreateCustomVariable(ctx context.Context, request *shared.CustomVariableInput, opts ...operations.Option) (*operations.CreateCustomVariableResponse, error) { o := operations.Options{} supportedOptions := []string{ - operations.SupportedOptionRetries, operations.SupportedOptionTimeout, } @@ -48,12 +45,26 @@ func (s *CustomVariables) CreateCustomVariable(ctx context.Context, request *sha } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } opURL, err := url.JoinPath(baseURL, "/v1/custom-variables") if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) } + hookCtx := hooks.HookContext{ + SDK: s.rootSDK, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "createCustomVariable", + OAuth2Scopes: nil, + SecuritySource: s.sdkConfiguration.Security, + } bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, false, true, "Request", "json", `request:"mediaType=application/json"`) if err != nil { return nil, err @@ -76,105 +87,44 @@ func (s *CustomVariables) CreateCustomVariable(ctx context.Context, request *sha } req.Header.Set("Accept", "application/json") req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) - req.Header.Set("Content-Type", reqContentType) + if reqContentType != "" { + req.Header.Set("Content-Type", reqContentType) + } if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil { return nil, err } - globalRetryConfig := s.sdkConfiguration.RetryConfig - retryConfig := o.Retries - if retryConfig == nil { - if globalRetryConfig != nil { - retryConfig = globalRetryConfig - } else { - retryConfig = &retry.Config{ - Strategy: "backoff", Backoff: &retry.BackoffStrategy{ - InitialInterval: 5000, - MaxInterval: 60000, - Exponent: 1.5, - MaxElapsedTime: 3600000, - }, - RetryConnectionErrors: true, - } - } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) } - var httpRes *http.Response - if retryConfig != nil { - httpRes, err = utils.Retry(ctx, utils.Retries{ - Config: retryConfig, - StatusCodes: []string{ - "5XX", - "5XX", - }, - }, func() (*http.Response, error) { - if req.Body != nil { - copyBody, err := req.GetBody() - if err != nil { - return nil, err - } - req.Body = copyBody - } - - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) - if err != nil { - if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { - return nil, err - } - - return nil, retry.Permanent(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.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) - } - return httpRes, err - }) + 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 { - return nil, err + err = fmt.Errorf("error sending request: %w", err) } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } + err = fmt.Errorf("error sending request: no response") } - } else { - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + + _, 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 } - - 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.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { return nil, err - } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { - _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) - if err != nil { - return nil, err - } else if _httpRes != nil { - httpRes = _httpRes - } - } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } } } @@ -224,16 +174,8 @@ func (s *CustomVariables) CreateCustomVariable(ctx context.Context, request *sha // DeleteCustomVariable - Delete custom variable // Immediately and permanently deletes a custom variable func (s *CustomVariables) DeleteCustomVariable(ctx context.Context, request operations.DeleteCustomVariableRequest, opts ...operations.Option) (*operations.DeleteCustomVariableResponse, error) { - hookCtx := hooks.HookContext{ - Context: ctx, - OperationID: "deleteCustomVariable", - OAuth2Scopes: []string{}, - SecuritySource: s.sdkConfiguration.Security, - } - o := operations.Options{} supportedOptions := []string{ - operations.SupportedOptionRetries, operations.SupportedOptionTimeout, } @@ -243,12 +185,27 @@ func (s *CustomVariables) DeleteCustomVariable(ctx context.Context, request oper } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } opURL, err := utils.GenerateURL(ctx, baseURL, "/v1/custom-variables/{id}", request, nil) if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) } + hookCtx := hooks.HookContext{ + SDK: s.rootSDK, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "deleteCustomVariable", + OAuth2Scopes: nil, + SecuritySource: s.sdkConfiguration.Security, + } + timeout := o.Timeout if timeout == nil { timeout = s.sdkConfiguration.Timeout @@ -271,99 +228,36 @@ func (s *CustomVariables) DeleteCustomVariable(ctx context.Context, request oper return nil, err } - globalRetryConfig := s.sdkConfiguration.RetryConfig - retryConfig := o.Retries - if retryConfig == nil { - if globalRetryConfig != nil { - retryConfig = globalRetryConfig - } else { - retryConfig = &retry.Config{ - Strategy: "backoff", Backoff: &retry.BackoffStrategy{ - InitialInterval: 5000, - MaxInterval: 60000, - Exponent: 1.5, - MaxElapsedTime: 3600000, - }, - RetryConnectionErrors: true, - } - } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) } - var httpRes *http.Response - if retryConfig != nil { - httpRes, err = utils.Retry(ctx, utils.Retries{ - Config: retryConfig, - StatusCodes: []string{ - "5XX", - "5XX", - }, - }, func() (*http.Response, error) { - if req.Body != nil { - copyBody, err := req.GetBody() - if err != nil { - return nil, err - } - req.Body = copyBody - } - - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) - if err != nil { - if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { - return nil, err - } - - return nil, retry.Permanent(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.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) - } - return httpRes, err - }) + 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 { - return nil, err + err = fmt.Errorf("error sending request: %w", err) } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } + err = fmt.Errorf("error sending request: no response") } - } else { - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + + _, 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 } - - 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.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { return nil, err - } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { - _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) - if err != nil { - return nil, err - } else if _httpRes != nil { - httpRes = _httpRes - } - } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } } } @@ -375,7 +269,6 @@ func (s *CustomVariables) DeleteCustomVariable(ctx context.Context, request oper switch { case httpRes.StatusCode == 204: - fallthrough case httpRes.StatusCode == 403: default: rawBody, err := utils.ConsumeRawBody(httpRes) @@ -392,16 +285,8 @@ func (s *CustomVariables) DeleteCustomVariable(ctx context.Context, request oper // GetBluePrintTableConfig - Get default table config // Get default table config func (s *CustomVariables) GetBluePrintTableConfig(ctx context.Context, opts ...operations.Option) (*operations.GetBluePrintTableConfigResponse, error) { - hookCtx := hooks.HookContext{ - Context: ctx, - OperationID: "getBluePrintTableConfig", - OAuth2Scopes: []string{}, - SecuritySource: s.sdkConfiguration.Security, - } - o := operations.Options{} supportedOptions := []string{ - operations.SupportedOptionRetries, operations.SupportedOptionTimeout, } @@ -411,12 +296,27 @@ func (s *CustomVariables) GetBluePrintTableConfig(ctx context.Context, opts ...o } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } opURL, err := url.JoinPath(baseURL, "/v1/custom-variables/order-table-blueprint") if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) } + hookCtx := hooks.HookContext{ + SDK: s.rootSDK, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "getBluePrintTableConfig", + OAuth2Scopes: nil, + SecuritySource: s.sdkConfiguration.Security, + } + timeout := o.Timeout if timeout == nil { timeout = s.sdkConfiguration.Timeout @@ -439,99 +339,36 @@ func (s *CustomVariables) GetBluePrintTableConfig(ctx context.Context, opts ...o return nil, err } - globalRetryConfig := s.sdkConfiguration.RetryConfig - retryConfig := o.Retries - if retryConfig == nil { - if globalRetryConfig != nil { - retryConfig = globalRetryConfig - } else { - retryConfig = &retry.Config{ - Strategy: "backoff", Backoff: &retry.BackoffStrategy{ - InitialInterval: 5000, - MaxInterval: 60000, - Exponent: 1.5, - MaxElapsedTime: 3600000, - }, - RetryConnectionErrors: true, - } - } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) } - var httpRes *http.Response - if retryConfig != nil { - httpRes, err = utils.Retry(ctx, utils.Retries{ - Config: retryConfig, - StatusCodes: []string{ - "5XX", - "5XX", - }, - }, func() (*http.Response, error) { - if req.Body != nil { - copyBody, err := req.GetBody() - if err != nil { - return nil, err - } - req.Body = copyBody - } - - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) - if err != nil { - if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { - return nil, err - } - - return nil, retry.Permanent(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.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) - } - return httpRes, err - }) + 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 { - return nil, err + err = fmt.Errorf("error sending request: %w", err) } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } + err = fmt.Errorf("error sending request: no response") } - } else { - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + + _, 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 } - - 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.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { return nil, err - } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { - _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) - if err != nil { - return nil, err - } else if _httpRes != nil { - httpRes = _httpRes - } - } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } } } @@ -579,16 +416,8 @@ func (s *CustomVariables) GetBluePrintTableConfig(ctx context.Context, opts ...o // GetCustomVariable - Get custom variable // Get custom variable func (s *CustomVariables) GetCustomVariable(ctx context.Context, request operations.GetCustomVariableRequest, opts ...operations.Option) (*operations.GetCustomVariableResponse, error) { - hookCtx := hooks.HookContext{ - Context: ctx, - OperationID: "getCustomVariable", - OAuth2Scopes: []string{}, - SecuritySource: s.sdkConfiguration.Security, - } - o := operations.Options{} supportedOptions := []string{ - operations.SupportedOptionRetries, operations.SupportedOptionTimeout, } @@ -598,12 +427,27 @@ func (s *CustomVariables) GetCustomVariable(ctx context.Context, request operati } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } opURL, err := utils.GenerateURL(ctx, baseURL, "/v1/custom-variables/{id}", request, nil) if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) } + hookCtx := hooks.HookContext{ + SDK: s.rootSDK, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "getCustomVariable", + OAuth2Scopes: nil, + SecuritySource: s.sdkConfiguration.Security, + } + timeout := o.Timeout if timeout == nil { timeout = s.sdkConfiguration.Timeout @@ -626,99 +470,36 @@ func (s *CustomVariables) GetCustomVariable(ctx context.Context, request operati return nil, err } - globalRetryConfig := s.sdkConfiguration.RetryConfig - retryConfig := o.Retries - if retryConfig == nil { - if globalRetryConfig != nil { - retryConfig = globalRetryConfig - } else { - retryConfig = &retry.Config{ - Strategy: "backoff", Backoff: &retry.BackoffStrategy{ - InitialInterval: 5000, - MaxInterval: 60000, - Exponent: 1.5, - MaxElapsedTime: 3600000, - }, - RetryConnectionErrors: true, - } - } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) } - var httpRes *http.Response - if retryConfig != nil { - httpRes, err = utils.Retry(ctx, utils.Retries{ - Config: retryConfig, - StatusCodes: []string{ - "5XX", - "5XX", - }, - }, func() (*http.Response, error) { - if req.Body != nil { - copyBody, err := req.GetBody() - if err != nil { - return nil, err - } - req.Body = copyBody - } - - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) - if err != nil { - if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { - return nil, err - } - - return nil, retry.Permanent(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.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) - } - return httpRes, err - }) + 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 { - return nil, err + err = fmt.Errorf("error sending request: %w", err) } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } + err = fmt.Errorf("error sending request: no response") } - } else { - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + + _, 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 } - - 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.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { return nil, err - } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { - _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) - if err != nil { - return nil, err - } else if _httpRes != nil { - httpRes = _httpRes - } - } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } } } @@ -768,16 +549,8 @@ func (s *CustomVariables) GetCustomVariable(ctx context.Context, request operati // GetCustomVariables - Get custom variables // Get all custom variables of organization func (s *CustomVariables) GetCustomVariables(ctx context.Context, opts ...operations.Option) (*operations.GetCustomVariablesResponse, error) { - hookCtx := hooks.HookContext{ - Context: ctx, - OperationID: "getCustomVariables", - OAuth2Scopes: []string{}, - SecuritySource: s.sdkConfiguration.Security, - } - o := operations.Options{} supportedOptions := []string{ - operations.SupportedOptionRetries, operations.SupportedOptionTimeout, } @@ -787,12 +560,27 @@ func (s *CustomVariables) GetCustomVariables(ctx context.Context, opts ...operat } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } opURL, err := url.JoinPath(baseURL, "/v1/custom-variables") if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) } + hookCtx := hooks.HookContext{ + SDK: s.rootSDK, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "getCustomVariables", + OAuth2Scopes: nil, + SecuritySource: s.sdkConfiguration.Security, + } + timeout := o.Timeout if timeout == nil { timeout = s.sdkConfiguration.Timeout @@ -815,100 +603,37 @@ func (s *CustomVariables) GetCustomVariables(ctx context.Context, opts ...operat return nil, err } - globalRetryConfig := s.sdkConfiguration.RetryConfig - retryConfig := o.Retries - if retryConfig == nil { - if globalRetryConfig != nil { - retryConfig = globalRetryConfig - } else { - retryConfig = &retry.Config{ - Strategy: "backoff", Backoff: &retry.BackoffStrategy{ - InitialInterval: 5000, - MaxInterval: 60000, - Exponent: 1.5, - MaxElapsedTime: 3600000, - }, - RetryConnectionErrors: true, - } - } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) } - var httpRes *http.Response - if retryConfig != nil { - httpRes, err = utils.Retry(ctx, utils.Retries{ - Config: retryConfig, - StatusCodes: []string{ - "5XX", - "5XX", - }, - }, func() (*http.Response, error) { - if req.Body != nil { - copyBody, err := req.GetBody() - if err != nil { - return nil, err - } - req.Body = copyBody - } - - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) - if err != nil { - if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { - return nil, err - } - - return nil, retry.Permanent(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") - } + req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + if err != nil { + return nil, err + } - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) - } - return httpRes, 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 { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } + } else if _httpRes != nil { + httpRes = _httpRes } } else { - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) 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.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) - return nil, err - } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { - _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) - if err != nil { - return nil, err - } else if _httpRes != nil { - httpRes = _httpRes - } - } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } - } } res := &operations.GetCustomVariablesResponse{ @@ -955,16 +680,8 @@ func (s *CustomVariables) GetCustomVariables(ctx context.Context, opts ...operat // SearchCustomVariables - searchCustomVariables // Search custom variables func (s *CustomVariables) SearchCustomVariables(ctx context.Context, request *shared.CustomVariablesSearchParams, opts ...operations.Option) (*operations.SearchCustomVariablesResponse, error) { - hookCtx := hooks.HookContext{ - Context: ctx, - OperationID: "searchCustomVariables", - OAuth2Scopes: []string{}, - SecuritySource: s.sdkConfiguration.Security, - } - o := operations.Options{} supportedOptions := []string{ - operations.SupportedOptionRetries, operations.SupportedOptionTimeout, } @@ -974,12 +691,26 @@ func (s *CustomVariables) SearchCustomVariables(ctx context.Context, request *sh } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } opURL, err := url.JoinPath(baseURL, "/v1/custom-variables:search") if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) } + hookCtx := hooks.HookContext{ + SDK: s.rootSDK, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "searchCustomVariables", + OAuth2Scopes: nil, + SecuritySource: s.sdkConfiguration.Security, + } bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, false, true, "Request", "json", `request:"mediaType=application/json"`) if err != nil { return nil, err @@ -1002,105 +733,44 @@ func (s *CustomVariables) SearchCustomVariables(ctx context.Context, request *sh } req.Header.Set("Accept", "application/json") req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) - req.Header.Set("Content-Type", reqContentType) + if reqContentType != "" { + req.Header.Set("Content-Type", reqContentType) + } if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil { return nil, err } - globalRetryConfig := s.sdkConfiguration.RetryConfig - retryConfig := o.Retries - if retryConfig == nil { - if globalRetryConfig != nil { - retryConfig = globalRetryConfig - } else { - retryConfig = &retry.Config{ - Strategy: "backoff", Backoff: &retry.BackoffStrategy{ - InitialInterval: 5000, - MaxInterval: 60000, - Exponent: 1.5, - MaxElapsedTime: 3600000, - }, - RetryConnectionErrors: true, - } - } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) } - var httpRes *http.Response - if retryConfig != nil { - httpRes, err = utils.Retry(ctx, utils.Retries{ - Config: retryConfig, - StatusCodes: []string{ - "5XX", - "5XX", - }, - }, func() (*http.Response, error) { - if req.Body != nil { - copyBody, err := req.GetBody() - if err != nil { - return nil, err - } - req.Body = copyBody - } - - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) - if err != nil { - if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { - return nil, err - } - - return nil, retry.Permanent(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.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) - } - return httpRes, err - }) + 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 { - return nil, err + err = fmt.Errorf("error sending request: %w", err) } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } + err = fmt.Errorf("error sending request: no response") } - } else { - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + + _, 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 } - - 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.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { return nil, err - } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { - _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) - if err != nil { - return nil, err - } else if _httpRes != nil { - httpRes = _httpRes - } - } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } } } @@ -1148,16 +818,8 @@ func (s *CustomVariables) SearchCustomVariables(ctx context.Context, request *sh // UpdateCustomVariable - Update custom variable // Update custom variable func (s *CustomVariables) UpdateCustomVariable(ctx context.Context, request operations.UpdateCustomVariableRequest, opts ...operations.Option) (*operations.UpdateCustomVariableResponse, error) { - hookCtx := hooks.HookContext{ - Context: ctx, - OperationID: "updateCustomVariable", - OAuth2Scopes: []string{}, - SecuritySource: s.sdkConfiguration.Security, - } - o := operations.Options{} supportedOptions := []string{ - operations.SupportedOptionRetries, operations.SupportedOptionTimeout, } @@ -1167,12 +829,26 @@ func (s *CustomVariables) UpdateCustomVariable(ctx context.Context, request oper } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } opURL, err := utils.GenerateURL(ctx, baseURL, "/v1/custom-variables/{id}", request, nil) if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) } + hookCtx := hooks.HookContext{ + SDK: s.rootSDK, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "updateCustomVariable", + OAuth2Scopes: nil, + SecuritySource: s.sdkConfiguration.Security, + } bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, false, true, "CustomVariable", "json", `request:"mediaType=application/json"`) if err != nil { return nil, err @@ -1195,105 +871,44 @@ func (s *CustomVariables) UpdateCustomVariable(ctx context.Context, request oper } req.Header.Set("Accept", "application/json") req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) - req.Header.Set("Content-Type", reqContentType) + if reqContentType != "" { + req.Header.Set("Content-Type", reqContentType) + } if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil { return nil, err } - globalRetryConfig := s.sdkConfiguration.RetryConfig - retryConfig := o.Retries - if retryConfig == nil { - if globalRetryConfig != nil { - retryConfig = globalRetryConfig - } else { - retryConfig = &retry.Config{ - Strategy: "backoff", Backoff: &retry.BackoffStrategy{ - InitialInterval: 5000, - MaxInterval: 60000, - Exponent: 1.5, - MaxElapsedTime: 3600000, - }, - RetryConnectionErrors: true, - } - } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) } - var httpRes *http.Response - if retryConfig != nil { - httpRes, err = utils.Retry(ctx, utils.Retries{ - Config: retryConfig, - StatusCodes: []string{ - "5XX", - "5XX", - }, - }, func() (*http.Response, error) { - if req.Body != nil { - copyBody, err := req.GetBody() - if err != nil { - return nil, err - } - req.Body = copyBody - } - - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) - if err != nil { - if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { - return nil, err - } - - return nil, retry.Permanent(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.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) - } - return httpRes, err - }) + 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 { - return nil, err + err = fmt.Errorf("error sending request: %w", err) } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } + err = fmt.Errorf("error sending request: no response") } - } else { - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + + _, 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 } - - 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.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { return nil, err - } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { - _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) - if err != nil { - return nil, err - } else if _httpRes != nil { - httpRes = _httpRes - } - } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } } } diff --git a/internal/sdk/internal/config/sdkconfiguration.go b/internal/sdk/internal/config/sdkconfiguration.go new file mode 100644 index 0000000..aa2ccc6 --- /dev/null +++ b/internal/sdk/internal/config/sdkconfiguration.go @@ -0,0 +1,33 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package config + +import ( + "context" + "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/retry" + "net/http" + "time" +) + +type HTTPClient interface { + Do(req *http.Request) (*http.Response, error) +} + +type SDKConfiguration struct { + Client HTTPClient + Security func(context.Context) (interface{}, error) + ServerURL string + ServerIndex int + ServerList []string + UserAgent string + RetryConfig *retry.Config + Timeout *time.Duration +} + +func (c *SDKConfiguration) GetServerDetails() (string, map[string]string) { + if c.ServerURL != "" { + return c.ServerURL, nil + } + + return c.ServerList[c.ServerIndex], nil +} diff --git a/internal/sdk/internal/hooks/hooks.go b/internal/sdk/internal/hooks/hooks.go index 8ea491a..1cd66d0 100644 --- a/internal/sdk/internal/hooks/hooks.go +++ b/internal/sdk/internal/hooks/hooks.go @@ -5,6 +5,7 @@ package hooks import ( "context" "errors" + "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/internal/config" "net/http" ) @@ -24,10 +25,13 @@ type HTTPClient interface { } type HookContext struct { - Context context.Context - OperationID string - OAuth2Scopes []string - SecuritySource func(context.Context) (interface{}, error) + SDK any + SDKConfiguration config.SDKConfiguration + BaseURL string + Context context.Context + OperationID string + OAuth2Scopes []string + SecuritySource func(context.Context) (interface{}, error) } type BeforeRequestContext struct { @@ -70,6 +74,11 @@ type Hooks struct { afterErrorHook []afterErrorHook } +var _ sdkInitHook = (*Hooks)(nil) +var _ beforeRequestHook = (*Hooks)(nil) +var _ afterSuccessHook = (*Hooks)(nil) +var _ afterErrorHook = (*Hooks)(nil) + func New() *Hooks { h := &Hooks{ sdkInitHooks: []sdkInitHook{}, diff --git a/internal/sdk/internal/utils/form.go b/internal/sdk/internal/utils/form.go index 19dcb76..be0e5ee 100644 --- a/internal/sdk/internal/utils/form.go +++ b/internal/sdk/internal/utils/form.go @@ -10,16 +10,19 @@ import ( "strings" "time" - "github.com/ericlagergren/decimal" - + "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/optionalnullable" "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/types" ) -func populateForm(paramName string, explode bool, objType reflect.Type, objValue reflect.Value, delimiter string, getFieldName func(reflect.StructField) string) url.Values { +func populateForm(paramName string, explode bool, objType reflect.Type, objValue reflect.Value, delimiter string, defaultValue *string, getFieldName func(reflect.StructField) string) url.Values { formValues := url.Values{} if isNil(objType, objValue) { + if defaultValue != nil { + formValues.Add(paramName, *defaultValue) + } + return formValues } @@ -37,8 +40,6 @@ func populateForm(paramName string, explode bool, objType reflect.Type, objValue formValues.Add(paramName, valToString(objValue.Interface())) case big.Int: formValues.Add(paramName, valToString(objValue.Interface())) - case decimal.Big: - formValues.Add(paramName, valToString(objValue.Interface())) default: var items []string @@ -60,7 +61,13 @@ func populateForm(paramName string, explode bool, objType reflect.Type, objValue } if explode { - formValues.Add(fieldName, valToString(valType.Interface())) + if valType.Kind() == reflect.Slice || valType.Kind() == reflect.Array { + for i := 0; i < valType.Len(); i++ { + formValues.Add(fieldName, valToString(valType.Index(i).Interface())) + } + } else { + formValues.Add(fieldName, valToString(valType.Interface())) + } } else { items = append(items, fmt.Sprintf("%s%s%s", fieldName, delimiter, valToString(valType.Interface()))) } @@ -71,6 +78,16 @@ func populateForm(paramName string, explode bool, objType reflect.Type, objValue } } case reflect.Map: + // check if optionalnullable.OptionalNullable[T] + if nullableValue, ok := optionalnullable.AsOptionalNullable(objValue); ok { + // Handle optionalnullable.OptionalNullable[T] using GetUntyped method + if value, isSet := nullableValue.GetUntyped(); isSet && value != nil { + formValues.Add(paramName, valToString(value)) + } + // If not set or explicitly null, skip adding to form + return formValues + } + items := []string{} iter := objValue.MapRange() diff --git a/internal/sdk/internal/utils/headers.go b/internal/sdk/internal/utils/headers.go index a07608b..c46fbe3 100644 --- a/internal/sdk/internal/utils/headers.go +++ b/internal/sdk/internal/utils/headers.go @@ -8,6 +8,8 @@ import ( "net/http" "reflect" "strings" + + "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/optionalnullable" ) func PopulateHeaders(_ context.Context, req *http.Request, headers interface{}, globals interface{}) { @@ -98,6 +100,16 @@ func serializeHeader(objType reflect.Type, objValue reflect.Value, explode bool) return strings.Join(items, ",") case reflect.Map: + // check if optionalnullable.OptionalNullable[T] + if nullableValue, ok := optionalnullable.AsOptionalNullable(objValue); ok { + // Handle optionalnullable.OptionalNullable[T] using GetUntyped method + if value, isSet := nullableValue.GetUntyped(); isSet && value != nil { + return valToString(value) + } + // If not set or explicitly null, return empty string + return "" + } + items := []string{} iter := objValue.MapRange() diff --git a/internal/sdk/internal/utils/json.go b/internal/sdk/internal/utils/json.go index 57e3a4b..9bd60da 100644 --- a/internal/sdk/internal/utils/json.go +++ b/internal/sdk/internal/utils/json.go @@ -5,6 +5,7 @@ package utils import ( "bytes" "encoding/json" + "errors" "fmt" "math/big" "reflect" @@ -14,8 +15,6 @@ import ( "unsafe" "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/types" - - "github.com/ericlagergren/decimal" ) func MarshalJSON(v interface{}, tag reflect.StructTag, topLevel bool) ([]byte, error) { @@ -40,21 +39,30 @@ func MarshalJSON(v interface{}, tag reflect.StructTag, topLevel bool) ([]byte, e fieldName := field.Name omitEmpty := false + omitZero := false jsonTag := field.Tag.Get("json") if jsonTag != "" { for _, tag := range strings.Split(jsonTag, ",") { if tag == "omitempty" { omitEmpty = true + } else if tag == "omitzero" { + omitZero = true } else { fieldName = tag } } } - if isNil(field.Type, fieldVal) && field.Tag.Get("const") == "" { - if omitEmpty { + if (omitEmpty || omitZero) && field.Tag.Get("const") == "" { + // Both omitempty and omitzero skip zero values (including nil) + if isNil(field.Type, fieldVal) { + continue + } + + if omitZero && fieldVal.IsZero() { continue } + } if !field.IsExported() && field.Tag.Get("const") == "" { @@ -114,9 +122,9 @@ func MarshalJSON(v interface{}, tag reflect.StructTag, topLevel bool) ([]byte, e } } -func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool, disallowUnknownFields bool) error { +func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool, requiredFields []string) error { if reflect.TypeOf(v).Kind() != reflect.Ptr { - return fmt.Errorf("v must be a pointer") + return errors.New("v must be a pointer") } typ, val := dereferencePointers(reflect.TypeOf(v), reflect.ValueOf(v)) @@ -124,19 +132,25 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool switch { case isModelType(typ): if topLevel || bytes.Equal(b, []byte("null")) { - d := json.NewDecoder(bytes.NewReader(b)) - if disallowUnknownFields { - d.DisallowUnknownFields() - } - return d.Decode(v) + return json.Unmarshal(b, v) } - var unmarhsaled map[string]json.RawMessage + var unmarshaled map[string]json.RawMessage - if err := json.Unmarshal(b, &unmarhsaled); err != nil { + if err := json.Unmarshal(b, &unmarshaled); err != nil { return err } + missingFields := []string{} + for _, requiredField := range requiredFields { + if _, ok := unmarshaled[requiredField]; !ok { + missingFields = append(missingFields, requiredField) + } + } + if len(missingFields) > 0 { + return fmt.Errorf("missing required fields: %s", strings.Join(missingFields, ", ")) + } + var additionalPropertiesField *reflect.StructField var additionalPropertiesValue *reflect.Value @@ -149,7 +163,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool jsonTag := field.Tag.Get("json") if jsonTag != "" { for _, tag := range strings.Split(jsonTag, ",") { - if tag != "omitempty" { + if tag != "omitempty" && tag != "omitzero" { fieldName = tag } } @@ -163,7 +177,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 := unmarhsaled[fieldName]; ok { + if r, ok := unmarshaled[fieldName]; ok { val := string(r) if strings.HasPrefix(val, `"`) && strings.HasSuffix(val, `"`) { @@ -178,40 +192,36 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } - delete(unmarhsaled, fieldName) + delete(unmarshaled, fieldName) } } else if !field.IsExported() { continue } - value, ok := unmarhsaled[fieldName] + value, ok := unmarshaled[fieldName] if !ok { - defaultTag := field.Tag.Get("default") - if defaultTag != "" { + defaultTag, defaultOk := field.Tag.Lookup("default") + if defaultOk { value = handleDefaultConstValue(defaultTag, fieldVal.Interface(), field.Tag) ok = true } } else { - delete(unmarhsaled, fieldName) + delete(unmarshaled, fieldName) } if ok { - if err := unmarshalValue(value, fieldVal, field.Tag, disallowUnknownFields); err != nil { + if err := unmarshalValue(value, fieldVal, field.Tag); err != nil { return err } } } - keys := make([]string, 0, len(unmarhsaled)) - for k := range unmarhsaled { + keys := make([]string, 0, len(unmarshaled)) + for k := range unmarshaled { keys = append(keys, k) } if len(keys) > 0 { - if disallowUnknownFields && (additionalPropertiesField == nil || additionalPropertiesValue == nil) { - return fmt.Errorf("unknown fields: %v", keys) - } - if additionalPropertiesField != nil && additionalPropertiesValue != nil { typeOfMap := additionalPropertiesField.Type if additionalPropertiesValue.Type().Kind() == reflect.Interface { @@ -222,10 +232,10 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool mapValue := reflect.MakeMap(typeOfMap) - for key, value := range unmarhsaled { + for key, value := range unmarshaled { val := reflect.New(typeOfMap.Elem()) - if err := unmarshalValue(value, val, additionalPropertiesField.Tag, disallowUnknownFields); err != nil { + if err := unmarshalValue(value, val, additionalPropertiesField.Tag); err != nil { return err } @@ -244,7 +254,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } default: - return unmarshalValue(b, reflect.ValueOf(v), tag, disallowUnknownFields) + return unmarshalValue(b, reflect.ValueOf(v), tag) } return nil @@ -257,8 +267,8 @@ func marshalValue(v interface{}, tag reflect.StructTag) (json.RawMessage, error) } if isNil(reflect.TypeOf(v), reflect.ValueOf(v)) { - defaultTag := tag.Get("default") - if defaultTag != "" { + defaultTag, ok := tag.Lookup("default") + if ok { return handleDefaultConstValue(defaultTag, v, tag), nil } @@ -284,6 +294,11 @@ func marshalValue(v interface{}, tag reflect.StructTag) (json.RawMessage, error) return []byte("null"), nil } + // Check if the map implements json.Marshaler (like optionalnullable.OptionalNullable[T]) + if marshaler, ok := val.Interface().(json.Marshaler); ok { + return marshaler.MarshalJSON() + } + out := map[string]json.RawMessage{} for _, key := range val.MapKeys() { @@ -337,17 +352,6 @@ func marshalValue(v interface{}, tag reflect.StructTag) (json.RawMessage, error) b := val.Interface().(big.Int) return []byte(fmt.Sprintf(`"%s"`, (&b).String())), nil } - case reflect.TypeOf(decimal.Big{}): - format := tag.Get("decimal") - if format == "number" { - b := val.Interface().(decimal.Big) - f, ok := (&b).Float64() - if ok { - return []byte(b.String()), nil - } - - return []byte(fmt.Sprintf(`%f`, f)), nil - } } } @@ -378,11 +382,6 @@ func handleDefaultConstValue(tagValue string, val interface{}, tag reflect.Struc if format == "string" { return []byte(fmt.Sprintf(`"%s"`, tagValue)) } - case reflect.TypeOf(decimal.Big{}): - decimalTag := tag.Get("decimal") - if decimalTag != "number" { - return []byte(fmt.Sprintf(`"%s"`, tagValue)) - } case reflect.TypeOf(types.Date{}): return []byte(fmt.Sprintf(`"%s"`, tagValue)) default: @@ -394,7 +393,7 @@ func handleDefaultConstValue(tagValue string, val interface{}, tag reflect.Struc return []byte(tagValue) } -func unmarshalValue(value json.RawMessage, v reflect.Value, tag reflect.StructTag, disallowUnknownFields bool) error { +func unmarshalValue(value json.RawMessage, v reflect.Value, tag reflect.StructTag) error { if bytes.Equal(value, []byte("null")) { if v.CanAddr() { return json.Unmarshal(value, v.Addr().Interface()) @@ -466,18 +465,18 @@ func unmarshalValue(value json.RawMessage, v reflect.Value, tag reflect.StructTa } } - var unmarhsaled map[string]json.RawMessage + var unmarshaled map[string]json.RawMessage - if err := json.Unmarshal(value, &unmarhsaled); err != nil { + if err := json.Unmarshal(value, &unmarshaled); err != nil { return err } m := reflect.MakeMap(typ) - for k, value := range unmarhsaled { + for k, value := range unmarshaled { itemVal := reflect.New(typ.Elem()) - if err := unmarshalValue(value, itemVal, tag, disallowUnknownFields); err != nil { + if err := unmarshalValue(value, itemVal, tag); err != nil { return err } @@ -498,7 +497,7 @@ func unmarshalValue(value json.RawMessage, v reflect.Value, tag reflect.StructTa for index, value := range unmarshaled { itemVal := reflect.New(typ.Elem()) - if err := unmarshalValue(value, itemVal, tag, disallowUnknownFields); err != nil { + if err := unmarshalValue(value, itemVal, tag); err != nil { return err } @@ -563,27 +562,6 @@ func unmarshalValue(value json.RawMessage, v reflect.Value, tag reflect.StructTa v.Set(reflect.ValueOf(b)) return nil - case reflect.TypeOf(decimal.Big{}): - var d *decimal.Big - format := tag.Get("decimal") - if format == "number" { - var ok bool - d, ok = new(decimal.Big).SetString(string(value)) - if !ok { - return fmt.Errorf("failed to parse number as decimal.Big") - } - } else { - if err := json.Unmarshal(value, &d); err != nil { - return err - } - } - - if v.Kind() == reflect.Ptr && v.Elem().Kind() == reflect.Ptr { - v = v.Elem() - } - - v.Set(reflect.ValueOf(d)) - return nil case reflect.TypeOf(types.Date{}): var s string @@ -616,11 +594,7 @@ func unmarshalValue(value json.RawMessage, v reflect.Value, tag reflect.StructTa val = v.Interface() } - d := json.NewDecoder(bytes.NewReader(value)) - if disallowUnknownFields { - d.DisallowUnknownFields() - } - return d.Decode(val) + return json.Unmarshal(value, val) } func dereferencePointers(typ reflect.Type, val reflect.Value) (reflect.Type, reflect.Value) { @@ -652,8 +626,6 @@ func isComplexValueType(typ reflect.Type) bool { fallthrough case reflect.TypeOf(big.Int{}): fallthrough - case reflect.TypeOf(decimal.Big{}): - fallthrough case reflect.TypeOf(types.Date{}): return true } @@ -673,3 +645,215 @@ func isModelType(typ reflect.Type) bool { return false } + +// CalculateJSONSize returns the byte size of the JSON representation of a value. +// This is used to determine which union type variant has the most data. +func CalculateJSONSize(v interface{}) int { + data, err := json.Marshal(v) + if err != nil { + return 0 + } + return len(data) +} + +// UnionCandidate represents a candidate type during union deserialization +type UnionCandidate struct { + FieldCount int + Size int + Type any // The union type enum value + Value any // The unmarshaled value +} + +// CountFields recursively counts the number of valid (non-nil, non-zero) fields set in a value. +// This is used as the primary discriminator for union types, with JSON size as a tiebreaker. +func CountFields(v interface{}) int { + if v == nil { + return 0 + } + + typ := reflect.TypeOf(v) + val := reflect.ValueOf(v) + + // Dereference pointers + for typ.Kind() == reflect.Ptr { + if val.IsNil() { + return 0 + } + typ = typ.Elem() + val = val.Elem() + } + + return countFieldsRecursive(typ, val) +} + +// PickBestCandidate selects the best union type candidate using a multi-stage filtering approach: +// 1. If multiple candidates, filter by field count (keep only those with max field count) +// 2. If still multiple, filter by JSON size (keep only those with max size) +// 3. Return the first remaining candidate +func PickBestCandidate(candidates []UnionCandidate) *UnionCandidate { + if len(candidates) == 0 { + return nil + } + + if len(candidates) == 1 { + return &candidates[0] + } + + // Filter by field count if we have multiple candidates + if len(candidates) > 1 { + maxFieldCount := -1 + for i := range candidates { + candidates[i].FieldCount = CountFields(candidates[i].Value) + if candidates[i].FieldCount > maxFieldCount { + maxFieldCount = candidates[i].FieldCount + } + } + + // Keep only candidates with maximum field count + filtered := make([]UnionCandidate, 0, len(candidates)) + for _, c := range candidates { + if c.FieldCount == maxFieldCount { + filtered = append(filtered, c) + } + } + candidates = filtered + } + + if len(candidates) == 1 { + return &candidates[0] + } + + // Filter by JSON size if we still have multiple candidates + if len(candidates) > 1 { + maxSize := -1 + for i := range candidates { + candidates[i].Size = CalculateJSONSize(candidates[i].Value) + if candidates[i].Size > maxSize { + maxSize = candidates[i].Size + } + } + + // Keep only candidates with maximum size + filtered := make([]UnionCandidate, 0, len(candidates)) + for _, c := range candidates { + if c.Size == maxSize { + filtered = append(filtered, c) + } + } + candidates = filtered + } + + // Pick the first remaining candidate + return &candidates[0] +} + +func countFieldsRecursive(typ reflect.Type, val reflect.Value) int { + count := 0 + + switch typ.Kind() { + case reflect.Struct: + // Handle special types + switch typ { + case reflect.TypeOf(time.Time{}): + if !val.Interface().(time.Time).IsZero() { + return 1 + } + return 0 + case reflect.TypeOf(big.Int{}): + b := val.Interface().(big.Int) + if b.Sign() != 0 { + return 1 + } + return 0 + case reflect.TypeOf(types.Date{}): + // Date is always counted if it exists + return 1 + } + + // For regular structs, count non-zero fields + for i := 0; i < typ.NumField(); i++ { + field := typ.Field(i) + fieldVal := val.Field(i) + + // Skip unexported fields and const fields + if !field.IsExported() || field.Tag.Get("const") != "" { + continue + } + + // Skip fields tagged with json:"-" + jsonTag := field.Tag.Get("json") + if jsonTag == "-" { + continue + } + + fieldTyp := field.Type + // Dereference pointer types for the field + for fieldTyp.Kind() == reflect.Ptr { + if fieldVal.IsNil() { + break + } + fieldTyp = fieldTyp.Elem() + fieldVal = fieldVal.Elem() + } + + if !isNil(field.Type, val.Field(i)) { + count += countFieldsRecursive(fieldTyp, fieldVal) + } + } + + case reflect.Slice, reflect.Array: + if val.IsNil() || val.Len() == 0 { + return 0 + } + // Count each array/slice element + for i := 0; i < val.Len(); i++ { + itemVal := val.Index(i) + itemTyp := itemVal.Type() + + // Dereference pointer types + for itemTyp.Kind() == reflect.Ptr { + if itemVal.IsNil() { + break + } + itemTyp = itemTyp.Elem() + itemVal = itemVal.Elem() + } + + if !isNil(itemTyp, itemVal) { + count += countFieldsRecursive(itemTyp, itemVal) + } + } + + case reflect.String: + if val.String() != "" { + count = 1 + } + + case reflect.Bool: + // Bools always count as a field (even if false) + count = 1 + + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + if val.Int() != 0 { + count = 1 + } + + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: + if val.Uint() != 0 { + count = 1 + } + + case reflect.Float32, reflect.Float64: + if val.Float() != 0 { + count = 1 + } + + default: + // For any other type, if it's not zero, count it as 1 + if !val.IsZero() { + count = 1 + } + } + + return count +} diff --git a/internal/sdk/internal/utils/pathparams.go b/internal/sdk/internal/utils/pathparams.go index 9406587..15300c2 100644 --- a/internal/sdk/internal/utils/pathparams.go +++ b/internal/sdk/internal/utils/pathparams.go @@ -11,8 +11,7 @@ import ( "strings" "time" - "github.com/ericlagergren/decimal" - + "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/optionalnullable" "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/types" ) @@ -114,6 +113,16 @@ func getSimplePathParams(parentName string, objType reflect.Type, objValue refle } pathParams[parentName] = strings.Join(ppVals, ",") case reflect.Map: + // check if optionalnullable.OptionalNullable[T] + if nullableValue, ok := optionalnullable.AsOptionalNullable(objValue); ok { + // Handle optionalnullable.OptionalNullable[T] using GetUntyped method + if value, isSet := nullableValue.GetUntyped(); isSet && value != nil { + pathParams[parentName] = valToString(value) + } + // If not set or explicitly null, return nil (skip parameter) + return pathParams + } + if objValue.Len() == 0 { return nil } @@ -135,8 +144,6 @@ func getSimplePathParams(parentName string, objType reflect.Type, objValue refle pathParams[parentName] = valToString(objValue.Interface()) case big.Int: pathParams[parentName] = valToString(objValue.Interface()) - case decimal.Big: - pathParams[parentName] = valToString(objValue.Interface()) default: var ppVals []string for i := 0; i < objType.NumField(); i++ { diff --git a/internal/sdk/internal/utils/queryparams.go b/internal/sdk/internal/utils/queryparams.go index b21584e..b4cc23f 100644 --- a/internal/sdk/internal/utils/queryparams.go +++ b/internal/sdk/internal/utils/queryparams.go @@ -12,8 +12,7 @@ import ( "reflect" "time" - "github.com/ericlagergren/decimal" - + "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/optionalnullable" "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/types" ) @@ -43,10 +42,13 @@ func PopulateQueryParams(_ context.Context, req *http.Request, queryParams inter } func populateQueryParams(queryParams interface{}, globals interface{}, values url.Values, skipFields []string) ([]string, error) { - queryParamsStructType, queryParamsValType := dereferencePointers(reflect.TypeOf(queryParams), reflect.ValueOf(queryParams)) + queryParamsVal := reflect.ValueOf(queryParams) + if queryParamsVal.Kind() == reflect.Pointer && queryParamsVal.IsNil() { + return nil, nil + } + queryParamsStructType, queryParamsValType := dereferencePointers(reflect.TypeOf(queryParams), queryParamsVal) globalsAlreadyPopulated := []string{} - for i := 0; i < queryParamsStructType.NumField(); i++ { fieldType := queryParamsStructType.Field(i) valType := queryParamsValType.Field(i) @@ -65,6 +67,14 @@ func populateQueryParams(queryParams interface{}, globals interface{}, values ur continue } + constValue := parseConstTag(fieldType) + if constValue != nil { + values.Add(qpTag.ParamName, *constValue) + continue + } + + defaultValue := parseDefaultTag(fieldType) + if globals != nil { var globalFound bool fieldType, valType, globalFound = populateFromGlobals(fieldType, valType, queryParamTagKey, globals) @@ -91,14 +101,14 @@ func populateQueryParams(queryParams interface{}, globals interface{}, values ur } } case "form": - vals := populateFormParams(qpTag, fieldType.Type, valType, ",") + vals := populateFormParams(qpTag, fieldType.Type, valType, ",", defaultValue) for k, v := range vals { for _, vv := range v { values.Add(k, vv) } } case "pipeDelimited": - vals := populateFormParams(qpTag, fieldType.Type, valType, "|") + vals := populateFormParams(qpTag, fieldType.Type, valType, "|", defaultValue) for k, v := range vals { for _, vv := range v { values.Add(k, vv) @@ -149,6 +159,16 @@ func populateDeepObjectParams(tag *paramTag, objType reflect.Type, objValue refl switch objValue.Kind() { case reflect.Map: + // check if optionalnullable.OptionalNullable[T] + if nullableValue, ok := optionalnullable.AsOptionalNullable(objValue); ok { + // Handle optionalnullable.OptionalNullable[T] using GetUntyped method + if value, isSet := nullableValue.GetUntyped(); isSet && value != nil { + values.Add(tag.ParamName, valToString(value)) + } + // If not set or explicitly null, skip adding to values + return values + } + populateDeepObjectParamsMap(values, tag.ParamName, objValue) case reflect.Struct: populateDeepObjectParamsStruct(values, tag.ParamName, objValue) @@ -214,7 +234,11 @@ func populateDeepObjectParamsStruct(qsValues url.Values, priorScope string, stru continue } - scope := priorScope + "[" + qpTag.ParamName + "]" + scope := priorScope + + if !qpTag.Inline { + scope = priorScope + "[" + qpTag.ParamName + "]" + } switch fieldValue.Kind() { case reflect.Array, reflect.Slice: @@ -223,7 +247,7 @@ func populateDeepObjectParamsStruct(qsValues url.Values, priorScope string, stru populateDeepObjectParamsMap(qsValues, scope, fieldValue) case reflect.Struct: switch fieldValue.Type() { - case reflect.TypeOf(big.Int{}), reflect.TypeOf(decimal.Big{}), reflect.TypeOf(time.Time{}), reflect.TypeOf(types.Date{}): + case reflect.TypeOf(big.Int{}), reflect.TypeOf(time.Time{}), reflect.TypeOf(types.Date{}): qsValues.Add(scope, valToString(fieldValue.Interface())) continue @@ -236,8 +260,8 @@ func populateDeepObjectParamsStruct(qsValues url.Values, priorScope string, stru } } -func populateFormParams(tag *paramTag, objType reflect.Type, objValue reflect.Value, delimiter string) url.Values { - return populateForm(tag.ParamName, tag.Explode, objType, objValue, delimiter, func(fieldType reflect.StructField) string { +func populateFormParams(tag *paramTag, objType reflect.Type, objValue reflect.Value, delimiter string, defaultValue *string) url.Values { + return populateForm(tag.ParamName, tag.Explode, objType, objValue, delimiter, defaultValue, func(fieldType reflect.StructField) string { qpTag := parseQueryParamTag(fieldType) if qpTag == nil { return "" @@ -252,6 +276,13 @@ type paramTag struct { Explode bool ParamName string Serialization string + + // Inline is a special case for union/oneOf. When a wrapper struct type is + // used, each union/oneOf value field should be inlined (e.g. not appended + // in deepObject style with the name) as if the value was directly on the + // parent struct field. Without this annotation, the value would not be + // encoded by downstream logic that requires the struct field tag. + Inline bool } func parseQueryParamTag(field reflect.StructField) *paramTag { diff --git a/internal/sdk/internal/utils/requestbody.go b/internal/sdk/internal/utils/requestbody.go index 000226e..91d8317 100644 --- a/internal/sdk/internal/utils/requestbody.go +++ b/internal/sdk/internal/utils/requestbody.go @@ -7,10 +7,15 @@ import ( "context" "fmt" "io" + "mime" "mime/multipart" + "net/textproto" "net/url" + "path/filepath" "reflect" "regexp" + + "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/optionalnullable" ) const ( @@ -166,9 +171,21 @@ func encodeMultipartFormData(w io.Writer, data interface{}) (string, error) { tag := parseMultipartFormTag(field) if tag.File { - if err := encodeMultipartFormDataFile(writer, fieldType, valType); err != nil { - writer.Close() - return "", err + switch fieldType.Kind() { + case reflect.Slice, reflect.Array: + for i := 0; i < valType.Len(); i++ { + arrayVal := valType.Index(i) + + if err := encodeMultipartFormDataFile(writer, tag.Name+"[]", arrayVal.Type(), arrayVal); err != nil { + writer.Close() + return "", err + } + } + default: + if err := encodeMultipartFormDataFile(writer, tag.Name, fieldType, valType); err != nil { + writer.Close() + return "", err + } } } else if tag.JSON { jw, err := writer.CreateFormField(tag.Name) @@ -211,12 +228,11 @@ func encodeMultipartFormData(w io.Writer, data interface{}) (string, error) { return writer.FormDataContentType(), nil } -func encodeMultipartFormDataFile(w *multipart.Writer, fieldType reflect.Type, valType reflect.Value) error { +func encodeMultipartFormDataFile(w *multipart.Writer, fieldName string, fieldType reflect.Type, valType reflect.Value) error { if fieldType.Kind() != reflect.Struct { return fmt.Errorf("invalid type %s for multipart/form-data file", valType.Type()) } - var fieldName string var fileName string var reader io.Reader @@ -236,16 +252,26 @@ func encodeMultipartFormDataFile(w *multipart.Writer, fieldType reflect.Type, va reader = val.Interface().(io.Reader) } } else { - fieldName = tag.Name fileName = val.String() } } - if fieldName == "" || fileName == "" || reader == nil { + if fileName == "" || reader == nil { return fmt.Errorf("invalid multipart/form-data file") } - fw, err := w.CreateFormFile(fieldName, fileName) + // Detect content type based on file extension + contentType := mime.TypeByExtension(filepath.Ext(fileName)) + if contentType == "" { + contentType = "application/octet-stream" + } + + // Create multipart header with proper content type + h := make(textproto.MIMEHeader) + h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="%s"; filename="%s"`, fieldName, fileName)) + h.Set("Content-Type", contentType) + + fw, err := w.CreatePart(h) if err != nil { return err } @@ -253,6 +279,11 @@ func encodeMultipartFormDataFile(w *multipart.Writer, fieldType reflect.Type, va return err } + // Reset seek position to 0 if the reader supports seeking + if seeker, ok := reader.(io.Seeker); ok { + _, _ = seeker.Seek(0, io.SeekStart) + } + return nil } @@ -294,7 +325,7 @@ func encodeFormData(fieldName string, w io.Writer, data interface{}) error { switch tag.Style { // TODO: support other styles case "form": - values := populateForm(tag.Name, tag.Explode, fieldType, valType, ",", func(sf reflect.StructField) string { + values := populateForm(tag.Name, tag.Explode, fieldType, valType, ",", nil, func(sf reflect.StructField) string { tag := parseFormTag(field) if tag == nil { return "" @@ -311,6 +342,17 @@ func encodeFormData(fieldName string, w io.Writer, data interface{}) error { } } case reflect.Map: + // check if optionalnullable.OptionalNullable[T] + if nullableValue, ok := optionalnullable.AsOptionalNullable(requestValType); ok { + // Handle optionalnullable.OptionalNullable[T] using GetUntyped method + if value, isSet := nullableValue.GetUntyped(); isSet && value != nil { + dataValues.Set(fieldName, valToString(value)) + } + // If not set or explicitly null, skip adding to form + break + } + + // Handle regular map for _, k := range requestValType.MapKeys() { v := requestValType.MapIndex(k) dataValues.Set(fmt.Sprintf("%v", k.Interface()), valToString(v.Interface())) diff --git a/internal/sdk/internal/utils/retries.go b/internal/sdk/internal/utils/retries.go index 92d0883..245cabd 100644 --- a/internal/sdk/internal/utils/retries.go +++ b/internal/sdk/internal/utils/retries.go @@ -7,10 +7,12 @@ import ( "errors" "fmt" "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/retry" + "io" "math" "math/rand" "net/http" "net/url" + "slices" "strconv" "strings" "time" @@ -27,6 +29,17 @@ type Retries struct { StatusCodes []string } +var ( + // IETF RFC 7231 4.2 safe and idempotent HTTP methods for connection retries + idempotentHTTPMethods = []string{ + http.MethodDelete, + http.MethodGet, + http.MethodHead, + http.MethodOptions, + http.MethodPut, + } +) + func Retry(ctx context.Context, r Retries, operation func() (*http.Response, error)) (*http.Response, error) { switch r.Config.Strategy { case "backoff": @@ -49,11 +62,48 @@ func Retry(ctx context.Context, r Retries, operation func() (*http.Response, err res, err := operation() if err != nil { + if !r.Config.RetryConnectionErrors { + return retry.Permanent(err) + } + + var httpMethod string + + // Use http.Request method if available + if res != nil && res.Request != nil { + httpMethod = res.Request.Method + } + + isIdempotentHTTPMethod := slices.Contains(idempotentHTTPMethods, httpMethod) urlError := new(url.Error) + if errors.As(err, &urlError) { - if (urlError.Temporary() || urlError.Timeout()) && r.Config.RetryConnectionErrors { + if urlError.Temporary() || urlError.Timeout() { return err } + + // In certain error cases, the http.Request may not have + // been populated, so use url.Error.Op which only has its + // first character capitalized from the original request + // HTTP method. + if httpMethod == "" { + httpMethod = strings.ToUpper(urlError.Op) + } + + isIdempotentHTTPMethod = slices.Contains(idempotentHTTPMethods, httpMethod) + + // Connection closed + if errors.Is(urlError.Err, io.EOF) && isIdempotentHTTPMethod { + return err + } + } + + // syscall detection is not available on every platform, so + // fallback to best effort string detection. + isBrokenPipeError := strings.Contains(err.Error(), "broken pipe") + isConnectionResetError := strings.Contains(err.Error(), "connection reset") + + if (isBrokenPipeError || isConnectionResetError) && isIdempotentHTTPMethod { + return err } return retry.Permanent(err) diff --git a/internal/sdk/internal/utils/utils.go b/internal/sdk/internal/utils/utils.go index f1ff9e0..0415b53 100644 --- a/internal/sdk/internal/utils/utils.go +++ b/internal/sdk/internal/utils/utils.go @@ -14,8 +14,6 @@ import ( "strconv" "strings" "time" - - "github.com/ericlagergren/decimal" ) const ( @@ -40,8 +38,8 @@ func UnmarshalJsonFromResponseBody(body io.Reader, out interface{}, tag string) if err != nil { return fmt.Errorf("error reading response body: %w", err) } - if err := UnmarshalJSON(data, out, reflect.StructTag(tag), true, false); err != nil { - return fmt.Errorf("error unmarshalling json response body: %w", err) + if err := UnmarshalJSON(data, out, reflect.StructTag(tag), true, nil); err != nil { + return fmt.Errorf("error unmarshaling json response body: %w", err) } return nil @@ -96,6 +94,26 @@ func AsSecuritySource(security interface{}) func(context.Context) (interface{}, } } +func parseConstTag(field reflect.StructField) *string { + value := field.Tag.Get("const") + + if value == "" { + return nil + } + + return &value +} + +func parseDefaultTag(field reflect.StructField) *string { + value := field.Tag.Get("default") + + if value == "" { + return nil + } + + return &value +} + func parseStructTag(tagKey string, field reflect.StructField) map[string]string { tag := field.Tag.Get(tagKey) if tag == "" { @@ -127,6 +145,7 @@ func parseStructTag(tagKey string, field reflect.StructField) map[string]string func parseParamTag(tagKey string, field reflect.StructField, defaultStyle string, defaultExplode bool) *paramTag { // example `{tagKey}:"style=simple,explode=false,name=apiID"` + // example `{tagKey}:"inline"` values := parseStructTag(tagKey, field) if values == nil { return nil @@ -140,6 +159,8 @@ func parseParamTag(tagKey string, field reflect.StructField, defaultStyle string for k, v := range values { switch k { + case "inline": + tag.Inline = v == "true" case "style": tag.Style = v case "explode": @@ -160,8 +181,6 @@ func valToString(val interface{}) string { return v.Format(time.RFC3339Nano) case big.Int: return v.String() - case decimal.Big: - return v.String() default: return fmt.Sprintf("%v", v) } @@ -222,6 +241,21 @@ func isNil(typ reflect.Type, val reflect.Value) bool { return false } +func isEmptyContainer(typ reflect.Type, val reflect.Value) bool { + if isNil(typ, val) { + return true + } + + switch typ.Kind() { + case reflect.Slice, reflect.Array: + return val.Len() == 0 + case reflect.Map: + return val.Len() == 0 + default: + return false + } +} + func contains(arr []string, str string) bool { for _, a := range arr { if a == str { diff --git a/internal/sdk/models/operations/createcustomvariable.go b/internal/sdk/models/operations/createcustomvariable.go index fe4d1ab..e5fbcef 100644 --- a/internal/sdk/models/operations/createcustomvariable.go +++ b/internal/sdk/models/operations/createcustomvariable.go @@ -18,30 +18,30 @@ type CreateCustomVariableResponse struct { RawResponse *http.Response } -func (o *CreateCustomVariableResponse) GetContentType() string { - if o == nil { +func (c *CreateCustomVariableResponse) GetContentType() string { + if c == nil { return "" } - return o.ContentType + return c.ContentType } -func (o *CreateCustomVariableResponse) GetCustomVariable() *shared.CustomVariable { - if o == nil { +func (c *CreateCustomVariableResponse) GetCustomVariable() *shared.CustomVariable { + if c == nil { return nil } - return o.CustomVariable + return c.CustomVariable } -func (o *CreateCustomVariableResponse) GetStatusCode() int { - if o == nil { +func (c *CreateCustomVariableResponse) GetStatusCode() int { + if c == nil { return 0 } - return o.StatusCode + return c.StatusCode } -func (o *CreateCustomVariableResponse) GetRawResponse() *http.Response { - if o == nil { +func (c *CreateCustomVariableResponse) GetRawResponse() *http.Response { + if c == nil { return nil } - return o.RawResponse + return c.RawResponse } diff --git a/internal/sdk/models/operations/deletecustomvariable.go b/internal/sdk/models/operations/deletecustomvariable.go index 462bc1e..f310731 100644 --- a/internal/sdk/models/operations/deletecustomvariable.go +++ b/internal/sdk/models/operations/deletecustomvariable.go @@ -11,11 +11,11 @@ type DeleteCustomVariableRequest struct { ID string `pathParam:"style=simple,explode=false,name=id"` } -func (o *DeleteCustomVariableRequest) GetID() string { - if o == nil { +func (d *DeleteCustomVariableRequest) GetID() string { + if d == nil { return "" } - return o.ID + return d.ID } type DeleteCustomVariableResponse struct { @@ -27,23 +27,23 @@ type DeleteCustomVariableResponse struct { RawResponse *http.Response } -func (o *DeleteCustomVariableResponse) GetContentType() string { - if o == nil { +func (d *DeleteCustomVariableResponse) GetContentType() string { + if d == nil { return "" } - return o.ContentType + return d.ContentType } -func (o *DeleteCustomVariableResponse) GetStatusCode() int { - if o == nil { +func (d *DeleteCustomVariableResponse) GetStatusCode() int { + if d == nil { return 0 } - return o.StatusCode + return d.StatusCode } -func (o *DeleteCustomVariableResponse) GetRawResponse() *http.Response { - if o == nil { +func (d *DeleteCustomVariableResponse) GetRawResponse() *http.Response { + if d == nil { return nil } - return o.RawResponse + return d.RawResponse } diff --git a/internal/sdk/models/operations/getblueprinttableconfig.go b/internal/sdk/models/operations/getblueprinttableconfig.go index 628a1aa..ff70a98 100644 --- a/internal/sdk/models/operations/getblueprinttableconfig.go +++ b/internal/sdk/models/operations/getblueprinttableconfig.go @@ -18,30 +18,30 @@ type GetBluePrintTableConfigResponse struct { RawResponse *http.Response } -func (o *GetBluePrintTableConfigResponse) GetContentType() string { - if o == nil { +func (g *GetBluePrintTableConfigResponse) GetContentType() string { + if g == nil { return "" } - return o.ContentType + return g.ContentType } -func (o *GetBluePrintTableConfigResponse) GetCustomVariable() *shared.CustomVariable { - if o == nil { +func (g *GetBluePrintTableConfigResponse) GetCustomVariable() *shared.CustomVariable { + if g == nil { return nil } - return o.CustomVariable + return g.CustomVariable } -func (o *GetBluePrintTableConfigResponse) GetStatusCode() int { - if o == nil { +func (g *GetBluePrintTableConfigResponse) GetStatusCode() int { + if g == nil { return 0 } - return o.StatusCode + return g.StatusCode } -func (o *GetBluePrintTableConfigResponse) GetRawResponse() *http.Response { - if o == nil { +func (g *GetBluePrintTableConfigResponse) GetRawResponse() *http.Response { + if g == nil { return nil } - return o.RawResponse + return g.RawResponse } diff --git a/internal/sdk/models/operations/getcategories.go b/internal/sdk/models/operations/getcategories.go index 0a7f2c4..16ff04a 100644 --- a/internal/sdk/models/operations/getcategories.go +++ b/internal/sdk/models/operations/getcategories.go @@ -17,17 +17,17 @@ func (g GetCategoriesRequest) MarshalJSON() ([]byte, error) { } func (g *GetCategoriesRequest) UnmarshalJSON(data []byte) error { - if err := utils.UnmarshalJSON(data, &g, "", false, false); err != nil { + if err := utils.UnmarshalJSON(data, &g, "", false, nil); err != nil { return err } return nil } -func (o *GetCategoriesRequest) GetLang() *string { - if o == nil { +func (g *GetCategoriesRequest) GetLang() *string { + if g == nil { return nil } - return o.Lang + return g.Lang } type GetCategoriesResponse struct { @@ -41,30 +41,30 @@ type GetCategoriesResponse struct { Classes []shared.CategoryResult } -func (o *GetCategoriesResponse) GetContentType() string { - if o == nil { +func (g *GetCategoriesResponse) GetContentType() string { + if g == nil { return "" } - return o.ContentType + return g.ContentType } -func (o *GetCategoriesResponse) GetStatusCode() int { - if o == nil { +func (g *GetCategoriesResponse) GetStatusCode() int { + if g == nil { return 0 } - return o.StatusCode + return g.StatusCode } -func (o *GetCategoriesResponse) GetRawResponse() *http.Response { - if o == nil { +func (g *GetCategoriesResponse) GetRawResponse() *http.Response { + if g == nil { return nil } - return o.RawResponse + return g.RawResponse } -func (o *GetCategoriesResponse) GetClasses() []shared.CategoryResult { - if o == nil { +func (g *GetCategoriesResponse) GetClasses() []shared.CategoryResult { + if g == nil { return nil } - return o.Classes + return g.Classes } diff --git a/internal/sdk/models/operations/getcustomvariable.go b/internal/sdk/models/operations/getcustomvariable.go index ed7a55b..b1e5843 100644 --- a/internal/sdk/models/operations/getcustomvariable.go +++ b/internal/sdk/models/operations/getcustomvariable.go @@ -12,11 +12,11 @@ type GetCustomVariableRequest struct { ID string `pathParam:"style=simple,explode=false,name=id"` } -func (o *GetCustomVariableRequest) GetID() string { - if o == nil { +func (g *GetCustomVariableRequest) GetID() string { + if g == nil { return "" } - return o.ID + return g.ID } type GetCustomVariableResponse struct { @@ -30,30 +30,30 @@ type GetCustomVariableResponse struct { RawResponse *http.Response } -func (o *GetCustomVariableResponse) GetContentType() string { - if o == nil { +func (g *GetCustomVariableResponse) GetContentType() string { + if g == nil { return "" } - return o.ContentType + return g.ContentType } -func (o *GetCustomVariableResponse) GetCustomVariable() *shared.CustomVariable { - if o == nil { +func (g *GetCustomVariableResponse) GetCustomVariable() *shared.CustomVariable { + if g == nil { return nil } - return o.CustomVariable + return g.CustomVariable } -func (o *GetCustomVariableResponse) GetStatusCode() int { - if o == nil { +func (g *GetCustomVariableResponse) GetStatusCode() int { + if g == nil { return 0 } - return o.StatusCode + return g.StatusCode } -func (o *GetCustomVariableResponse) GetRawResponse() *http.Response { - if o == nil { +func (g *GetCustomVariableResponse) GetRawResponse() *http.Response { + if g == nil { return nil } - return o.RawResponse + return g.RawResponse } diff --git a/internal/sdk/models/operations/getcustomvariables.go b/internal/sdk/models/operations/getcustomvariables.go index 65f80e3..2eee72f 100644 --- a/internal/sdk/models/operations/getcustomvariables.go +++ b/internal/sdk/models/operations/getcustomvariables.go @@ -18,30 +18,30 @@ type GetCustomVariablesResponse struct { Classes []shared.CustomVariable } -func (o *GetCustomVariablesResponse) GetContentType() string { - if o == nil { +func (g *GetCustomVariablesResponse) GetContentType() string { + if g == nil { return "" } - return o.ContentType + return g.ContentType } -func (o *GetCustomVariablesResponse) GetStatusCode() int { - if o == nil { +func (g *GetCustomVariablesResponse) GetStatusCode() int { + if g == nil { return 0 } - return o.StatusCode + return g.StatusCode } -func (o *GetCustomVariablesResponse) GetRawResponse() *http.Response { - if o == nil { +func (g *GetCustomVariablesResponse) GetRawResponse() *http.Response { + if g == nil { return nil } - return o.RawResponse + return g.RawResponse } -func (o *GetCustomVariablesResponse) GetClasses() []shared.CustomVariable { - if o == nil { +func (g *GetCustomVariablesResponse) GetClasses() []shared.CustomVariable { + if g == nil { return nil } - return o.Classes + return g.Classes } diff --git a/internal/sdk/models/operations/getvariablecontext.go b/internal/sdk/models/operations/getvariablecontext.go index a76d618..a6d77df 100644 --- a/internal/sdk/models/operations/getvariablecontext.go +++ b/internal/sdk/models/operations/getvariablecontext.go @@ -11,11 +11,11 @@ type GetVariableContextRequestBody struct { Parameters *shared.VariableParameters `json:"parameters,omitempty"` } -func (o *GetVariableContextRequestBody) GetParameters() *shared.VariableParameters { - if o == nil { +func (g *GetVariableContextRequestBody) GetParameters() *shared.VariableParameters { + if g == nil { return nil } - return o.Parameters + return g.Parameters } type GetVariableContextResponse struct { @@ -29,30 +29,30 @@ type GetVariableContextResponse struct { VariableContext *shared.VariableContext } -func (o *GetVariableContextResponse) GetContentType() string { - if o == nil { +func (g *GetVariableContextResponse) GetContentType() string { + if g == nil { return "" } - return o.ContentType + return g.ContentType } -func (o *GetVariableContextResponse) GetStatusCode() int { - if o == nil { +func (g *GetVariableContextResponse) GetStatusCode() int { + if g == nil { return 0 } - return o.StatusCode + return g.StatusCode } -func (o *GetVariableContextResponse) GetRawResponse() *http.Response { - if o == nil { +func (g *GetVariableContextResponse) GetRawResponse() *http.Response { + if g == nil { return nil } - return o.RawResponse + return g.RawResponse } -func (o *GetVariableContextResponse) GetVariableContext() *shared.VariableContext { - if o == nil { +func (g *GetVariableContextResponse) GetVariableContext() *shared.VariableContext { + if g == nil { return nil } - return o.VariableContext + return g.VariableContext } diff --git a/internal/sdk/models/operations/options.go b/internal/sdk/models/operations/options.go index dc26f62..d995fe5 100644 --- a/internal/sdk/models/operations/options.go +++ b/internal/sdk/models/operations/options.go @@ -12,7 +12,6 @@ import ( var ErrUnsupportedOption = errors.New("unsupported option") const ( - SupportedOptionServerURL = "serverURL" SupportedOptionRetries = "retries" SupportedOptionTimeout = "timeout" SupportedOptionAcceptHeaderOverride = "acceptHeaderOverride" @@ -22,8 +21,8 @@ const ( type AcceptHeaderEnum string const ( - AcceptHeaderEnumApplicationJson AcceptHeaderEnum = "application/json" - AcceptHeaderEnumWildcardWildcard AcceptHeaderEnum = "*/*" + AcceptHeaderEnumApplicationJson AcceptHeaderEnum = "application/json" + AcceptHeaderEnumWildcardRootWildcard AcceptHeaderEnum = "*/*" ) func (e AcceptHeaderEnum) ToPointer() *AcceptHeaderEnum { @@ -36,6 +35,7 @@ type Options struct { Timeout *time.Duration AcceptHeaderOverride *AcceptHeaderEnum URLOverride *string + SetHeaders map[string]string } type Option func(*Options, ...string) error @@ -43,10 +43,6 @@ type Option func(*Options, ...string) error // WithServerURL allows providing an alternative server URL. func WithServerURL(serverURL string) Option { return func(opts *Options, supportedOptions ...string) error { - if !utils.Contains(supportedOptions, SupportedOptionServerURL) { - return ErrUnsupportedOption - } - opts.ServerURL = &serverURL return nil } @@ -55,10 +51,6 @@ func WithServerURL(serverURL string) Option { // WithTemplatedServerURL allows providing an alternative server URL with templated parameters. func WithTemplatedServerURL(serverURL string, params map[string]string) Option { return func(opts *Options, supportedOptions ...string) error { - if !utils.Contains(supportedOptions, SupportedOptionServerURL) { - return ErrUnsupportedOption - } - if params != nil { serverURL = utils.ReplaceParameters(serverURL, params) } @@ -114,3 +106,12 @@ func WithURLOverride(urlOverride string) Option { return nil } } + +// WithSetHeaders takes a map of headers that will applied to a request. If the +// request contains headers that are in the map then they will be overwritten. +func WithSetHeaders(hdrs map[string]string) Option { + return func(opts *Options, supportedOptions ...string) error { + opts.SetHeaders = hdrs + return nil + } +} diff --git a/internal/sdk/models/operations/replacetemplates.go b/internal/sdk/models/operations/replacetemplates.go index 57985e2..a31cecb 100644 --- a/internal/sdk/models/operations/replacetemplates.go +++ b/internal/sdk/models/operations/replacetemplates.go @@ -12,18 +12,18 @@ type ReplaceTemplatesRequestBody struct { Parameters *shared.VariableParameters `json:"parameters,omitempty"` } -func (o *ReplaceTemplatesRequestBody) GetInputs() []string { - if o == nil { +func (r *ReplaceTemplatesRequestBody) GetInputs() []string { + if r == nil { return nil } - return o.Inputs + return r.Inputs } -func (o *ReplaceTemplatesRequestBody) GetParameters() *shared.VariableParameters { - if o == nil { +func (r *ReplaceTemplatesRequestBody) GetParameters() *shared.VariableParameters { + if r == nil { return nil } - return o.Parameters + return r.Parameters } // ReplaceTemplatesResponseBody - ok @@ -31,11 +31,11 @@ type ReplaceTemplatesResponseBody struct { Outputs []string `json:"outputs,omitempty"` } -func (o *ReplaceTemplatesResponseBody) GetOutputs() []string { - if o == nil { +func (r *ReplaceTemplatesResponseBody) GetOutputs() []string { + if r == nil { return nil } - return o.Outputs + return r.Outputs } type ReplaceTemplatesResponse struct { @@ -49,30 +49,30 @@ type ReplaceTemplatesResponse struct { Object *ReplaceTemplatesResponseBody } -func (o *ReplaceTemplatesResponse) GetContentType() string { - if o == nil { +func (r *ReplaceTemplatesResponse) GetContentType() string { + if r == nil { return "" } - return o.ContentType + return r.ContentType } -func (o *ReplaceTemplatesResponse) GetStatusCode() int { - if o == nil { +func (r *ReplaceTemplatesResponse) GetStatusCode() int { + if r == nil { return 0 } - return o.StatusCode + return r.StatusCode } -func (o *ReplaceTemplatesResponse) GetRawResponse() *http.Response { - if o == nil { +func (r *ReplaceTemplatesResponse) GetRawResponse() *http.Response { + if r == nil { return nil } - return o.RawResponse + return r.RawResponse } -func (o *ReplaceTemplatesResponse) GetObject() *ReplaceTemplatesResponseBody { - if o == nil { +func (r *ReplaceTemplatesResponse) GetObject() *ReplaceTemplatesResponseBody { + if r == nil { return nil } - return o.Object + return r.Object } diff --git a/internal/sdk/models/operations/searchcustomvariables.go b/internal/sdk/models/operations/searchcustomvariables.go index 2bf8d6b..f068f76 100644 --- a/internal/sdk/models/operations/searchcustomvariables.go +++ b/internal/sdk/models/operations/searchcustomvariables.go @@ -14,18 +14,18 @@ type SearchCustomVariablesResponseBody struct { Results []shared.CustomVariable `json:"results,omitempty"` } -func (o *SearchCustomVariablesResponseBody) GetHits() *int64 { - if o == nil { +func (s *SearchCustomVariablesResponseBody) GetHits() *int64 { + if s == nil { return nil } - return o.Hits + return s.Hits } -func (o *SearchCustomVariablesResponseBody) GetResults() []shared.CustomVariable { - if o == nil { +func (s *SearchCustomVariablesResponseBody) GetResults() []shared.CustomVariable { + if s == nil { return nil } - return o.Results + return s.Results } type SearchCustomVariablesResponse struct { @@ -39,30 +39,30 @@ type SearchCustomVariablesResponse struct { Object *SearchCustomVariablesResponseBody } -func (o *SearchCustomVariablesResponse) GetContentType() string { - if o == nil { +func (s *SearchCustomVariablesResponse) GetContentType() string { + if s == nil { return "" } - return o.ContentType + return s.ContentType } -func (o *SearchCustomVariablesResponse) GetStatusCode() int { - if o == nil { +func (s *SearchCustomVariablesResponse) GetStatusCode() int { + if s == nil { return 0 } - return o.StatusCode + return s.StatusCode } -func (o *SearchCustomVariablesResponse) GetRawResponse() *http.Response { - if o == nil { +func (s *SearchCustomVariablesResponse) GetRawResponse() *http.Response { + if s == nil { return nil } - return o.RawResponse + return s.RawResponse } -func (o *SearchCustomVariablesResponse) GetObject() *SearchCustomVariablesResponseBody { - if o == nil { +func (s *SearchCustomVariablesResponse) GetObject() *SearchCustomVariablesResponseBody { + if s == nil { return nil } - return o.Object + return s.Object } diff --git a/internal/sdk/models/operations/searchvariables.go b/internal/sdk/models/operations/searchvariables.go index 5943962..3598c14 100644 --- a/internal/sdk/models/operations/searchvariables.go +++ b/internal/sdk/models/operations/searchvariables.go @@ -24,52 +24,52 @@ func (s SearchVariablesRequestBody) MarshalJSON() ([]byte, error) { } func (s *SearchVariablesRequestBody) UnmarshalJSON(data []byte) error { - if err := utils.UnmarshalJSON(data, &s, "", false, false); err != nil { + if err := utils.UnmarshalJSON(data, &s, "", false, []string{"query", "template_type"}); err != nil { return err } return nil } -func (o *SearchVariablesRequestBody) GetEntitySchemas() []string { - if o == nil { +func (s *SearchVariablesRequestBody) GetEntitySchemas() []string { + if s == nil { return nil } - return o.EntitySchemas + return s.EntitySchemas } -func (o *SearchVariablesRequestBody) GetFrom() *int64 { - if o == nil { +func (s *SearchVariablesRequestBody) GetFrom() *int64 { + if s == nil { return nil } - return o.From + return s.From } -func (o *SearchVariablesRequestBody) GetLang() *string { - if o == nil { +func (s *SearchVariablesRequestBody) GetLang() *string { + if s == nil { return nil } - return o.Lang + return s.Lang } -func (o *SearchVariablesRequestBody) GetQuery() string { - if o == nil { +func (s *SearchVariablesRequestBody) GetQuery() string { + if s == nil { return "" } - return o.Query + return s.Query } -func (o *SearchVariablesRequestBody) GetSize() *int64 { - if o == nil { +func (s *SearchVariablesRequestBody) GetSize() *int64 { + if s == nil { return nil } - return o.Size + return s.Size } -func (o *SearchVariablesRequestBody) GetTemplateType() shared.TemplateType { - if o == nil { +func (s *SearchVariablesRequestBody) GetTemplateType() shared.TemplateType { + if s == nil { return shared.TemplateType("") } - return o.TemplateType + return s.TemplateType } type SearchVariablesResponse struct { @@ -83,30 +83,30 @@ type SearchVariablesResponse struct { Classes []shared.VariableResult } -func (o *SearchVariablesResponse) GetContentType() string { - if o == nil { +func (s *SearchVariablesResponse) GetContentType() string { + if s == nil { return "" } - return o.ContentType + return s.ContentType } -func (o *SearchVariablesResponse) GetStatusCode() int { - if o == nil { +func (s *SearchVariablesResponse) GetStatusCode() int { + if s == nil { return 0 } - return o.StatusCode + return s.StatusCode } -func (o *SearchVariablesResponse) GetRawResponse() *http.Response { - if o == nil { +func (s *SearchVariablesResponse) GetRawResponse() *http.Response { + if s == nil { return nil } - return o.RawResponse + return s.RawResponse } -func (o *SearchVariablesResponse) GetClasses() []shared.VariableResult { - if o == nil { +func (s *SearchVariablesResponse) GetClasses() []shared.VariableResult { + if s == nil { return nil } - return o.Classes + return s.Classes } diff --git a/internal/sdk/models/operations/updatecustomvariable.go b/internal/sdk/models/operations/updatecustomvariable.go index a3da371..53b1c23 100644 --- a/internal/sdk/models/operations/updatecustomvariable.go +++ b/internal/sdk/models/operations/updatecustomvariable.go @@ -8,23 +8,23 @@ import ( ) type UpdateCustomVariableRequest struct { - CustomVariable *shared.CustomVariable `request:"mediaType=application/json"` + CustomVariable *shared.CustomVariableInput `request:"mediaType=application/json"` // Custom variable ID ID string `pathParam:"style=simple,explode=false,name=id"` } -func (o *UpdateCustomVariableRequest) GetCustomVariable() *shared.CustomVariable { - if o == nil { +func (u *UpdateCustomVariableRequest) GetCustomVariable() *shared.CustomVariableInput { + if u == nil { return nil } - return o.CustomVariable + return u.CustomVariable } -func (o *UpdateCustomVariableRequest) GetID() string { - if o == nil { +func (u *UpdateCustomVariableRequest) GetID() string { + if u == nil { return "" } - return o.ID + return u.ID } type UpdateCustomVariableResponse struct { @@ -38,30 +38,30 @@ type UpdateCustomVariableResponse struct { RawResponse *http.Response } -func (o *UpdateCustomVariableResponse) GetContentType() string { - if o == nil { +func (u *UpdateCustomVariableResponse) GetContentType() string { + if u == nil { return "" } - return o.ContentType + return u.ContentType } -func (o *UpdateCustomVariableResponse) GetCustomVariable() *shared.CustomVariable { - if o == nil { +func (u *UpdateCustomVariableResponse) GetCustomVariable() *shared.CustomVariable { + if u == nil { return nil } - return o.CustomVariable + return u.CustomVariable } -func (o *UpdateCustomVariableResponse) GetStatusCode() int { - if o == nil { +func (u *UpdateCustomVariableResponse) GetStatusCode() int { + if u == nil { return 0 } - return o.StatusCode + return u.StatusCode } -func (o *UpdateCustomVariableResponse) GetRawResponse() *http.Response { - if o == nil { +func (u *UpdateCustomVariableResponse) GetRawResponse() *http.Response { + if u == nil { return nil } - return o.RawResponse + return u.RawResponse } diff --git a/internal/sdk/models/shared/categoryresult.go b/internal/sdk/models/shared/categoryresult.go index b1955cb..f0d3fda 100644 --- a/internal/sdk/models/shared/categoryresult.go +++ b/internal/sdk/models/shared/categoryresult.go @@ -7,16 +7,16 @@ type CategoryResult struct { Description *string `json:"description,omitempty"` } -func (o *CategoryResult) GetCategory() *string { - if o == nil { +func (c *CategoryResult) GetCategory() *string { + if c == nil { return nil } - return o.Category + return c.Category } -func (o *CategoryResult) GetDescription() *string { - if o == nil { +func (c *CategoryResult) GetDescription() *string { + if c == nil { return nil } - return o.Description + return c.Description } diff --git a/internal/sdk/models/shared/customvariable.go b/internal/sdk/models/shared/customvariable.go index 5a6a4f4..c6ae953 100644 --- a/internal/sdk/models/shared/customvariable.go +++ b/internal/sdk/models/shared/customvariable.go @@ -7,6 +7,10 @@ import ( "fmt" ) +// Config - Variable configuration +type Config struct { +} + // Type - Custom variable type type Type string @@ -14,6 +18,7 @@ const ( TypeOrderTable Type = "order_table" TypeCustom Type = "custom" TypeJourneyLink Type = "journey_link" + TypeSnippet Type = "snippet" ) func (e Type) ToPointer() *Type { @@ -30,6 +35,8 @@ func (e *Type) UnmarshalJSON(data []byte) error { case "custom": fallthrough case "journey_link": + fallthrough + case "snippet": *e = Type(v) return nil default: @@ -39,8 +46,9 @@ func (e *Type) UnmarshalJSON(data []byte) error { type CustomVariable struct { // The tags of custom variable - Tags []string `json:"_tags,omitempty"` - Config any `json:"config,omitempty"` + Tags []string `json:"_tags,omitempty"` + // Variable configuration + Config *Config `json:"config,omitempty"` // Creation time CreatedAt *string `json:"created_at,omitempty"` // Created by @@ -52,11 +60,11 @@ type CustomVariable struct { // ID ID *string `json:"id,omitempty"` // The key which is used for Handlebar variable syntax {{"{{"}}key}} - Key *string `json:"key,omitempty"` + Key string `json:"key"` // Custom variable name Name *string `json:"name,omitempty"` // Handlebar template that used to generate the variable content - Template *string `json:"template,omitempty"` + Template string `json:"template"` // Custom variable type Type *Type `json:"type,omitempty"` // Last update time @@ -65,93 +73,177 @@ type CustomVariable struct { UpdatedBy *string `json:"updated_by,omitempty"` } -func (o *CustomVariable) GetTags() []string { - if o == nil { +func (c *CustomVariable) GetTags() []string { + if c == nil { + return nil + } + return c.Tags +} + +func (c *CustomVariable) GetConfig() *Config { + if c == nil { return nil } - return o.Tags + return c.Config } -func (o *CustomVariable) GetConfig() any { - if o == nil { +func (c *CustomVariable) GetCreatedAt() *string { + if c == nil { return nil } - return o.Config + return c.CreatedAt +} + +func (c *CustomVariable) GetCreatedBy() *string { + if c == nil { + return nil + } + return c.CreatedBy +} + +func (c *CustomVariable) GetHelperLogic() *string { + if c == nil { + return nil + } + return c.HelperLogic +} + +func (c *CustomVariable) GetHelperParams() []string { + if c == nil { + return nil + } + return c.HelperParams +} + +func (c *CustomVariable) GetID() *string { + if c == nil { + return nil + } + return c.ID +} + +func (c *CustomVariable) GetKey() string { + if c == nil { + return "" + } + return c.Key } -func (o *CustomVariable) GetCreatedAt() *string { - if o == nil { +func (c *CustomVariable) GetName() *string { + if c == nil { return nil } - return o.CreatedAt + return c.Name +} + +func (c *CustomVariable) GetTemplate() string { + if c == nil { + return "" + } + return c.Template } -func (o *CustomVariable) GetCreatedBy() *string { - if o == nil { +func (c *CustomVariable) GetType() *Type { + if c == nil { return nil } - return o.CreatedBy + return c.Type } -func (o *CustomVariable) GetHelperLogic() *string { - if o == nil { +func (c *CustomVariable) GetUpdatedAt() *string { + if c == nil { return nil } - return o.HelperLogic + return c.UpdatedAt } -func (o *CustomVariable) GetHelperParams() []string { - if o == nil { +func (c *CustomVariable) GetUpdatedBy() *string { + if c == nil { return nil } - return o.HelperParams + return c.UpdatedBy } -func (o *CustomVariable) GetID() *string { - if o == nil { +type CustomVariableInput struct { + // The tags of custom variable + Tags []string `json:"_tags,omitempty"` + // Variable configuration + Config *Config `json:"config,omitempty"` + // The helper function logic + HelperLogic *string `json:"helper_logic,omitempty"` + // The helper function parameter's names + HelperParams []string `json:"helper_params,omitempty"` + // ID + ID *string `json:"id,omitempty"` + // The key which is used for Handlebar variable syntax {{"{{"}}key}} + Key string `json:"key"` + // Custom variable name + Name *string `json:"name,omitempty"` + // Handlebar template that used to generate the variable content + Template string `json:"template"` + // Custom variable type + Type *Type `json:"type,omitempty"` +} + +func (c *CustomVariableInput) GetTags() []string { + if c == nil { return nil } - return o.ID + return c.Tags } -func (o *CustomVariable) GetKey() *string { - if o == nil { +func (c *CustomVariableInput) GetConfig() *Config { + if c == nil { return nil } - return o.Key + return c.Config } -func (o *CustomVariable) GetName() *string { - if o == nil { +func (c *CustomVariableInput) GetHelperLogic() *string { + if c == nil { return nil } - return o.Name + return c.HelperLogic } -func (o *CustomVariable) GetTemplate() *string { - if o == nil { +func (c *CustomVariableInput) GetHelperParams() []string { + if c == nil { return nil } - return o.Template + return c.HelperParams } -func (o *CustomVariable) GetType() *Type { - if o == nil { +func (c *CustomVariableInput) GetID() *string { + if c == nil { return nil } - return o.Type + return c.ID } -func (o *CustomVariable) GetUpdatedAt() *string { - if o == nil { +func (c *CustomVariableInput) GetKey() string { + if c == nil { + return "" + } + return c.Key +} + +func (c *CustomVariableInput) GetName() *string { + if c == nil { return nil } - return o.UpdatedAt + return c.Name +} + +func (c *CustomVariableInput) GetTemplate() string { + if c == nil { + return "" + } + return c.Template } -func (o *CustomVariable) GetUpdatedBy() *string { - if o == nil { +func (c *CustomVariableInput) GetType() *Type { + if c == nil { return nil } - return o.UpdatedBy + return c.Type } diff --git a/internal/sdk/models/shared/customvariablessearchparams.go b/internal/sdk/models/shared/customvariablessearchparams.go index 5dd6040..269e850 100644 --- a/internal/sdk/models/shared/customvariablessearchparams.go +++ b/internal/sdk/models/shared/customvariablessearchparams.go @@ -15,6 +15,7 @@ const ( CustomVariablesSearchParamsTypeOrderTable CustomVariablesSearchParamsType = "order_table" CustomVariablesSearchParamsTypeCustom CustomVariablesSearchParamsType = "custom" CustomVariablesSearchParamsTypeJourneyLink CustomVariablesSearchParamsType = "journey_link" + CustomVariablesSearchParamsTypeSnippet CustomVariablesSearchParamsType = "snippet" ) func (e CustomVariablesSearchParamsType) ToPointer() *CustomVariablesSearchParamsType { @@ -31,6 +32,8 @@ func (e *CustomVariablesSearchParamsType) UnmarshalJSON(data []byte) error { case "custom": fallthrough case "journey_link": + fallthrough + case "snippet": *e = CustomVariablesSearchParamsType(v) return nil default: @@ -58,57 +61,57 @@ func (c CustomVariablesSearchParams) MarshalJSON() ([]byte, error) { } func (c *CustomVariablesSearchParams) UnmarshalJSON(data []byte) error { - if err := utils.UnmarshalJSON(data, &c, "", false, false); err != nil { + if err := utils.UnmarshalJSON(data, &c, "", false, nil); err != nil { return err } return nil } -func (o *CustomVariablesSearchParams) GetFields() []string { - if o == nil { +func (c *CustomVariablesSearchParams) GetFields() []string { + if c == nil { return nil } - return o.Fields + return c.Fields } -func (o *CustomVariablesSearchParams) GetFrom() *int64 { - if o == nil { +func (c *CustomVariablesSearchParams) GetFrom() *int64 { + if c == nil { return nil } - return o.From + return c.From } -func (o *CustomVariablesSearchParams) GetQuery() *string { - if o == nil { +func (c *CustomVariablesSearchParams) GetQuery() *string { + if c == nil { return nil } - return o.Query + return c.Query } -func (o *CustomVariablesSearchParams) GetSize() *int64 { - if o == nil { +func (c *CustomVariablesSearchParams) GetSize() *int64 { + if c == nil { return nil } - return o.Size + return c.Size } -func (o *CustomVariablesSearchParams) GetSortBy() *string { - if o == nil { +func (c *CustomVariablesSearchParams) GetSortBy() *string { + if c == nil { return nil } - return o.SortBy + return c.SortBy } -func (o *CustomVariablesSearchParams) GetTags() []string { - if o == nil { +func (c *CustomVariablesSearchParams) GetTags() []string { + if c == nil { return nil } - return o.Tags + return c.Tags } -func (o *CustomVariablesSearchParams) GetType() *CustomVariablesSearchParamsType { - if o == nil { +func (c *CustomVariablesSearchParams) GetType() *CustomVariablesSearchParamsType { + if c == nil { return nil } - return o.Type + return c.Type } diff --git a/internal/sdk/models/shared/externalcustomvariable.go b/internal/sdk/models/shared/externalcustomvariable.go index 10cd2a0..8527223 100644 --- a/internal/sdk/models/shared/externalcustomvariable.go +++ b/internal/sdk/models/shared/externalcustomvariable.go @@ -7,16 +7,16 @@ type ExternalCustomVariable struct { Variable *string `json:"variable,omitempty"` } -func (o *ExternalCustomVariable) GetValue() *string { - if o == nil { +func (e *ExternalCustomVariable) GetValue() *string { + if e == nil { return nil } - return o.Value + return e.Value } -func (o *ExternalCustomVariable) GetVariable() *string { - if o == nil { +func (e *ExternalCustomVariable) GetVariable() *string { + if e == nil { return nil } - return o.Variable + return e.Variable } diff --git a/internal/sdk/models/shared/security.go b/internal/sdk/models/shared/security.go index 80bc620..3f31cc2 100644 --- a/internal/sdk/models/shared/security.go +++ b/internal/sdk/models/shared/security.go @@ -7,16 +7,16 @@ type Security struct { EpilotOrg *string `security:"scheme,type=apiKey,subtype=header,name=x-ivy-org-id"` } -func (o *Security) GetEpilotAuth() *string { - if o == nil { +func (s *Security) GetEpilotAuth() *string { + if s == nil { return nil } - return o.EpilotAuth + return s.EpilotAuth } -func (o *Security) GetEpilotOrg() *string { - if o == nil { +func (s *Security) GetEpilotOrg() *string { + if s == nil { return nil } - return o.EpilotOrg + return s.EpilotOrg } diff --git a/internal/sdk/models/shared/variablecontext.go b/internal/sdk/models/shared/variablecontext.go index b31ded5..30b968e 100644 --- a/internal/sdk/models/shared/variablecontext.go +++ b/internal/sdk/models/shared/variablecontext.go @@ -9,30 +9,30 @@ type VariableContext struct { UnsubscribeURL *string `json:"unsubscribe_url,omitempty"` } -func (o *VariableContext) GetBrand() map[string]any { - if o == nil { +func (v *VariableContext) GetBrand() map[string]any { + if v == nil { return nil } - return o.Brand + return v.Brand } -func (o *VariableContext) GetContact() map[string]any { - if o == nil { +func (v *VariableContext) GetContact() map[string]any { + if v == nil { return nil } - return o.Contact + return v.Contact } -func (o *VariableContext) GetMain() map[string]any { - if o == nil { +func (v *VariableContext) GetMain() map[string]any { + if v == nil { return nil } - return o.Main + return v.Main } -func (o *VariableContext) GetUnsubscribeURL() *string { - if o == nil { +func (v *VariableContext) GetUnsubscribeURL() *string { + if v == nil { return nil } - return o.UnsubscribeURL + return v.UnsubscribeURL } diff --git a/internal/sdk/models/shared/variableparameters.go b/internal/sdk/models/shared/variableparameters.go index e7eb50c..482c478 100644 --- a/internal/sdk/models/shared/variableparameters.go +++ b/internal/sdk/models/shared/variableparameters.go @@ -6,14 +6,14 @@ import ( "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/internal/utils" ) -// ContextData - If context data is avaialble, this data will be used for variable replace. +// ContextData - If context data is available, this data will be used for variable replace. type ContextData struct { } type VariableParameters struct { // Brand ID BrandID *float64 `json:"brand_id,omitempty"` - // If context data is avaialble, this data will be used for variable replace. + // If context data is available, this data will be used for variable replace. ContextData *ContextData `json:"context_data,omitempty"` // Custom variables with specified values form other services. CustomVariables []ExternalCustomVariable `json:"custom_variables,omitempty"` @@ -39,85 +39,85 @@ func (v VariableParameters) MarshalJSON() ([]byte, error) { } func (v *VariableParameters) UnmarshalJSON(data []byte) error { - if err := utils.UnmarshalJSON(data, &v, "", false, false); err != nil { + if err := utils.UnmarshalJSON(data, &v, "", false, []string{"template_type"}); err != nil { return err } return nil } -func (o *VariableParameters) GetBrandID() *float64 { - if o == nil { +func (v *VariableParameters) GetBrandID() *float64 { + if v == nil { return nil } - return o.BrandID + return v.BrandID } -func (o *VariableParameters) GetContextData() *ContextData { - if o == nil { +func (v *VariableParameters) GetContextData() *ContextData { + if v == nil { return nil } - return o.ContextData + return v.ContextData } -func (o *VariableParameters) GetCustomVariables() []ExternalCustomVariable { - if o == nil { +func (v *VariableParameters) GetCustomVariables() []ExternalCustomVariable { + if v == nil { return nil } - return o.CustomVariables + return v.CustomVariables } -func (o *VariableParameters) GetLanguage() *string { - if o == nil { +func (v *VariableParameters) GetLanguage() *string { + if v == nil { return nil } - return o.Language + return v.Language } -func (o *VariableParameters) GetMainEntityID() *string { - if o == nil { +func (v *VariableParameters) GetMainEntityID() *string { + if v == nil { return nil } - return o.MainEntityID + return v.MainEntityID } -func (o *VariableParameters) GetTemplateName() *string { - if o == nil { +func (v *VariableParameters) GetTemplateName() *string { + if v == nil { return nil } - return o.TemplateName + return v.TemplateName } -func (o *VariableParameters) GetTemplateTags() []string { - if o == nil { +func (v *VariableParameters) GetTemplateTags() []string { + if v == nil { return nil } - return o.TemplateTags + return v.TemplateTags } -func (o *VariableParameters) GetTemplateType() TemplateType { - if o == nil { +func (v *VariableParameters) GetTemplateType() TemplateType { + if v == nil { return TemplateType("") } - return o.TemplateType + return v.TemplateType } -func (o *VariableParameters) GetUserID() *string { - if o == nil { +func (v *VariableParameters) GetUserID() *string { + if v == nil { return nil } - return o.UserID + return v.UserID } -func (o *VariableParameters) GetUserOrgID() *string { - if o == nil { +func (v *VariableParameters) GetUserOrgID() *string { + if v == nil { return nil } - return o.UserOrgID + return v.UserOrgID } -func (o *VariableParameters) GetVariablesVersion() *string { - if o == nil { +func (v *VariableParameters) GetVariablesVersion() *string { + if v == nil { return nil } - return o.VariablesVersion + return v.VariablesVersion } diff --git a/internal/sdk/models/shared/variableresult.go b/internal/sdk/models/shared/variableresult.go index 6778bf0..09e3845 100644 --- a/internal/sdk/models/shared/variableresult.go +++ b/internal/sdk/models/shared/variableresult.go @@ -45,37 +45,37 @@ type VariableResult struct { Type *VariableResultType `json:"type,omitempty"` } -func (o *VariableResult) GetDescription() *string { - if o == nil { +func (v *VariableResult) GetDescription() *string { + if v == nil { return nil } - return o.Description + return v.Description } -func (o *VariableResult) GetGroup() *string { - if o == nil { +func (v *VariableResult) GetGroup() *string { + if v == nil { return nil } - return o.Group + return v.Group } -func (o *VariableResult) GetInsert() *string { - if o == nil { +func (v *VariableResult) GetInsert() *string { + if v == nil { return nil } - return o.Insert + return v.Insert } -func (o *VariableResult) GetQrdata() *string { - if o == nil { +func (v *VariableResult) GetQrdata() *string { + if v == nil { return nil } - return o.Qrdata + return v.Qrdata } -func (o *VariableResult) GetType() *VariableResultType { - if o == nil { +func (v *VariableResult) GetType() *VariableResultType { + if v == nil { return nil } - return o.Type + return v.Type } diff --git a/internal/sdk/optionalnullable/optionalnullable.go b/internal/sdk/optionalnullable/optionalnullable.go new file mode 100644 index 0000000..c6739be --- /dev/null +++ b/internal/sdk/optionalnullable/optionalnullable.go @@ -0,0 +1,233 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package optionalnullable + +import ( + "bytes" + "encoding/json" + "reflect" +) + +// OptionalNullable represents a field that can distinguish between three states: +// 1. Set to a value: field is present with a non-nil value +// 2. Set to nil: field is present but explicitly set to null in JSON +// 3. Unset: field is omitted from JSON entirely +// +// This type is designed to work with JSON marshaling/unmarshaling and supports +// the `omitempty` struct tag to properly omit unset fields from JSON output. +// +// Usage: +// +// type User struct { +// Name OptionalNullable[string] `json:"name,omitempty"` +// Age OptionalNullable[int] `json:"age,omitempty"` +// Tags OptionalNullable[[]string] `json:"tags,omitempty"` +// } +// +// // Set to value +// name := "John" +// user.Name = From(&name) +// +// // Set to nil (will appear as "name": null in JSON) +// user.Name = From[string](nil) +// +// // Leave unset (will be omitted from JSON with omitempty) +// user := User{} +// +// WARNING: Do NOT use *OptionalNullable[T] as a field type. Always use OptionalNullable[T] directly. +// Using *OptionalNullable[T] will break the omitempty behavior and JSON marshaling. +// +// The type is implemented as a map[bool]*T where: +// - nil map represents unset state +// - Map with true key represents set state (value may be nil) +type OptionalNullable[T any] map[bool]*T + +// From creates a new OptionalNullable with the given value. +// Pass nil to create a OptionalNullable that is set to null. +// Pass a pointer to a value to create a OptionalNullable with that value. +// +// Examples: +// +// hello := "hello" +// From(&hello) // set to "hello" +// From[string](nil) // set to null +func From[T any](value *T) OptionalNullable[T] { + return map[bool]*T{ + true: value, + } +} + +// IsNull returns true if the OptionalNullable is explicitly set to nil. +// Returns false if the OptionalNullable is unset or has a value. +// +// Note: This differs from traditional null checks because unset fields +// return false, not true. Use IsSet() to check if a field was provided. +func (n OptionalNullable[T]) IsNull() bool { + v, ok := n[true] + return ok && v == nil +} + +// IsSet returns true if the OptionalNullable has been explicitly set (to either a value or nil). +// Returns false if the OptionalNullable is unset (omitted from JSON). +// +// This is the key method for distinguishing between: +// - Set to nil: IsSet() = true, IsNull() = true +// - Unset: IsSet() = false, IsNull() = false +func (n OptionalNullable[T]) IsSet() bool { + _, ok := n[true] + return ok +} + +// Get returns the internal pointer and whether the field was set. +// +// Return values: +// - (ptr, true): field was set (ptr may be nil if set to null) +// - (nil, false): field was unset/omitted +// +// This method provides direct access to the internal pointer representation. +func (n OptionalNullable[T]) Get() (*T, bool) { + v, ok := n[true] + return v, ok +} + +// GetOrZero returns the value and whether it was set. +// +// Return values: +// - (value, true): field was set to a non-nil value +// - (zero, true): field was explicitly set to nil +// - (zero, false): field was unset/omitted +// +// Examples: +// +// val, ok := nullable.GetOrZero() +// if !ok { +// // Field was unset/omitted +// } else if nullable.IsNull() { +// // Field was explicitly set to null +// } else { +// // Field has a value: val +// } +func (n OptionalNullable[T]) GetOrZero() (T, bool) { + var zero T + + if v, ok := n[true]; ok { + if v == nil { + return zero, true + } + return *v, true + } + return zero, false +} + +// GetUntyped returns the value as interface{} and whether it was set. +// This is useful for reflection-based code that needs to work with the value +// without knowing the specific type T. +// +// Return values: +// - (value, true): field was set to a non-nil value +// - (nil, true): field was explicitly set to nil +// - (nil, false): field was unset/omitted +func (n OptionalNullable[T]) GetUntyped() (interface{}, bool) { + if v, ok := n[true]; ok { + if v == nil { + return nil, true + } + return *v, true + } + return nil, false +} + +// Set sets the OptionalNullable to the given value pointer. +// Pass nil to set the field to null. +// Pass a pointer to a value to set the field to that value. +// +// Examples: +// +// nullable.Set(ptrFrom("hello")) // set to "hello" +// nullable.Set(nil) // set to null +func (n *OptionalNullable[T]) Set(value *T) { + *n = map[bool]*T{ + true: value, + } +} + +// Unset removes the value, making the field unset/omitted. +// After calling Unset(), IsSet() will return false and the field +// will be omitted from JSON output when using omitempty. +func (n *OptionalNullable[T]) Unset() { + *n = map[bool]*T{} +} + +// MarshalJSON implements json.Marshaler. +// +// Behavior: +// - Unset fields: omitted from JSON when struct field has omitempty tag +// - Null fields: serialized as "null" +// - Value fields: serialized as the actual value +// +// The omitempty behavior works because an empty map is considered +// a zero value by Go's JSON package. +func (n OptionalNullable[T]) MarshalJSON() ([]byte, error) { + if n.IsNull() { + return []byte("null"), nil + } + + return json.Marshal(n[true]) +} + +// UnmarshalJSON implements json.Unmarshaler. +// +// Behavior: +// - "null" in JSON: sets the field to null (IsSet=true, IsNull=true) +// - Any other value: sets the field to that value (IsSet=true, IsNull=false) +// - Missing from JSON: field remains unset (IsSet=false, IsNull=false) +func (n *OptionalNullable[T]) UnmarshalJSON(data []byte) error { + if bytes.Equal(data, []byte("null")) { + n.Set(nil) + return nil + } + var v T + if err := json.Unmarshal(data, &v); err != nil { + return err + } + n.Set(&v) + return nil +} + +// NullableInterface defines the interface that all OptionalNullable[T] types implement. +// This interface provides untyped access to optional nullable values for reflection-based code. +type OptionalNullableInterface interface { + GetUntyped() (interface{}, bool) +} + +// AsOptionalNullable attempts to convert a reflect.Value to a OptionalNullableInterface. +// This is a helper function for reflection-based code that needs to check +// if a value implements the optional nullable interface pattern. +// +// Returns: +// - (nullable, true): if the value implements OptionalNullableInterface +// - (nil, false): if the value does not implement OptionalNullableInterface +// +// Example usage: +// +// if nullable, ok := AsOptionalNullable(reflectValue); ok { +// if value, isSet := nullable.GetUntyped(); isSet { +// // Handle the nullable value +// } +// } +func AsOptionalNullable(v reflect.Value) (OptionalNullableInterface, bool) { + // Check if the value can be converted to an interface first + if !v.CanInterface() { + return nil, false + } + + // Check if the underlying value is a nil map (unset nullable) + if v.Kind() == reflect.Map && v.IsNil() { + return nil, false + } + + if nullable, ok := v.Interface().(OptionalNullableInterface); ok { + return nullable, true + } + return nil, false +} diff --git a/internal/sdk/optionalnullable/optionalnullable_test.go b/internal/sdk/optionalnullable/optionalnullable_test.go new file mode 100644 index 0000000..e6e5a01 --- /dev/null +++ b/internal/sdk/optionalnullable/optionalnullable_test.go @@ -0,0 +1,1806 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package optionalnullable + +import ( + "encoding/json" + "reflect" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +// Test helper function to create pointers from values +func ptrFrom[T any](value T) *T { + return &value +} + +// Test helper types for comprehensive testing +type TestStruct struct { + Name string `json:"name"` + Age int `json:"age"` +} + +type TestContainer struct { + StringField OptionalNullable[string] `json:"string_field,omitempty"` + IntField OptionalNullable[int] `json:"int_field,omitempty"` + SliceField OptionalNullable[[]string] `json:"slice_field,omitempty"` + StructField OptionalNullable[TestStruct] `json:"struct_field,omitempty"` +} + +// TestNewNullable tests the From constructor +func TestNewNullable(t *testing.T) { + t.Parallel() + t.Run("with string value", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom("test")) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, "test", got) + }) + + t.Run("with nil pointer", func(t *testing.T) { + t.Parallel() + nullable := From[string](nil) + + assert.True(t, nullable.IsSet()) + assert.True(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, "", got) // zero value for string + }) + + t.Run("with int value", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom(42)) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, 42, got) + }) + + t.Run("with slice value", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom([]string{"a", "b", "c"})) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, []string{"a", "b", "c"}, got) + }) + + t.Run("with empty slice", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom([]string{})) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, []string{}, got) + }) + + t.Run("with struct value", func(t *testing.T) { + t.Parallel() + val := TestStruct{Name: "John", Age: 30} + nullable := From(&val) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + v, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, val, v) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, TestStruct{Name: "John", Age: 30}, got) + }) +} + +// TestNewNullableUnset tests the NewNullableUnset constructor +func TestNewNullableUnset(t *testing.T) { + t.Parallel() + t.Run("string type", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[string] + + assert.False(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) // Unset is not null + + got, ok := nullable.GetOrZero() + assert.False(t, ok) + assert.Equal(t, "", got) // zero value for string + }) + + t.Run("int type", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[int] + + assert.False(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) // Unset is not null + + got, ok := nullable.GetOrZero() + assert.False(t, ok) + assert.Equal(t, 0, got) // zero value for int + }) + + t.Run("slice type", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[[]string] + + assert.False(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) // Unset is not null + + got, ok := nullable.GetOrZero() + assert.False(t, ok) + assert.Nil(t, got) // zero value for slice is nil + }) +} + +// TestIsNull tests the IsNull method +func TestIsNull(t *testing.T) { + t.Parallel() + t.Run("with value", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom("test")) + assert.False(t, nullable.IsNull()) + }) + + t.Run("with nil pointer", func(t *testing.T) { + t.Parallel() + nullable := From[string](nil) + assert.True(t, nullable.IsNull()) + }) + + t.Run("unset", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[string] + assert.False(t, nullable.IsNull()) + }) +} + +// TestIsSet tests the IsSet method +func TestIsSet(t *testing.T) { + t.Parallel() + t.Run("with value", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom("test")) + assert.True(t, nullable.IsSet()) + }) + + t.Run("with nil pointer", func(t *testing.T) { + t.Parallel() + nullable := From[string](nil) + assert.True(t, nullable.IsSet()) + }) + + t.Run("unset", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[string] + assert.False(t, nullable.IsSet()) + }) +} + +// TestGet tests the Get method +func TestGet(t *testing.T) { + t.Parallel() + t.Run("with string value", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom("test")) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, "test", got) + }) + + t.Run("with nil pointer", func(t *testing.T) { + t.Parallel() + nullable := From[string](nil) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, "", got) // zero value + }) + + t.Run("unset", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[string] + + got, ok := nullable.GetOrZero() + assert.False(t, ok) + assert.Equal(t, "", got) // zero value + }) + + t.Run("with slice value", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom([]string{"a", "b"})) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, []string{"a", "b"}, got) + }) + + t.Run("with nil slice pointer", func(t *testing.T) { + t.Parallel() + nullable := From[[]string](nil) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Nil(t, got) // zero value for slice is nil + }) +} + +// TestPointer tests the Pointer method +func TestPointer(t *testing.T) { + t.Parallel() + t.Run("with value", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom("test")) + + ptr, ok := nullable.Get() + assert.True(t, ok) + assert.NotNil(t, ptr) + assert.Equal(t, "test", *ptr) + }) + + t.Run("with nil pointer", func(t *testing.T) { + t.Parallel() + nullable := From[string](nil) + + ptr, ok := nullable.Get() + assert.True(t, ok) + assert.Nil(t, ptr) + }) + + t.Run("unset", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[string] + + ptr, ok := nullable.Get() + assert.False(t, ok) + assert.Nil(t, ptr) + }) +} + +// TestSet tests the Set method +func TestSet(t *testing.T) { + t.Parallel() + t.Run("set string value", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[string] + + // Initially unset + assert.False(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) // Unset is not null + + // Set a value + nullable.Set(ptrFrom("test")) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, "test", got) + }) + + t.Run("set int value", func(t *testing.T) { + t.Parallel() + nullable := OptionalNullable[int]{} + + nullable.Set(ptrFrom(42)) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, 42, got) + }) + + t.Run("set slice value", func(t *testing.T) { + t.Parallel() + nullable := OptionalNullable[[]string]{} + + slice := []string{"a", "b"} + nullable.Set(ptrFrom(slice)) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, []string{"a", "b"}, got) + }) + + t.Run("set empty slice", func(t *testing.T) { + t.Parallel() + nullable := OptionalNullable[[]string]{} + + slice := []string{} + nullable.Set(ptrFrom(slice)) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, []string{}, got) + }) + + t.Run("overwrite existing value", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom("original")) + + // Verify original value + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, "original", got) + + // Set new value + nullable.Set(ptrFrom("new")) + + got, ok = nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, "new", got) + }) +} + +// TestUnset tests the Unset method +func TestUnset(t *testing.T) { + t.Parallel() + t.Run("unset from value", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom("test")) + + // Initially set + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + // Unset + nullable.Unset() + + assert.False(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) // After unset is not null + // Value is now internal to the map implementation + + got, ok := nullable.GetOrZero() + assert.False(t, ok) + assert.Equal(t, "", got) // zero value + }) + + t.Run("unset from nil", func(t *testing.T) { + t.Parallel() + nullable := From[string](nil) + + // Initially set to nil + assert.True(t, nullable.IsSet()) + assert.True(t, nullable.IsNull()) // Set to nil should be null + + // Unset + nullable.Unset() + + assert.False(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) // After unset is not null + }) + + t.Run("unset already unset", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[string] + + // Initially unset + assert.False(t, nullable.IsSet()) + + // Unset again + nullable.Unset() + + assert.False(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) // Empty map is not null + }) +} + +// TestMarshalJSON tests JSON marshaling +func TestMarshalJSON(t *testing.T) { + t.Parallel() + t.Run("marshal string value", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom("test")) + + data, err := json.Marshal(nullable) + require.NoError(t, err) + assert.Equal(t, `"test"`, string(data)) + }) + + t.Run("marshal int value", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom(42)) + + data, err := json.Marshal(nullable) + require.NoError(t, err) + assert.Equal(t, `42`, string(data)) + }) + + t.Run("marshal nil value", func(t *testing.T) { + t.Parallel() + nullable := From[string](nil) + + data, err := json.Marshal(nullable) + require.NoError(t, err) + assert.Equal(t, `null`, string(data)) + }) + + t.Run("marshal slice value", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom([]string{"a", "b", "c"})) + + data, err := json.Marshal(nullable) + require.NoError(t, err) + assert.Equal(t, `["a","b","c"]`, string(data)) + }) + + t.Run("marshal empty slice", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom([]string{})) + + data, err := json.Marshal(nullable) + require.NoError(t, err) + assert.Equal(t, `[]`, string(data)) + }) + + t.Run("marshal struct value", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom(TestStruct{Name: "John", Age: 30})) + + data, err := json.Marshal(nullable) + require.NoError(t, err) + assert.Equal(t, `{"name":"John","age":30}`, string(data)) + }) + + // Note: Unset values are not tested here because the current implementation + // doesn't handle unset fields in marshaling (see TODO in the code) +} + +// TestUnmarshalJSON tests JSON unmarshaling +func TestUnmarshalJSON(t *testing.T) { + t.Parallel() + t.Run("unmarshal string value", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[string] + err := json.Unmarshal([]byte(`"test"`), &nullable) + require.NoError(t, err) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, "test", got) + }) + + t.Run("unmarshal int value", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[int] + err := json.Unmarshal([]byte(`42`), &nullable) + require.NoError(t, err) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, 42, got) + }) + + t.Run("unmarshal null value", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[string] + err := json.Unmarshal([]byte(`null`), &nullable) + require.NoError(t, err) + + assert.True(t, nullable.IsSet()) + assert.True(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, "", got) // zero value + }) + + t.Run("unmarshal slice value", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[[]string] + err := json.Unmarshal([]byte(`["a","b","c"]`), &nullable) + require.NoError(t, err) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, []string{"a", "b", "c"}, got) + }) + + t.Run("unmarshal empty slice", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[[]string] + err := json.Unmarshal([]byte(`[]`), &nullable) + require.NoError(t, err) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, []string{}, got) + }) + + t.Run("unmarshal struct value", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[TestStruct] + err := json.Unmarshal([]byte(`{"name":"John","age":30}`), &nullable) + require.NoError(t, err) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, TestStruct{Name: "John", Age: 30}, got) + }) + + t.Run("unmarshal invalid JSON", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[string] + err := json.Unmarshal([]byte(`invalid`), &nullable) + assert.Error(t, err) + + // Ensure the nullable remains unset after error + assert.False(t, nullable.IsSet()) + }) + + t.Run("unmarshal invalid JSON for int", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[int] + err := json.Unmarshal([]byte(`"not_a_number"`), &nullable) + assert.Error(t, err) + + // Ensure the nullable remains unset after error + assert.False(t, nullable.IsSet()) + }) + + t.Run("unmarshal malformed JSON", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[TestStruct] + err := json.Unmarshal([]byte(`{invalid json`), &nullable) + assert.Error(t, err) + + // Ensure the nullable remains unset after error + assert.False(t, nullable.IsSet()) + }) +} + +// TestJSONRoundTrip tests marshaling and unmarshaling together +func TestJSONRoundTrip(t *testing.T) { + t.Parallel() + t.Run("string value round trip", func(t *testing.T) { + t.Parallel() + nullable1 := From(ptrFrom("test value")) + + // Marshal + data, err := json.Marshal(nullable1) + require.NoError(t, err) + + // Unmarshal + var nullable2 OptionalNullable[string] + err = json.Unmarshal(data, &nullable2) + require.NoError(t, err) + + // Compare + assert.Equal(t, nullable1.IsSet(), nullable2.IsSet()) + assert.Equal(t, nullable1.IsNull(), nullable2.IsNull()) + + got1, ok1 := nullable1.GetOrZero() + got2, ok2 := nullable2.GetOrZero() + assert.Equal(t, ok1, ok2) + assert.Equal(t, got1, got2) + }) + + t.Run("nil value round trip", func(t *testing.T) { + t.Parallel() + nullable1 := From[string](nil) + + // Marshal + data, err := json.Marshal(nullable1) + require.NoError(t, err) + + // Unmarshal + var nullable2 OptionalNullable[string] + err = json.Unmarshal(data, &nullable2) + require.NoError(t, err) + + // Compare + assert.Equal(t, nullable1.IsSet(), nullable2.IsSet()) + assert.Equal(t, nullable1.IsNull(), nullable2.IsNull()) + + got1, ok1 := nullable1.GetOrZero() + got2, ok2 := nullable2.GetOrZero() + assert.Equal(t, ok1, ok2) + assert.Equal(t, got1, got2) + }) + + t.Run("slice round trip", func(t *testing.T) { + t.Parallel() + nullable1 := From(ptrFrom([]string{"a", "b", "c"})) + + // Marshal + data, err := json.Marshal(nullable1) + require.NoError(t, err) + + // Unmarshal + var nullable2 OptionalNullable[[]string] + err = json.Unmarshal(data, &nullable2) + require.NoError(t, err) + + // Compare + assert.Equal(t, nullable1.IsSet(), nullable2.IsSet()) + assert.Equal(t, nullable1.IsNull(), nullable2.IsNull()) + + got1, ok1 := nullable1.GetOrZero() + got2, ok2 := nullable2.GetOrZero() + assert.Equal(t, ok1, ok2) + assert.Equal(t, got1, got2) + }) +} + +// TestJSONToJSONRoundTrip tests starting with JSON and ensuring we can serialize back to the same JSON +func TestJSONToJSONRoundTrip(t *testing.T) { + t.Parallel() + t.Run("string value JSON round trip", func(t *testing.T) { + t.Parallel() + originalJSON := `"hello world"` + + // Unmarshal from JSON + var nullable OptionalNullable[string] + err := json.Unmarshal([]byte(originalJSON), &nullable) + require.NoError(t, err) + + // Verify state + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, "hello world", got) + + // Marshal back to JSON + resultJSON, err := json.Marshal(nullable) + require.NoError(t, err) + assert.Equal(t, originalJSON, string(resultJSON)) + }) + + t.Run("null value JSON round trip", func(t *testing.T) { + t.Parallel() + originalJSON := `null` + + // Unmarshal from JSON + var nullable OptionalNullable[string] + err := json.Unmarshal([]byte(originalJSON), &nullable) + require.NoError(t, err) + + // Verify state + assert.True(t, nullable.IsSet()) + assert.True(t, nullable.IsNull()) + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, "", got) // zero value + + // Marshal back to JSON + resultJSON, err := json.Marshal(nullable) + require.NoError(t, err) + assert.Equal(t, originalJSON, string(resultJSON)) + }) + + t.Run("int value JSON round trip", func(t *testing.T) { + t.Parallel() + originalJSON := `42` + + // Unmarshal from JSON + var nullable OptionalNullable[int] + err := json.Unmarshal([]byte(originalJSON), &nullable) + require.NoError(t, err) + + // Verify state + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, 42, got) + + // Marshal back to JSON + resultJSON, err := json.Marshal(nullable) + require.NoError(t, err) + assert.Equal(t, originalJSON, string(resultJSON)) + }) + + t.Run("slice value JSON round trip", func(t *testing.T) { + t.Parallel() + originalJSON := `["a","b","c"]` + + // Unmarshal from JSON + var nullable OptionalNullable[[]string] + err := json.Unmarshal([]byte(originalJSON), &nullable) + require.NoError(t, err) + + // Verify state + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, []string{"a", "b", "c"}, got) + + // Marshal back to JSON + resultJSON, err := json.Marshal(nullable) + require.NoError(t, err) + assert.Equal(t, originalJSON, string(resultJSON)) + }) + + t.Run("empty slice JSON round trip", func(t *testing.T) { + t.Parallel() + originalJSON := `[]` + + // Unmarshal from JSON + var nullable OptionalNullable[[]string] + err := json.Unmarshal([]byte(originalJSON), &nullable) + require.NoError(t, err) + + // Verify state + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, []string{}, got) + + // Marshal back to JSON + resultJSON, err := json.Marshal(nullable) + require.NoError(t, err) + assert.Equal(t, originalJSON, string(resultJSON)) + }) + + t.Run("struct value JSON round trip", func(t *testing.T) { + t.Parallel() + originalJSON := `{"name":"Alice","age":25}` + + // Unmarshal from JSON + var nullable OptionalNullable[TestStruct] + err := json.Unmarshal([]byte(originalJSON), &nullable) + require.NoError(t, err) + + // Verify state + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, TestStruct{Name: "Alice", Age: 25}, got) + + // Marshal back to JSON + resultJSON, err := json.Marshal(nullable) + require.NoError(t, err) + assert.Equal(t, originalJSON, string(resultJSON)) + }) +} + +// TestContainerStates tests comprehensive state detection and serialization with TestContainer +func TestContainerStates(t *testing.T) { + t.Parallel() + t.Run("all fields set to values", func(t *testing.T) { + t.Parallel() + container := TestContainer{ + StringField: From(ptrFrom("hello")), + IntField: From(ptrFrom(42)), + SliceField: From(ptrFrom([]string{"a", "b"})), + StructField: From(ptrFrom(TestStruct{Name: "John", Age: 30})), + } + + // Verify all fields are set and not null + assert.True(t, container.StringField.IsSet()) + assert.False(t, container.StringField.IsNull()) + assert.True(t, container.IntField.IsSet()) + assert.False(t, container.IntField.IsNull()) + assert.True(t, container.SliceField.IsSet()) + assert.False(t, container.SliceField.IsNull()) + assert.True(t, container.StructField.IsSet()) + assert.False(t, container.StructField.IsNull()) + + // Verify values + stringVal, ok := container.StringField.GetOrZero() + assert.True(t, ok) + assert.Equal(t, "hello", stringVal) + + intVal, ok := container.IntField.GetOrZero() + assert.True(t, ok) + assert.Equal(t, 42, intVal) + + sliceVal, ok := container.SliceField.GetOrZero() + assert.True(t, ok) + assert.Equal(t, []string{"a", "b"}, sliceVal) + + structVal, ok := container.StructField.GetOrZero() + assert.True(t, ok) + assert.Equal(t, TestStruct{Name: "John", Age: 30}, structVal) + + // Test JSON serialization + data, err := json.Marshal(container) + require.NoError(t, err) + + var result map[string]interface{} + err = json.Unmarshal(data, &result) + require.NoError(t, err) + + assert.Equal(t, "hello", result["string_field"]) + assert.Equal(t, float64(42), result["int_field"]) // JSON numbers are float64 + assert.Equal(t, []interface{}{"a", "b"}, result["slice_field"]) + structResult := result["struct_field"].(map[string]interface{}) + assert.Equal(t, "John", structResult["name"]) + assert.Equal(t, float64(30), structResult["age"]) + }) + + t.Run("all fields set to nil", func(t *testing.T) { + t.Parallel() + container := TestContainer{ + StringField: From[string](nil), + IntField: From[int](nil), + SliceField: From[[]string](nil), + StructField: From[TestStruct](nil), + } + + // Verify all fields are set but null + assert.True(t, container.StringField.IsSet()) + assert.True(t, container.StringField.IsNull()) + assert.True(t, container.IntField.IsSet()) + assert.True(t, container.IntField.IsNull()) + assert.True(t, container.SliceField.IsSet()) + assert.True(t, container.SliceField.IsNull()) + assert.True(t, container.StructField.IsSet()) + assert.True(t, container.StructField.IsNull()) + + // Verify GetOrZero() behavior for nil values + stringVal, ok := container.StringField.GetOrZero() + assert.True(t, ok) // set to nil still returns true + assert.Equal(t, "", stringVal) // zero value + + intVal, ok := container.IntField.GetOrZero() + assert.True(t, ok) + assert.Equal(t, 0, intVal) // zero value + + sliceVal, ok := container.SliceField.GetOrZero() + assert.True(t, ok) + assert.Nil(t, sliceVal) // zero value for slice is nil + + structVal, ok := container.StructField.GetOrZero() + assert.True(t, ok) + assert.Equal(t, TestStruct{}, structVal) // zero value + + // Test JSON serialization - all should be null + data, err := json.Marshal(container) + require.NoError(t, err) + + var result map[string]interface{} + err = json.Unmarshal(data, &result) + require.NoError(t, err) + + assert.Nil(t, result["string_field"]) + assert.Nil(t, result["int_field"]) + assert.Nil(t, result["slice_field"]) + assert.Nil(t, result["struct_field"]) + }) + + t.Run("all fields unset", func(t *testing.T) { + t.Parallel() + container := TestContainer{} + + // Verify all fields are unset + assert.False(t, container.StringField.IsSet()) + assert.False(t, container.StringField.IsNull()) // unset is not null in new implementation + assert.False(t, container.IntField.IsSet()) + assert.False(t, container.IntField.IsNull()) + assert.False(t, container.SliceField.IsSet()) + assert.False(t, container.SliceField.IsNull()) + assert.False(t, container.StructField.IsSet()) + assert.False(t, container.StructField.IsNull()) + + // Verify GetOrZero() behavior for unset values + stringVal, ok := container.StringField.GetOrZero() + assert.False(t, ok) // unset returns false + assert.Equal(t, "", stringVal) // zero value + + intVal, ok := container.IntField.GetOrZero() + assert.False(t, ok) + assert.Equal(t, 0, intVal) // zero value + + sliceVal, ok := container.SliceField.GetOrZero() + assert.False(t, ok) + assert.Nil(t, sliceVal) // zero value + + structVal, ok := container.StructField.GetOrZero() + assert.False(t, ok) + assert.Equal(t, TestStruct{}, structVal) // zero value + + // Test JSON serialization - unset fields should be omitted due to omitempty + data, err := json.Marshal(container) + require.NoError(t, err) + + var result map[string]interface{} + err = json.Unmarshal(data, &result) + require.NoError(t, err) + + // With omitempty, unset fields should not appear in JSON + assert.NotContains(t, result, "string_field") + assert.NotContains(t, result, "int_field") + assert.NotContains(t, result, "slice_field") + assert.NotContains(t, result, "struct_field") + }) + + t.Run("slice field states: nil vs unset vs empty vs set", func(t *testing.T) { + t.Parallel() + // Test all possible slice states + nilSlice := TestContainer{ + SliceField: From[[]string](nil), // explicitly set to nil + } + unsetSlice := TestContainer{} // unset + emptySlice := TestContainer{ + SliceField: From(ptrFrom([]string{})), // empty slice + } + setSlice := TestContainer{ + SliceField: From(ptrFrom([]string{"a", "b"})), // slice with values + } + + // Verify nil slice + assert.True(t, nilSlice.SliceField.IsSet()) + assert.True(t, nilSlice.SliceField.IsNull()) + val, ok := nilSlice.SliceField.GetOrZero() + assert.True(t, ok) + assert.Nil(t, val) + + // Verify unset slice + assert.False(t, unsetSlice.SliceField.IsSet()) + assert.False(t, unsetSlice.SliceField.IsNull()) // Unset is not null + val, ok = unsetSlice.SliceField.GetOrZero() + assert.False(t, ok) + assert.Nil(t, val) + + // Verify empty slice + assert.True(t, emptySlice.SliceField.IsSet()) + assert.False(t, emptySlice.SliceField.IsNull()) + val, ok = emptySlice.SliceField.GetOrZero() + assert.True(t, ok) + assert.Equal(t, []string{}, val) + + // Verify set slice + assert.True(t, setSlice.SliceField.IsSet()) + assert.False(t, setSlice.SliceField.IsNull()) + val, ok = setSlice.SliceField.GetOrZero() + assert.True(t, ok) + assert.Equal(t, []string{"a", "b"}, val) + + // Test JSON serialization for each state + nilData, err := json.Marshal(nilSlice) + require.NoError(t, err) + assert.Contains(t, string(nilData), `"slice_field":null`) + + unsetData, err := json.Marshal(unsetSlice) + require.NoError(t, err) + assert.NotContains(t, string(unsetData), "slice_field") // omitted due to omitempty + + emptyData, err := json.Marshal(emptySlice) + require.NoError(t, err) + assert.Contains(t, string(emptyData), `"slice_field":[]`) + + setData, err := json.Marshal(setSlice) + require.NoError(t, err) + assert.Contains(t, string(setData), `"slice_field":["a","b"]`) + }) + + t.Run("mixed states container", func(t *testing.T) { + t.Parallel() + container := TestContainer{ + StringField: From(ptrFrom("hello")), // set to value + IntField: From[int](nil), // set to nil + StructField: From(ptrFrom(TestStruct{Name: "Alice", Age: 25})), // set to value + } + + // Verify states + assert.True(t, container.StringField.IsSet()) + assert.False(t, container.StringField.IsNull()) + + assert.True(t, container.IntField.IsSet()) + assert.True(t, container.IntField.IsNull()) + + assert.False(t, container.SliceField.IsSet()) + assert.False(t, container.SliceField.IsNull()) // Unset is not null + + assert.True(t, container.StructField.IsSet()) + assert.False(t, container.StructField.IsNull()) + + // Test JSON serialization + data, err := json.Marshal(container) + require.NoError(t, err) + + var result map[string]interface{} + err = json.Unmarshal(data, &result) + require.NoError(t, err) + + assert.Equal(t, "hello", result["string_field"]) + assert.Nil(t, result["int_field"]) + assert.NotContains(t, result, "slice_field") // unset, so omitted + structResult := result["struct_field"].(map[string]interface{}) + assert.Equal(t, "Alice", structResult["name"]) + assert.Equal(t, float64(25), structResult["age"]) + }) + + t.Run("JSON unmarshaling preserves states", func(t *testing.T) { + t.Parallel() + // JSON with some fields missing, some null, some with values + jsonData := `{ + "string_field": "test", + "int_field": null, + "struct_field": {"name": "Bob", "age": 35} + }` + + var container TestContainer + err := json.Unmarshal([]byte(jsonData), &container) + require.NoError(t, err) + + // string_field: present with value + assert.True(t, container.StringField.IsSet()) + assert.False(t, container.StringField.IsNull()) + stringVal, ok := container.StringField.GetOrZero() + assert.True(t, ok) + assert.Equal(t, "test", stringVal) + + // int_field: present but null + assert.True(t, container.IntField.IsSet()) + assert.True(t, container.IntField.IsNull()) + intVal, ok := container.IntField.GetOrZero() + assert.True(t, ok) + assert.Equal(t, 0, intVal) // zero value + + // slice_field: missing from JSON, should remain unset + assert.False(t, container.SliceField.IsSet()) + assert.False(t, container.SliceField.IsNull()) // Unset is not null + sliceVal, ok := container.SliceField.GetOrZero() + assert.False(t, ok) + assert.Nil(t, sliceVal) + + // struct_field: present with value + assert.True(t, container.StructField.IsSet()) + assert.False(t, container.StructField.IsNull()) + structVal, ok := container.StructField.GetOrZero() + assert.True(t, ok) + assert.Equal(t, TestStruct{Name: "Bob", Age: 35}, structVal) + }) +} + +// TestNilVsUnsetDistinction tests the key feature of distinguishing nil from unset +func TestNilVsUnsetDistinction(t *testing.T) { + t.Parallel() + t.Run("explicit nil vs unset", func(t *testing.T) { + t.Parallel() + // Explicitly set to nil + explicitNil := From[string](nil) + + // Unset + var unset OptionalNullable[string] + + // Both are null, but only one is set + assert.True(t, explicitNil.IsNull()) + assert.True(t, explicitNil.IsSet()) + + assert.False(t, unset.IsNull()) // Unset is not null + assert.False(t, unset.IsSet()) + + // Get behavior differs + got1, ok1 := explicitNil.GetOrZero() + got2, ok2 := unset.GetOrZero() + + assert.True(t, ok1) // explicitly set to nil returns true + assert.False(t, ok2) // unset returns false + assert.Equal(t, "", got1) // both return zero value + assert.Equal(t, "", got2) + + // Get behavior differs + ptr1, ok1 := explicitNil.Get() + ptr2, ok2 := unset.Get() + + assert.True(t, ok1) // explicitly set to nil returns true + assert.False(t, ok2) // unset returns false + assert.Nil(t, ptr1) // both return nil pointer + assert.Nil(t, ptr2) + }) + + t.Run("empty slice vs nil slice vs unset", func(t *testing.T) { + t.Parallel() + // Empty slice + emptyNullable := From(ptrFrom([]string{})) + + // Nil slice + nilNullable := From[[]string](nil) + + // Unset + var unsetNullable OptionalNullable[[]string] + + // All have different characteristics + assert.True(t, emptyNullable.IsSet()) + assert.False(t, emptyNullable.IsNull()) + + assert.True(t, nilNullable.IsSet()) + assert.True(t, nilNullable.IsNull()) + + assert.False(t, unsetNullable.IsSet()) + assert.False(t, unsetNullable.IsNull()) // Unset is not null + + // Get behavior + got1, ok1 := emptyNullable.GetOrZero() + got2, ok2 := nilNullable.GetOrZero() + got3, ok3 := unsetNullable.GetOrZero() + + assert.True(t, ok1) + assert.Equal(t, []string{}, got1) + + assert.True(t, ok2) + assert.Nil(t, got2) + + assert.False(t, ok3) + assert.Nil(t, got3) + }) +} + +// TestJSONOmitEmpty tests behavior with omitempty tag +func TestJSONOmitEmpty(t *testing.T) { + t.Parallel() + t.Run("marshal with omitempty", func(t *testing.T) { + t.Parallel() + // Test container with various nullable states + container := TestContainer{ + StringField: From(ptrFrom("test")), + IntField: From(ptrFrom(42)), + StructField: From[TestStruct](nil), // explicitly nil + } + + data, err := json.Marshal(container) + require.NoError(t, err) + + // Parse back to verify structure + var result map[string]interface{} + err = json.Unmarshal(data, &result) + require.NoError(t, err) + + // Should contain set fields + assert.Contains(t, result, "string_field") + assert.Contains(t, result, "int_field") + assert.Contains(t, result, "struct_field") + + // Should not contain unset field (due to omitempty) + // Note: This depends on how the marshaling handles unset fields + // The current implementation doesn't handle this case properly (see TODO) + }) + + t.Run("unmarshal missing fields", func(t *testing.T) { + t.Parallel() + // JSON with some fields missing + jsonData := `{"string_field": "test", "int_field": null}` + + var container TestContainer + err := json.Unmarshal([]byte(jsonData), &container) + require.NoError(t, err) + + // Present fields should be set + assert.True(t, container.StringField.IsSet()) + assert.False(t, container.StringField.IsNull()) + got, ok := container.StringField.GetOrZero() + assert.True(t, ok) + assert.Equal(t, "test", got) + + // Null field should be set to nil + assert.True(t, container.IntField.IsSet()) + assert.True(t, container.IntField.IsNull()) + + // Missing fields should remain unset + assert.False(t, container.SliceField.IsSet()) + assert.False(t, container.StructField.IsSet()) + }) +} + +// TestEdgeCases tests various edge cases +func TestEdgeCases(t *testing.T) { + t.Parallel() + t.Run("zero values", func(t *testing.T) { + t.Parallel() + // Test with zero values that are not nil + intNullable := From(ptrFrom(0)) + stringNullable := From(ptrFrom("")) + + assert.True(t, intNullable.IsSet()) + assert.False(t, intNullable.IsNull()) + got, ok := intNullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, 0, got) + + assert.True(t, stringNullable.IsSet()) + assert.False(t, stringNullable.IsNull()) + got2, ok2 := stringNullable.GetOrZero() + assert.True(t, ok2) + assert.Equal(t, "", got2) + }) + + t.Run("pointer to pointer", func(t *testing.T) { + t.Parallel() + // Test with pointer to pointer type + inner := "test" + nullable := From(ptrFrom(&inner)) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, &inner, got) + assert.Equal(t, "test", *got) + }) + + t.Run("complex struct", func(t *testing.T) { + t.Parallel() + complexStruct := struct { + Name string + Values []int + Metadata map[string]string + }{ + Name: "complex", + Values: []int{1, 2, 3}, + Metadata: map[string]string{ + "key1": "value1", + "key2": "value2", + }, + } + + nullable := From(ptrFrom(complexStruct)) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, complexStruct, got) + }) +} + +// TestDoublePointers tests comprehensive double pointer scenarios +func TestDoublePointers(t *testing.T) { + t.Parallel() + + t.Run("string double pointer with value", func(t *testing.T) { + t.Parallel() + inner := "hello world" + ptr := &inner + nullable := From(ptrFrom(ptr)) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, ptr, got) + assert.Equal(t, &inner, got) + assert.Equal(t, "hello world", *got) + }) + + t.Run("int double pointer with value", func(t *testing.T) { + t.Parallel() + inner := 42 + ptr := &inner + nullable := From(ptrFrom(ptr)) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, ptr, got) + assert.Equal(t, &inner, got) + assert.Equal(t, 42, *got) + }) + + t.Run("double pointer to nil", func(t *testing.T) { + t.Parallel() + var ptr *string = nil + nullable := From(ptrFrom(ptr)) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, ptr, got) + assert.Nil(t, got) + }) + + t.Run("nil double pointer", func(t *testing.T) { + t.Parallel() + nullable := From[*string](nil) + + assert.True(t, nullable.IsSet()) + assert.True(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Nil(t, got) // zero value for **string is nil + }) + + t.Run("unset double pointer", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[*string] + + assert.False(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.False(t, ok) + assert.Nil(t, got) // zero value for **string is nil + }) + + t.Run("double pointer modification", func(t *testing.T) { + t.Parallel() + inner := "original" + ptr := &inner + nullable := From(ptrFrom(ptr)) + + // Verify original value + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, "original", *got) + + // Modify through double pointer + *got = "modified" + assert.Equal(t, "modified", inner) + assert.Equal(t, "modified", *got) + }) + + t.Run("double pointer to struct", func(t *testing.T) { + t.Parallel() + inner := TestStruct{Name: "Alice", Age: 30} + ptr := &inner + nullable := From(ptrFrom(ptr)) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, ptr, got) + assert.Equal(t, TestStruct{Name: "Alice", Age: 30}, *got) + + // Modify through double pointer + (*got).Name = "Bob" + assert.Equal(t, "Bob", inner.Name) + assert.Equal(t, "Bob", (*got).Name) + }) + + t.Run("double pointer to slice", func(t *testing.T) { + t.Parallel() + inner := []string{"a", "b", "c"} + ptr := &inner + nullable := From(ptrFrom(ptr)) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, ptr, got) + assert.Equal(t, []string{"a", "b", "c"}, *got) + + // Modify through double pointer + *got = append(*got, "d") + assert.Equal(t, []string{"a", "b", "c", "d"}, inner) + assert.Equal(t, []string{"a", "b", "c", "d"}, *got) + }) + + t.Run("double pointer to empty slice", func(t *testing.T) { + t.Parallel() + inner := []string{} + ptr := &inner + nullable := From(ptrFrom(ptr)) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, ptr, got) + assert.Equal(t, []string{}, *got) + }) + + t.Run("double pointer to nil slice", func(t *testing.T) { + t.Parallel() + var inner []string = nil + ptr := &inner + nullable := From(ptrFrom(ptr)) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, ptr, got) + assert.Nil(t, *got) + }) + + t.Run("double pointer JSON marshaling", func(t *testing.T) { + t.Parallel() + inner := "json test" + ptr := &inner + nullable := From(ptrFrom(ptr)) + + data, err := json.Marshal(nullable) + require.NoError(t, err) + assert.Equal(t, `"json test"`, string(data)) + }) + + t.Run("double pointer JSON unmarshaling", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[*string] + err := json.Unmarshal([]byte(`"json test"`), &nullable) + require.NoError(t, err) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.NotNil(t, got) + assert.Equal(t, "json test", *got) + }) + + t.Run("double pointer JSON null marshaling", func(t *testing.T) { + t.Parallel() + nullable := From[*string](nil) + + data, err := json.Marshal(nullable) + require.NoError(t, err) + assert.Equal(t, `null`, string(data)) + }) + + t.Run("double pointer JSON null unmarshaling", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[*string] + err := json.Unmarshal([]byte(`null`), &nullable) + require.NoError(t, err) + + assert.True(t, nullable.IsSet()) + assert.True(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Nil(t, got) + }) + + t.Run("double pointer round trip", func(t *testing.T) { + t.Parallel() + inner := "round trip test" + ptr := &inner + nullable1 := From(ptrFrom(ptr)) + + // Marshal + data, err := json.Marshal(nullable1) + require.NoError(t, err) + + // Unmarshal + var nullable2 OptionalNullable[*string] + err = json.Unmarshal(data, &nullable2) + require.NoError(t, err) + + // Compare states + assert.Equal(t, nullable1.IsSet(), nullable2.IsSet()) + assert.Equal(t, nullable1.IsNull(), nullable2.IsNull()) + + got1, ok1 := nullable1.GetOrZero() + got2, ok2 := nullable2.GetOrZero() + assert.Equal(t, ok1, ok2) + + // Values should be equal + assert.Equal(t, *got1, *got2) + }) + + t.Run("triple pointer", func(t *testing.T) { + t.Parallel() + inner := "triple" + ptr1 := &inner + ptr2 := &ptr1 + nullable := From(ptrFrom(ptr2)) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, ptr2, got) + assert.Equal(t, ptr1, *got) + assert.Equal(t, "triple", **got) + }) + + t.Run("double pointer set and unset", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[*string] + + // Initially unset + assert.False(t, nullable.IsSet()) + + // Set to double pointer + inner := "set test" + ptr := &inner + nullable.Set(ptrFrom(ptr)) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, "set test", *got) + + // Set to nil + nullable.Set(nil) + + assert.True(t, nullable.IsSet()) + assert.True(t, nullable.IsNull()) + + got, ok = nullable.GetOrZero() + assert.True(t, ok) + assert.Nil(t, got) + + // Unset + nullable.Unset() + + assert.False(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok = nullable.GetOrZero() + assert.False(t, ok) + assert.Nil(t, got) + }) + + t.Run("double pointer Get method", func(t *testing.T) { + t.Parallel() + inner := "get test" + ptr := &inner + nullable := From(ptrFrom(ptr)) + + // Test Get method + gotPtr, ok := nullable.Get() + assert.True(t, ok) + assert.NotNil(t, gotPtr) + assert.Equal(t, ptr, *gotPtr) + assert.Equal(t, "get test", **gotPtr) + + // Test with nil + nilNullable := From[*string](nil) + gotPtr, ok = nilNullable.Get() + assert.True(t, ok) + assert.Nil(t, gotPtr) + + // Test with unset + var unsetNullable OptionalNullable[*string] + gotPtr, ok = unsetNullable.Get() + assert.False(t, ok) + assert.Nil(t, gotPtr) + }) + + t.Run("double pointer zero values", func(t *testing.T) { + t.Parallel() + // Test with zero value string + inner := "" + ptr := &inner + nullable := From(ptrFrom(ptr)) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, "", *got) + + // Test with zero value int + innerInt := 0 + ptrInt := &innerInt + nullableInt := From(ptrFrom(ptrInt)) + + assert.True(t, nullableInt.IsSet()) + assert.False(t, nullableInt.IsNull()) + + gotInt, okInt := nullableInt.GetOrZero() + assert.True(t, okInt) + assert.Equal(t, 0, *gotInt) + }) +} + +// TestAsOptionalNullable tests the AsOptionalNullable helper function +func TestAsOptionalNullable(t *testing.T) { + t.Parallel() + + t.Run("with nullable string", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom("test")) + reflectValue := reflect.ValueOf(nullable) + + result, ok := AsOptionalNullable(reflectValue) + assert.True(t, ok) + assert.NotNil(t, result) + + value, isSet := result.GetUntyped() + assert.True(t, isSet) + assert.Equal(t, "test", value) + }) + + t.Run("with nullable int", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom(42)) + reflectValue := reflect.ValueOf(nullable) + + result, ok := AsOptionalNullable(reflectValue) + assert.True(t, ok) + assert.NotNil(t, result) + + value, isSet := result.GetUntyped() + assert.True(t, isSet) + assert.Equal(t, 42, value) + }) + + t.Run("with nullable nil", func(t *testing.T) { + t.Parallel() + nullable := From[string](nil) + reflectValue := reflect.ValueOf(nullable) + + result, ok := AsOptionalNullable(reflectValue) + assert.True(t, ok) + assert.NotNil(t, result) + + value, isSet := result.GetUntyped() + assert.True(t, isSet) + assert.Nil(t, value) + }) + + t.Run("with unset nullable", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[string] + reflectValue := reflect.ValueOf(nullable) + + result, ok := AsOptionalNullable(reflectValue) + assert.False(t, ok) + assert.Nil(t, result) + }) + + t.Run("with non-nullable string", func(t *testing.T) { + t.Parallel() + regularString := "not nullable" + reflectValue := reflect.ValueOf(regularString) + + result, ok := AsOptionalNullable(reflectValue) + assert.False(t, ok) + assert.Nil(t, result) + }) + + t.Run("with non-nullable int", func(t *testing.T) { + t.Parallel() + regularInt := 42 + reflectValue := reflect.ValueOf(regularInt) + + result, ok := AsOptionalNullable(reflectValue) + assert.False(t, ok) + assert.Nil(t, result) + }) + + t.Run("with non-nullable map", func(t *testing.T) { + t.Parallel() + regularMap := map[string]int{"key": 42} + reflectValue := reflect.ValueOf(regularMap) + + result, ok := AsOptionalNullable(reflectValue) + assert.False(t, ok) + assert.Nil(t, result) + }) + + t.Run("with non-nullable struct", func(t *testing.T) { + t.Parallel() + regularStruct := TestStruct{Name: "test", Age: 30} + reflectValue := reflect.ValueOf(regularStruct) + + result, ok := AsOptionalNullable(reflectValue) + assert.False(t, ok) + assert.Nil(t, result) + }) + + t.Run("with nullable double pointer", func(t *testing.T) { + t.Parallel() + inner := "test" + ptr := &inner + nullable := From(ptrFrom(ptr)) + reflectValue := reflect.ValueOf(nullable) + + result, ok := AsOptionalNullable(reflectValue) + assert.True(t, ok) + assert.NotNil(t, result) + + value, isSet := result.GetUntyped() + assert.True(t, isSet) + assert.Equal(t, ptr, value) + assert.Equal(t, "test", *value.(*string)) + }) + + t.Run("with nullable slice", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom([]string{"a", "b", "c"})) + reflectValue := reflect.ValueOf(nullable) + + result, ok := AsOptionalNullable(reflectValue) + assert.True(t, ok) + assert.NotNil(t, result) + + value, isSet := result.GetUntyped() + assert.True(t, isSet) + assert.Equal(t, []string{"a", "b", "c"}, value) + }) + + t.Run("with nullable struct", func(t *testing.T) { + t.Parallel() + testStruct := TestStruct{Name: "Alice", Age: 25} + nullable := From(ptrFrom(testStruct)) + reflectValue := reflect.ValueOf(nullable) + + result, ok := AsOptionalNullable(reflectValue) + assert.True(t, ok) + assert.NotNil(t, result) + + value, isSet := result.GetUntyped() + assert.True(t, isSet) + assert.Equal(t, testStruct, value) + }) + + t.Run("with pointer to nullable", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom("test")) + ptrToNullable := &nullable + reflectValue := reflect.ValueOf(ptrToNullable) + + // This should work since the pointer to nullable still contains a nullable + result, ok := AsOptionalNullable(reflectValue) + assert.True(t, ok) + assert.NotNil(t, result) + + value, isSet := result.GetUntyped() + assert.True(t, isSet) + assert.Equal(t, "test", value) + }) + + t.Run("with interface containing nullable", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom("test")) + var iface interface{} = nullable + reflectValue := reflect.ValueOf(iface) + + result, ok := AsOptionalNullable(reflectValue) + assert.True(t, ok) + assert.NotNil(t, result) + + value, isSet := result.GetUntyped() + assert.True(t, isSet) + assert.Equal(t, "test", value) + }) +} diff --git a/internal/sdk/retry/config.go b/internal/sdk/retry/config.go index aa4b334..aa809fc 100644 --- a/internal/sdk/retry/config.go +++ b/internal/sdk/retry/config.go @@ -20,6 +20,9 @@ type BackoffStrategy struct { // Config configures a retry policy. type Config struct { + // Strategy sets the algorithm to use for a retry loop. It can be one of: + // - "backoff": retry with exponential backoff and random jitter. + // - "none" or "": disables retries. Strategy string Backoff *BackoffStrategy RetryConnectionErrors bool diff --git a/internal/sdk/sdk.go b/internal/sdk/sdk.go index f9920b5..3e67ff3 100644 --- a/internal/sdk/sdk.go +++ b/internal/sdk/sdk.go @@ -2,9 +2,12 @@ package sdk +// Generated from OpenAPI doc version 1.0.0 and generator version 2.735.1 + import ( "context" "fmt" + "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/internal/config" "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/internal/hooks" "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/internal/utils" "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/models/shared" @@ -16,9 +19,11 @@ import ( // ServerList contains the list of servers available to the SDK var ServerList = []string{ "https://template-variables-api.sls.epilot.io", + // Production server + "https://template-variables-api.dev.sls.epilot.io", } -// HTTPClient provides an interface for suplying the SDK with a custom HTTP client +// HTTPClient provides an interface for supplying the SDK with a custom HTTP client type HTTPClient interface { Do(req *http.Request) (*http.Response, error) } @@ -44,36 +49,16 @@ func Float64(f float64) *float64 { return &f } // Pointer provides a helper function to return a pointer to a type func Pointer[T any](v T) *T { return &v } -type sdkConfiguration struct { - Client HTTPClient - Security func(context.Context) (interface{}, error) - ServerURL string - ServerIndex int - Language string - OpenAPIDocVersion string - SDKVersion string - GenVersion string - UserAgent string - RetryConfig *retry.Config - Hooks *hooks.Hooks - Timeout *time.Duration -} - -func (c *sdkConfiguration) GetServerDetails() (string, map[string]string) { - if c.ServerURL != "" { - return c.ServerURL, nil - } - - return ServerList[c.ServerIndex], nil -} - // SDK - Template Variables API: API to provide variables for email and document templates. type SDK struct { + SDKVersion string + // Custom variables CustomVariables *CustomVariables // Variables Variables *Variables - sdkConfiguration sdkConfiguration + sdkConfiguration config.SDKConfiguration + hooks *hooks.Hooks } type SDKOption func(*SDK) @@ -146,14 +131,12 @@ func WithTimeout(timeout time.Duration) SDKOption { // New creates a new instance of the SDK with the provided options func New(opts ...SDKOption) *SDK { sdk := &SDK{ - sdkConfiguration: sdkConfiguration{ - Language: "go", - OpenAPIDocVersion: "1.0.0", - SDKVersion: "0.0.1", - GenVersion: "2.472.1", - UserAgent: "speakeasy-sdk/go 0.0.1 2.472.1 1.0.0 github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk", - Hooks: hooks.New(), + SDKVersion: "1.3.0", + sdkConfiguration: config.SDKConfiguration{ + UserAgent: "speakeasy-sdk/terraform 1.3.0 2.735.1 1.0.0 github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk", + ServerList: ServerList, }, + hooks: hooks.New(), } for _, opt := range opts { opt(sdk) @@ -166,14 +149,13 @@ func New(opts ...SDKOption) *SDK { currentServerURL, _ := sdk.sdkConfiguration.GetServerDetails() serverURL := currentServerURL - serverURL, sdk.sdkConfiguration.Client = sdk.sdkConfiguration.Hooks.SDKInit(currentServerURL, sdk.sdkConfiguration.Client) - if serverURL != currentServerURL { + serverURL, sdk.sdkConfiguration.Client = sdk.hooks.SDKInit(currentServerURL, sdk.sdkConfiguration.Client) + if currentServerURL != serverURL { sdk.sdkConfiguration.ServerURL = serverURL } - sdk.CustomVariables = newCustomVariables(sdk.sdkConfiguration) - - sdk.Variables = newVariables(sdk.sdkConfiguration) + sdk.CustomVariables = newCustomVariables(sdk, sdk.sdkConfiguration, sdk.hooks) + sdk.Variables = newVariables(sdk, sdk.sdkConfiguration, sdk.hooks) return sdk } diff --git a/internal/sdk/types/decimal.go b/internal/sdk/types/decimal.go deleted file mode 100644 index d8429bc..0000000 --- a/internal/sdk/types/decimal.go +++ /dev/null @@ -1,20 +0,0 @@ -// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - -package types - -import ( - "fmt" - - "github.com/ericlagergren/decimal" -) - -// MustNewDecimalFromString returns an instance of Decimal from a string -// Avoid using this function in production code. -func MustNewDecimalFromString(s string) *decimal.Big { - d, ok := new(decimal.Big).SetString(s) - if !ok { - panic(fmt.Errorf("failed to parse string as decimal.Big")) - } - - return d -} diff --git a/internal/sdk/variables.go b/internal/sdk/variables.go index a55aee9..252cf54 100644 --- a/internal/sdk/variables.go +++ b/internal/sdk/variables.go @@ -6,40 +6,36 @@ import ( "bytes" "context" "fmt" + "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/internal/config" "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/internal/hooks" "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/internal/utils" "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/models/errors" "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/models/operations" "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/models/shared" - "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/retry" "net/http" "net/url" ) // Variables type Variables struct { - sdkConfiguration sdkConfiguration + rootSDK *SDK + sdkConfiguration config.SDKConfiguration + hooks *hooks.Hooks } -func newVariables(sdkConfig sdkConfiguration) *Variables { +func newVariables(rootSDK *SDK, sdkConfig config.SDKConfiguration, hooks *hooks.Hooks) *Variables { return &Variables{ + rootSDK: rootSDK, sdkConfiguration: sdkConfig, + hooks: hooks, } } // GetCategories - getCategories // Get all template variable categories func (s *Variables) GetCategories(ctx context.Context, request operations.GetCategoriesRequest, opts ...operations.Option) (*operations.GetCategoriesResponse, error) { - hookCtx := hooks.HookContext{ - Context: ctx, - OperationID: "getCategories", - OAuth2Scopes: []string{}, - SecuritySource: s.sdkConfiguration.Security, - } - o := operations.Options{} supportedOptions := []string{ - operations.SupportedOptionRetries, operations.SupportedOptionTimeout, } @@ -49,12 +45,27 @@ func (s *Variables) GetCategories(ctx context.Context, request operations.GetCat } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } opURL, err := url.JoinPath(baseURL, "/v1/template-variables/categories") if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) } + hookCtx := hooks.HookContext{ + SDK: s.rootSDK, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "getCategories", + OAuth2Scopes: nil, + SecuritySource: s.sdkConfiguration.Security, + } + timeout := o.Timeout if timeout == nil { timeout = s.sdkConfiguration.Timeout @@ -81,99 +92,36 @@ func (s *Variables) GetCategories(ctx context.Context, request operations.GetCat return nil, err } - globalRetryConfig := s.sdkConfiguration.RetryConfig - retryConfig := o.Retries - if retryConfig == nil { - if globalRetryConfig != nil { - retryConfig = globalRetryConfig - } else { - retryConfig = &retry.Config{ - Strategy: "backoff", Backoff: &retry.BackoffStrategy{ - InitialInterval: 5000, - MaxInterval: 60000, - Exponent: 1.5, - MaxElapsedTime: 3600000, - }, - RetryConnectionErrors: true, - } - } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) } - var httpRes *http.Response - if retryConfig != nil { - httpRes, err = utils.Retry(ctx, utils.Retries{ - Config: retryConfig, - StatusCodes: []string{ - "5XX", - "5XX", - }, - }, func() (*http.Response, error) { - if req.Body != nil { - copyBody, err := req.GetBody() - if err != nil { - return nil, err - } - req.Body = copyBody - } - - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) - if err != nil { - if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { - return nil, err - } - - return nil, retry.Permanent(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.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) - } - return httpRes, err - }) + 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 { - return nil, err + err = fmt.Errorf("error sending request: %w", err) } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } + err = fmt.Errorf("error sending request: no response") } - } else { - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + + _, 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 } - - 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.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { return nil, err - } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { - _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) - if err != nil { - return nil, err - } else if _httpRes != nil { - httpRes = _httpRes - } - } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } } } @@ -222,16 +170,8 @@ func (s *Variables) GetCategories(ctx context.Context, request operations.GetCat // // Calls Entity API, User API, Brand API and others to construct full context object used for template variable replace func (s *Variables) GetVariableContext(ctx context.Context, request *operations.GetVariableContextRequestBody, opts ...operations.Option) (*operations.GetVariableContextResponse, error) { - hookCtx := hooks.HookContext{ - Context: ctx, - OperationID: "getVariableContext", - OAuth2Scopes: []string{}, - SecuritySource: s.sdkConfiguration.Security, - } - o := operations.Options{} supportedOptions := []string{ - operations.SupportedOptionRetries, operations.SupportedOptionTimeout, } @@ -241,12 +181,26 @@ func (s *Variables) GetVariableContext(ctx context.Context, request *operations. } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } opURL, err := url.JoinPath(baseURL, "/v1/template-variables:context") if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) } + hookCtx := hooks.HookContext{ + SDK: s.rootSDK, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "getVariableContext", + OAuth2Scopes: nil, + SecuritySource: s.sdkConfiguration.Security, + } bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, false, true, "Request", "json", `request:"mediaType=application/json"`) if err != nil { return nil, err @@ -269,105 +223,44 @@ func (s *Variables) GetVariableContext(ctx context.Context, request *operations. } req.Header.Set("Accept", "application/json") req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) - req.Header.Set("Content-Type", reqContentType) + if reqContentType != "" { + req.Header.Set("Content-Type", reqContentType) + } if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil { return nil, err } - globalRetryConfig := s.sdkConfiguration.RetryConfig - retryConfig := o.Retries - if retryConfig == nil { - if globalRetryConfig != nil { - retryConfig = globalRetryConfig - } else { - retryConfig = &retry.Config{ - Strategy: "backoff", Backoff: &retry.BackoffStrategy{ - InitialInterval: 5000, - MaxInterval: 60000, - Exponent: 1.5, - MaxElapsedTime: 3600000, - }, - RetryConnectionErrors: true, - } - } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) } - var httpRes *http.Response - if retryConfig != nil { - httpRes, err = utils.Retry(ctx, utils.Retries{ - Config: retryConfig, - StatusCodes: []string{ - "5XX", - "5XX", - }, - }, func() (*http.Response, error) { - if req.Body != nil { - copyBody, err := req.GetBody() - if err != nil { - return nil, err - } - req.Body = copyBody - } - - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) - if err != nil { - if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { - return nil, err - } - - return nil, retry.Permanent(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.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) - } - return httpRes, err - }) + 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 { - return nil, err + err = fmt.Errorf("error sending request: %w", err) } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } + err = fmt.Errorf("error sending request: no response") } - } else { - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + + _, 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 } - - 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.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { return nil, err - } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { - _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) - if err != nil { - return nil, err - } else if _httpRes != nil { - httpRes = _httpRes - } - } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } } } @@ -416,16 +309,8 @@ func (s *Variables) GetVariableContext(ctx context.Context, request *operations. // // Takes in an array of input templates and outputs the output text with replaced variables func (s *Variables) ReplaceTemplates(ctx context.Context, request *operations.ReplaceTemplatesRequestBody, opts ...operations.Option) (*operations.ReplaceTemplatesResponse, error) { - hookCtx := hooks.HookContext{ - Context: ctx, - OperationID: "replaceTemplates", - OAuth2Scopes: []string{}, - SecuritySource: s.sdkConfiguration.Security, - } - o := operations.Options{} supportedOptions := []string{ - operations.SupportedOptionRetries, operations.SupportedOptionTimeout, } @@ -435,12 +320,26 @@ func (s *Variables) ReplaceTemplates(ctx context.Context, request *operations.Re } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } opURL, err := url.JoinPath(baseURL, "/v1/template-variables:replace") if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) } + hookCtx := hooks.HookContext{ + SDK: s.rootSDK, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "replaceTemplates", + OAuth2Scopes: nil, + SecuritySource: s.sdkConfiguration.Security, + } bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, false, true, "Request", "json", `request:"mediaType=application/json"`) if err != nil { return nil, err @@ -463,105 +362,44 @@ func (s *Variables) ReplaceTemplates(ctx context.Context, request *operations.Re } req.Header.Set("Accept", "application/json") req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) - req.Header.Set("Content-Type", reqContentType) + if reqContentType != "" { + req.Header.Set("Content-Type", reqContentType) + } if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil { return nil, err } - globalRetryConfig := s.sdkConfiguration.RetryConfig - retryConfig := o.Retries - if retryConfig == nil { - if globalRetryConfig != nil { - retryConfig = globalRetryConfig - } else { - retryConfig = &retry.Config{ - Strategy: "backoff", Backoff: &retry.BackoffStrategy{ - InitialInterval: 5000, - MaxInterval: 60000, - Exponent: 1.5, - MaxElapsedTime: 3600000, - }, - RetryConnectionErrors: true, - } - } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) } - var httpRes *http.Response - if retryConfig != nil { - httpRes, err = utils.Retry(ctx, utils.Retries{ - Config: retryConfig, - StatusCodes: []string{ - "5XX", - "5XX", - }, - }, func() (*http.Response, error) { - if req.Body != nil { - copyBody, err := req.GetBody() - if err != nil { - return nil, err - } - req.Body = copyBody - } - - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) - if err != nil { - if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { - return nil, err - } - - return nil, retry.Permanent(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.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) - } - return httpRes, err - }) + 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 { - return nil, err + err = fmt.Errorf("error sending request: %w", err) } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } + err = fmt.Errorf("error sending request: no response") } - } else { - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + + _, 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 } - - 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.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { return nil, err - } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { - _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) - if err != nil { - return nil, err - } else if _httpRes != nil { - httpRes = _httpRes - } - } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } } } @@ -608,16 +446,8 @@ func (s *Variables) ReplaceTemplates(ctx context.Context, request *operations.Re // SearchVariables - searchVariables // Search variables func (s *Variables) SearchVariables(ctx context.Context, request *operations.SearchVariablesRequestBody, opts ...operations.Option) (*operations.SearchVariablesResponse, error) { - hookCtx := hooks.HookContext{ - Context: ctx, - OperationID: "searchVariables", - OAuth2Scopes: []string{}, - SecuritySource: s.sdkConfiguration.Security, - } - o := operations.Options{} supportedOptions := []string{ - operations.SupportedOptionRetries, operations.SupportedOptionTimeout, } @@ -627,12 +457,26 @@ func (s *Variables) SearchVariables(ctx context.Context, request *operations.Sea } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } opURL, err := url.JoinPath(baseURL, "/v1/template-variables:search") if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) } + hookCtx := hooks.HookContext{ + SDK: s.rootSDK, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "searchVariables", + OAuth2Scopes: nil, + SecuritySource: s.sdkConfiguration.Security, + } bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, false, true, "Request", "json", `request:"mediaType=application/json"`) if err != nil { return nil, err @@ -655,105 +499,44 @@ func (s *Variables) SearchVariables(ctx context.Context, request *operations.Sea } req.Header.Set("Accept", "application/json") req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) - req.Header.Set("Content-Type", reqContentType) + if reqContentType != "" { + req.Header.Set("Content-Type", reqContentType) + } if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil { return nil, err } - globalRetryConfig := s.sdkConfiguration.RetryConfig - retryConfig := o.Retries - if retryConfig == nil { - if globalRetryConfig != nil { - retryConfig = globalRetryConfig - } else { - retryConfig = &retry.Config{ - Strategy: "backoff", Backoff: &retry.BackoffStrategy{ - InitialInterval: 5000, - MaxInterval: 60000, - Exponent: 1.5, - MaxElapsedTime: 3600000, - }, - RetryConnectionErrors: true, - } - } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) } - var httpRes *http.Response - if retryConfig != nil { - httpRes, err = utils.Retry(ctx, utils.Retries{ - Config: retryConfig, - StatusCodes: []string{ - "5XX", - "5XX", - }, - }, func() (*http.Response, error) { - if req.Body != nil { - copyBody, err := req.GetBody() - if err != nil { - return nil, err - } - req.Body = copyBody - } - - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) - if err != nil { - if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { - return nil, err - } - - return nil, retry.Permanent(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.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) - } - return httpRes, err - }) + 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 { - return nil, err + err = fmt.Errorf("error sending request: %w", err) } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } + err = fmt.Errorf("error sending request: no response") } - } else { - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + + _, 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 } - - 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.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { return nil, err - } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { - _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) - if err != nil { - return nil, err - } else if _httpRes != nil { - httpRes = _httpRes - } - } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } } } diff --git a/internal/validators/float32validators/not_null.go b/internal/validators/float32validators/not_null.go new file mode 100644 index 0000000..c9a8973 --- /dev/null +++ b/internal/validators/float32validators/not_null.go @@ -0,0 +1,49 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package float32validators + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework/schema/validator" +) + +var _ validator.Float32 = Float32NotNullValidator{} + +// Float32NotNullValidator validates that an attribute is not null. Most +// attributes should set Required: true instead, however in certain scenarios, +// such as a computed nested attribute, all underlying attributes must also be +// computed for planning to not show unexpected differences. +type Float32NotNullValidator struct{} + +// Description describes the validation in plain text formatting. +func (v Float32NotNullValidator) Description(_ context.Context) string { + return "value must be configured" +} + +// MarkdownDescription describes the validation in Markdown formatting. +func (v Float32NotNullValidator) MarkdownDescription(ctx context.Context) string { + return v.Description(ctx) +} + +// Validate performs the validation. +func (v Float32NotNullValidator) ValidateFloat32(ctx context.Context, req validator.Float32Request, resp *validator.Float32Response) { + if !req.ConfigValue.IsNull() { + return + } + + resp.Diagnostics.AddAttributeError( + req.Path, + "Missing Attribute Value", + req.Path.String()+": "+v.Description(ctx), + ) +} + +// NotNull returns an validator which ensures that the attribute is +// configured. Most attributes should set Required: true instead, however in +// certain scenarios, such as a computed nested attribute, all underlying +// attributes must also be computed for planning to not show unexpected +// differences. +func NotNull() validator.Float32 { + return Float32NotNullValidator{} +} diff --git a/internal/validators/int32validators/not_null.go b/internal/validators/int32validators/not_null.go new file mode 100644 index 0000000..ec9a3f1 --- /dev/null +++ b/internal/validators/int32validators/not_null.go @@ -0,0 +1,49 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package int32validators + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework/schema/validator" +) + +var _ validator.Int32 = Int32NotNullValidator{} + +// Int32NotNullValidator validates that an attribute is not null. Most +// attributes should set Required: true instead, however in certain scenarios, +// such as a computed nested attribute, all underlying attributes must also be +// computed for planning to not show unexpected differences. +type Int32NotNullValidator struct{} + +// Description describes the validation in plain text formatting. +func (v Int32NotNullValidator) Description(_ context.Context) string { + return "value must be configured" +} + +// MarkdownDescription describes the validation in Markdown formatting. +func (v Int32NotNullValidator) MarkdownDescription(ctx context.Context) string { + return v.Description(ctx) +} + +// Validate performs the validation. +func (v Int32NotNullValidator) ValidateInt32(ctx context.Context, req validator.Int32Request, resp *validator.Int32Response) { + if !req.ConfigValue.IsNull() { + return + } + + resp.Diagnostics.AddAttributeError( + req.Path, + "Missing Attribute Value", + req.Path.String()+": "+v.Description(ctx), + ) +} + +// NotNull returns an validator which ensures that the attribute is +// configured. Most attributes should set Required: true instead, however in +// certain scenarios, such as a computed nested attribute, all underlying +// attributes must also be computed for planning to not show unexpected +// differences. +func NotNull() validator.Int32 { + return Int32NotNullValidator{} +}