Skip to content

Definition Tests

Omar del Valle edited this page Jun 10, 2019 · 11 revisions

Testing your Swagger 2.0 API definition

Run tests:

driven-swagger-test ./swagger.yaml

Examples in test folder

Testing GET methods

√  Should be contain (200,202,206) response.
√  Should be contain consumes (accept) definition.

Testing POST methods

√  Should be contain (200,201,202,204,206) response.
√  Should be contain (400) response.
√  Should be contain produces (content-type) definition.

Testing PUT/PATCH methods

√  Should be contain (200,202,204,206) response.
√  Should be contain (400) response.
√  Should be contain produces (content-type) definition.

Testing DELETE methods

√  Should be contain (200,202,204) response.
√  Should be contain produces (content-type) definition.

Testing Parameters

√  Parameter distinct of type string, in PATH or QUERY, should be contain bad request (400) response.
√  Enum parameters in PATH or QUERY, should be contain bad request (400) response.
√  Parameters required in PATH or QUERY, should be contain not found (404) response.
√  (Warning) Parameters required in QUERY, maybe should be change to 'in: path' definition.
√  Query string parameter [PARAM-NAME] should be lower case.

Special case x-pm-test-ignore404

What would happend if you define GET /pet/findByStatus?status=pending and don't have results?

  • Do you prefer to return 404? (default)
  • Do you prefer to return 200 and an empty array? (use x-pm-test-ignore404: true in swagger)
/pet/findByStatus:
  get:
    x-pm-test-ignore404: true
    tags:
    - "pet"
    summary: "Finds Pets by status"
    description: "Multiple status values can be provided with comma separated strings"
    operationId: "findPetsByStatus"
    consumes:
    - "application/json"
    parameters:
    - name: "status"
      in: "query"
      description: "Status values that need to be considered for filter"
      required: true
      type: "array"
      items:
        type: "string"
        enum:
        - "available"
        - "pending"
        - "sold"

Testing Security definitions

√  Security definition, should be contain (401) response.