Skip to content

[BUG][Golang][Client] reserved word collision for required API parameter #3485

@grokify

Description

@grokify

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

When a required parameter with the name url is included, url is used as the query parameter name in the function parameter list which conflicts with the net/url package that is loaded for query and form requests. This results in the following compile time error:

../../engagedigital/api_webhooks.go:68:28: url.Values undefined (type string has no field or method Values)

The actual output is:

func (a *WebhooksApiService) CreateWebhook(ctx context.Context, accessToken string, label string, url string, registeredEvents []string, localVarOptionals *CreateWebhookOpts) (Webhook, *http.Response, error) {
	var (
		localVarHttpMethod   = http.MethodPost
		localVarPostBody     interface{}
		localVarFormFileName string
		localVarFileName     string
		localVarFileBytes    []byte
		localVarReturnValue  Webhook
	)

	// create path and map variables
	localVarPath := a.client.cfg.BasePath + "/webhooks"

	localVarHeaderParams := make(map[string]string)
	localVarQueryParams := url.Values{}
	localVarFormParams := url.Values{}

The expected output is no collision between parameter name url and the net/url library when instantiating url.Values{}.

openapi-generator version

4.1.0-SNAPSHOT

OpenAPI declaration file content or url

https://raw.githubusercontent.com/grokify/go-ringcentral-engage/8e520ea8355190939c1cc8990ba562fe487095e7/codegen/partial-specs_v3.0.0/openapi-spec_webhooks.json

          {
            "name":"url",
            "in":"query",
            "required":true,
            "description":"The url of a webhook. This is used to determine the endpoint of your webhook, where",
            "schema":{
              "type":"string"
            }
          }
Command line used for generation

java -jar openapi-generator-cli.jar generate -i openapi-spec_v3.0.0.json -g go -o engagedigital --package-name engagedigital

https://github.com/grokify/go-ringcentral-engage/blob/8e520ea8355190939c1cc8990ba562fe487095e7/codegen/generate.sh

Steps to reproduce

Generate a client with a required API query parameter named url and then attempt to compile the resulting library.

Related issues/PRs

none found.

Suggest a fix

Some approaches include:

  • When using the the current variable naming approach but adding a _ suffix, add imported library names to the reserved word list.
  • Add a prefix to all parameter names in function definitions.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions