oapi-codegen icon indicating copy to clipboard operation
oapi-codegen copied to clipboard

Duplicate typename issue while generating types from paypal openAPI spec

Open BackendDevZetexa opened this issue 2 years ago • 1 comments

Hi,

I am trying to integrate the paypal with my ecommerce solution. I am trying to generate client code , types from PayPal OpenAPI spec given in https://github.com/paypal/paypal-rest-api-specifications.

The particular open API i am using is , checkout_orders_v2 attached here. checkout_orders_v2.json

When i try to generate types as shown below i get error

hvk@LAPTOP-GH4L4EUD:/mnt/c/Users/paypal-integration$ oapi-codegen -generate types -o types.go -package main checkout_orders_v2.json
error generating code: error generating type definitions: error generating code for type definitions: duplicate typename 'AuthorizationStatus' detected, can't auto-rename, please use x-go-name to specify your own name for one of them

BackendDevZetexa avatar Jan 29 '24 09:01 BackendDevZetexa

got the same error for a different (YAML based) spec and using v2.1.0 of the generator to generate models and client.

The spec: https://raw.githubusercontent.com/apideck-libraries/openapi-specs/main/hris.yml

error generating code: error generating type definitions: error generating code for type definitions: duplicate typename 'EmployeeId' detected, can't auto-rename, please use x-go-name to specify your own name for one of them

i checked that there is only one schemadefinition

ernest-ag5 avatar May 15 '24 15:05 ernest-ag5

after some debugging, I think the issue is related to this test:

func TypeDefinitionsEquivalent(t1, t2 TypeDefinition) bool {
	if t1.TypeName != t2.TypeName {
		return false
	}
	return reflect.DeepEqual(t1.Schema.OAPISchema, t2.Schema.OAPISchema)
}

I suspect the DeepEqual is considering too many fields

ernest-ag5 avatar May 23 '24 07:05 ernest-ag5

hmm, after change the code a bit, I found that (in my case) they are different. Continuing debugging...

ernest-ag5 avatar May 23 '24 08:05 ernest-ag5