Forum Discussion

apires's avatar
apires
New Contributor
20 days ago

Validate different http codes using different requests to the same endpoint in OpenAPI 3

Hello,

I've been looking everywhere for a solution for this and couldn't find anything about it. What I'm trying to do is testing a single endpoint using different requests to trigger different HTTP code responses. I am making this test using an OpenAPI 3 yaml file.

So for instance: I'm testing HTTP code 200 response where I'm sending a valid requestBody. This is working fine, but I also want to write a test where the requestBody is invalid, and I get a 422 HTTP code back from the call to the endpoint.

openapi: 3.0.0
info:
  title: Local API 
  version: 0.0.1
paths:
  /api/v1/flows/:
    post:
      summary: Creates a new flow.
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - name
            example:
              name: Test
              description: Testing Simple Contract
              endpoint_name: test-test
              is_component: false
              data:
                nodes: []
                edges: []
                viewport:
                  x: 0
                  y: 0
                  zoom: 1
      responses:
        "201":
          description: Created flow object.
          content:
            application/json:
              schema:
                type: object
                properties:
                  description: 
                    type: string
                  icon: 
                    type: string
                  icon_bg_color: 
                    type: string
                  gradient: 
                    type: string
                  data: 
                    type: object
                  is_component: 
                    type: boolean
                  updated_at: 
                    type: string
                  webhook: 
                    type: boolean
                  endpoint_name: 
                    type: string
                  tags: 
                    type: object
                  id:
                    type: string
                  user_id:
                    type: string
                  folder_id:
                    type: string
              example:
                id: faedc59b-21ff-430b-96b9-237d591f41d5
                user_id: e6a2054c-c955-44ef-b227-cb3218857625
                folder_id: 5828ce69-225c-4c9b-bbd6-0210b3af9256
                name: Test
                description: Testing Simple Contract
                endpoint_name: test-test
                is_component: false
                data:
                  nodes: []
                  edges: []
                  viewport:
                    x: 0
                    y: 0
                    zoom: 1

Is this possible in any way without having to duplicate code?

No RepliesBe the first to reply