Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger: is it possible to make an operation parameter constant / readonly?

Tags:

swagger

This is the description of a certain parameter I have:

{
    "name": "myParam",
    "description": "My param description",
    "required": true,
    "paramType": "query",
    "type": "string",
    "defaultValue":"myValue"
}

The defaultValue is the only value the parameter can have, so is there a way to declare this? Seen in the context of the swagger-ui, I need the parameter's textbox to be read-only. I'm using swagger 1.2.

Thanks

like image 537
DeZot Avatar asked Sep 25 '14 13:09

DeZot


2 Answers

The proper way to declare this would be:

{
    "name": "myParam",
    "description": "My param description",
    "required": true,
    "paramType": "query",
    "type": "string",
    "enum": [ "myValue" ]
}

The "enum" property sets the possible values. Once you set a single value to it, that's the only one that could be used and that would be available in the UI for the user to choose from.

like image 152
Ron Avatar answered Nov 10 '22 21:11

Ron


I'm a bit late to the game but with OpenAPI 3.1 you can do the following:

defaultValue:
  type: string
  const:
   - myValue

like image 2
Gergo Avatar answered Nov 10 '22 21:11

Gergo