autorest icon indicating copy to clipboard operation
autorest copied to clipboard

Single property is not wrapped in the container object in composite AutoRest

Open pscofield opened this issue 10 years ago • 1 comments

One of my API paths needs a parameter from the body the definition for which is as following. It contains ONLY one property named 'TargetSchemaVersion'. The generated code has the following signature where it contains a string instead of the class named 'GenerateUpgradedDefinitionParameters'. I have a repro if someone wants to check. This repros ONLY in composite client generator and not in the standalone autorest generator.

SWAGGER:

          {
            "name": "parameters",
            "description": "Parameters for generating an upgraded definition.",
            "in": "body",
            "required": true,
            "schema": {
              "$ref": "#/definitions/GenerateUpgradedDefinitionParameters"
            }
    "GenerateUpgradedDefinitionParameters": {
      "type": "object",
      "properties": {
        "targetSchemaVersion": {
          "type": "string",
          "description": "The target schema version."
        }
      }
    }

GENERATED CODE:

Expected:
public static object GenerateUpgradedDefinition(this IWorkflowsOperations operations, string resourceGroupName, string workflowName, GenerateUpgradedDefinitionParameters parameters)

Observed:
public static async Task<object> GenerateUpgradedDefinitionAsync(this IWorkflowsOperations operations, string resourceGroupName, string workflowName, string targetSchemaVersion = default(string), CancellationToken cancellationToken = default(CancellationToken))

Note: It generates the class if I add another property to the 'GenerateUpgraded...' definition.

pscofield avatar Jul 19 '16 23:07 pscofield

@pscofield were you using a -PayloadFlatteningThreshold with that?

That looks like it's flattening the parameter.

@dsgouda can you verify what's happening (if it still does)? If the -PayloadFlatteningThreshold is not specified I'm pretty sure it should be zero, and this shouldn't happen by default.

fearthecowboy avatar Nov 01 '16 20:11 fearthecowboy