Azure / autorest

OpenAPI (f.k.a Swagger) Specification code generator. Supports C#, PowerShell, Go, Java, Node.js, TypeScript, Python
MIT License
4.63k stars 739 forks source link

Add Support for Parameter Objects with Content Property #4480

Open peombwa opened 2 years ago

peombwa commented 2 years ago

AutoREST.PowerShell fails with error | Error: Plugin modelerfour reported failure when the parameter object of an operation contains content property: image

Repro Steps

  1. Use an OpenAPI description where the parameter object of an operation is defined as content. e.g., DeviceManagement.Functions.yml.
  2. Run AutoREST to generate a module using the above OpenAPI file:
        $OpenApiFile = "https://gist.githubusercontent.com/peombwa/8be839787ab6356d30366229f9fd9dc3/raw/bd442972339ea00b523ccb5c79c2e87ef5dd8aab/DeviceManagement.Functions.yml"
        autorest --powershell --input-file:$OpenApiFile --debug
  3. AutoREST fails with:
        AutoRest code generation utility [cli version: 3.6.0; node: v14.11.0]
        info    |    Loading AutoRest extension '@autorest/powershell' (~3.0.0->3.0.471)
        info    |    Loading AutoRest extension '@autorest/modelerfour' (4.15.414->4.15.414)
        ...
        C:\Users\peter\.autorest\@autorest_modelerfour@4.15.414\node_modules\@autorest\modelerfour\dist\modeler\plugin-modelerfour.js - FAILURE  "Unresolved item." undefined
        PLUGIN FAILURE: undefined, undefined, "Unresolved item."
        fatal   | Unresolved item.
        C:\Users\peter\.autorest\@autorest_core@3.7.4\node_modules\@autorest\core\dist\src_lib_autorest-core_ts.js - FAILURE Error: Plugin modelerfour reported failure.
            at C:\Users\peter\.autorest\@autorest_core@3.7.4\node_modules\@autorest\core\dist\src_lib_autorest-core_ts.js:2779:19
            at ScheduleNode (C:\Users\peter\.autorest\@autorest_core@3.7.4\node_modules\@autorest\core\dist\src_lib_autorest-core_ts.js:1317:33)
        fatal   | Process() cancelled due to exception : Plugin modelerfour reported failure. / Error: Plugin modelerfour reported failure.
            at C:\Users\peter\.autorest\@autorestcore@3.7.4\node_modules\@autorest\core\dist\src_lib_autorest-corets.js:2779:19
            at ScheduleNode (C:\Users\peter\.autorest\@autorestcore@3.7.4\node_modules\@autorest\core\dist\src_lib_autorest-corets.js:1317:33)
        error   |   Error: Plugin modelerfour reported failure.
        debug   | [2.56 s] Shutting Down.
        debug   | [2.56 s] Exiting.

Expected behavior

AutoREST.PowerShell should generate a command for /deviceManagement/microsoft.graph.getRoleScopeTagsByIds(ids={ids}) that makes GET /deviceManagement/microsoft.graph.getRoleScopeTagsByIds(ids=["1","2","3"]) request.

According to the OpenAPI spec:

For more complex scenarios, the content property can define the media type and schema of the parameter. A parameter MUST contain either a schema property, or a content property, but not both.

dolauli commented 2 years ago

It is a modelerfour issue. Transfer it to autorest.

timotheeguerin commented 2 years ago

Duplicate of #4303, is this a demand from services? I did brings this up in autorest scrum a while back and there wasn't much interest in supporting it in the generators without a real demand.

peombwa commented 2 years ago

@timotheeguerin, yes, this is a demand from a service. MS Graph API supports GET /deviceManagement/microsoft.graph.getRoleScopeTagsByIds(ids=["1","2","3"]), which can only be described with a parameter object of Content.application/json. See the discussion in https://github.com/microsoftgraph/microsoft-graph-devx-api/issues/902#issuecomment-1069133352.