Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generator-go-sdk feature propose: request option support configuration #2889

Closed
wuxu92 opened this issue Aug 3, 2023 · 2 comments · Fixed by #2894
Closed

generator-go-sdk feature propose: request option support configuration #2889

wuxu92 opened this issue Aug 3, 2023 · 2 comments · Fixed by #2894
Labels
data/swagger-issue An issue related to the Swagger/OpenAPI Definitions question Further information is requested

Comments

@wuxu92
Copy link
Collaborator

wuxu92 commented Aug 3, 2023

An API Request like

func (c RegistryManagementClient) RegistriesCreateOrUpdate(
	ctx context.Context,
	id RegistryId,
	input RegistryTrackedResource) (result RegistriesCreateOrUpdateOperationResponse, err error) {

from method_registriescreateorupdate.go

can we provide an varadic argument func (*client.RequestOptions) to the method so we can configure the behavior to workaround some swagger issues like Azure/azure-rest-api-specs#25119. This is right a service swagger issue, but with Options our sdk can be more flexible and stronger.

then the new method may look like:

type Option func(*clinet.RequestOptions)

func (c RegistryManagementClient) RegistriesCreateOrUpdate(
	ctx context.Context,
	id RegistryId,
	input RegistryTrackedResource,
	options ...Option
) (result RegistriesCreateOrUpdateOperationResponse, err error) {

we can call the Option func before build the request:

for _, opt := range options {
	option(opts)
}
req, err := c.Client.NewRequest(ctx, opts)

the SDK call from azurerm can be:

client.RegistriesCreateOrUpdate(ctx, id, input, func (opt *client.RequestOptions) {
	opt.ExpectedStatusCodes = append(opt.ExpectedStatusCodes, http.StatusAccepted)
})
@tombuildsstuff
Copy link
Contributor

tombuildsstuff commented Aug 3, 2023

@wuxu92 we already have this functionality, but it's intentionally not in the Go SDK and instead handled within the Importer.

In short, we can add a Swagger workaround (example PR) to extend this operation to support the new status code - however we'll need a PR on the upstream Azure/azure-rest-api-specs repository which applies the fix too - as such would you be able to:

  1. Send a PR to the Azure/azure-rest-api-specs repository adding this new status code
  2. Send a PR to this repository, adding a Swagger workaround for this operation

Once that's done, we have both a long term fix (that is, the fix in the Swagger repository) and the short-term fix (in the form of the Workaround) - meaning that users of the SDK don't need to provide these types of overrides.

Each workaround is named workaround_{service}_{pr_number}.go - which is why we require a Pull Request rather than an issue on the upstream Azure/azure-rest-api-specs repository

@tombuildsstuff tombuildsstuff added question Further information is requested data/swagger-issue An issue related to the Swagger/OpenAPI Definitions labels Aug 3, 2023
@wuxu92
Copy link
Collaborator Author

wuxu92 commented Aug 3, 2023

@tombuildsstuff thanks for you quick review! I created a PR to add the workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data/swagger-issue An issue related to the Swagger/OpenAPI Definitions question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants