Forum Discussion

apires's avatar
apires
New Contributor
19 days ago
Solved

Validating endpoint response by types

I am making a test call to an endpoint that returns a JSON object using OpenAPI 3.0 definitions. The thing is, the comparison is being made between a valid JSON response, with data that varies, and an empty JSON generated by my yaml file definition.

I was wondering if there's a way to create my schemas in a way that I'm not validating the exact property values that are being returned, but just their type.

These are my yaml definitions:

openapi: 3.0.0
info:
  title: RESTful Flows
  version: 0.0.1
servers:
  - url: http://localhost:7860
    description: Local development environment
paths:
  /api/v1/flows/:
    post:
      summary: Creates a new flow.
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
            example:
              name: Flow
      responses:
        "201":
          description: Created flow object.
          content:
            application/json:
              schema:
                type: object
                properties:
                  name: 
                    type: string
                  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

Generated JSON response body:

{
  "name": "",
  "description": "",
  "icon": "",
  "icon_bg_color": "",
  "gradient": "",
  "data": {},
  "is_component": false,
  "updated_at": "",
  "webhook": false,
  "endpoint_name": "",
  "tags": {}
}

Actual JSON response body from server:

{
  "name": "Flow (7)",
  "description": null,
  "icon": null,
  "icon_bg_color": null,
  "gradient": null,
  "data": null,
  "is_component": false,
  "updated_at": "2025-01-20T16:11:13+00:00",
  "webhook": false,
  "endpoint_name": null,
  "tags": null,
  "id": "faedc59b-21ff-430b-96b9-237d591f41d5",
  "user_id": "e6a2054c-c955-44ef-b227-cb3218857625",
  "folder_id": "5828ce69-225c-4c9b-bbd6-0210b3af9256"
}
  • This has been solved by adding a valid example section to the response.

  • apires's avatar
    apires
    New Contributor

    This has been solved by adding a valid example section to the response.