Create a Swagger 2.0 with a hard-coded value for body or for query param?

133 views Asked by At
 /test:
    post:
      consumes:
        - "application/json"
      parameters:
        - in: "body"
          name: "TestEntity"
          schema:
            $ref: "#/definitions/TestEntity"
      produces:
        - "application/json"
      responses:
        200:
          description: "200 response"
          schema:
            $ref: "#/definitions/TestEntity"
  /user/login:
    get:
      produces:
      - "application/json"
      parameters:
      - name: "username"
        in: "query"
        default: 'John Smith'
        required: true
        type: "string"


definitions:
 TestEntity:
    properties:
      address:
        type: string
        default: '1 street'
    required:
      - address

Hi, I have got this Swagger 2.0 config for path and TestEntity in definitions.

Can a value for address/username property be hardcoded explicitly? except using default option

I mean user mustn't specify this value, it should be set by Swagger itself.

1

There are 1 answers

0
tom redfern On BEST ANSWER

Can a value for address/username property be hardcoded explicitly?

No, you cannot hard code the value of schemas defined in swagger. Your options are:

it is ok to hardcode value for Header by using default option?

Yes it is fine to do that. For example,

  /user/login:
    get:
      parameters:
      - name: MyHeader
        in: header
        type: string
        default: 'some value'