Skip to content

A float32 in a oneOf with a nullable type can lead to syntax errors #2636

Closed

Description

@jamietanna

I.e. found in rootlyhq/rootly-go#189

Where: spec version openapi: 3.0.1, in two places:

  • #/components/schemas/new_ai_automation/properties/data/properties/attributes/properties/max_credits_per_run
  • #/components/schemas/update_ai_automation/properties/data/properties/attributes/properties/max_credits_per_run

Current schema:

"max_credits_per_run": {
  "oneOf": [
    { "type": "number", "enum": [0] },
    { "type": "number", "minimum": 1, "maximum": 1000 },
    { "type": "number", "nullable": true, "enum": [null] }
  ]
}

In this case, we see it as "this is a float32 and "this could be null and is nullable", which then results in

NewAiAutomationDataAttributesMaxCreditsPerRun2LessThanNil NewAiAutomationDataAttributesMaxCreditsPerRun2 = <nil>

which is invalid.

We should see if we can handle this better.

Activity

  1. added theissue type on Oct 27, 2026
  2. changed the issue type fromtoon Oct 27, 2026
  3. jamietanna commented on Oct 27, 2026

    @jamietanna
    MemberAuthor

    (This is also something that could be classed as a "spec issue", but outputting the literal <nil> is a syntax error either way, so we should harden this)

  4. mromaszewicz commented on Oct 27, 2026

    @mromaszewicz
    Member

    Yeah, I can see how this happens. We don't have an understanding of types, it's just type generation heuristics in the code, and that is a very, very weird construct.

    It looks like you want this number to be either 0, 1 to 1000, or null.

    wouldn't something like this be better and clearer?

    max_credits_per_run:
       type: number
       minimum: 0
       maximum: 1000
       nullable: true
    

    I've been thinking for some time of coming up with a preprocessing pass on the spec, to convert it into a more canonical format, before actually running codegen, which would greatly simplify the codegen and move the special casing logic to its own module.

    We can certainly detect this special case; if all the branches in a oneOf are the same type, but the differences are the constraints, then we convert it to the top level type and just set the constraints directly. I'm always on the fence about how much we go out of our way to read ugly specs.

  5. added a commit that references this issue on Nov 9, 2026
    72ca3cf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions