Skip to content

Commit 6f848c0

Browse files
authored
Change TypeScript default version to 4.3 (#1855)
1 parent 1187c69 commit 6f848c0

File tree

87 files changed

+393
-1877
lines changed

Some content is hidden

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

87 files changed

+393
-1877
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<VersionPrefix>11.4.1</VersionPrefix>
3+
<VersionPrefix>11.5.0</VersionPrefix>
44

55
<Authors>Rico Suter</Authors>
66
<Copyright>Copyright © Rico Suter, 2022</Copyright>

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ The previously generated JSON Schema would generate the following TypeScript int
230230

231231
**Settings:**
232232

233-
new TypeScriptGeneratorSettings { TypeStyle = TypeScriptTypeStyle.Interface, TypeScriptVersion = 2.0m }
233+
new TypeScriptGeneratorSettings { TypeStyle = TypeScriptTypeStyle.Interface, TypeScriptVersion = 4.3m }
234234

235235
**Output:**
236236

@@ -265,7 +265,7 @@ export interface Person {
265265

266266
**Settings:**
267267

268-
new TypeScriptGeneratorSettings { TypeStyle = TypeScriptTypeStyle.Class, TypeScriptVersion = 2.0m }
268+
new TypeScriptGeneratorSettings { TypeStyle = TypeScriptTypeStyle.Class, TypeScriptVersion = 4.3m }
269269

270270
**Output:**
271271

src/NJsonSchema.CodeGeneration.Tests/EnumGenerationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public async Task When_enum_has_string_value_then_TS_code_has_string_value()
153153
var schemaData = schema.ToJson();
154154

155155
// Act
156-
var generator = new TypeScriptGenerator(schema, new TypeScriptGeneratorSettings { TypeScriptVersion = 1.8m });
156+
var generator = new TypeScriptGenerator(schema, new TypeScriptGeneratorSettings());
157157
var code = generator.GenerateFile("MyClass");
158158

159159
// Assert

src/NJsonSchema.CodeGeneration.Tests/Samples/SampleTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public async Task Demo()
5454
var schema = NewtonsoftJsonSchemaGenerator.FromType<Person>();
5555
var schemaJsonData = schema.ToJson();
5656
var errors = schema.Validate("{}");
57-
var generator = new TypeScriptGenerator(schema, new TypeScriptGeneratorSettings { TypeStyle = TypeScriptTypeStyle.Class, TypeScriptVersion = 2.0m });
57+
var generator = new TypeScriptGenerator(schema, new TypeScriptGeneratorSettings { TypeStyle = TypeScriptTypeStyle.Class });
5858
var code = generator.GenerateFile();
5959
}
6060

@@ -64,7 +64,7 @@ public async Task Demo2()
6464
var schema = NewtonsoftJsonSchemaGenerator.FromType<Person>();
6565
var schemaJsonData = schema.ToJson();
6666
var errors = schema.Validate("{}");
67-
var generator = new TypeScriptGenerator(schema, new TypeScriptGeneratorSettings { TypeStyle = TypeScriptTypeStyle.Interface, TypeScriptVersion = 2.0m });
67+
var generator = new TypeScriptGenerator(schema, new TypeScriptGeneratorSettings { TypeStyle = TypeScriptTypeStyle.Interface });
6868
var code = generator.GenerateFile();
6969
}
7070

src/NJsonSchema.CodeGeneration.Tests/Snapshots/EnumGenerationTests.When_enum_has_string_value_then_TS_code_has_string_value.verified.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export enum StringEnum {
1515
}
1616

1717
export class MyClass implements IMyClass {
18-
bar: StringEnum;
18+
bar!: StringEnum;
1919

2020
constructor(data?: IMyClass) {
2121
if (data) {

src/NJsonSchema.CodeGeneration.Tests/Snapshots/InheritanceSerializationTests.When_schema_contains_discriminator_and_inheritance_hierarchy_then_TypeScript_is_correctly_generated.verified.txt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class Dog extends Animal implements IDog {
6363
this._discriminator = "Dog";
6464
}
6565

66-
init(_data?: any) {
66+
override init(_data?: any) {
6767
super.init(_data);
6868
if (_data) {
6969
this.bar = _data["Bar"];
@@ -75,14 +75,14 @@ export class Dog extends Animal implements IDog {
7575
}
7676
}
7777

78-
static fromJS(data: any): Dog {
78+
static override fromJS(data: any): Dog {
7979
data = typeof data === 'object' ? data : {};
8080
let result = new Dog();
8181
result.init(data);
8282
return result;
8383
}
8484

85-
toJSON(data?: any) {
85+
override toJSON(data?: any) {
8686
data = typeof data === 'object' ? data : {};
8787
data["Bar"] = this.bar;
8888
if (Array.isArray(this.subElements)) {
@@ -157,21 +157,21 @@ export class SubClass1 extends SubClass implements ISubClass1 {
157157
this._discriminator = "SubClass1";
158158
}
159159

160-
init(_data?: any) {
160+
override init(_data?: any) {
161161
super.init(_data);
162162
if (_data) {
163163
this.prop1 = _data["Prop1"];
164164
}
165165
}
166166

167-
static fromJS(data: any): SubClass1 {
167+
static override fromJS(data: any): SubClass1 {
168168
data = typeof data === 'object' ? data : {};
169169
let result = new SubClass1();
170170
result.init(data);
171171
return result;
172172
}
173173

174-
toJSON(data?: any) {
174+
override toJSON(data?: any) {
175175
data = typeof data === 'object' ? data : {};
176176
data["Prop1"] = this.prop1;
177177
super.toJSON(data);
@@ -191,14 +191,14 @@ export class SubClass2 extends SubClass implements ISubClass2 {
191191
this._discriminator = "SubClass2";
192192
}
193193

194-
init(_data?: any) {
194+
override init(_data?: any) {
195195
super.init(_data);
196196
if (_data) {
197197
this.prop2 = _data["Prop2"];
198198
}
199199
}
200200

201-
static fromJS(data: any): SubClass2 {
201+
static override fromJS(data: any): SubClass2 {
202202
data = typeof data === 'object' ? data : {};
203203
if (data["discriminator"] === "SubClass3") {
204204
let result = new SubClass3();
@@ -210,7 +210,7 @@ export class SubClass2 extends SubClass implements ISubClass2 {
210210
return result;
211211
}
212212

213-
toJSON(data?: any) {
213+
override toJSON(data?: any) {
214214
data = typeof data === 'object' ? data : {};
215215
data["Prop2"] = this.prop2;
216216
super.toJSON(data);
@@ -230,21 +230,21 @@ export class SubClass3 extends SubClass2 implements ISubClass3 {
230230
this._discriminator = "SubClass3";
231231
}
232232

233-
init(_data?: any) {
233+
override init(_data?: any) {
234234
super.init(_data);
235235
if (_data) {
236236
this.prop3 = _data["Prop3"];
237237
}
238238
}
239239

240-
static fromJS(data: any): SubClass3 {
240+
static override fromJS(data: any): SubClass3 {
241241
data = typeof data === 'object' ? data : {};
242242
let result = new SubClass3();
243243
result.init(data);
244244
return result;
245245
}
246246

247-
toJSON(data?: any) {
247+
override toJSON(data?: any) {
248248
data = typeof data === 'object' ? data : {};
249249
data["Prop3"] = this.prop3;
250250
super.toJSON(data);

src/NJsonSchema.CodeGeneration.TypeScript.Tests/AbstractGenerationTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public async Task When_class_is_abstract_then_is_abstract_TypeScript_keyword_is_
2222
var json = schema.ToJson();
2323

2424
// Act
25-
var generator = new TypeScriptGenerator(schema, new TypeScriptGeneratorSettings { TypeScriptVersion = 2.0m });
25+
var generator = new TypeScriptGenerator(schema, new TypeScriptGeneratorSettings());
2626
var code = generator.GenerateFile("AbstractClass");
2727

2828
// Assert
@@ -44,7 +44,7 @@ public async Task When_property_is_required_and_abstract_then_it_is_not_instanti
4444
var json = schema.ToJson();
4545

4646
// Act
47-
var generator = new TypeScriptGenerator(schema, new TypeScriptGeneratorSettings { TypeScriptVersion = 2.0m });
47+
var generator = new TypeScriptGenerator(schema, new TypeScriptGeneratorSettings());
4848
var code = generator.GenerateFile("ContainerClass");
4949

5050
// Assert
@@ -72,7 +72,7 @@ public async Task When_abstract_class_is_in_inheritance_hierarchy_then_it_is_new
7272
var schema = NewtonsoftJsonSchemaGenerator.FromType<AbstractClass>();
7373

7474
// Act
75-
var generator = new TypeScriptGenerator(schema, new TypeScriptGeneratorSettings { TypeScriptVersion = 2.0m });
75+
var generator = new TypeScriptGenerator(schema, new TypeScriptGeneratorSettings());
7676
var code = generator.GenerateFile("AbstractClass");
7777

7878
// Assert

src/NJsonSchema.CodeGeneration.TypeScript.Tests/ClassGenerationTests.cs

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -45,28 +45,18 @@ public class Person
4545
}
4646

4747
[Theory]
48-
[InlineData(TypeScriptTypeStyle.Class, 1.8)]
49-
[InlineData(TypeScriptTypeStyle.Class, 2.1)]
50-
[InlineData(TypeScriptTypeStyle.Class, 2.7)]
51-
[InlineData(TypeScriptTypeStyle.Class, 4.3)]
52-
[InlineData(TypeScriptTypeStyle.KnockoutClass, 1.8)]
53-
[InlineData(TypeScriptTypeStyle.KnockoutClass, 2.1)]
54-
[InlineData(TypeScriptTypeStyle.KnockoutClass, 2.7)]
55-
[InlineData(TypeScriptTypeStyle.KnockoutClass, 4.3)]
56-
[InlineData(TypeScriptTypeStyle.Interface, 1.8)]
57-
[InlineData(TypeScriptTypeStyle.Interface, 2.1)]
58-
[InlineData(TypeScriptTypeStyle.Interface, 2.7)]
59-
[InlineData(TypeScriptTypeStyle.Interface, 4.3)]
60-
public async Task Verify_output(TypeScriptTypeStyle style, decimal version)
48+
[InlineData(TypeScriptTypeStyle.Class)]
49+
[InlineData(TypeScriptTypeStyle.KnockoutClass)]
50+
[InlineData(TypeScriptTypeStyle.Interface)]
51+
public async Task Verify_output(TypeScriptTypeStyle style)
6152
{
6253
var settings = new TypeScriptGeneratorSettings
6354
{
64-
TypeStyle = style,
65-
TypeScriptVersion = version
55+
TypeStyle = style
6656
};
6757
var output = await PrepareAsync(settings);
6858

69-
await VerifyHelper.Verify(output).UseParameters(style, version);
59+
await VerifyHelper.Verify(output).UseParameters(style);
7060
}
7161

7262
private static Task<string> PrepareAsync(TypeScriptGeneratorSettings settings)
@@ -115,8 +105,7 @@ public async Task When_array_property_is_required_or_not_then_the_code_has_corre
115105
var generator = new TypeScriptGenerator(schema, new TypeScriptGeneratorSettings
116106
{
117107
TypeStyle = TypeScriptTypeStyle.Class,
118-
SchemaType = SchemaType.Swagger2,
119-
TypeScriptVersion = 1.8m
108+
SchemaType = SchemaType.Swagger2
120109
});
121110
var code = generator.GenerateFile("MyClass");
122111

@@ -160,8 +149,7 @@ public async Task When_dictionary_property_is_required_or_not_then_the_code_has_
160149
var generator = new TypeScriptGenerator(schema, new TypeScriptGeneratorSettings
161150
{
162151
TypeStyle = TypeScriptTypeStyle.Class,
163-
SchemaType = SchemaType.Swagger2,
164-
TypeScriptVersion = 1.8m
152+
SchemaType = SchemaType.Swagger2
165153
});
166154
var code = generator.GenerateFile("MyClass");
167155

@@ -213,8 +201,7 @@ public async Task When_object_property_is_required_or_not_then_the_code_has_corr
213201
var generator = new TypeScriptGenerator(schema, new TypeScriptGeneratorSettings
214202
{
215203
TypeStyle = TypeScriptTypeStyle.Class,
216-
SchemaType = SchemaType.Swagger2,
217-
TypeScriptVersion = 1.8m
204+
SchemaType = SchemaType.Swagger2
218205
});
219206
var code = generator.GenerateFile("MyClass");
220207

@@ -262,8 +249,7 @@ public async Task When_Knockout_class_is_generated_then_initializers_are_correct
262249
var code = await PrepareAsync(new TypeScriptGeneratorSettings
263250
{
264251
TypeStyle = TypeScriptTypeStyle.KnockoutClass,
265-
GenerateConstructorInterface = false,
266-
TypeScriptVersion = 2.0m
252+
GenerateConstructorInterface = false
267253
});
268254

269255
// Assert

src/NJsonSchema.CodeGeneration.TypeScript.Tests/ConstructorInterfaceTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ public async Task When_constructor_interface_and_conversion_code_is_generated_th
5959
var generator = new TypeScriptGenerator(schema, new TypeScriptGeneratorSettings
6060
{
6161
GenerateConstructorInterface = true,
62-
ConvertConstructorInterfaceData = true,
63-
TypeScriptVersion = 1.8m
62+
ConvertConstructorInterfaceData = true
6463
});
6564

6665
var output = generator.GenerateFile("MyClass");

src/NJsonSchema.CodeGeneration.TypeScript.Tests/DictionaryTests.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ public async Task When_property_is_dto_dictionary_then_assignment_may_create_new
129129
var codeGenerator = new TypeScriptGenerator(schema, new TypeScriptGeneratorSettings
130130
{
131131
TypeStyle = TypeScriptTypeStyle.Class,
132-
NullValue = TypeScriptNullValue.Null,
133-
TypeScriptVersion = 1.8m
132+
NullValue = TypeScriptNullValue.Null
134133
});
135134
var code = codeGenerator.GenerateFile("Test");
136135

@@ -190,8 +189,7 @@ public async Task When_property_is_string_dictionary_then_assignment_is_correct(
190189
var codeGenerator = new TypeScriptGenerator(schema, new TypeScriptGeneratorSettings
191190
{
192191
TypeStyle = TypeScriptTypeStyle.Class,
193-
NullValue = TypeScriptNullValue.Undefined,
194-
TypeScriptVersion = 1.8m
192+
NullValue = TypeScriptNullValue.Undefined
195193
});
196194
var code = codeGenerator.GenerateFile("Test");
197195

@@ -226,8 +224,7 @@ public async Task When_property_uses_custom_dictionary_class_then_class_is_gener
226224
TypeStyle = TypeScriptTypeStyle.Class,
227225
NullValue = TypeScriptNullValue.Undefined,
228226
ConvertConstructorInterfaceData = convertConstructorInterfaceData,
229-
InlineNamedDictionaries = inlineNamedDictionaries,
230-
TypeScriptVersion = 1.8m
227+
InlineNamedDictionaries = inlineNamedDictionaries
231228
});
232229
var code = codeGenerator.GenerateFile("Test");
233230

@@ -271,8 +268,7 @@ public async Task When_dictionary_has_arbitrary_nonenum_key_then_generated_types
271268
var codeGenerator = new TypeScriptGenerator(schema, new TypeScriptGeneratorSettings
272269
{
273270
ConvertConstructorInterfaceData = true,
274-
TypeStyle = TypeScriptTypeStyle.Class,
275-
TypeScriptVersion = 2.7m
271+
TypeStyle = TypeScriptTypeStyle.Class
276272
});
277273

278274
var code = codeGenerator.GenerateFile("Test");

0 commit comments

Comments
 (0)