Forum Discussion

oleksa's avatar
oleksa
New Contributor
6 years ago

ApiClient ApiException Configuration namespaces do not match to packageName option

Dears

 

I'm trying to generate csharp client form petstore json OpenAPI with packageName parameter specified

However the problem is that not all generated files has packageName value from config.

Files

 

ApiClient.cs
ApiException.cs
Configuration.cs

 

are generated with default IO.Swagger.Client namespace. This is not correct I suppose

and Api\*.cs and Model\*.cs source code files are generated with custom namespace (This is correct)

 

I use curl command like below to generate client source code (it has to be executed using bash)

 

curl -H "Content-type: application/json" -X POST -d '{"options": {"packageName": "pet_store"},"swaggerUrl": "http://petstore.swagger.io/v2/swagger.json"}' https://generator.swagger.io/api/gen/clients/csharp-dotnet2

Then I download archive using url from output (https://generator.swagger.io/api/gen/download/bf95a63d-5be5-4f46-89fc-720ab2a692f7)

 

The problem is that ApiClient.cs ApiException.cs and Configuration.cs files are generated with default IO.Swagger.Client namespace however I expect that namespace value have to be set to pet_store according to parameterization.

 

I replace namespace manually in the generated files however it would be nice to have namespace generated as it was parameterized.

When offline swagger-codegen is used with config file it generates namepace in the same way

java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i https://petstore.swagger.io/v2/swagger.json -l csharp-dotnet2 -o D:\temp\cw -c D:\temp\cw\config.json

config.json:

{ "packageName" : "petT_store" } 

 

Is there any other option to set namespace for all generated files?

 

 

2 Replies

  • oleksa's avatar
    oleksa
    New Contributor

    sorry, there is clientPackage option available

    Please excuse me for inconvenience

     

    Regards

  • Check your case again. Seems like it was fixed. I had the same issue, but I've resolved it using the config file with the offline generator a few days ago.

    java -jar swagger-codegen-cli.jar generate -i <url>swagger/docs/1.0 -l csharp -o <resultFolderPath> -c <configFolderPath>swagger-codegen-config.json

    Config file:

    {
      "packageName": "Name.Of.Package"
    }