OpenAPITools / OpenAPITools/openapi-generator
[BUG][OCaml] Generating stripe api fails with unreferenced enums
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)?
- I tried this, but it crashed the page, as the schema is quite large (5mb)
- 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 openapi specification for Stripe fails with the following error:
Exception in thread "main" java.lang.RuntimeException: Could not process model 'payment_source'.Please make sure that your schema is correct!
at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:539)
at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:960)
at org.openapitools.codegen.cmd.Generate.execute(Generate.java:511)
at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
Caused by: java.lang.IllegalArgumentException: Unreferenced enum custom,express,standard,ach_credit_transfer,ach_debit,acss_debit,alipay,au_becs_debit,bancontact,card,card_present,eps,giropay,ideal,klarna,multibanco,p24,sepa_debit,sofort,three_d_secure,wechat
at org.openapitools.codegen.languages.OCamlClientCodegen.toEnumName(OCamlClientCodegen.java:787)
at org.openapitools.codegen.DefaultCodegen.fromProperty(DefaultCodegen.java:4057)
at org.openapitools.codegen.DefaultCodegen.fromProperty(DefaultCodegen.java:3854)
at org.openapitools.codegen.DefaultCodegen.addVars(DefaultCodegen.java:5882)
at org.openapitools.codegen.DefaultCodegen.addVars(DefaultCodegen.java:5803)
at org.openapitools.codegen.DefaultCodegen.updateModelForComposedSchema(DefaultCodegen.java:2850)
at org.openapitools.codegen.DefaultCodegen.fromModel(DefaultCodegen.java:3132)
at org.openapitools.codegen.DefaultGenerator.processModels(DefaultGenerator.java:1341)
at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:534)
... 4 more
With a subset of the spec that contains an enum with an empty string, the following exception is thrown:
at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:539)
at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:960)
at org.openapitools.codegen.cmd.Generate.execute(Generate.java:511)
at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
Caused by: java.lang.IllegalArgumentException: Unreferenced enum
at org.openapitools.codegen.languages.OCamlClientCodegen.toEnumName(OCamlClientCodegen.java:787)
at org.openapitools.codegen.DefaultCodegen.fromProperty(DefaultCodegen.java:4057)
at org.openapitools.codegen.DefaultCodegen.fromProperty(DefaultCodegen.java:3854)
at org.openapitools.codegen.DefaultCodegen.getComposedProperties(DefaultCodegen.java:8183)
at org.openapitools.codegen.DefaultCodegen.getComposedSchemas(DefaultCodegen.java:8165)
at org.openapitools.codegen.DefaultCodegen.fromModel(DefaultCodegen.java:3106)
at org.openapitools.codegen.DefaultGenerator.processModels(DefaultGenerator.java:1341)
at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:534)
... 4 more
openapi-generator version
7.0.1
OpenAPI declaration file content or url
https://github.com/stripe/openapi/blob/master/openapi/spec3.json
Generation Details
openapi-generator-cli generate -i spec3.json -g ocaml -o stripe-api
Steps to reproduce
Run above command and see that it quickly fails with the first exception. Slimming down the spec to a single endpoint that has an empty string as an enum shows the second error:
cat spec3.json | jq '(.paths = {"/v1/customers": .paths["/v1/customers"]}) | .components = {}' > spec3-slim.json
openapi-generator-cli generate -i spec3-slim.json -g ocaml -o stripe-api --skip-validate-spec
An example of the enum that trips it up is:
"support_url": {
"anyOf": [
{
"type": "string"
},
{
"enum": [
""
],
"type": "string"
}
]
}
After removing the empty enum, the generation succeeds for this single endpoint.
Related issues/PRs
Suggest a fix
For the first issue, it's unclear to me what the underlying problem is. For the second issue, it seems that empty string enums trip up the generator. I tried this with the java generator and it succeeded, so it seems to be specific to this generator.
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 failure with the Stripe spec and the slim spec using the commands in the report. Start at OCamlClientCodegen.java:787 and trace the enum handling through DefaultCodegen.fromProperty; done means both reproductions generate successfully without the unreferenced-enum exceptions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ocaml, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100