Azure / autorest.csharp

Extension for AutoRest (https://github.com/Azure/autorest) that generates C# code
MIT License
142 stars 166 forks source link

Code generation fails when multiple schemas are in the specification #927

Open vrdmr opened 4 years ago

vrdmr commented 4 years ago

Describe the issue or request

When the swagger specification has multiple schemas, the code generation fails.

Here's a sample file with multiple schemas (by @RupengLiu), and when I use the latest pre-release of the autorest.csharp - 3.0.0-dev.20200911.1 to generate code, I hit the following exceptions:

Click to expand the full stacktrace ```bash autorest --use:https://github.com/Azure/autorest.csharp/releases/download/3.0.0-dev.20200911.1/autorest-csharp-v3-3.0.0-dev.20200911.1.tgz \ --output-folder:/Users/varadmeru/work/microsoft/stencil/StencilDemo/test_autorest_cs \ --input-file:/Users/varadmeru/work/microsoft/stencil/StencilDemo/616772b0f22d42ea8566b11732bd0be2.json \ --namespace:Company.Function --shared-source-folder:. AutoRest code generation utility [cli version: 3.0.6247; node: v12.17.0, max-memory: 2048 gb] (C) 2018 Microsoft Corporation. https://aka.ms/autorest Loading AutoRest core '/Users/varadmeru/.nvm/versions/node/v12.17.0/lib/node_modules/@autorest/core/dist' (3.0.6320) Loading AutoRest extension '@autorest/csharp-v3' (https://github.com/Azure/autorest.csharp/releases/download/3.0.0-dev.20200911.1/autorest-csharp-v3-3.0.0-dev.20200911.1.tgz->3.0.0-dev.20200911.1) Loading AutoRest extension '@autorest/modelerfour' (4.15.416->4.15.416) WARNING (PreCheck/CheckDuplicateSchemas): Checking for duplicate schemas, this could take a (long) while. Run with --verbose for more detail. FATAL: System.InvalidOperationException: Constant type mismatch at AutoRest.CSharp.V3.Output.Models.Shared.Constant..ctor(Object value, CSharpType type) in D:\a\1\s\autorest.csharp\src\AutoRest.CSharp.V3\Output\Models\Shared\Constant.cs:line 47 at AutoRest.CSharp.V3.Output.Builders.BuilderHelpers.ParseConstant(Object value, CSharpType type) in D:\a\1\s\autorest.csharp\src\AutoRest.CSharp.V3\Output\Builders\BuilderHelpers.cs:line 54 at AutoRest.CSharp.V3.Output.Models.Types.EnumType.BuildValues() in D:\a\1\s\autorest.csharp\src\AutoRest.CSharp.V3\Output\Models\Types\EnumType.cs:line 77 at AutoRest.CSharp.V3.Output.Models.Types.EnumType.get_Values() in D:\a\1\s\autorest.csharp\src\AutoRest.CSharp.V3\Output\Models\Types\EnumType.cs:line 68 at AutoRest.CSharp.V3.Generation.Writers.ModelWriter.WriteChoiceSchema(CodeWriter writer, EnumType schema) in D:\a\1\s\autorest.csharp\src\AutoRest.CSharp.V3\Generation\Writers\ModelWriter.cs:line 275 at AutoRest.CSharp.V3.Generation.Writers.ModelWriter.WriteModel(CodeWriter writer, TypeProvider model) in D:\a\1\s\autorest.csharp\src\AutoRest.CSharp.V3\Generation\Writers\ModelWriter.cs:line 26 at AutoRest.CSharp.V3.AutoRest.Plugins.CSharpGen.ExecuteAsync(CodeModel codeModel, Configuration configuration) in D:\a\1\s\autorest.csharp\src\AutoRest.CSharp.V3\AutoRest\Plugins\CSharpGen.cs:line 48 at AutoRest.CSharp.V3.AutoRest.Plugins.CSharpGen.Execute(IPluginCommunication autoRest) in D:\a\1\s\autorest.csharp\src\AutoRest.CSharp.V3\AutoRest\Plugins\CSharpGen.cs:line 130 at AutoRest.CSharp.V3.AutoRest.Plugins.PluginProcessor.Start(IPluginCommunication autoRest) in D:\a\1\s\autorest.csharp\src\AutoRest.CSharp.V3\AutoRest\Plugins\PluginProcessor.cs:line 36 Error: Plugin csharpgen reported failure. ```

This is specific to C# generators as other generators handle that.

This fails

"host": "devportal-lrp.azure-api.net",
"basePath": "/uniquetesgk",
"schemes": [
    "http", 
    "https"
],

This works

"host": "devportal-lrp.azure-api.net",
"basePath": "/uniquetesgk",
"schemes": [
    "http"
],

Trying out python generator

➜ autorest --azure-functions-python --no-namespace-folders:True \
--output-folder:/Users/varadmeru/work/microsoft/stencil/StencilDemo/test_autorest_py \
--input-file:/Users/varadmeru/work/microsoft/stencil/StencilDemo/616772b0f22d42ea8566b11732bd0be2.json

AutoRest code generation utility [cli version: 3.0.6247; node: v12.17.0, max-memory: 2048 gb]
(C) 2018 Microsoft Corporation.
https://aka.ms/autorest
   Loading AutoRest core      '/Users/varadmeru/.nvm/versions/node/v12.17.0/lib/node_modules/@autorest/core/dist' (3.0.6320)
   Loading AutoRest extension '@autorest/azure-functions-python' (latest->0.1.0-preview)
   Loading AutoRest extension '@autorest/modelerfour' (4.15.414->4.15.414)
Executing: /Users/varadmeru/.autorest/@autorest_azure-functions-python@0.1.0-preview/node_modules/@autorest/azure-functions-python/venv/bin/python3 -m autorest.jsonrpc.server

WARNING (PreCheck/CheckDuplicateSchemas): Checking for duplicate schemas, this could take a (long) while.  Run with --verbose for more detail.
[2.1 s] Generation Complete

Describe your ideas for solutions

No solutions currently - to get more information about the exception, I added some more content to the error, which points to a string vs object (array in our case) issue.

FATAL: System.InvalidOperationException: Constant type mismatch. 
value: http://devportal-lrp.azure-api.net/uniquetesgk | 
type.IsFrameworkType True | 
System.String != System.Object

Add labels

V3

Extra: forked from #921.

/cc @pakrym @ShivangiReja

RupengLiu commented 4 years ago

Hi Guys, any timeline when this can be fixed.

pakrym commented 4 years ago

I'm sorry. There is currently no estimate on when we would be able to fix this issue.