Skip to content

Bug: sum path parameter cannot decode other variants than first #1649

Description

@shagohead

What version of ogen are you using?

v1.20.1

Can this issue be reproduced with the latest version?

Yes

What did you do?

Define sum path parameter with that schema:

oneOf:
  - type: integer
  - type: string

Try to decode in second, non integer variant.

What did you expect to see?

String variant value.

What did you see instead?

io.EOF

Explanation

Generated code will try to decode each variant sequentially, calling DecodeValue each time.
For path parameters decoder will be a pointer of uri.PathDecoder.
Its DecodeValue method calls cursor.readAll, which have that code:

func (c *cursor) readAll() (string, error) {
	if c.pos == len(c.src) {
		return "", io.EOF
	}

	defer func() { c.pos = len(c.src) }()
	return c.src[c.pos:], nil
}

On the first call, parameter value will be consumed and pos moves after it.
Subsequent calls results in returning io.EOF.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions