Skip to content

[Backport release-2.3] xrd: Opportunistically infer integer types when generating from an XR#112

Merged
adamwg merged 2 commits into
release-2.3from
backport-108-to-release-2.3
Jun 15, 2026
Merged

[Backport release-2.3] xrd: Opportunistically infer integer types when generating from an XR#112
adamwg merged 2 commits into
release-2.3from
backport-108-to-release-2.3

Conversation

@github-actions

Copy link
Copy Markdown

Description

Backport of #108 to release-2.3.

adamwg added 2 commits June 15, 2026 19:18
When generating an XRD from an example XR, we have to infer the type of each
field from the example input. We do this by unmarshalling into a
`map[string]any` and then observing the actual type of each value.

Since the JSON specification has only a single numerical type, which is floating
point, `json.Unmarshal` treats all numbers as floats. This means a field like
`replicas: 3` in an example XR produces a `number` field in the OpenAPI spec
when an `integer` field would be more appropriate.

Detect integers by comparing the truncation of the value to the original
value. This is an imperfect heuristic since not all integers are representable
as floats, but it will work for common cases (small integers) and produce less
surprising behavior for users.

Signed-off-by: Adam Wolfe Gordon <awg@upbound.io>
(cherry picked from commit 24976cd)
If an array in an example XR contains a mix of integers and floats, use "number"
as the array's element type rather than returning an error.

Signed-off-by: Adam Wolfe Gordon <awg@upbound.io>
(cherry picked from commit 25a5e5a)
@github-actions github-actions Bot requested review from a team, jcogilvie and tampakrap as code owners June 15, 2026 19:18
@github-actions github-actions Bot requested review from haarchri and removed request for a team June 15, 2026 19:18
@adamwg adamwg merged commit d7e38df into release-2.3 Jun 15, 2026
7 of 9 checks passed
@adamwg adamwg deleted the backport-108-to-release-2.3 branch June 15, 2026 21:00
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.

1 participant