Skip to content

Commit 226e820

Browse files
authored
Merge pull request #2287 from MaxwellAt/fix/allof-additionalProperties-false
Fix/allof additional properties false
2 parents 4067da8 + 6df1237 commit 226e820

File tree

42 files changed

+841
-424
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+841
-424
lines changed

.changeset/sweet-swans-shout.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(zod): improve handling of additional properties

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
packages/openapi-ts/README.md
1+
packages/openapi-ts/README.md

packages/openapi-ts-tests/main/test/2.0.x.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ describe(`OpenAPI ${version}`, () => {
4444
};
4545

4646
const scenarios = [
47+
{
48+
config: createConfig({
49+
input: 'additional-properties-false.json',
50+
output: 'additional-properties-false',
51+
}),
52+
description: 'forbids arbitrary properties on objects',
53+
},
4754
{
4855
config: createConfig({
4956
input: 'additional-properties-true.json',
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
export * from './types.gen';
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
export type Foo = {
4+
foo: string;
5+
};
6+
7+
export type Bar = Foo & {};
8+
9+
export type Baz = Foo & {
10+
bar: string;
11+
};
12+
13+
export type ClientOptions = {
14+
baseUrl: string;
15+
};

packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/additional-properties-false/types.gen.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ export type Foo = {
44
foo: string;
55
};
66

7-
export type Bar = Foo & {
8-
[key: string]: never;
9-
};
7+
export type Bar = Foo & {};
108

119
export type Baz = Foo & {
1210
bar: string;

packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/additional-properties-false/types.gen.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ export type Foo = {
44
foo: string;
55
};
66

7-
export type Bar = Foo & {
8-
[key: string]: never;
9-
};
7+
export type Bar = Foo & {};
108

119
export type Baz = Foo & {
1210
bar: string;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"swagger": "2.0",
3+
"info": {
4+
"title": "OpenAPI 2.0 additional properties false example",
5+
"version": "1"
6+
},
7+
"definitions": {
8+
"Foo": {
9+
"required": ["foo"],
10+
"type": "object",
11+
"properties": {
12+
"foo": {
13+
"type": "string"
14+
}
15+
},
16+
"additionalProperties": false
17+
},
18+
"Bar": {
19+
"allOf": [
20+
{
21+
"$ref": "#/definitions/Foo"
22+
},
23+
{
24+
"type": "object",
25+
"additionalProperties": false
26+
}
27+
]
28+
},
29+
"Baz": {
30+
"allOf": [
31+
{
32+
"$ref": "#/definitions/Foo"
33+
},
34+
{
35+
"required": ["bar"],
36+
"type": "object",
37+
"properties": {
38+
"bar": {
39+
"type": "string"
40+
}
41+
},
42+
"additionalProperties": false
43+
}
44+
]
45+
}
46+
}
47+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
export * from './types.gen';
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
export type Foo = {
4+
foo: string;
5+
};
6+
7+
export type Bar = Foo & {};
8+
9+
export type Baz = Foo & {
10+
bar: string;
11+
};
12+
13+
export type ClientOptions = {
14+
baseUrl: string;
15+
};

0 commit comments

Comments
 (0)