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

Generated OpenAPI for Java byte is incorrect #2126

Closed
dhoffer opened this issue Jan 3, 2025 · 1 comment · Fixed by #2128
Closed

Generated OpenAPI for Java byte is incorrect #2126

dhoffer opened this issue Jan 3, 2025 · 1 comment · Fixed by #2128
Labels
bug Something isn't working

Comments

@dhoffer
Copy link

dhoffer commented Jan 3, 2025

If we have Java code like this:

@JSONVIEW(Views.Abridged.class)
@Schema(description = "Velocity of the sensor in the vertical direction, in decimeters per second.", minimum = "-128", maximum = "127", example="2")
private byte d17;

@JSONVIEW(Views.Abridged.class)
@Schema(description = "Standard deviation of the estimate of the sensor track, in degrees.", minimum = "0", maximum = "45", example="2")
private byte d18;

Currently this generates this OpenAPI:

d17:
type: string
format: byte
description: "Velocity of the sensor in the vertical direction, in decimeters
\ per second."
maximum: 127
minimum: -128
example: "2"
d18:
type: string
format: byte
description: "Standard deviation of the estimate of the sensor track, in
\ degrees."
maximum: 45
minimum: 0
example: "2"

The best I can find from the OpenAPI spec is here: https://spec.openapis.org/registry/format/

Which leads me to think this should be defined in OpenAPI as:

"d17": {
                        "maximum": 127,
                        "minimum": -128,
                        "type": "number",
                        "description": "Velocity of the sensor in the vertical direction, in decimeters per second.",
                        "format": "int8",
                        "example": 2
},
"d18": {
                        "maximum": 45,
                        "minimum": 0,
                        "type": "number",
                        "description": "Standard deviation of the estimate of the sensor track, in degrees.",
                        "format": "int8",
                        "example": 2
},

or possibly this:

"d17": {
                        "maximum": 127,
                        "minimum": -128,
                        "type": "integer",
                        "description": "Velocity of the sensor in the vertical direction, in decimeters per second.",
                        "format": "int8",
                        "example": 2
},
"d18": {
                        "maximum": 45,
                        "minimum": 0,
                        "type": "integer",
                        "description": "Standard deviation of the estimate of the sensor track, in degrees.",
                        "format": "int8",
                        "example": 2
},

So the type would not be a string. Also having a maximum & minimum string makes no sense. Only when the type is a number or integer do those make sense.

But the key is the "format": "int8" as that makes it clear this is a signed 8 bit number.

Thanks,
-David

@MikeEdgar MikeEdgar added the bug Something isn't working label Jan 4, 2025
@MikeEdgar
Copy link
Member

I agree with using int8 for byte (and similarly int16 for short). Both imply the min/max values so I don't think they need to be explicitly generated by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants