Azure / autorest.csharp

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

Autorest generation does not make RequestContext optional #5135

Open MattCosturos opened 1 week ago

MattCosturos commented 1 week ago

Describe the issue or request Autorest changed RequestContext from optional to required.

Previously, query parameters were set to null, and every request had an optional RequestContext. Now every method has a required RequestContext parameter.

Our entire codebase is calling methods WITHOUT providing a RequestContext. This change will require work to update every single auto rest call.

Swagger excerpt.

"get": {
        "tags": [
          "Assets"
        ],
        "operationId": "GET_Assets",
        "parameters": [
          {
            "name": "id",
            "in": "query",
            "schema": {
              "title": "Guid",
              "type": "string",
              "format": "uuid"
            }
          }

Previously generated signature public virtual Response Assets(Guid? id = null, RequestContext context = null)

Newly generated signature public virtual Response Assets(Guid? id, RequestContext context)

Previous command autorest --version:3.9.3 --input-file=$1 --csharp --output-folder=$2 --use=@autorest/csharp@3.0.0-beta.20230706.1 --verbose

New command autorest --version:3.10.3 --input-file=$1 --csharp --output-folder=$2 --use=@autorest/csharp@3.0.0-beta.20241030.1 --verbose

We ran into this problem last year, and that is why we haven't updated auto rest since July 2023.

Is there any flag we can set to make RequestContext optional again?

Full swagger file here https://smartfactory-dev.eastus2.cloudapp.azure.com/ea/api/swagger/v1/swagger.json

Logs

AutoRest code generation utility [cli version: 3.7.1; node: v23.1.0]
(C) 2018 Microsoft Corporation.
https://aka.ms/autorest
info    | AutoRest core version selected from configuration: 3.10.3.
info    |    Loading AutoRest core      '/Users/userName/.autorest/@autorestcore@3.10.3/nodemodules/@autorest/core/dist' (3.10.3)
verbose | [0.68 s] No configuration found at 'file:///Users/userName/repos/moog-connect-cloud/'.
verbose | [0.68 s]    Including configuration file 'file:///Users/userName/.autorest/@autorestcore@3.10.3/nodemodules/@autorest/core/dist/resources/default-configuration.md'
verbose | [0.70 s]    Including configuration file 'file:///Users/userName/.autorest/@autorestcore@3.10.3/nodemodules/@autorest/core/dist/resources/inspect.md'
verbose | [0.71 s]    Including configuration file 'file:///Users/userName/.autorest/@autorestcore@3.10.3/nodemodules/@autorest/core/dist/resources/directives.md'
verbose | [0.71 s]    Including configuration file 'file:///Users/userName/.autorest/@autorestcore@3.10.3/nodemodules/@autorest/core/dist/resources/pipeline.md'
verbose | [0.72 s]    Including configuration file 'file:///Users/userName/.autorest/@autorestcore@3.10.3/nodemodules/@autorest/core/dist/resources/loader-openapi.md'
verbose | [0.73 s]    Including configuration file 'file:///Users/userName/.autorest/@autorestcore@3.10.3/nodemodules/@autorest/core/dist/resources/miscellaneous.md'
verbose | [0.74 s]    Including configuration file 'file:///Users/userName/.autorest/@autorestcore@3.10.3/nodemodules/@autorest/core/dist/resources/plugin-powershell.md'
verbose | [0.75 s]    Including configuration file 'file:///Users/userName/.autorest/@autorestcore@3.10.3/nodemodules/@autorest/core/dist/resources/plugin-azureresourceschema.md'
verbose | [0.76 s]    Including configuration file 'file:///Users/userName/.autorest/@autorestcore@3.10.3/nodemodules/@autorest/core/dist/resources/plugin-csharp.md'
verbose | [0.77 s]    Including configuration file 'file:///Users/userName/.autorest/@autorestcore@3.10.3/nodemodules/@autorest/core/dist/resources/plugin-go.md'
verbose | [0.78 s]    Including configuration file 'file:///Users/userName/.autorest/@autorestcore@3.10.3/nodemodules/@autorest/core/dist/resources/plugin-java.md'
verbose | [0.79 s]    Including configuration file 'file:///Users/userName/.autorest/@autorestcore@3.10.3/nodemodules/@autorest/core/dist/resources/plugin-nodejs.md'
verbose | [0.81 s]    Including configuration file 'file:///Users/userName/.autorest/@autorestcore@3.10.3/nodemodules/@autorest/core/dist/resources/plugin-php.md'
verbose | [0.82 s]    Including configuration file 'file:///Users/userName/.autorest/@autorestcore@3.10.3/nodemodules/@autorest/core/dist/resources/plugin-python.md'
verbose | [0.83 s]    Including configuration file 'file:///Users/userName/.autorest/@autorestcore@3.10.3/nodemodules/@autorest/core/dist/resources/plugin-ruby.md'
verbose | [0.84 s]    Including configuration file 'file:///Users/userName/.autorest/@autorestcore@3.10.3/nodemodules/@autorest/core/dist/resources/plugin-typescript.md'
verbose | [0.85 s]    Including configuration file 'file:///Users/userName/.autorest/@autorestcore@3.10.3/nodemodules/@autorest/core/dist/resources/plugin-validators.md'
verbose | [0.86 s]    Including configuration file 'file:///Users/userName/.autorest/@autorestcore@3.10.3/nodemodules/@autorest/core/dist/resources/plugin-az.md'
verbose | [0.87 s]    Including configuration file 'file:///Users/userName/.autorest/@autorestcore@3.10.3/nodemodules/@autorest/core/dist/resources/plugin-terraform.md'
verbose | [0.88 s]    Including configuration file 'file:///Users/userName/.autorest/@autorestcore@3.10.3/nodemodules/@autorest/core/dist/resources/plugin-azure-functions.md'
verbose | [0.90 s]    Including configuration file 'file:///Users/userName/.autorest/@autorestcore@3.10.3/nodemodules/@autorest/core/dist/resources/plugin-openapi-to-typespec.md'
verbose | [0.91 s]    Including configuration file 'file:///Users/userName/.autorest/@autorestcore@3.10.3/nodemodules/@autorest/core/dist/resources/graphs.md'
verbose | [0.93 s]    Including configuration file 'file:///Users/userName/.autorest/@autorestcore@3.10.3/nodemodules/@autorest/core/dist/resources/help-configuration.md'
info    |    Loading AutoRest extension '@autorest/csharp' (3.0.0-beta.20241030.1->3.0.0-beta.20241030.1)
verbose | [1.00 s]    Including extension configuration file 'file:///Users/userName/.autorest/@autorestcsharp@3.0.0-beta.20241030.1/nodemodules/@autorest/csharp/readme.md'
verbose | [1.00 s]    Including configuration file 'file:///Users/userName/.autorest/@autorestcsharp@3.0.0-beta.20241030.1/nodemodules/@autorest/csharp/readme.md'
info    |    Loading AutoRest extension '@autorest/modelerfour' (4.26.0->4.26.0)
verbose | [1.08 s]    Including extension configuration file 'file:///Users/userName/.autorest/@autorestmodelerfour@4.26.0/nodemodules/@autorest/modelerfour/readme.md'
verbose | [1.08 s]    Including configuration file 'file:///Users/userName/.autorest/@autorestmodelerfour@4.26.0/nodemodules/@autorest/modelerfour/readme.md'
verbose | [2.83 s] Reading OpenAPI 3.0 file https://smartfactory-dev.eastus2.cloudapp.azure.com/ea/api/swagger/v1/swagger.json
warning | PreCheck/CheckDuplicateSchemas | Checking for duplicate schemas, this could take a (long) while.  Run with --verbose for more detail.
verbose | [5.66 s] Found and removed 0 duplicate schema
verbose | [7.50 s]   ModelerFour/api-version-mode:client
verbose | [7.50 s]   ModelerFour/api-version-parameter:constant
verbose | [7.50 s]   ModelerFour/use-model-namespace:false
warning | Modeler/MissingType | The schema 'Object' has no type or format information whatsoever. Location:
   https://smartfactory-dev.eastus2.cloudapp.azure.com/ea/api/swagger/v1/swagger.json#/components/schemas/Object
warning | ? | Operation 'DELETE/DeviceSimulators' really should not have a media type (because there should be no body)
warning | ? | Operation 'DELETE/DeviceTwins/{id}/property' really should not have a media type (because there should be no body)
warning | ? | Operation 'DELETE/DeviceTwins/{id}/tag' really should not have a media type (because there should be no body)
warning | Modeler/MissingType | The schema 'Object2' has no type or format information whatsoever. Location:
   https://smartfactory-dev.eastus2.cloudapp.azure.com/ea/api/swagger/v1/swagger.json#/components/schemas/Object2
warning | Modeler/MissingType | The schema 'Object0' has no type or format information whatsoever. Location:
   https://smartfactory-dev.eastus2.cloudapp.azure.com/ea/api/swagger/v1/swagger.json#/components/schemas/Object0
warning | Modeler/MissingType | The schema 'Object1' has no type or format information whatsoever. Location:
   https://smartfactory-dev.eastus2.cloudapp.azure.com/ea/api/swagger/v1/swagger.json#/components/schemas/Object1
info    | Autorest completed in 53.95s. 20 files generated.
pshao25 commented 1 week ago

You could set keep-non-overloadable-protocol-signature to true.

MattCosturos commented 1 week ago

Yes that will do the trick. Thank you.

Is there a document somewhere listing all the possible flags and arguments? I reviewed this list but it doesn't contain keep-non-overloadable-protocol-signature