autorest icon indicating copy to clipboard operation
autorest copied to clipboard

Investigate properties with allOf to a ref

Open timotheeguerin opened this issue 4 years ago • 1 comments

In openapi you cannot use any properties next to a $ref``. Autorest does allow a few to be able to be used on model properties like description, readonly`, etc.

Foo:
  name: 
    readOnly: true
    $ref: "#components/schemas/name"

However it should really be defined this way

Foo:
  name: 
    readOnly: true
    allOf: 
     - $ref: "#components/schemas/name"

Autorest does support this but needs a flag to be enabled --modelerfour.remove-empty-child-schemas and will log warnings. Believe we can be smart and figure out when this pattern is used and not log any warnings and remove the need for the flag.

timotheeguerin avatar Oct 08 '21 21:10 timotheeguerin

One more thing to investigate:

          "foo": {
            "allOf": [
              {
                "$ref": "#/components/schemas/Foo"
              }
            ],
            "nullable": true
          }

Produces this code - ignores nullabe: true:

                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }

aelij avatar Oct 19 '21 05:10 aelij