Skip to content

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

@madpah

Description

@madpah
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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions