ctaggart/autorust_openapi

$ref with sibling elements

ctaggart opened this issue · 4 comments

I do not think $ref could be used with other values. In this case description and x-ms-client-flatten.

    "ExpressRouteAuthorization": {
      "description": "ExpressRoute Circuit Authorization",
      "allOf": [
        {
          "$ref": "#/definitions/Resource"
        }
      ],
      "properties": {
        "properties": {
          "description": "The properties of an ExpressRoute Circuit Authorization resource",
          "$ref": "#/definitions/ExpressRouteAuthorizationProperties",
          "x-ms-client-flatten": true
        }
      }
    },

This is from ../azure-rest-api-specs/specification/vmware/resource-manager/Microsoft.AVS/stable/2020-03-20/vmware.json

The sibling elements are not valid and should be ignore. It is documented at the end of this:
https://swagger.io/docs/specification/using-ref/

Many specs use sibling elements of x-ms-client-flatten, title, and description. I'm adding support for AutoRest compatability.

With #18, I've added several schema fields that can be overridden according to the specs in the test suite.

// $ref with sibling elements are not OpenAPI spec compliant
// https://github.com/ctaggart/autorust_openapi/issues/13
#[serde(skip_serializing_if = "Option::is_none")]
title: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
description: Option<String>,
// specifying "type" feels like a bug in the spec
#[serde(rename = "type", skip_serializing_if = "Option::is_none")]
type_: Option<DataType>,
#[serde(rename = "readOnly", skip_serializing_if = "Option::is_none")]
read_only: Option<bool>,
/// flattens client model property or parameter
/// https://github.com/Azure/autorest/blob/master/docs/extensions/readme.md#x-ms-client-flatten
#[serde(rename = "x-ms-client-flatten", skip_serializing_if = "Option::is_none")]
x_ms_client_flatten: Option<bool>,

Azure specs do not follow OpenAPI spec in this regard.