Skip to content

Generated code has duplicate case in type switch causing compilation failure #1

@lanej

Description

@lanej

When generating code from a valid OpenAPI spec, ogen produces a type switch with duplicate case statements, resulting in Go compilation error.

Reproduction

Using spec from: https://github.com/gojitsu/jitsu

ogen --target /tmp/test --clean carriers/jitsu/specs/openapi.yaml
cd /tmp/test && go mod init test && go mod tidy && go build ./...

Error

./oas_response_encoders_gen.go:42:7: duplicate case *NewShipmentResponseStatusCode in type switch
	./oas_response_encoders_gen.go:17:7: previous case

Generated Code (oas_response_encoders_gen.go)

func encodeNewShipmentResponse(response NewShipmentRes, w http.ResponseWriter, span trace.Span) error {
	switch v := response.(type) {
	case *NewShipmentResponseStatusCode:  // Line 17
		// ...
	// ... other cases ...
	case *NewShipmentResponseStatusCode:  // Line 42 - DUPLICATE!
		// ...
	}
}

Expected

Generated Go code should compile without errors

Actual

Duplicate case statements in generated switch statement - Go compilation fails

Impact

Valid OpenAPI 3.0.1 spec cannot generate working Go client. This is a critical bug as the spec is valid but codegen produces invalid Go.

Environment

  • ogen version: v1.16.0
  • Go version: 1.21+
  • OS: macOS

Context

Discovered while validating 20 carrier/logistics API specs. This appears to be related to how ogen generates response encoders when multiple response status codes share the same schema type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions