Skip to content

Fix build error#1625

Merged
ernado merged 1 commit intoogen-go:mainfrom
jjkoh95:fix-discriminator
Feb 17, 2026
Merged

Fix build error#1625
ernado merged 1 commit intoogen-go:mainfrom
jjkoh95:fix-discriminator

Conversation

@jjkoh95
Copy link
Contributor

@jjkoh95 jjkoh95 commented Feb 16, 2026

This happens when discriminator has complete same field name and type.

How to reproduce

openapi: "3.1.3"
info:
  title: "Reproducer"
  version: "0.1.0"
paths:
  /check:
    post:
      operationId: "check"
      responses:
        "200":
          description: "OK"
          content:
            application/json:
              schema:
                type: "object"
                properties:
                  status:
                    type: "string"
        "412":
          description: "Business error"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/BusinessError"
        default:
          description: "Error"
          content:
            application/json:
              schema:
                type: "object"
                properties:
                  message:
                    type: "string"
components:
  schemas:
    BusinessError:
      oneOf:
        - $ref: "#/components/schemas/NotFoundError"
        - $ref: "#/components/schemas/BlockedError"
      discriminator:
        propertyName: "code"
        mapping:
          NOT_FOUND: "#/components/schemas/NotFoundError"
          BLOCKED: "#/components/schemas/BlockedError"
    NotFoundError:
      type: "object"
      required:
        - "code"
        - "type"
      properties:
        code:
          type: "string"
          const: "NOT_FOUND"
        type:
          type: "string"
          const: "general"
    BlockedError:
      type: "object"
      required:
        - "code"
        - "type"
      properties:
        code:
          type: "string"
          const: "BLOCKED"
        type:
          type: "string"
          const: "endpoint"

Build the app using the below yaml, the generated go code are invalid, you will find error like

gen/oas_json_gen.go:140:4: declared and not used: s
gen/oas_json_gen.go:150:4: declared and not used: s

@ernado ernado self-assigned this Feb 16, 2026
@ernado ernado merged commit 0b1ca6d into ogen-go:main Feb 17, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants