4
votes

We are using swagger 2.0 to document our .Net Web API's which we are hosting in Azure behind Azure API Management. I am having troubles getting the documentation to detail the complex objects that are being posted as part of the body. Azure shows no details about the object at all leaving me to have to document them myself. Below is the json file that I imported into Azure API Management.

{
    "swagger": "2.0",
    "info": {
        "version": "1.0.0",
        "title": "Hotel Search",
        "description": "The seodecnvewjkl"
    },
    "basePath": "/v1",
    "consumes": [
        "application/xml",
        "application/json"
    ],
    "produces": [
        "application/xml",
        "application/json"
    ],
    "schemes": [
        "http",
        "https"
    ],
    "paths": {
        "/hotels/search": {
            "post": {
                "operationId": "searchCommand",
                "description": "Searches for hotels",
                "parameters": [
                    {
                        "name": "hotelSearchRq",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/HotelSearchRq"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Successful response",
                        "schema": {
                            "title": "HotelSearchRs",
                            "$ref": "#/definitions/HotelSearchRs"
                        }
                    },
                    "400": {
                        "description": "Bad Request"
                    },
                    "404": {
                        "description": "Unauthorised"
                    }
                }
            },
            "get": {
                "operationId": "searchQuery",
                "parameters": [
                    {
                        "name": "CorrelationId",
                        "in": "query",
                        "type": "string"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Successful response"
                    }
                }
            }
        }
    },
    "definitions": {
        "StayDetail": {
            "type": "object",
            "properties": {
                "NumberOfGuests": {
                    "type": "integer"
                },
                "CheckinDate": {
                    "type": "string",
                    "format": "date",
                    "description": "the date that the stay starts from"
                }
            }
        },
        "HotelSearchCriteria": {
            "type": "object",
            "properties": {
                "MaximumResults": {
                    "type": "integer",
                    "format": "int64"
                },
                "StayDetails": {
                    "$ref": "#/definitions/StayDetail"
                }
            }
        },
        "HotelSearchRq": {
            "type": "object",
            "properties": {
                "CustomerTransactionIdentifier": {
                    "type": "string",
                    "description": "The customers transaction identifier"
                },
                "search_criteria": {
                    "$ref": "#/definitions/HotelSearchCriteria"
                }
            }
        },
        "HotelSearchRs": {
            "type": "object"
        }
    }
}

Azure Api Management operation screen

Can someone please help me with how I can get the body documented automatically from the swagger documentation?

1
I know this feature has been worked on recently. Let me try and get you more information on when it will be available.Darrel Miller
Thanks for this Darrel, do you have any idea when it might be available? It is just that it would help us a lot because we are potentially going to have 40+ API's that we would need to document all the request and response bodies separately.John Sharland
Sorry I don't have any timeline for that. The feature that I had heard about was the ability to validate responses based on schema. If importing schema and example responses for display on the docs is important to you then might I suggest adding a suggestion to the feedback site feedback.azure.com/forums/248703-api-management Thanks.Darrel Miller
One additional comment though and feel free to take it or leave it. My experience with building APIs has led me to the conclusion that documenting structures that specific to a particular URL/request/response leads to a significant amount of duplication. Defining a vocabulary for your problem domain, the valid structures and relationships between their structures is a more precise way of describing your domain that can then be reused across many resources/APIs. e.g. github.com/darrelmiller/conference-talk/blob/master/…Darrel Miller
Disappointing to see that in 2017 that this is still not resolvedMicky

1 Answers

1
votes

Currently the request and response body information from a Swagger doc are not displayed in the developer portal documentation.

This is no longer the case. Samples and schema are displayed in the developer portal.