Skip to content

[BUG] Generated tests in Go Client have bad type when non-primitive type used in PATH #21106

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

Open
madpah opened this issue Apr 17, 2025 · 0 comments

Comments

@madpah
Copy link
Contributor

madpah commented Apr 17, 2025

Description

Generated tests in Go Client don't properly reference non-primitive types for parameters it seems.

Generated Go Code is currently:

func Test_tea_client_TEAProductAPIService(t *testing.T) {

	configuration := tea_client.NewConfiguration()
	apiClient := tea_client.NewAPIClient(configuration)

	t.Run("Test TEAProductAPIService GetTeaProductByIdentifier", func(t *testing.T) {

		t.Skip("skip test")  // remove to run test

		var productIdentifierType TypeProductIdentifierType

		resp, httpRes, err := apiClient.TEAProductAPI.GetTeaProductByIdentifier(context.Background(), productIdentifierType).Execute()

		require.Nil(t, err)
		require.NotNil(t, resp)
		assert.Equal(t, 200, httpRes.StatusCode)

	})

var productIdentifierType TypeProductIdentifierType should be var productIdentifierType tea_client.TypeProductIdentifierType

openapi-generator version
docker run \
    --rm \
    -v "$(PWD):/local" \
    openapitools/openapi-generator-cli:v7.12.0 \
    batch --clean /local/spec/generators/go.yaml

See CycloneDX/transparency-exchange-api#118 for full context.

OpenAPI declaration file content or url
paths:
  /product/{product-identifier-type}/{product-identifier}:
    get:
      description: Returns a list of TEA products. Note that multiple products may
        match.
      operationId: getTeaProductByIdentifier
      parameters:
        - $ref: "#/components/parameters/product-identifier-type"
        - $ref: "#/components/parameters/product-identifier"
        - $ref: "#/components/parameters/page-offset"
        - $ref: "#/components/parameters/page-size"
      responses:
        200:
          description: Product retrieved successfully
          $ref: "#/components/responses/paginated-tea-product"
        400:
          $ref: "#/components/responses/400-invalid-request"
        404:
          $ref: "#/components/responses/404-object-by-id-not-found"
      tags:
        - TEA Product
...
components:
  parameters:
    product-identifier-type:
      name: product-identifier-type
      description: The identifier type (enum)
      in: path
      required: true
      schema:
        $ref: "#/components/schemas/type_product_identifier_type" 
  ...
  schemas:
    type_product_identifier_type:
      type: string
      description: Identifier types
      enum:
        - tei
        - purl
        - cpe    
Related issues/PRs
Suggest a fix

I'll work on a PR to address this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant