Skip to content

Commit 2472e51

Browse files
authored
Merge pull request #2530 from hey-api/fix(transformer)--Split-schemas-with-readOnly-or-writeOnly-properties
Fix(transformer): Fix readWrite transformer splitting logic
2 parents 2204900 + 7a8b34a commit 2472e51

File tree

127 files changed

+4847
-23397
lines changed

Some content is hidden

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

127 files changed

+4847
-23397
lines changed

.changeset/tender-files-check.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): improve `readWrite` transformer splitting logic

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/schemas/default/schemas.gen.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,4 +668,73 @@ export const failure_FailureSchema = {
668668
type: 'string'
669669
}
670670
}
671+
} as const;
672+
673+
export const ModelWithPropertiesWritableSchema = {
674+
description: 'This is a model with one nested property',
675+
type: 'object',
676+
required: ['required', 'requiredAndReadOnly'],
677+
properties: {
678+
required: {
679+
type: 'string'
680+
},
681+
string: {
682+
type: 'string'
683+
},
684+
number: {
685+
type: 'number'
686+
},
687+
boolean: {
688+
type: 'boolean'
689+
},
690+
reference: {
691+
'$ref': '#/definitions/ModelWithString'
692+
},
693+
'property with space': {
694+
type: 'string'
695+
},
696+
default: {
697+
type: 'string'
698+
},
699+
try: {
700+
type: 'string'
701+
}
702+
}
703+
} as const;
704+
705+
export const ModelWithPatternWritableSchema = {
706+
description: 'This is a model that contains a some patterns',
707+
type: 'object',
708+
required: ['key', 'name'],
709+
properties: {
710+
key: {
711+
maxLength: 64,
712+
pattern: '^[a-zA-Z0-9_]*$',
713+
type: 'string'
714+
},
715+
name: {
716+
maxLength: 255,
717+
type: 'string'
718+
},
719+
id: {
720+
type: 'string',
721+
pattern: '^\\d{2}-\\d{3}-\\d{4}$'
722+
},
723+
text: {
724+
type: 'string',
725+
pattern: '^\\w+$'
726+
},
727+
patternWithSingleQuotes: {
728+
type: 'string',
729+
pattern: "^[a-zA-Z0-9']*$"
730+
},
731+
patternWithNewline: {
732+
type: 'string',
733+
pattern: 'aaa\\nbbb'
734+
},
735+
patternWithBacktick: {
736+
type: 'string',
737+
pattern: 'aaa`bbb'
738+
}
739+
}
671740
} as const;

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/default/types.gen.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,33 @@ export type FailureFailure = {
406406
reference_code?: string;
407407
};
408408

409+
/**
410+
* This is a model with one nested property
411+
*/
412+
export type ModelWithPropertiesWritable = {
413+
required: string;
414+
string?: string;
415+
number?: number;
416+
boolean?: boolean;
417+
reference?: ModelWithString;
418+
'property with space'?: string;
419+
default?: string;
420+
try?: string;
421+
};
422+
423+
/**
424+
* This is a model that contains a some patterns
425+
*/
426+
export type ModelWithPatternWritable = {
427+
key: string;
428+
name: string;
429+
id?: string;
430+
text?: string;
431+
patternWithSingleQuotes?: string;
432+
patternWithNewline?: string;
433+
patternWithBacktick?: string;
434+
};
435+
409436
export type ServiceWithEmptyTagData = {
410437
body?: never;
411438
path?: never;

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/throwOnError/types.gen.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,33 @@ export type FailureFailure = {
406406
reference_code?: string;
407407
};
408408

409+
/**
410+
* This is a model with one nested property
411+
*/
412+
export type ModelWithPropertiesWritable = {
413+
required: string;
414+
string?: string;
415+
number?: number;
416+
boolean?: boolean;
417+
reference?: ModelWithString;
418+
'property with space'?: string;
419+
default?: string;
420+
try?: string;
421+
};
422+
423+
/**
424+
* This is a model that contains a some patterns
425+
*/
426+
export type ModelWithPatternWritable = {
427+
key: string;
428+
name: string;
429+
id?: string;
430+
text?: string;
431+
patternWithSingleQuotes?: string;
432+
patternWithNewline?: string;
433+
patternWithBacktick?: string;
434+
};
435+
409436
export type ServiceWithEmptyTagData = {
410437
body?: never;
411438
path?: never;

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/typescript/transforms-read-write-custom-name/types.gen.ts

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
// This file is auto-generated by @hey-api/openapi-ts
22

3-
export type FooRead = BarRead & {
4-
readonly foo?: string;
5-
};
6-
7-
export type BarRead = Baz & {
8-
readonly bar?: string;
9-
};
10-
113
export type Baz = {
124
baz?: string;
135
};
@@ -16,20 +8,40 @@ export type QuxAllRead = {
168
readonly baz?: string;
179
};
1810

19-
export type Quux = {
11+
export type ReadableFooRead = ReadableBarRead & {
12+
readonly foo?: string;
13+
};
14+
15+
export type WritableFooRead = WritableBarRead;
16+
17+
export type ReadableBarRead = Baz & {
18+
readonly bar?: string;
19+
};
20+
21+
export type WritableBarRead = Baz;
22+
23+
export type ReadableQuux = {
2024
baz?: Array<Baz>;
2125
qux?: QuxAllRead;
2226
};
2327

24-
export type Corge = {
28+
export type WritableQuux = {
29+
baz?: Array<Baz>;
30+
};
31+
32+
export type ReadableCorge = {
2533
foo?: string;
2634
bar?: {
2735
readonly baz?: boolean;
2836
};
2937
};
3038

39+
export type WritableCorge = {
40+
foo?: string;
41+
};
42+
3143
export type PostFooReadData = {
32-
body: FooRead;
44+
body: WritableFooRead;
3345
path?: never;
3446
query?: never;
3547
url: '/foo-read';
@@ -39,7 +51,7 @@ export type PostFooReadResponses = {
3951
/**
4052
* OK
4153
*/
42-
200: FooRead;
54+
200: ReadableFooRead;
4355
};
4456

4557
export type PostFooReadResponse = PostFooReadResponses[keyof PostFooReadResponses];

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@pinia/colada/fetch/types.gen.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,33 @@ export type FailureFailure = {
406406
reference_code?: string;
407407
};
408408

409+
/**
410+
* This is a model with one nested property
411+
*/
412+
export type ModelWithPropertiesWritable = {
413+
required: string;
414+
string?: string;
415+
number?: number;
416+
boolean?: boolean;
417+
reference?: ModelWithString;
418+
'property with space'?: string;
419+
default?: string;
420+
try?: string;
421+
};
422+
423+
/**
424+
* This is a model that contains a some patterns
425+
*/
426+
export type ModelWithPatternWritable = {
427+
key: string;
428+
name: string;
429+
id?: string;
430+
text?: string;
431+
patternWithSingleQuotes?: string;
432+
patternWithNewline?: string;
433+
patternWithBacktick?: string;
434+
};
435+
409436
export type ServiceWithEmptyTagData = {
410437
body?: never;
411438
path?: never;

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@pinia/colada/group-by-tag/types.gen.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,33 @@ export type FailureFailure = {
406406
reference_code?: string;
407407
};
408408

409+
/**
410+
* This is a model with one nested property
411+
*/
412+
export type ModelWithPropertiesWritable = {
413+
required: string;
414+
string?: string;
415+
number?: number;
416+
boolean?: boolean;
417+
reference?: ModelWithString;
418+
'property with space'?: string;
419+
default?: string;
420+
try?: string;
421+
};
422+
423+
/**
424+
* This is a model that contains a some patterns
425+
*/
426+
export type ModelWithPatternWritable = {
427+
key: string;
428+
name: string;
429+
id?: string;
430+
text?: string;
431+
patternWithSingleQuotes?: string;
432+
patternWithNewline?: string;
433+
patternWithBacktick?: string;
434+
};
435+
409436
export type ServiceWithEmptyTagData = {
410437
body?: never;
411438
path?: never;

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/axios/types.gen.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,33 @@ export type FailureFailure = {
406406
reference_code?: string;
407407
};
408408

409+
/**
410+
* This is a model with one nested property
411+
*/
412+
export type ModelWithPropertiesWritable = {
413+
required: string;
414+
string?: string;
415+
number?: number;
416+
boolean?: boolean;
417+
reference?: ModelWithString;
418+
'property with space'?: string;
419+
default?: string;
420+
try?: string;
421+
};
422+
423+
/**
424+
* This is a model that contains a some patterns
425+
*/
426+
export type ModelWithPatternWritable = {
427+
key: string;
428+
name: string;
429+
id?: string;
430+
text?: string;
431+
patternWithSingleQuotes?: string;
432+
patternWithNewline?: string;
433+
patternWithBacktick?: string;
434+
};
435+
409436
export type ServiceWithEmptyTagData = {
410437
body?: never;
411438
path?: never;

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/fetch/types.gen.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,33 @@ export type FailureFailure = {
406406
reference_code?: string;
407407
};
408408

409+
/**
410+
* This is a model with one nested property
411+
*/
412+
export type ModelWithPropertiesWritable = {
413+
required: string;
414+
string?: string;
415+
number?: number;
416+
boolean?: boolean;
417+
reference?: ModelWithString;
418+
'property with space'?: string;
419+
default?: string;
420+
try?: string;
421+
};
422+
423+
/**
424+
* This is a model that contains a some patterns
425+
*/
426+
export type ModelWithPatternWritable = {
427+
key: string;
428+
name: string;
429+
id?: string;
430+
text?: string;
431+
patternWithSingleQuotes?: string;
432+
patternWithNewline?: string;
433+
patternWithBacktick?: string;
434+
};
435+
409436
export type ServiceWithEmptyTagData = {
410437
body?: never;
411438
path?: never;

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/axios/types.gen.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,33 @@ export type FailureFailure = {
406406
reference_code?: string;
407407
};
408408

409+
/**
410+
* This is a model with one nested property
411+
*/
412+
export type ModelWithPropertiesWritable = {
413+
required: string;
414+
string?: string;
415+
number?: number;
416+
boolean?: boolean;
417+
reference?: ModelWithString;
418+
'property with space'?: string;
419+
default?: string;
420+
try?: string;
421+
};
422+
423+
/**
424+
* This is a model that contains a some patterns
425+
*/
426+
export type ModelWithPatternWritable = {
427+
key: string;
428+
name: string;
429+
id?: string;
430+
text?: string;
431+
patternWithSingleQuotes?: string;
432+
patternWithNewline?: string;
433+
patternWithBacktick?: string;
434+
};
435+
409436
export type ServiceWithEmptyTagData = {
410437
body?: never;
411438
path?: never;

0 commit comments

Comments
 (0)