OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.36k stars 6.46k forks source link

[BUG][Swift5] Recursion error in generated code for OpenAPI spec from Bokun API docs #15240

Open 1amageek opened 1 year ago

1amageek commented 1 year ago

Bug Report Checklist

It contains syntax that cannot be expressed in Swift.

public struct A: Codable {

    public var a: A // Value type 'A' cannot have a stored property that recursively contains it

    public init(a: A) {
        self.a = a
    }
}
Description

When generating Swift5 code using the openapi-generator-cli-6.5.0.jar with the OpenAPI spec from this URL https://raw.githubusercontent.com/Bokun/api-docs/gh-pages/bokun.yaml, the following error occurred:

Value type 'RouteBookingDto' cannot have a stored property that recursively contains it.

openapi-generator version

openapi-generator-cli-6.5.0

OpenAPI declaration file content or url

https://raw.githubusercontent.com/Bokun/api-docs/gh-pages/bokun.yaml

Generation Details
java -jar ./openapi-generator-cli-6.5.0.jar generate \
  -i https://raw.githubusercontent.com/Bokun/api-docs/gh-pages/bokun.yaml \
  -g swift5 \
  -o ./OpenAPI
Steps to reproduce
  1. Install openapi-generator-cli-6.5.0.
  2. Run the following command:
java -jar ./openapi-generator-cli-6.5.0.jar generate \
  -i https://raw.githubusercontent.com/Bokun/api-docs/gh-pages/bokun.yaml \
  -g swift5 \
  -o ./OpenAPI
Related issues/PRs

-

Suggest a fix

-

herrernst commented 11 months ago

I also have this issue for our API

herrernst commented 11 months ago

A workaround is to use classes instead of struct, pass --additional-properties=useClasses=true to command