amzn / selling-partner-api-models

This repository contains OpenAPI models for developers to use when developing software to call Selling Partner APIs.
Apache License 2.0
610 stars 733 forks source link

Can't generate client library for .netstandard framework #186

Closed tarurar closed 6 months ago

tarurar commented 3 years ago

Steps to reproduce:

Output:

i.s.codegen.v3.AbstractGenerator - writing file /Users/atarutin/RiderProjects/selling-partner-api-client-library/./docs/Participation.md
Exception in thread "Thread-0" java.lang.RuntimeException: Could not generate api file for 'Sellers'
    at io.swagger.codegen.v3.DefaultGenerator.generateApis(DefaultGenerator.java:579)
    at io.swagger.codegen.v3.DefaultGenerator.generate(DefaultGenerator.java:782)
    at io.swagger.codegen.v3.cli.cmd.Generate.run(Generate.java:388)
    at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: com.github.jknack.handlebars.HandlebarsException: /handlebars/csharp-dotnet2/Users/atarutin/RiderProjects/selling-partner-api-client-library/../selling-partner-api-models/clients/sellingpartner-api-aa-csharp/src/Amazon.SellingPartnerAPIAA/resources/swagger-codegen/templates/api.mustache:1:3: The partial '/handlebars/csharp-dotnet2/partial_header.mustache' at '/handlebars/csharp-dotnet2/partial_header.mustache' could not be found
    at com.github.jknack.handlebars.internal.Partial.merge(Partial.java:236)
    at com.github.jknack.handlebars.internal.BaseTemplate.apply(BaseTemplate.java:130)
    at com.github.jknack.handlebars.internal.TemplateList.merge(TemplateList.java:95)
    at com.github.jknack.handlebars.internal.BaseTemplate.apply(BaseTemplate.java:130)
    at com.github.jknack.handlebars.internal.BaseTemplate.apply(BaseTemplate.java:118)
    at com.github.jknack.handlebars.internal.ForwardingTemplate.apply(ForwardingTemplate.java:72)
    at io.swagger.codegen.v3.templates.HandlebarTemplateEngine.getRendered(HandlebarTemplateEngine.java:25)
    at io.swagger.codegen.v3.DefaultGenerator.processTemplateToFile(DefaultGenerator.java:795)
    at io.swagger.codegen.v3.DefaultGenerator.generateApis(DefaultGenerator.java:538)
    ... 3 more
coder771 commented 2 years ago

Steps to reproduce:

  • install swagger-codegen client
  • clone the selling partner api models repository
  • run the code generation for example, for Sellers API: swagger-codegen generate -i ../selling-partner-api-models/models/sellers-api-model/sellers.json -l csharp-dotnet2 -t ../selling-partner-api-models/clients/sellingpartner-api-aa-csharp/src/Amazon.SellingPartnerAPIAA/resources/swagger-codegen/templates

Output:

i.s.codegen.v3.AbstractGenerator - writing file /Users/atarutin/RiderProjects/selling-partner-api-client-library/./docs/Participation.md
Exception in thread "Thread-0" java.lang.RuntimeException: Could not generate api file for 'Sellers'
  at io.swagger.codegen.v3.DefaultGenerator.generateApis(DefaultGenerator.java:579)
  at io.swagger.codegen.v3.DefaultGenerator.generate(DefaultGenerator.java:782)
  at io.swagger.codegen.v3.cli.cmd.Generate.run(Generate.java:388)
  at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: com.github.jknack.handlebars.HandlebarsException: /handlebars/csharp-dotnet2/Users/atarutin/RiderProjects/selling-partner-api-client-library/../selling-partner-api-models/clients/sellingpartner-api-aa-csharp/src/Amazon.SellingPartnerAPIAA/resources/swagger-codegen/templates/api.mustache:1:3: The partial '/handlebars/csharp-dotnet2/partial_header.mustache' at '/handlebars/csharp-dotnet2/partial_header.mustache' could not be found
  at com.github.jknack.handlebars.internal.Partial.merge(Partial.java:236)
  at com.github.jknack.handlebars.internal.BaseTemplate.apply(BaseTemplate.java:130)
  at com.github.jknack.handlebars.internal.TemplateList.merge(TemplateList.java:95)
  at com.github.jknack.handlebars.internal.BaseTemplate.apply(BaseTemplate.java:130)
  at com.github.jknack.handlebars.internal.BaseTemplate.apply(BaseTemplate.java:118)
  at com.github.jknack.handlebars.internal.ForwardingTemplate.apply(ForwardingTemplate.java:72)
  at io.swagger.codegen.v3.templates.HandlebarTemplateEngine.getRendered(HandlebarTemplateEngine.java:25)
  at io.swagger.codegen.v3.DefaultGenerator.processTemplateToFile(DefaultGenerator.java:795)
  at io.swagger.codegen.v3.DefaultGenerator.generateApis(DefaultGenerator.java:538)
  ... 3 more

did this ever work for you?

franciscocha commented 2 years ago

@tarurar If you don't specify and output it will try to output the results on the folder you are executing this command. So it might be a permissions issue. I would suggest to use the "-o" option in order to specify an output.

smargoli2 commented 2 years ago

I'm having a similar issue with the templates. When I try to generate using -t and the folder with the templates, I get the following error: ERROR io.swagger.codegen.AbstractGenerator - csharp-dotnet2\partial_header.mustache (The system cannot find the path specified) java.lang.RuntimeException: can't load template csharp-dotnet2\partial_header.mustache

franciscocha commented 2 years ago

@smargoli2 can you post the entire string that you are trying to execute?

smargoli2 commented 2 years ago

I ended up creating empty partial_header.mustache and visibility.mustache files and the templates processed correctly. Now I have an error that 'The type or namespace name 'IApiAccessor' could not be found (are you missing a using directive or an assembly reference?)' in each API. Where is this interface defined? Also, how can I generate one API Client to use for all the models, instead of having an API client generated for each model?

smargoli2 commented 2 years ago

There are many issues with the code generated from the templates. The IReadableConfiguration interface which is implemented by the configuration is not generated when using the mustache templates - there is no such interface. It is also missing the ExceptionFactory and GlobalConfiguration classes. Please advise!

franciscocha commented 2 years ago

@smargoli2 I haven't run into any issues with the code generation. If you post the full generation string you are using I might be able to help you troubleshoot.

smargoli2 commented 2 years ago

java -jar swagger-codegen-cli.jar generate -i "AmazonAPIJsonModels\models\fba-small-and-light-api-model\fbaSmallandLight.json" -l csharp-dotnet2 -o "AmazonGeneratedModels\FBASmallLight" -t "AmazonAPIJsonModels\clients\sellingpartner-api-aa-csharp\src\Amazon.SellingPartnerAPIAA\resources\swagger-codegen\templates" --api-package FBASmallLightApi -DpackageName=FBASmallLightModel The json file and templates are downloaded to my machine.

smargoli2 commented 2 years ago

I found my issue, I was using the wrong language version in my generation string. It should be -l csharp, not csharp-dotnet2. I am still having an issue though when I try using the build.bat to create a dll.

ApiClient.cs(24,7): error CS0246: The type or namespace name 'RateLimiter' could not be found (are you missing a using directive or an assembly reference?)
ApiClient.cs(37,17): error CS0246: The type or namespace name 'TimeLimiter' could not be found (are you missing a using directive or an assembly reference?)

Is there a package reference that is missing?

franciscocha commented 2 years ago

@smargoli2 we use Java and I don't remember if we ran into this issue. But I do remember that how the swagger json was made the namespace of various classes were set to swagger.io. I manually fixed all of them to a more sensical namespace before generating anything from that.

smargoli2 commented 2 years ago

Right, I did customize those namespaces. The Java ApiClient.mustache has this import statement: import com.google.common.util.concurrent.RateLimiter; while the C# version says using RateLimiter; but the Nuget package is not included. Do you have the package in your generated Java code...?

franciscocha commented 2 years ago

We do have have that package imported and had no issues using it. But again this is in Java and I did have some issues with dependencies but I don't remember if it was specific to import com.google.common.util.concurrent.RateLimiter. I'm not sure if you run into these types of issues in C# but when we do in Java I end up removing all of the downloaded dependencies and force the application to redownload them.

github-actions[bot] commented 6 months ago

This is a very old issue that is probably not getting as much attention as it deserves. We encourage you to check if this is still an issue after the latest release and if you find that this is still a problem, please feel free to open a new issue and make a reference to this one.

github-actions[bot] commented 6 months ago

closed for inactivity