2

Is that possible that I define a constant value in swagger?

eg:

constants:
    minAValue: 3

parameters:
    - name: value
      in: formData
      type: number
      minimum: constants.minAValue
desmondlee
  • 1,643
  • 4
  • 21
  • 33
  • 1
    Maybe, but I don't know how to do it. But if you're using YAML, you can use an alias. Add `&minAValue ` before the `3` and then later use `minimum: *minAValue` – tinita Jun 01 '18 at 12:57
  • Could you elaborate on what the use case here is? Do you want to reuse the same value in multiple places in the spec? – Helen Jun 01 '18 at 13:25
  • @Helen No, the constant in most of the case is not being reused. I just want to define constant value for any magic value like minimum, maximum integer, min, max length etc. so that in parameters or somewhere else i can define like `minimum: constant`. This is to ensure that it is easier for me to identify and change the value in the constant definition part only should there be any change in the requirement. What i need is global constant not global parameter. – desmondlee Jun 01 '18 at 13:30
  • The use case is that when i have requirement change on to change the minimum or maximum value validation i just need to see the constant section to change it instead of searching it through the long yaml file for the specific path in specific parameter. – desmondlee Jun 01 '18 at 13:35
  • Then it's pretty much what @tinita said. See [Use YAML with variables](https://stackoverflow.com/q/4150782/113116) for more examples. – Helen Jun 01 '18 at 15:45

0 Answers0