transparency-exchange-api icon indicating copy to clipboard operation
transparency-exchange-api copied to clipboard

Golang Library fails to generate

Open madpah opened this issue 8 months ago • 2 comments

See https://github.com/CycloneDX/transparency-exchange-api/actions/runs/14516836198/job/40727807660

Run go get github.com/stretchr/testify/assert
go: downloading github.com/stretchr/testify v1.10.0
go: downloading github.com/davecgh/go-spew v1.1.1
go: downloading github.com/pmezard/go-difflib v1.0.0
go: downloading gopkg.in/yaml.v3 v3.0.1
go: added github.com/davecgh/go-spew v1.1.1
go: added github.com/pmezard/go-difflib v1.0.0
go: added github.com/stretchr/testify v1.10.0
go: added gopkg.in/yaml.v3 v3.0.1
# github.com/CycloneDX/transparency-exchange-api-go/test [github.com/CycloneDX/transparency-exchange-api-go/test.test]
Error: test/api_tea_product_test.go:2[9](https://github.com/CycloneDX/transparency-exchange-api/actions/runs/14516836198/job/40727807660#step:5:10):29: undefined: TypeProductIdentifierType
FAIL	github.com/CycloneDX/transparency-exchange-api-go/test [build failed]
FAIL
Error: Process completed with exit code 1.

madpah avatar Apr 17 '25 13:04 madpah

This appears to be a bug in OpenAPI Generator v7.12.0 and prior versions, where generated tests don't properly respect non-primitive types passed in the PATH.

Snippet of bad generated code:

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

madpah avatar Apr 17 '25 14:04 madpah

https://github.com/OpenAPITools/openapi-generator/pull/21107 has been opened against OpenAPI Generator to resolve the pending Go issue.

FYI @oej @vpetersson @ppkarwasz

madpah avatar Apr 17 '25 15:04 madpah

Fixed

oej avatar May 09 '25 13:05 oej