swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
17.09k stars 6.03k forks source link

CSharp language generator fails for Bitbuckets swagger JSON #5576

Open mminns opened 7 years ago

mminns commented 7 years ago
Description
  1. Using codegen built from the latest master the CSharp language generator fails when trying to parse https://api.bitbucket.org/swagger.json.
Swagger-codegen version

Built from master @ commit ea16da813

Swagger declaration file content or url

https://api.bitbucket.org/swagger.json

Command line used for generation

java -jar C:\Users\mminn\Source\github.com\mminns\swagger-codegen\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar generate -i swagger.json -l csharp -o client-mminns/csharp

Results:

"C:\Program Files (x86)\Java\jdk1.7.0_55\bin\java" -Dfile.encoding=windows-1252 -jar C:\Users\mminn\Source\github.com\mminns\swagger-codegen\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar generate -i swagger.json -l csharp -o client-mminnns/csharp-debug [main] INFO io.swagger.parser.Swagger20Parser - reading from swagger.json [main] INFO io.swagger.codegen.languages.CSharpClientCodegen - Generating code for .NET Framework v4.5 Exception in thread "main" java.lang.RuntimeException: Could not process model 'pipeline_ref_target'.Please make sure that your schema is correct! at io.swagger.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:315) at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:665) at io.swagger.codegen.cmd.Generate.run(Generate.java:234) at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:43) Caused by: java.lang.NullPointerException at io.swagger.codegen.DefaultCodegen.fromModel(DefaultCodegen.java:1264) at io.swagger.codegen.languages.CSharpClientCodegen.fromModel(CSharpClientCodegen.java:428) at io.swagger.codegen.DefaultCodegen.fromModel(DefaultCodegen.java:1246) at io.swagger.codegen.languages.CSharpClientCodegen.fromModel(CSharpClientCodegen.java:431) at io.swagger.codegen.DefaultGenerator.processModels(DefaultGenerator.java:907) at io.swagger.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:310) ... 3 more

Process finished with exit code 1

The problem is in CSharpClientCodegen https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CSharpClientCodegen.java#L430

When it tries to look up the parent model it is using the parent model name, but the collection allDefinitions is keyed on schema name.

The PetStore examples never hit this problem because the Model's don't have parents.

Related issues

https://github.com/swagger-api/swagger-codegen/issues/5577

Suggest a Fix

Changing the line: https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CSharpClientCodegen.java#L430

see also: https://github.com/mminns/swagger-codegen/tree/issue/fix-csharp-for-bitbucket

I'd like to submit the above fix as a PR

mminns commented 7 years ago

see https://github.com/swagger-api/swagger-codegen/pull/5682