Skip to content

[BUG] [RUST Server] Invalid validation generated for large integers after updating to 7.15 #21805

@pgoodjohn

Description

@pgoodjohn

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • 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

After updating the generator to 7.15, building our Rust Server fails to compile due to invalid validation rules being generated for large integers.

openapi-generator version

The generation works fine on both version however, after updating to 7.15, the generated code does not compile and fails with the following error:

error[E0600]: cannot apply unary operator `-` to type `u64`
   --> src/models.rs:887:34
    |
887 |             range(min = 0, max = -8446744073709551616),
    |                                  ^ cannot apply unary operator `-`
    |
    = note: unsigned values cannot be negated
OpenAPI declaration file content or url
openapi: 3.0.0

info:
  title: 'Example'
  description: 'test'
  version: 0.0.1
  contact:
    email: 'info@pietrobongiovanni.com'

servers:
  - url: '{protocol}://{hostname}:{port}/api/v1'
    variables:
      protocol:
        enum:
          - http
          - https
        default: http
      hostname:
        default: 'localhost'
      port:
        default: '8080'

components:

  schemas:
    paginationResponse:
      type: object
      properties:
        page:
          type: integer
          minimum: 0
          maximum: 10000000000000000000
          example: 0
        pageSize:
          type: integer
          minimum: 1
          maximum: 10000000000000000000
          example: 100
      required:
        - page
        - pageSize

    deviceId:
      type: string
      description: 'Device unique identifier'
      example: 'device_01jrd1sbzpfg89kqzcfazy6d0q'

    device:
      allOf:
        - type: object
          required:
            - id
          properties:
            id:
              $ref: '#/components/schemas/deviceId'

    paginatedDevices:
      type: object
      required:
        - items
        - pagination
      properties:
        items:
          type: array
          items:
            $ref: '#/components/schemas/device'
        pagination:
          $ref: '#/components/schemas/paginationResponse'

paths:
  /devices:
    summary: 'Devices'
    get:
      operationId: getDevices
      responses:
        '200':
          description: '(200) OK'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/paginatedDevices'
Generation Details

We generate the code in a podman container. Generation works fine but the subsequent cargo build of the server fails. Please see this generate.sh:

#!/bin/bash

OPENAPI_GENERATOR_VERSION=v7.14.0

set -x

rm -rf generated/

podman run --rm -v "$(pwd)":/repo:Z openapitools/openapi-generator-cli:$OPENAPI_GENERATOR_VERSION \
    generate \
    -i /repo/openapi.yaml \
    -g rust-server \
    -o /repo/generated/rust-server \
    --model-name-prefix api \
    --additional-properties hideGenerationTimestamp=true

pushd "$(pwd)/generated/rust-server" > /dev/null
echo
echo "Building rust-server library..."
echo
cargo build
echo
echo "Building rust-server example client..."
echo
cargo build --example client
echo
echo "Building rust-server example server..."
echo
cargo build --example server
popd > /dev/null
Steps to reproduce

Copy the above openapi.yaml and generate.sh in a folder and run generate.sh to generate and build the rust server.
With OPENAPI_GENERATOR_VERSION=v7.14.0 the server will compile successfully.
If you set OPENAPI_GENERATOR_VERSION to v7.15.0 the compilation of the server will fail:

error[E0600]: cannot apply unary operator `-` to type `u64`
   --> src/models.rs:461:34
    |
461 |             range(min = 1, max = -8446744073709551616),
    |                                  ^ cannot apply unary operator `-`
    |
    = note: unsigned values cannot be negated

For more information about this error, try `rustc --explain E0600`.

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