Skip to content

[BUG][rust-axum] Support for Unsigned Long Values in Integer Maximum Handling #19291

Open
@pranav-kumar-hex

Description

@pranav-kumar-hex

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

The issue involves incorrect handling of maximum integer values in openapi-yaml. The core issue resolves around not handling of upper half of unsigned 64 bit value i.e. (2^63 to 2^64-1).

openapi-generator version

master branch

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: User Api
  version: 1.0.0
  description: Unhandled unsigned long values

paths:
  /user:
    post:
      summary: User Api
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                id:
                  description: |
                      Integer where the allowed values correspond to the value range of an unsigned 64-bit integer.
                  maximum: 18446744073709551615
                  minimum: 0
                  type: integer
      responses:
        '200':
          description: Successful operation
        '400':
          description: Invalid IPv6 address
Generation Details
openapi-generator generate -g rust-axum -o testing -i openapi.yaml -c config.yaml

Config.yaml:

packageName: User-Server
projectName: User-Server
hideGenerationTimestamp: true
enablePostProcessFile: true
Generated Code:
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)]
#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
pub struct UserPostRequest {
    /// Integer where the allowed values correspond to the value range of an unsigned 64-bit integer.
    #[serde(rename = "id")]
    #[validate(
            range(min = 0, max = -1),
        )]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub id: Option<u8>,
}
Expected Code:
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)]
#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
pub struct UserPostRequest {
    /// Integer where the allowed values correspond to the value range of an unsigned 64-bit integer.
    #[serde(rename = "id")]
    #[validate(
            range(min = 0, max = 18446744073709551615),
        )]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub id: Option<u8>,
}
Related issues/PRs

No

Suggest a fix

The following code pointer is causing the change

if (maximum != null) {
if (isIntegerSchema(schema)) {
target.setMaximum(String.valueOf(maximum.longValue()));
} else {
target.setMaximum(String.valueOf(maximum));
}

should be changed to

if (maximum != null) {
            if (isIntegerSchema(schema)) {
                target.setMaximum(String.valueOf(maximum.toBigInteger().toString()));
            } else {
                target.setMaximum(String.valueOf(maximum.toBigInteger().toString()));
            }
            if (exclusiveMaximum != null) target.setExclusiveMaximum(exclusiveMaximum);
        }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions