1
votes

I'm trying to write a client to a large non Swagger-documented API and thought that writing the swagger.json for it and using AutoRest would be a good way to accomplish that. The case is that this API wraps each operation's response data into a larger object with control information, like this:

{
    "resp_code": "SUCCESS",
    "caller_ref": "2016111116233156169531",
    "server_ref": "2016111116233189512798",

    "data": {
        "id": "idstring",
        "name": "nameString",
        "address": "addressString",
        ...
        }
}

Where "data" in this case would be a "Client" definition for us. Is there a way to define the 200 OK response schema and the definitions in the swagger.json file so that AutoRest would map this "data" to a Client class?

1
with "Client definition" you mean that you already have a class definition for the "data" property? So you want AutoRest to use your definition instead of generating its own (which is the default behavior)? - olydis
No, @olydis, please see answer below, thanks for commenting, - lccarvalho

1 Answers

0
votes

In fact the answer is quite trivial, all I had to do is to write the "responses" object of the swagger file like this:

"responses": {
                "200": {
                    "description": "successful operation",
                    "schema": {
                        "type": "object",
                        "properties": {
                            "data": {
                                "$ref": "#/definitions/Client"
                            }
                        }                            
                    }
                }
            }

Besides creating the Client definition. AutoRest generates code that retrieves the "data" object, giving access to the Client within.