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

x-go-name for a type uses the name for field names of the type

Open wizardishungry opened this issue 3 years ago • 0 comments

I've had to post-process a 3rd party spec because it has names that cause generated type names to collide – components.schemas.deleteEventsResponse collides with the DeleteEventsResponse generated for a "operationId": "deleteEvents",. I suffixed each schema with Schema in x-go-name. After doing I discovered that generated structs use the type's x-go-name for the field name, yielding duplicate field names.

For example, :

// DmeHealthStatusSchema defines model for dmeHealthStatus.
type DmeHealthStatusSchema struct {
	BootTime         *time.Time        `json:"bootTime,omitempty"`
	HealthEnumSchema *HealthEnumSchema `json:"cpuUsageHealth,omitempty"`
	CpuUsagePercent  *float32          `json:"cpuUsagePercent,omitempty"`
	HealthEnumSchema *HealthEnumSchema `json:"diskContentHealth,omitempty"`
	DiskContentTotal *int              `json:"diskContentTotal,omitempty"`
	DiskContentUsed  *int              `json:"diskContentUsed,omitempty"`
	HealthEnumSchema *HealthEnumSchema `json:"diskSystemHealth,omitempty"`
}

This is not specific to enums.

(It was not clear to me if fields also supported using x-go-name. I have found another workaround for name collisions.)

wizardishungry avatar Dec 17 '22 19:12 wizardishungry