Skip to content

Commit b33d572

Browse files
authored
fix: support exclusiveMinimum & exclusiveMaximum boolean values (#1609)
1 parent 61889ce commit b33d572

File tree

4 files changed

+95
-2
lines changed

4 files changed

+95
-2
lines changed

.changeset/rotten-parrots-draw.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'fets': patch
3+
---
4+
5+
Support `exclusiveMinimum` or `exclusiveMaximum` as booleans instead of numbers only

packages/fets/src/client/types.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,10 @@ export type OASModel<
242242
: never;
243243

244244
// Later suggest using json-machete
245-
export type FixJSONSchema<T> = FixAdditionalPropertiesForAllOf<
246-
FixMissingAdditionalProperties<FixMissingTypeObject<FixExtraRequiredFields<T>>>
245+
export type FixJSONSchema<T> = RemoveExclusiveMinimumAndMaximum<
246+
FixAdditionalPropertiesForAllOf<
247+
FixMissingAdditionalProperties<FixMissingTypeObject<FixExtraRequiredFields<T>>>
248+
>
247249
>;
248250

249251
type FixAdditionalPropertiesForAllOf<T> = T extends { allOf: any[] }
@@ -270,6 +272,14 @@ type FixExtraRequiredFields<T> = T extends {
270272
}
271273
: T;
272274

275+
// Currently boolean values for those two are not supported
276+
type RemoveExclusiveMinimumAndMaximum<T> = T extends {
277+
exclusiveMinimum?: boolean;
278+
exclusiveMaximum?: boolean;
279+
}
280+
? Omit<T, 'exclusiveMinimum' | 'exclusiveMaximum'>
281+
: T;
282+
273283
export type OASRequestParams<
274284
TOAS extends OpenAPIDocument,
275285
TPath extends keyof OASPathMap<TOAS>,
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { createClient, NormalizeOAS } from 'fets';
2+
import exampleExclusiveOas from './fixtures/example-exclusive-oas';
3+
4+
const client = createClient<NormalizeOAS<typeof exampleExclusiveOas>>({});
5+
6+
const res = await client['/minmaxtest'].post({
7+
json: {
8+
sequence: 1,
9+
},
10+
});
11+
12+
if (res.ok) {
13+
const successBody = await res.json();
14+
console.log(successBody.sequence);
15+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
export default {
2+
openapi: '3.0.3',
3+
info: {
4+
title: 'Minmaxtest',
5+
description: 'Minmaxtest',
6+
version: '0.1.0',
7+
},
8+
components: {
9+
securitySchemes: {
10+
basicAuth: {
11+
type: 'http',
12+
scheme: 'basic',
13+
},
14+
},
15+
schemas: {},
16+
},
17+
paths: {
18+
'/minmaxtest': {
19+
post: {
20+
requestBody: {
21+
content: {
22+
'application/json': {
23+
schema: {
24+
type: 'object',
25+
properties: {
26+
sequence: {
27+
type: 'integer',
28+
exclusiveMinimum: true,
29+
minimum: 0,
30+
},
31+
},
32+
required: ['sequence'],
33+
additionalProperties: false,
34+
},
35+
},
36+
},
37+
required: true,
38+
},
39+
responses: {
40+
'201': {
41+
description: 'Default Response',
42+
content: {
43+
'application/json': {
44+
schema: {
45+
type: 'object',
46+
properties: {
47+
sequence: {
48+
type: 'integer',
49+
exclusiveMinimum: true,
50+
minimum: 0,
51+
},
52+
},
53+
required: ['sequence'],
54+
additionalProperties: false,
55+
},
56+
},
57+
},
58+
},
59+
},
60+
},
61+
},
62+
},
63+
} as const;

0 commit comments

Comments
 (0)