Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a "maximum" limit to an integer changes the inner Rust type #589

Open
jgallagher opened this issue May 13, 2024 · 2 comments · May be fixed by #733
Open

Adding a "maximum" limit to an integer changes the inner Rust type #589

jgallagher opened this issue May 13, 2024 · 2 comments · May be fixed by #733
Assignees

Comments

@jgallagher
Copy link

In the following JSON schema, all three ByteCountN variants have the same type and format, and only differ by maximum:

  • ByteCount1 omits maximum
  • ByteCount2 sets its maximum to i64::MAX
  • ByteCount3 sets its maximum to i64::MAX + 1
{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "definitions": {
        "ByteCount1": {
            "description": "Byte count to express memory or storage capacity.",
            "type": "integer",
            "format": "uint64",
            "minimum": 0
        },
        "ByteCount2": {
            "description": "Byte count to express memory or storage capacity.",
            "type": "integer",
            "format": "uint64",
            "minimum": 0,
            "maximum": 9223372036854775807
        },
        "ByteCount3": {
            "description": "Byte count to express memory or storage capacity.",
            "type": "integer",
            "format": "uint64",
            "minimum": 0,
            "maximum": 9223372036854775808
        }
    }
}

I expected all of these to produce a struct wrapping a u64, but ByteCount{2,3} use i64 instead:

% cargo typify bytecount.json && rg 'struct ByteCount' bytecount.rs
48:pub struct ByteCount1(pub u64);
114:pub struct ByteCount2(pub i64);
180:pub struct ByteCount3(pub i64);
@ahl
Copy link
Collaborator

ahl commented May 13, 2024

Oof.. ByteCount3 seems particularly stupid.

@ahl ahl self-assigned this May 13, 2024
@davetayls
Copy link

@ahl did you manage to create a fix for this?

davetayls added a commit to davetayls/typify that referenced this issue Jan 5, 2025
@davetayls davetayls linked a pull request Jan 5, 2025 that will close this issue
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 a pull request may close this issue.

3 participants