Search code examples
restapiyamlopenapiswaggerhub

how to set one value for few key's in YAML object


As far as I know there is no way to attach few keys to the single value in {key : value} pair in YAML. I am new to Swagger documentation (OpenAPI 3.0) and wondering is it possible somehow to combine my values together. For instance, I am messing with REST API documentation and when I want to list few responses without rewriting it every time, I have the following :

paths:
  /users:
      post:
//some additional information here
        responses:
          '500':
//and for example here I want to add not only 201 status code but also others
                description: >-
                  Something went wrong on back end
//however I have to do something like this (writing them all)
          '502':
                description: >-
                  Something went wrong on back end
//and so on..

What is best practices to overcome that? Maybe I have a bad point from the beginning.


Solution

  • You can use anchors and aliases:

    path:
      /users:
        responses:
          '500':
            description: &desc1 >-
              Something went wrong on back end
          '502':
            description: *desc1