Azure / autorest.csharp

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

Error running autorest to generate function app #921

Closed RupengLiu closed 4 years ago

RupengLiu commented 4 years ago

Describe the issue or request the command I ran: autorest --input-file:"c:\Users\rupliu\testFuncGen\616772b0f22d42ea8566b11732bd0be2.json" --output-folder:"c:\Users\rupliu\testFuncGen" --namespace:Company.Function --azure-functions-csharp

616772b0f22d42ea8566b11732bd0be2.txt

below is the error msg AutoRest code generation utility [cli version: 3.0.6247; node: v12.18.4, max-memory: 2048 gb] (C) 2018 Microsoft Corporation. https://aka.ms/autorest Loading AutoRest core 'C:\Users\rupliu\.autorest\@autorest_core@3.0.6320\node_modules\@autorest\core\dist' (3.0.6320) Loading AutoRest extension '@autorest/azure-functions-csharp' (latest->0.1.0-preview) Loading AutoRest extension '@autorest/modelerfour' (4.15.414->4.15.414) 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 /Users/varadmeru/work/microsoft/stencil/autorest.azure-functions-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 /Users/varadmeru/work/microsoft/stencil/autorest.azure-functions-csharp/src/AutoRest.CSharp.V3/Output/Builders/BuilderHelpers.cs:line 54 at AutoRest.CSharp.V3.Output.Models.Types.EnumType.BuildValues() in /Users/varadmeru/work/microsoft/stencil/autorest.azure-functions-csharp/src/AutoRest.CSharp.V3/Output/Models/Types/EnumType.cs:line 77 at AutoRest.CSharp.V3.Output.Models.Types.EnumType.get_Values() in /Users/varadmeru/work/microsoft/stencil/autorest.azure-functions-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 /Users/varadmeru/work/microsoft/stencil/autorest.azure-functions-csharp/src/AutoRest.CSharp.V3/Generation/Writers/ModelWriter.cs:line 276 at AutoRest.CSharp.V3.Generation.Writers.ModelWriter.WriteModel(CodeWriter writer, TypeProvider model) in /Users/varadmeru/work/microsoft/stencil/autorest.azure-functions-csharp/src/AutoRest.CSharp.V3/Generation/Writers/ModelWriter.cs:line 26 at AutoRest.CSharp.V3.AutoRest.Plugins.CSharpGen.ExecuteAsync(CodeModel codeModel, Configuration configuration) in /Users/varadmeru/work/microsoft/stencil/autorest.azure-functions-csharp/src/AutoRest.CSharp.V3/AutoRest/Plugins/CSharpGen.cs:line 65 at AutoRest.CSharp.V3.AutoRest.Plugins.CSharpGen.Execute(IPluginCommunication autoRest) in /Users/varadmeru/work/microsoft/stencil/autorest.azure-functions-csharp/src/AutoRest.CSharp.V3/AutoRest/Plugins/CSharpGen.cs:line 138 at AutoRest.CSharp.V3.AutoRest.Plugins.PluginProcessor.Start(IPluginCommunication autoRest) in /Users/varadmeru/work/microsoft/stencil/autorest.azure-functions-csharp/src/AutoRest.CSharp.V3/AutoRest/Plugins/PluginProcessor.cs:line 36 Error: Plugin azure-functions-csharp reported failure. Error: Failed to run "autorest" command. Check output window for more details.

Describe your ideas for solutions No idea

Add labels No workaround

These labels will help priority bug fixes and feature requests.

If this bug or feature request is for older versions of autorest, please remove the v3 label and add the v2 label as appropriate.

pakrym commented 4 years ago

Hello,

Unfortunately the azure-functions-csharp is not part of the repo and is not supported by this team.

RupengLiu commented 4 years ago

Okay, got it, thanks Pavel!

ShivangiReja commented 4 years ago

@RupengLiu Looks like azure-functions-csharp is a part of https://github.com/Azure/autorest.azure-functions-csharp repo. Checkout the usage.

vrdmr commented 4 years ago

@vrdmr Tagging self to take a look at the issue.

RupengLiu commented 4 years ago

@pakrym @ShivangiReja Yep, vrdmr will take a look at the azure-functions-csharp repo, close the issue since it's not on autorest.csharp side

vrdmr commented 4 years ago

@pakrym @ShivangiReja Looks like the issue still exists in autorest.csharp. The autorest.azure-functions-csharp plugin is essentially a copy of the autorest.csharp with some changes done in CsharpGen and CodeWriter to generate AzureFunctions app.

When I tried the sample file by @RupengLiu, with the latest pre-release of the autorest.csharp - 3.0.0-dev.20200911.1, I still hit the same exception as seen above.

I edited the details where the exception occurs to help pinpoint the issue.

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

Full stack.

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.
vrdmr commented 4 years ago

@RupengLiu, @pakrym, @ShivangiReja Found the issue - it has something to do with multiple schemas! 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
pakrym commented 4 years ago

Nice find!

Do you mind filling this a standalone issue?

vrdmr commented 4 years ago

@pakrym Done! :)

927