Skip to content
Compare
Choose a tag to compare
@github-actions github-actions released this 05 Mar 19:31
· 21 commits to master since this release
3359aeb

@api-ts/openapi-generator 5.7.0 (2025-03-05)

Features

  • Output boolean query parameters as booleans instead of string enums (#1017)

    This feature update changes how boolean parameters are represented in the OpenAPI specification generated by api-ts. Previously, boolean values in query parameters were represented as string enums with values "true" and "false". With this change, they are now represented as native OpenAPI boolean types.

    Concretely, this httpRoute:

    import * as t from 'io-ts';
    import * as h from '@api-ts/io-ts-http';
    import { BooleanFromString } from 'io-ts-types';
    
    export const route = h.httpRoute({
      path: '/resources',
      method: 'GET',
      request: h.httpRequest({
        query: {
          // Boolean parameters
          isActive: BooleanFromString,
          includeDeleted: BooleanFromString,
          // Mixed boolean/number union
          filterOption: t.union([BooleanFromString, t.number])
        }
      }),
      response: {
        200: t.type({
          results: t.array(t.string),
          pagination: t.type({
            hasMore: t.boolean
          })
        })
      }
    });

    now generates the following OpenAPI specification:

    {
      "openapi": "3.0.3",
      "paths": {
        "/resources": {
          "get": {
            "parameters": [
              {
                "name": "isActive",
                "in": "query",
                "required": true,
                "schema": {
    -              "type": "string",
    -              "enum": ["true", "false"]
    +              "type": "boolean"
                }
              },
              {
                "name": "includeDeleted",
                "in": "query",
                "required": true,
                "schema": {
    -              "type": "string",
    -              "enum": ["true", "false"]
    +              "type": "boolean"
                }
              },
              {
                "name": "filterOption",
                "in": "query",
                "required": true,
                "schema": {
                  "oneOf": [
    -                { "type": "string", "enum": ["true", "false"] },
    +                { "type": "boolean" },
                    { "type": "number" }
                  ]
                }
              }
            ],
            "responses": {
              "200": {
                "description": "OK",
                "content": {
                  "application/json": {
                    "schema": {
                      "type": "object",
                      "properties": {
                        "results": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        },
                        "pagination": {
                          "type": "object",
                          "properties": {
                            "hasMore": {
                              "type": "boolean"
                            }
                          },
                          "required": ["hasMore"]
                        }
                      },
                      "required": ["results", "pagination"]
                    }
                  }
                }
              }
            }
          }
        }
      }
    }

    This update aligns with OpenAPI best practices by using native types rather than string-based enumerations for boolean query parameters in API specifications.