OpenAPITools / OpenAPITools/openapi-generator
[BUG] Generated tests in Go Client have bad type when non-primitive type used in PATH
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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 https://github.com/CycloneDX/transparency-exchange-api/issues/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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the generated Go client tests using the OpenAPI declaration and the Docker command in the issue, with spec/generators/go.yaml. Inspect how path parameters referencing non-primitive schemas are rendered in the generated test, then verify that the qualified type is emitted and the generated test compiles.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100