OpenAPITools / OpenAPITools/openapi-generator
[BUG][OCaml] Dependency cycle when generating Stripe's API with the OCaml generator
Nobody has claimed this yet.
- 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 OCaml generator currently generates models in separate files.
This is creating dependency cycles when there's a mutual dependency between two types.
Here's an example from the Stripe API:
(* In src/models/issuing_transaction_authorization.ml *)
type t = {
...
transactions: Issuing_transaction.t list;
...
} [@@deriving yojson { strict = false }, show ];;
(* In src/models/issuing_transaction.ml *)
type t = {
...
authorization: Issuing_transaction_authorization.t option [@default None];
...
} [@@deriving yojson { strict = false }, show ];;
Building the generated project gives (among other errors):
Error: Dependency cycle between:
_build/default/.openapi.objs/openapi__Issuing_transaction_authorization.impl.all-deps
-> _build/default/.openapi.objs/openapi__Issuing_transaction.impl.all-deps
-> _build/default/.openapi.objs/openapi__Issuing_transaction_authorization.impl.all-deps
-> required by
_build/default/.openapi.objs/byte/openapi__Issuing_transaction_authorization.cmi
-> required by
_build/install/default/lib/openapi/openapi__Issuing_transaction_authorization.cmi
-> required by _build/default/openapi.install
-> required by alias install
-> required by alias default
openapi-generator version
openapi-generator-cli 6.0.0
commit : 69f79fb
built : 2022-05-26T02:54:15Z
source : https://github.com/openapitools/openapi-generator
docs : https://openapi-generator.tech/
OpenAPI declaration file content or url
https://github.com/stripe/openapi/blob/master/openapi/spec3.json
Generation Details
After downloading the spec above, I ran:
openapi-generator-cli generate -i spec3.json -g ocaml
Steps to reproduce
After generating the project, I ran dune build.
Related issues/PRs
Not exactly related to the issue above, but I also hit https://github.com/OpenAPITools/openapi-generator/issues/8397, which causes the generation of "empty" types when generating a project for the Stripe API, e.g.
(* In src/models/business_profile_specs_support_url.ml *)
type t = {
} [@@deriving yojson { strict = false }, show ];;
let create () : t = {
}
Which fails compilation with
File "src/models/business_profile_specs_support_url.ml", line 9, characters 0-1:
9 | } [@@deriving yojson { strict = false }, show ];;
^
Error: Syntax error
Suggest a fix
I'm not familiar with openapi-generator implementation, but if possible, a fix for it would be to generate all the models in the same file and use recursive modules.
The example above could look like this:
(* In src/models.ml *)
module rec Issuing_transaction_authorization = struct
type t = {
...
transactions: Issuing_transaction.t list;
...
} [@@deriving yojson { strict = false }, show ];;
end
and Issuing_transaction = struct
type t = {
...
authorization: Issuing_transaction_authorization.t option [@default None];
...
} [@@deriving yojson { strict = false }, show ];;
end
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the Stripe spec using openapi-generator-cli generate -i spec3.json -g ocaml, then run dune build on the generated project. Start by tracing how the OCaml generator writes the separate files under src/models/ and how mutually dependent types are represented. Done means the generated project builds without the reported dependency cycle.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ocaml
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100