OpenAPITools / OpenAPITools/openapi-generator

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

Open
#19,291 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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
https://github.com/OpenAPITools/openapi-generator/blob/da7105bc6a40f9c6e5f16e3d1b184a2d2538b903/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java#L1909-L1914
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);
        }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java at the linked lines and reproduce the issue with the provided OpenAPI YAML and rust-axum generation command. Trace how the maximum value is converted, then verify that generated validation preserves 18446744073709551615 instead of -1.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.