Skip to content

Commit c4632f6

Browse files
authored
Changes because of always defining request messages (#3098)
## Changes <!-- Brief summary of your changes that is easy to understand --> Changes because of always defining request messages. There is a bug in the Code Generator that sets the request to nil if it has no fields. As we fix the generator, it changes the generated code. To keep the generated code the same, we need to add exceptions for already existing requests. IsLegacyEmptyRequest returns true if the request has no fields and, for the above reason, is not rendered in the SDK. This PR also removes TODO from the template, which adds noise to the diff. Also, we don't need it to remind us to implement short flags. ## Why <!-- Why are these changes needed? Provide the context that the reviewer might be missing. For example, were there any decisions behind the change that are not reflected in the code itself? --> We made a few changes in the Code generator that ensure that the request can never be nil. However, we cannot add the request to the existing interface. So, adding an exception for legacy commands. ## Tests <!-- How have you tested the changes? --> Existing CI. Manually verified this change, only changed a few comments. <!-- If your PR needs to be included in the release notes for next release, add a separate entry in NEXT_CHANGELOG.md as part of your PR. -->
1 parent 26da4c1 commit c4632f6

File tree

146 files changed

+35
-1195
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

146 files changed

+35
-1195
lines changed

.codegen/service.go.tmpl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func New() *cobra.Command {
113113
// Functions can be added from the `init()` function in manually curated files in this directory.
114114
var {{.CamelName}}Overrides []func(
115115
*cobra.Command,
116-
{{- if .Request }}
116+
{{- if not .IsLegacyEmptyRequest }}
117117
*{{.Service.Package.Name}}.{{.Request.PascalName}},
118118
{{- end }}
119119
)
@@ -124,7 +124,7 @@ func new{{.PascalName}}() *cobra.Command {
124124
cmd := &cobra.Command{}
125125

126126
{{- $canUseJson := and .CanUseJson (not (in $excludeFromJson .KebabName )) -}}
127-
{{- if .Request}}
127+
{{- if not .IsLegacyEmptyRequest}}
128128

129129
var {{.CamelName}}Req {{.Service.Package.Name}}.{{.Request.PascalName}}
130130
{{- if .RequestBodyField }}
@@ -146,7 +146,7 @@ func new{{.PascalName}}() *cobra.Command {
146146
{{- if .RequestBodyField -}}
147147
{{- $request = .RequestBodyField.Entity -}}
148148
{{- end -}}
149-
{{if $request }}// TODO: short flags
149+
{{if $request }}
150150
{{- if $canUseJson}}
151151
cmd.Flags().Var(&{{.CamelName}}Json, "json", `either inline JSON string or @path/to/file.json with request body`)
152152
{{- end}}
@@ -188,7 +188,7 @@ func new{{.PascalName}}() *cobra.Command {
188188
{{- $wait := and .Wait (and (not .IsCrudRead) (not (eq .SnakeName "get_run"))) -}}
189189
{{- $hasRequiredArgs := and (not $hasIdPrompt) $hasPosArgs -}}
190190
{{- $hasSingleRequiredRequestBodyFieldWithPrompt := and (and $hasIdPrompt $request) (eq 1 (len $request.RequiredRequestBodyFields)) -}}
191-
{{- $onlyPathArgsRequiredAsPositionalArguments := and .Request (eq (len .RequiredPositionalArguments) (len .Request.RequiredPathFields)) -}}
191+
{{- $onlyPathArgsRequiredAsPositionalArguments := and (not .IsLegacyEmptyRequest) (eq (len .RequiredPositionalArguments) (len .Request.RequiredPathFields)) -}}
192192
{{- $hasDifferentArgsWithJsonFlag := and (not $onlyPathArgsRequiredAsPositionalArguments) (and $canUseJson (or $request.HasRequiredRequestBodyFields )) -}}
193193
{{- $hasCustomArgHandler := or $hasRequiredArgs $hasDifferentArgsWithJsonFlag -}}
194194

@@ -250,7 +250,7 @@ func new{{.PascalName}}() *cobra.Command {
250250
cmd.RunE = func(cmd *cobra.Command, args []string) (err error) {
251251
ctx := cmd.Context()
252252
{{if .Service.IsAccounts}}a := cmdctx.AccountClient(ctx){{else}}w := cmdctx.WorkspaceClient(ctx){{end}}
253-
{{- if .Request }}
253+
{{- if not .IsLegacyEmptyRequest }}
254254
{{ if $canUseJson }}
255255
if cmd.Flags().Changed("json") {
256256
diags := {{.CamelName}}Json.Unmarshal(&{{.CamelName}}Req{{ if .RequestBodyField }}.{{.RequestBodyField.PascalName}}{{ end }})
@@ -273,7 +273,7 @@ func new{{.PascalName}}() *cobra.Command {
273273
if len(args) == 0 {
274274
promptSpinner := cmdio.Spinner(ctx)
275275
promptSpinner <- "No{{range $request.RequiredFields}} {{.ConstantName}}{{end}} argument specified. Loading names for {{.Service.TitleName}} drop-down."
276-
names, err := {{if .Service.IsAccounts}}a{{else}}w{{end}}.{{(.Service.TrimPrefix "account").PascalName}}.{{.Service.List.NamedIdMap.PascalName}}(ctx{{if .Service.List.Request}}, {{.Service.Package.Name}}.{{.Service.List.Request.PascalName}}{}{{end}})
276+
names, err := {{if .Service.IsAccounts}}a{{else}}w{{end}}.{{(.Service.TrimPrefix "account").PascalName}}.{{.Service.List.NamedIdMap.PascalName}}(ctx{{if not .Service.List.IsLegacyEmptyRequest}}, {{.Service.Package.Name}}.{{.Service.List.Request.PascalName}}{}{{end}})
277277
close(promptSpinner)
278278
if err != nil {
279279
return fmt.Errorf("failed to load names for {{.Service.TitleName}} drop-down. Please manually specify required arguments. Original error: %w", err)
@@ -300,7 +300,7 @@ func new{{.PascalName}}() *cobra.Command {
300300
{{- end}}
301301
{{end}}
302302
{{if $wait -}}
303-
wait, err := {{if .Service.IsAccounts}}a{{else}}w{{end}}.{{.Service.PascalName}}.{{.PascalName}}(ctx{{if .Request}}, {{.CamelName}}Req{{end}})
303+
wait, err := {{if .Service.IsAccounts}}a{{else}}w{{end}}.{{.Service.PascalName}}.{{.PascalName}}(ctx{{if not .IsLegacyEmptyRequest}}, {{.CamelName}}Req{{end}})
304304
if err != nil {
305305
return err
306306
}
@@ -348,7 +348,7 @@ func new{{.PascalName}}() *cobra.Command {
348348
349349
// Apply optional overrides to this command.
350350
for _, fn := range {{.CamelName}}Overrides {
351-
fn(cmd{{if .Request}}, &{{.CamelName}}Req{{end}})
351+
fn(cmd{{if not .IsLegacyEmptyRequest}}, &{{.CamelName}}Req{{end}})
352352
}
353353
354354
return cmd
@@ -370,7 +370,7 @@ func new{{.PascalName}}() *cobra.Command {
370370
{{- else}}
371371
{{- (.Service.TrimPrefix "account").PascalName}}.
372372
{{- end}}
373-
{{- .PascalName}}(ctx{{if .Request}}, {{.CamelName}}Req{{end}})
373+
{{- .PascalName}}(ctx{{if not .IsLegacyEmptyRequest}}, {{.CamelName}}Req{{end}})
374374
{{- if not (and .Response .Pagination) }}
375375
if err != nil {
376376
return err

cmd/account/access-control/access-control.go

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/account/billable-usage/billable-usage.go

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/account/budget-policy/budget-policy.go

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/account/budgets/budgets.go

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/account/credentials/credentials.go

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/account/csp-enablement-account/csp-enablement-account.go

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/account/custom-app-integration/custom-app-integration.go

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/account/disable-legacy-features/disable-legacy-features.go

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/account/enable-ip-access-lists/enable-ip-access-lists.go

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)