From 247f5edf179da8befffb113a967198e240acda1a Mon Sep 17 00:00:00 2001 From: Heng Lu Date: Fri, 17 Nov 2023 14:49:55 +0800 Subject: [PATCH] bugfix: the generated resources are not in the correct order --- CHANGELOG.md | 1 + commands/generate.go | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da624df7..75339d70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ BUG FIXES: - Fix the bug that resource types with same name but different casing are not handled correctly. - Fix the bug that coverage reports are generated even if there are no valid test cases. - Fix the bug that other dependency resolvers are not called when error occurs in the previous dependency resolver. +- Fix the bug that the generated resources are not in the correct order. ## v0.12.0 FEATURES: diff --git a/commands/generate.go b/commands/generate.go index ee96e5e9..00ad3123 100644 --- a/commands/generate.go +++ b/commands/generate.go @@ -365,20 +365,30 @@ func (c *GenerateCommand) generate(apiPaths []swagger.ApiPath) int { } func azapiDefinitionOrder(azapiDefinition types.AzapiDefinition) int { + // 0. resource.azapi_resource + // 1. resource.azapi_update_resource Note: Now it will not be generated + // 2. azapi_resource_action with empty action + // 3. azapi_resource_action with action + // 4. data.azapi_resource + // 5. azapi_resource_list + switch azapiDefinition.ResourceName { case "azapi_resource": - return 0 + if azapiDefinition.Kind == types.KindResource { + return 0 + } + return 4 case "azapi_update_resource": - return 2 + return 1 case "azapi_resource_action": - if actionField := azapiDefinition.AdditionalFields["action"]; actionField == nil || actionField.String() == "" { - return 1 + if actionField := azapiDefinition.AdditionalFields["action"]; actionField == nil || actionField.String() == `""` { + return 2 } return 3 case "azapi_resource_list": - return 4 + return 5 } - return 5 + return 6 } func appendContent(filename string, hclContent string) error {