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
20.9k stars 6.35k forks source link

[BUG] Null Reference Exception when using --model-name-suffix for fsharp-giraffe-server generator #9623

Open HerrNiklasRaab opened 3 years ago

HerrNiklasRaab commented 3 years ago

When running this commande openapi-generator generate -i api.yml -g fsharp-giraffe-server --dry-run --model-name-suffix "Dto" I get the following exception:

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.util.Map.put(Object, Object)" because "models" is null
        at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:512)
        at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:875)
        at org.openapitools.codegen.cmd.Generate.execute(Generate.java:441)
        at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
        at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)

When I run it with any other generator, I don't get the exception: openapi-generator generate -i api.yml -g aspnetcore --dry-run --model-name-suffix "Dto"

When I run it without --model-name-suffix, I don't get the exception: openapi-generator generate -i api.yml -g fsharp-giraffe-server --dry-run

@nmfisher Could it be that this option is not supported yet for the F# generator?

nmfisher commented 3 years ago

It's been quite some time since I looked at this, but I just ran a quick grep over my latest version of this repository and while you're right that I didn't implement --model-name-suffix in the template, the Abstract F# generator should have taken care of the model name suffix (so at the least it shouldn't be throwing an exception).

nmfisher commented 3 years ago

@HerrNiklasRaab this should be fixed in https://github.com/nmfisher/openapi-generator/tree/fsharp-giraffe-fixes

Are you able to test it out for me?

wing328 commented 3 years ago

@nmfisher I did a test locally with your fix and no longer see any exceptions.

java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g fsharp-giraffe-server --dry-run --model-name-suffix "Dto" -o /tmp/fsharp/
[main] INFO  o.o.codegen.DefaultGenerator - Generating with dryRun=true
[main] INFO  o.o.c.ignore.CodegenIgnoreProcessor - Output directory (/tmp/fsharp) does not exist, or is inaccessible. No file (.openapi-generator-ignore) will be evaluated.
[main] INFO  o.o.codegen.DefaultGenerator - OpenAPI Generator: fsharp-giraffe-server (server)
[main] INFO  o.o.codegen.DefaultGenerator - Generator 'fsharp-giraffe-server' is considered beta.
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found in the OAS 'content' section, returning only the first one (application/xml)
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found in the OAS 'content' section, returning only the first one (application/xml)
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found in the OAS 'content' section, returning only the first one (application/xml)
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found in the OAS 'content' section, returning only the first one (application/xml)
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found in the OAS 'content' section, returning only the first one (application/xml)
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found in the OAS 'content' section, returning only the first one (application/xml)
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found in the OAS 'content' section, returning only the first one (application/xml)
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found in the OAS 'content' section, returning only the first one (application/xml)

Please file a PR when you've time and I'll merge accordingly.

nmfisher commented 3 years ago

Thanks @wing328, amazing response time! There are a couple of other changes there so it needs a bit more testing but will look to file a PR soon.