Skip to content

feat: add exclusiveMinimum and exclusiveMaximum#1843

Open
jefflembeck wants to merge 1 commit intolukeautry:masterfrom
jefflembeck:feat/exclusive-min-max
Open

feat: add exclusiveMinimum and exclusiveMaximum#1843
jefflembeck wants to merge 1 commit intolukeautry:masterfrom
jefflembeck:feat/exclusive-min-max

Conversation

@jefflembeck
Copy link
Copy Markdown
Contributor

Add @exclusiveMinimum and @exclusiveMaximum JSDoc annotations for strict inequality bounds (> / <), complementing @minimum/@maximum (>= / <=).

Spec output follows each OpenAPI version's JSON Schema draft:

  • Swagger 2.0 / OAS 3.0: boolean form (minimum: X, exclusiveMinimum: true)
  • OAS 3.1: numeric form (exclusiveMinimum: X)

When both @Minimum and @exclusiveMinimum are present, v2/v3.0 errors; v3.1 emits both.

Closes #1842

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?
  • Have you written unit tests?
  • Have you written unit tests that cover the negative cases (i.e.: if bad data is submitted, does the library respond properly)?
  • This PR is associated with an existing issue?

Closing issues

Put closes #XXXX (where XXXX is the issue number) in your comment to auto-close the issue that your PR fixes.

If this is a new feature submission:

Potential Problems With The Approach

  • @Minimum and @exclusiveMinimum (or @maximum/@exclusiveMaximum) cannot coexist in Swagger 2.0 and OAS 3.0
    because exclusiveMinimum is a boolean modifier on minimum in those spec versions. This PR throws at spec
    generation time if both are used together in 2.0/3.0. In OAS 3.1 they are independent numeric values and
    can coexist.
  • Runtime validation enforces both validators independently — there is no runtime conflict check for
    combining minimum + exclusiveMinimum, since the spec generators already prevent this for 2.0/3.0 and it's
    valid in 3.1.

Test plan

  • Unit tests (templateHelpers.spec.ts): 8 tests covering exclusiveMinimum and exclusiveMaximum for both
    integer and float validation — verifying values above the bound pass, and values equal to the bound are
    correctly rejected (the boundary condition for exclusive semantics).
  • Spec generation unit tests: Tests in definitions.spec.ts (Swagger 2.0), schemaDetails3.spec.ts (OAS 3.0),
    and schemaDetails31.spec.ts (OAS 3.1) verify correct schema output per spec version — boolean form for
    2.0/3.0, numeric form for 3.1 — and that combining @Minimum + @exclusiveMinimum throws in 2.0/3.0 but
    succeeds in 3.1.
  • Integration tests: All five server integration suites (express, hapi, koa, koa-no-additional,
    dynamic-controllers, openapi3-express) updated to validate that requests with
    exclusiveMinimum/exclusiveMaximum fields pass on valid input and return the correct error messages on
    boundary values.

@jefflembeck jefflembeck force-pushed the feat/exclusive-min-max branch 2 times, most recently from 2b27af7 to cadc882 Compare March 16, 2026 19:02
Add @exclusiveMinimum and @exclusiveMaximum JSDoc annotations for strict
inequality bounds (> / <), complementing @minimum/@maximum (>= / <=).

Spec output follows each OpenAPI version's JSON Schema draft:
- Swagger 2.0 / OAS 3.0: boolean form (minimum: X, exclusiveMinimum: true)
- OAS 3.1: numeric form (exclusiveMinimum: X)

When both @Minimum and @exclusiveMinimum are present, v2/v3.0 errors;
v3.1 emits both.

Closes lukeautry#1842
@jefflembeck jefflembeck force-pushed the feat/exclusive-min-max branch from cadc882 to 621264a Compare March 16, 2026 20:24
VannaDii added a commit to tsoa-next/tsoa-next that referenced this pull request Mar 22, 2026
This branch implements behavior derived from
lukeautry/tsoa#1843 in
https://github.com/VannaDii/tsoa-next.

Summary:
- add `@exclusiveMinimum` and `@exclusiveMaximum` support to validator
parsing
- enforce strict numeric bounds in runtime validation
- emit version-correct schema output for Swagger 2.0, OpenAPI 3.0, and
OpenAPI 3.1
- reject inclusive/exclusive conflicts for Swagger 2.0 and OpenAPI 3.0
while allowing coexistence in OpenAPI 3.1
- add metadata, schema, runtime, integration, and docs coverage

Tests:
- `npm run build` in `packages/runtime`
- `npm run build` in `packages/cli`
- `npm run prepare-test && npm run typecheck && npx mocha --require
ts-node/register --require tsconfig-paths/register
unit/swagger/templateHelpers.spec.ts
unit/swagger/exclusiveBounds.spec.ts`
- `npx mocha --require ts-node/register --require
tsconfig-paths/register
unit/swagger/definitionsGeneration/definitions.spec.ts
unit/swagger/schemaDetails3.spec.ts
unit/swagger/schemaDetails31.spec.ts`
- `npx mocha --require ts-node/register --require
tsconfig-paths/register integration/express-server.spec.ts
integration/koa-server.spec.ts integration/hapi-server.spec.ts
integration/dynamic-controllers-express-server.spec.ts
integration/openapi3-express.spec.ts
integration/koa-server-no-additional-allowed.spec.ts`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Support annotations (for validation and spec generation) for exclusiveMinimum/exclusiveMaximum

1 participant