Skip to content

Instantly share code, notes, and snippets.

@lmazuel
Last active February 7, 2022 23:29
Show Gist options
  • Save lmazuel/3ca2ee58992ff666bc65125ca4d2d3d7 to your computer and use it in GitHub Desktop.
Save lmazuel/3ca2ee58992ff666bc65125ca4d2d3d7 to your computer and use it in GitHub Desktop.
Swagger and flattening
{
"swagger": "2.0",
"info": {
"title": "AutoRest Resource Flattening Test Service",
"description": "Resource Flattening for AutoRest",
"version": "1.0.0"
},
"host": "localhost:3000",
"schemes": ["http"],
"produces": ["application/json"],
"consumes": ["application/json"],
"paths": {
"/model-flatten/array": {
"get": {
"operationId": "getModel",
"description": "Get a model",
"responses": {
"200": {
"description": "External Resource as an Array from get",
"schema": {
"$ref": "#/definitions/FlattenedProduct1"
}
}
}
}
}
},
"definitions": {
"Resource": {
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "Resource Id",
"readOnly": true
},
"type": {
"type": "string",
"description": "Resource Type",
"readOnly": true
},
"tags": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"location": {
"type": "string",
"description": "Resource Location"
},
"name": {
"type": "string",
"description": "Resource Name",
"readOnly": true
}
}
},
"FlattenedProduct1": {
"type": "object",
"allOf": [{
"$ref": "#/definitions/Resource"
}],
"description": "Flattened product.",
"properties": {
"x-ms-client-name": "FlattenedProductProperties1",
"properties": {
"type": "object",
"x-ms-client-flatten": true,
"properties": {
"p.name": {
"type": "string",
"description": "I have dot in my name, that caused troubles in runtime at time for bad reasons"
}
}
}
}
},
"FlattenedProduct2": {
"type": "object",
"allOf": [{
"$ref": "#/definitions/Resource"
}],
"description": "Flattened product.",
"properties": {
"x-ms-client-name": "FlattenedProductProperties2",
"properties": {
"type": "object",
"x-ms-client-flatten": true,
"properties": {
"type": {
"description": "I'm called type, and I'm flattened, and my AllOf has a type too",
"type": "string"
}
}
}
}
},
"FlattenedProduct3": {
"type": "object",
"allOf": [{
"$ref": "#/definitions/Resource"
}],
"description": "Flattened product.",
"properties": {
"x-ms-client-name": "FlattenedProductProperties3",
"optional": {
"type": "object",
"x-ms-client-flatten": true,
"properties": {
"optional_too": {
"description": "I want to send {\"properties\":{}} which is ok, since both the flatten container and the flatten fields are optional",
"type": "string"
}
}
}
}
},
"FlattenedProduct4": {
"type": "object",
"allOf": [{
"$ref": "#/definitions/Resource"
}],
"description": "Flattened product.",
"properties": {
"x-ms-client-name": "FlattenedProductProperties4",
"properties": {
"type": "object",
"x-ms-client-flatten": true,
"properties": {
"single_field": {
"description": "I have twice addProp, so I can send {\"foo\": true, \"properties\": {\"bar\": true, \"single_field\": \"a string\"}}",
"type": "string"
}
},
"additionalProperties": {
"type": "object"
}
}
},
"additionalProperties": {
"type": "object"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment