Swagger-ui: Definitions default value not working

Created on 19 Oct 2014  路  12Comments  路  Source: swagger-api/swagger-ui

I expect default means model click in try out will insert model JSON with default value

Most helpful comment

it works with "example" in pet store

but there is "default" in spec

or i misunderstood ?

All 12 comments

sample spec

"definitions": {
        "Menu": {
            "properties": {
                "menuId": {
                    "type": "string"
                },
                "partId": {
                    "type": "string"
                },
                "menuName": {
                    "type": "string"
                }
            }
        },
        "Part": {
            "properties": {
                "partId": {
                    "type": "string"
                },
                "partName": {
                    "type": "string"
                },
                "moduleId": {
                    "type": "string"
                },
                "menus": {
                    "type": "array",
                    "items": {
                        "$ref": "Menu"
                    }
                }
            }
        },
        "Module": {
            "required":[  
                "moduleId"
            ],
            "properties": {
                "moduleId": {
                    "type": "string",
                    "required" :true,
                    "description": "Unique identifire for the Module"
                },
                "moduleName": {
                    "type": "string"
                },
                "moduleVersion": {
                    "type": "string"
                },
                "moduleState": {
                    "type": "string",
                    "default": "",
                    "enum":[  
                        "STOPED",
                        "STARTED",
                        "DISABLED"
                    ]
                },
                "moduleDescription": {
                    "type": "string"
                },
                "moduleUrl": {
                    "type": "string"
                },
                "moduleIconUrl": {
                    "type": "string"
                },
                "moduleInfoUrl": {                    
                    "type": "string"                    
                },
                "parts": {
                    "type": "array",
                    "items": {
                        "$ref": "Part"
                    }
                }
            }
        }

Yes, currently the example value will be copied into the model JSON, as you'll see here:

http://petstore.swagger.wordnik.com/ui/#!/pet/addPet

But default should as well.

But dose not :)

correct. It _should_. This is a bug.

I've opened this:

https://github.com/wordnik/swagger-js/issues/151

If you can submit bugs with more detail like that, it'll help get them resolved faster.

it works with "example" in pet store

but there is "default" in spec

or i misunderstood ?

no, you are correct. Per the bug in swagger-js, it is a defect.

Thanks for immediate responses.

I appreciate very much.

I updated by default not working anyway.

maybe it has problem with enum ?

here is full spec

{
    "swagger": 2,
    "info": {
        "title": "#Module managment API",
        "description": "#Beta version of API ##xxx",
        "version": "1.0.0"
    },
    "host": "localhost:7777/eflow-manager",
    "schemes": [
        "http"
    ],
    "basePath": "/rest",
    "produces": [
        "application/json"
    ],
    "paths": {
        "/part/list": {
            "get": {
                "summary": "List of parts",
                "description": "Returns information about Parts.",
                "tags": [
                    "Parts"
                ],
                "responses": {
                    "200": {
                        "description": "An array of parts",
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "Part"
                            }
                        }
                    }
                }
            }
        },
        "/part/add": {
            "post": {
                "summary": "Add part",
                "description": "Add part information.",
                "tags": [
                    "Parts"
                ],
                "parameters": [
                    {
                        "name": "part",
                        "in": "body",
                        "description": "The Part JSON you want to post",
                        "schema": {
                            "$ref": "Part"
                        },
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                    }
                }
            }
        },


        "/menu/list": {
            "get": {
                "summary": "List of Menu items",
                "description": "Returns information about Menu.",
                "tags": [
                    "Menu"
                ],
                "responses": {
                    "200": {
                        "description": "An array of Menu items",
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "Menu"
                            }
                        }
                    }
                }
            }
        },
        "/menu/add": {
            "post": {
                "summary": "Add menu item",
                "description": "Add Menu item information.",
                "tags": [
                    "Menu"
                ],
                "parameters": [
                    {
                        "name": "menu",
                        "in": "body",
                        "description": "The Menu item JSON you want to post",
                        "schema": {
                            "$ref": "Menu"
                        },
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                    }
                }
            }
        },


        "/module/get": {
            "get": {
                "summary": "Get module information",
                "description": "Get module information.",
                "tags": [
                    "Modules"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "query",
                        "description": "ID of module",
                        "type": "string",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Result of operation.",
                        "schema": {
                            "$ref": "Module"
                        }
                    }
                }
            }
        },
        "/module/remove": {
            "get": {
                "summary": "Remove module",
                "description": "Remove module.",
                "tags": [
                    "Modules"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "query",
                        "description": "ID of module",
                        "type": "string",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Result of operation.",
                        "schema": {
                            "type": "string"
                        }
                    }
                }
            }
        },
        "/module/disable": {
            "get": {
                "summary": "Disable module",
                "description": "Disable module.",
                "tags": [
                    "Modules"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "query",
                        "description": "ID of module",
                        "type": "string",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Result of operation.",
                        "schema": {
                            "type": "string"
                        }
                    }
                }
            }
        },
        "/module/enable": {
            "get": {
                "summary": "Enable module",
                "description": "Enable module.",
                "tags": [
                    "Modules"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "query",
                        "description": "ID of module",
                        "type": "string",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Result of operation.",
                        "schema": {
                            "type": "string"
                        }
                    }
                }
            }
        },
        "/module/addUrl": {
            "get": {
                "summary": "Add module from URL",
                "description": "Add module from URL.",
                "tags": [
                    "Modules"
                ],
                "parameters": [
                    {
                        "name": "url",
                        "in": "query",
                        "description": "URL of module",
                        "type": "string",
                        "required": true
                    },{
                        "name": "info",
                        "in": "query",
                        "description": "Relative path to info rest service",
                        "type": "string",
                        "required": false
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Result of operation.",
                        "type": "string"
                    }
                }
            }
        },        
        "/module/add": {
            "post": {
                "summary": "Add module",
                "description": "Add module information.",
                "tags": [
                    "Modules"
                ],
                "parameters": [
                    {
                        "name": "module",
                        "in": "body",
                        "description": "The module JSON you want to post",
                        "schema": {
                            "$ref": "Module"
                        },
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Result of operation.",
                        "schema": {
                            "type": "string"
                        }
                    }
                }
            }
        },
        "/module/list": {
            "get": {
                "summary": "List of modules",
                "description": "Returns information about Modules.",
                "tags": [
                    "Modules"
                ],
                "responses": {
                    "200": {
                        "description": "An array of modules",
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "Module"
                            }
                        }
                    }
                }
            }
        },
        "/module/listAll": {
            "get": {
                "summary": "List of modules",
                "description": "Returns information about Modules.",
                "tags": [
                    "Modules"
                ],
                "responses": {
                    "200": {
                        "description": "An array of modules",
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "Module"
                            }
                        }
                    }
                }
            }
        }
    },
    "definitions": {
        "Menu": {
            "properties": {
                "menuId": {
                    "type": "string"
                },
                "partId": {
                    "type": "string"
                },
                "menuName": {
                    "type": "string"
                }
            }
        },
        "Part": {
            "properties": {
                "partId": {
                    "type": "string"
                },
                "partName": {
                    "type": "string"
                },
                "moduleId": {
                    "type": "string"
                },
                "menus": {
                    "type": "array",
                    "items": {
                        "$ref": "Menu"
                    }
                }
            }
        },
        "Module": {
            "required":[  
                "moduleId"
            ],
            "properties": {
                "moduleId": {
                    "type": "string",
                    "required" :true,
                    "description": "Unique identifire for the Module"
                },
                "moduleName": {
                    "type": "string"
                },
                "moduleVersion": {
                    "type": "string"
                },
                "moduleState": {
                    "type": "string",
                    "default": "",
                    "enum":[  
                        "STOPED",
                        "STARTED",
                        "DISABLED"
                    ]
                },
                "moduleDescription": {
                    "type": "string"
                },
                "moduleUrl": {
                    "type": "string"
                },
                "moduleIconUrl": {
                    "type": "string"
                },
                "moduleInfoUrl": {                    
                    "type": "string"                    
                },
                "parts": {
                    "type": "array",
                    "items": {
                        "$ref": "Part"
                    }
                }
            }
        }
    }
}

you have default value of "" with an enum. You can verify that this works by setting the default to "foo" and seeing that the model json is updated appropriately.

Listing the enums has not been done yet.

It works

Thanks a lot

Was this page helpful?
0 / 5 - 0 ratings

Related issues

peter004 picture peter004  路  49Comments

replaysMike picture replaysMike  路  120Comments

reginaldlouis picture reginaldlouis  路  43Comments

dalbani picture dalbani  路  42Comments

valdemon picture valdemon  路  37Comments