-
Notifications
You must be signed in to change notification settings - Fork 161
gen: Nested sum types generate broken (non-compilable) code #1480
Copy link
Copy link
Open
Labels
bugSomething isn't workingSomething isn't working
Description
What version of ogen are you using?
v1.14.0
Can this issue be reproduced with the latest version?
Yes
What did you do?
I ran ogen against a spec with nested sum types. See the following spec:
openapi: 3.0.0
info:
title: title
version: v0.1.0
paths:
/test:
get:
operationId: test
responses:
'200':
description: Test
content:
application/json:
schema:
$ref: '#/components/schemas/Sum'
components:
schemas:
Sum:
oneOf:
- $ref: '#/components/schemas/Sum1'
- $ref: '#/components/schemas/Sum2'
Sum1:
oneOf:
- type: object
required:
- common-1
- unique-1
properties:
common-1:
type: string
unique-1:
type: string
- type: object
required:
- common-1
- unique-2
properties:
common-1:
type: string
unique-2:
type: string
Sum2:
oneOf:
- type: object
required:
- common-1
- otherUnique-1
properties:
common-1:
type: string
otherUnique-1:
type: string
- type: object
required:
- common-1
- otherUnique-2
properties:
common-1:
type: string
otherUnique-2:
type: stringWhat did you expect to see?
Ogen generates code to determine what the type is based on unique fields.
What did you see instead?
Broken code is generated with a switch containing duplicate cases of jx.Object.
func (s *Sum) Decode(d *jx.Decoder) error {
if s == nil {
return errors.New("invalid: unable to decode Sum to nil")
}
// Sum type type_discriminator.
switch t := d.Next(); t {
case jx.Object:
if err := s.Sum1.Decode(d); err != nil {
return err
}
s.Type = Sum1Sum
case jx.Object:
if err := s.Sum2.Decode(d); err != nil {
return err
}
s.Type = Sum2Sum
default:
return errors.Errorf("unexpected json type %q", t)
}
return nil
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working