apple / swift-openapi-generator

Generate Swift client and server code from an OpenAPI document.
https://swiftpackageindex.com/apple/swift-openapi-generator/documentation
Apache License 2.0
1.45k stars 121 forks source link

Integer property with large min/max value fails #660

Closed atacan closed 1 month ago

atacan commented 1 month ago

Description

A property like the following

seed:
  type: integer
  minimum: -9223372036854776000
  maximum: 9223372036854776000
  nullable: true
  description: >

fails with Expected an Integer literal but found a floating point value (9.223372036854776e+18)

error: Inconsistency encountered when parsing `maximum` in Document.components.schemas.CreateChatCompletionRequest.properties.seed: Expected an Integer literal but found a floating point value (9.223372036854776e+18).Swift OpenAPI Generator is running with the following configuration:

- OpenAPI document path: /Sources/OpenAIAsyncHTTPClient/openapi.yaml
- Configuration path: /Sources/OpenAIAsyncHTTPClient/openapi-generator-config.yaml
- Generator modes: types, client
- Access modifier: public
- Feature flags: <none>
- Output file names: Types.swift, Client.swift
- Output directory: /Sources/OpenAIAsyncHTTPClient/GeneratedSources
- Diagnostics output path: <none - logs to stderr>
- Current directory: /Users/atacan/Developer/Repositories/SwiftOpenAIAPI
- Plugin source: command
- Is dry run: false
- Additional imports: <none>

Reproduction

You can use https://github.com/openai/openai-openapi/blob/c880fa100c99e42c029ef8497cb97aa63a8ab706/openapi.yaml#L12044

and manually generate swift package generate-code-from-openapi

Package version(s)

.
├── swift-openapi-generator<https://github.com/apple/swift-openapi-generator@1.2.1>
│   ├── swift-algorithms<https://github.com/apple/swift-algorithms@1.2.0>
│   │   └── swift-numerics<https://github.com/apple/swift-numerics.git@1.0.2>
│   ├── openapikit<https://github.com/mattpolzin/OpenAPIKit@3.1.2>
│   │   └── yams<https://github.com/jpsim/Yams@5.0.6>
│   ├── yams<https://github.com/jpsim/Yams@5.0.6>
│   └── swift-argument-parser<https://github.com/apple/swift-argument-parser@1.3.0>
├── swift-openapi-runtime<https://github.com/apple/swift-openapi-runtime@1.3.2>
│   └── swift-http-types<https://github.com/apple/swift-http-types@1.0.3>
├── swift-openapi-urlsession<https://github.com/apple/swift-openapi-urlsession@1.0.1>
│   ├── swift-openapi-runtime<https://github.com/apple/swift-openapi-runtime@1.3.2>
│   │   └── swift-http-types<https://github.com/apple/swift-http-types@1.0.3>
│   ├── swift-http-types<https://github.com/apple/swift-http-types@1.0.3>
│   └── swift-collections<https://github.com/apple/swift-collections@1.1.0>
└── swift-openapi-async-http-client<https://github.com/swift-server/swift-openapi-async-http-client@1.0.0>
    ├── swift-nio<https://github.com/apple/swift-nio@2.76.1>
    │   ├── swift-atomics<https://github.com/apple/swift-atomics.git@1.2.0>
    │   ├── swift-collections<https://github.com/apple/swift-collections@1.1.0>
    │   └── swift-system<https://github.com/apple/swift-system.git@1.4.0>
    ├── async-http-client<https://github.com/swift-server/async-http-client.git@1.23.1>
    │   ├── swift-nio<https://github.com/apple/swift-nio@2.76.1>
    │   │   ├── swift-atomics<https://github.com/apple/swift-atomics.git@1.2.0>
    │   │   ├── swift-collections<https://github.com/apple/swift-collections@1.1.0>
    │   │   └── swift-system<https://github.com/apple/swift-system.git@1.4.0>
    │   ├── swift-nio-ssl<https://github.com/apple/swift-nio-ssl.git@2.28.0>
    │   │   └── swift-nio<https://github.com/apple/swift-nio@2.76.1>
    │   │       ├── swift-atomics<https://github.com/apple/swift-atomics.git@1.2.0>
    │   │       ├── swift-collections<https://github.com/apple/swift-collections@1.1.0>
    │   │       └── swift-system<https://github.com/apple/swift-system.git@1.4.0>
    │   ├── swift-nio-http2<https://github.com/apple/swift-nio-http2.git@1.34.1>
    │   │   ├── swift-nio<https://github.com/apple/swift-nio@2.76.1>
    │   │   │   ├── swift-atomics<https://github.com/apple/swift-atomics.git@1.2.0>
    │   │   │   ├── swift-collections<https://github.com/apple/swift-collections@1.1.0>
    │   │   │   └── swift-system<https://github.com/apple/swift-system.git@1.4.0>
    │   │   └── swift-atomics<https://github.com/apple/swift-atomics.git@1.2.0>
    │   ├── swift-nio-extras<https://github.com/apple/swift-nio-extras.git@1.24.1>
    │   │   ├── swift-nio<https://github.com/apple/swift-nio@2.76.1>
    │   │   │   ├── swift-atomics<https://github.com/apple/swift-atomics.git@1.2.0>
    │   │   │   ├── swift-collections<https://github.com/apple/swift-collections@1.1.0>
    │   │   │   └── swift-system<https://github.com/apple/swift-system.git@1.4.0>
    │   │   ├── swift-nio-http2<https://github.com/apple/swift-nio-http2.git@1.34.1>
    │   │   │   ├── swift-nio<https://github.com/apple/swift-nio@2.76.1>
    │   │   │   │   ├── swift-atomics<https://github.com/apple/swift-atomics.git@1.2.0>
    │   │   │   │   ├── swift-collections<https://github.com/apple/swift-collections@1.1.0>
    │   │   │   │   └── swift-system<https://github.com/apple/swift-system.git@1.4.0>
    │   │   │   └── swift-atomics<https://github.com/apple/swift-atomics.git@1.2.0>
    │   │   └── swift-http-types<https://github.com/apple/swift-http-types@1.0.3>
    │   ├── swift-nio-transport-services<https://github.com/apple/swift-nio-transport-services.git@1.23.0>
    │   │   ├── swift-nio<https://github.com/apple/swift-nio@2.76.1>
    │   │   │   ├── swift-atomics<https://github.com/apple/swift-atomics.git@1.2.0>
    │   │   │   ├── swift-collections<https://github.com/apple/swift-collections@1.1.0>
    │   │   │   └── swift-system<https://github.com/apple/swift-system.git@1.4.0>
    │   │   └── swift-atomics<https://github.com/apple/swift-atomics.git@1.2.0>
    │   ├── swift-log<https://github.com/apple/swift-log.git@1.6.1>
    │   ├── swift-atomics<https://github.com/apple/swift-atomics.git@1.2.0>
    │   └── swift-algorithms<https://github.com/apple/swift-algorithms@1.2.0>
    │       └── swift-numerics<https://github.com/apple/swift-numerics.git@1.0.2>
    ├── swift-openapi-runtime<https://github.com/apple/swift-openapi-runtime@1.3.2>
    │   └── swift-http-types<https://github.com/apple/swift-http-types@1.0.3>
    └── swift-http-types<https://github.com/apple/swift-http-types@1.0.3>

Expected behavior

parse it as integer

Environment

swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
Target: arm64-apple-macosx15.0

Additional information

No response

czechboy0 commented 1 month ago

Int.max is 9223372036854775807, but the value in the document is higher, so it fails to parse (ends in 776000).

So the failure seems expected.

Who wrote the OpenAPI document? Why does it have a value larger than Int.max (on 64-bit platforms)?

atacan commented 1 month ago

Thank you for the information.

Who wrote the OpenAPI document?

It's OpenAI's official document

https://github.com/openai/openai-openapi/blob/c880fa100c99e42c029ef8497cb97aa63a8ab706/openapi.yaml#L12044

simonjbeaumont commented 1 month ago

This is not the first inaccuracy I've seen in this OpenAPI document. Perhaps you can file an issue on their repo? https://github.com/openai/openai-openapi