Skip to content

Commit 464ff4a

Browse files
authored
Merge pull request #2081 from hey-api/fix/parser-3-1-0-exclusive-limits
fix(parser): handle exclusiveMinimum and exclusiveMaximum in OpenAPI 3.1.x when they're 0
2 parents 86844c6 + 4c076ee commit 464ff4a

File tree

10 files changed

+20
-36
lines changed

10 files changed

+20
-36
lines changed

.changeset/hip-crabs-help.md

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ feat: upgraded input filters
88

99
Input filters now avoid generating invalid output without requiring you to specify every missing schema as in the previous releases. As part of this release, we changed the way filters are configured and removed the support for regular expressions. Let us know if regular expressions are still useful for you and want to bring them back!
1010

11-
::: code-group
12-
13-
```js [include]
11+
```js
1412
export default {
1513
input: {
1614
// match only the schema named `foo` and `GET` operation for the `/api/v1/foo` path
@@ -29,25 +27,3 @@ export default {
2927
plugins: ['@hey-api/client-fetch'],
3028
};
3129
```
32-
33-
```js [exclude]
34-
export default {
35-
input: {
36-
// match everything except for the schema named `foo` and `GET` operation for the `/api/v1/foo` path
37-
exclude: '^(#/components/schemas/foo|#/paths/api/v1/foo/get)$', // [!code --]
38-
filters: {
39-
operations: {
40-
exclude: ['GET /api/v1/foo'], // [!code ++]
41-
},
42-
schemas: {
43-
exclude: ['foo'], // [!code ++]
44-
},
45-
},
46-
path: 'https://get.heyapi.dev/hey-api/backend',
47-
},
48-
output: 'src/client',
49-
plugins: ['@hey-api/client-fetch'],
50-
};
51-
```
52-
53-
:::

.changeset/moody-socks-develop.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hey-api/openapi-ts': patch
3+
---
4+
5+
fix(parser): handle exclusiveMinimum and exclusiveMaximum in OpenAPI 3.1.x when they're 0

packages/openapi-ts-tests/test/__snapshots__/3.0.x/validators/valibot.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const vFoo: v.GenericSchema = v.optional(v.union([
1515
baz: v.optional(v.array(v.lazy(() => {
1616
return vFoo;
1717
}))),
18-
qux: v.optional(v.number(), 0)
18+
qux: v.optional(v.pipe(v.number(), v.integer(), v.gtValue(0)), 0)
1919
}),
2020
v.null()
2121
]), null);

packages/openapi-ts-tests/test/__snapshots__/3.0.x/validators/zod.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const zFoo: z.ZodTypeAny = z.union([
1515
baz: z.array(z.lazy(() => {
1616
return zFoo;
1717
})).optional(),
18-
qux: z.number().optional().default(0)
18+
qux: z.number().int().gt(0).optional().default(0)
1919
}),
2020
z.null()
2121
]).default(null);

packages/openapi-ts-tests/test/__snapshots__/3.1.x/validators/valibot.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const vFoo: v.GenericSchema = v.optional(v.union([
1515
baz: v.optional(v.array(v.lazy(() => {
1616
return vFoo;
1717
}))),
18-
qux: v.optional(v.number(), 0)
18+
qux: v.optional(v.pipe(v.number(), v.integer(), v.gtValue(0)), 0)
1919
}),
2020
v.null()
2121
]), null);

packages/openapi-ts-tests/test/__snapshots__/3.1.x/validators/zod.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const zFoo: z.ZodTypeAny = z.union([
1515
baz: z.array(z.lazy(() => {
1616
return zFoo;
1717
})).optional(),
18-
qux: z.number().optional().default(0)
18+
qux: z.number().int().gt(0).optional().default(0)
1919
}),
2020
z.null()
2121
]).default(null);

packages/openapi-ts-tests/test/openapi-ts.config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ export default defineConfig(() => {
2222
// },
2323
// },
2424
filters: {
25-
deprecated: false,
25+
// deprecated: false,
2626
// operations: {
2727
// include: ['POST /foo'],
2828
// },
29-
orphans: false,
29+
// orphans: false,
3030
// preserveOrder: true,
3131
// tags: {
3232
// exclude: ['bar'],
@@ -41,7 +41,7 @@ export default defineConfig(() => {
4141
// openapi: '3.1.0',
4242
// paths: {},
4343
// },
44-
path: path.resolve(__dirname, 'spec', '3.1.x', 'full.json'),
44+
path: path.resolve(__dirname, 'spec', '3.1.x', 'validators.json'),
4545
// path: 'http://localhost:4000/',
4646
// path: 'https://get.heyapi.dev/',
4747
// path: 'https://get.heyapi.dev/hey-api/backend?branch=main&version=1.0.0',

packages/openapi-ts-tests/test/spec/3.0.x/validators.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
},
2626
"qux": {
2727
"default": 0,
28-
"type": "number"
28+
"exclusiveMinimum": true,
29+
"minimum": 0,
30+
"type": "integer"
2931
}
3032
},
3133
"type": "object"

packages/openapi-ts-tests/test/spec/3.1.x/validators.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
},
2525
"qux": {
2626
"default": 0,
27-
"type": "number"
27+
"exclusiveMinimum": 0,
28+
"type": "integer"
2829
}
2930
},
3031
"type": ["object", "null"]

packages/openapi-ts/src/openApi/3.1.x/parser/schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ const parseSchemaMeta = ({
8888
irSchema.default = schema.default;
8989
}
9090

91-
if (schema.exclusiveMaximum) {
91+
if (schema.exclusiveMaximum !== undefined) {
9292
irSchema.exclusiveMaximum = schema.exclusiveMaximum;
9393
}
9494

95-
if (schema.exclusiveMinimum) {
95+
if (schema.exclusiveMinimum !== undefined) {
9696
irSchema.exclusiveMinimum = schema.exclusiveMinimum;
9797
}
9898

0 commit comments

Comments
 (0)