1

I have the following model definitions in an OpenAPI/Swagger spec:

"definitions": {
    "models.Equipment": {
        "title": "Equipment",
        "type": "object",
        "properties": {
            "Features": {
                "type": "array",
                "items": {
                    "$ref": "#/definitions/models.Feature"
                }
            },
            "Id": {
                "type": "integer",
                "format": "int64"
            },
            "IdType": {
                "type": "string"
            },
            "Name": {
                "type": "string"
            },
            "Price": {
                "type": "integer",
                "format": "int32"
            }
        }
    },
    "models.Feature": {
        "title": "Feature",
        "type": "object",
        "properties": {
            "Equipments": {
                "type": "array",
                "items": {
                    "$ref": "#/definitions/models.Equipment"
                }
            },
            "Id": {
                "type": "integer",
                "format": "int64"
            },
            "IdFeature": {
                "$ref": "#/definitions/models.Feature"
            },
            "Name": {
                "type": "string"
            }
        }
    }
}

In the Feature model, he Equipments property is defined as an array of Equipment models, but Swagger UI 3.x renders it as an empty array []. Everywhere Feature model is used, like as examples for POST method in Feature I have this kind of display.

swagger-ui bug

Is the definition incorrect in some way?

The complete spec is here:
https://dl.dropboxusercontent.com/s/anjfhgxhr0pfmnu/swagger-bug.json

1 Answer 1

1

This seems to be a bug in Swagger UI and is most likely caused by circular references in your models - models.Equipment references models.Feature, and models.Feature references models.Equipment. You can open an issue in the Swagger UI repository on GitHub.


Your spec also contains errors in the response definitions:

        "responses": {
            "200": {
                "schema": {
                    "$ref": "#/definitions/models.Equipment"
                }
            },
            "403": {}
        }

Each response must have a description, so the correct version would be:

        "responses": {
            "200": {
                "description": "OK",
                "schema": {
                    "$ref": "#/definitions/models.Equipment"
                }
            },
            "403": {
                "description": "Oops"
            }
        }
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much for rephrasing everything, I have been very lazy about this question, sorry for that. Thank you again for spotting the error! :) Here is the issue I reported: github.com/swagger-api/swagger-ui/issues/3325

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.