Skip to content

Commit b793a95

Browse files
allejomacjohnny
authored andcommitted
[typescript][fetch] Fix null typing errors (#3919)
* [typescript][fetch] fix null typing errors * [typescript][fetch] update sample generations * re-generate samples
1 parent 5610610 commit b793a95

Some content is hidden

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

65 files changed

+551
-551
lines changed

modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,14 @@ export class {{classname}} extends runtime.BaseAPI {
229229
{{/returnType}}
230230
}
231231

232-
/**
233-
{{#notes}}
234-
* {{&notes}}
235-
{{/notes}}
236-
{{#summary}}
237-
* {{&summary}}
238-
{{/summary}}
239-
*/
232+
/**
233+
{{#notes}}
234+
* {{&notes}}
235+
{{/notes}}
236+
{{#summary}}
237+
* {{&summary}}
238+
{{/summary}}
239+
*/
240240
{{^useSingleRequestParameter}}
241241
async {{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{#isNullable}} | null{{/isNullable}}{{/isEnum}}{{#hasMore}}, {{/hasMore}}{{/allParams}}): Promise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}> {
242242
{{#returnType}}

modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export function {{classname}}FromJSONTyped(json: any, ignoreDiscriminator: boole
100100
{{/hasVars}}
101101
}
102102

103-
export function {{classname}}ToJSON(value?: {{classname}}): any {
103+
export function {{classname}}ToJSON(value?: {{classname}} | null): any {
104104
{{#hasVars}}
105105
if (value === undefined) {
106106
return undefined;
@@ -116,14 +116,14 @@ export function {{classname}}ToJSON(value?: {{classname}}): any {
116116
{{#vars}}
117117
{{^isReadOnly}}
118118
{{#isPrimitiveType}}
119-
'{{baseName}}': {{#isDate}}{{^required}}value.{{name}} === undefined ? undefined : {{/required}}value.{{name}}.toISOString().substr(0,10){{/isDate}}{{#isDateTime}}{{^required}}value.{{name}} === undefined ? undefined : {{/required}}value.{{name}}.toISOString(){{/isDateTime}}{{^isDate}}{{^isDateTime}}value.{{name}}{{/isDateTime}}{{/isDate}},
119+
'{{baseName}}': {{#isDate}}{{^required}}value.{{name}} == null ? undefined : {{/required}}value.{{name}}.toISOString().substr(0,10){{/isDate}}{{#isDateTime}}{{^required}}value.{{name}} == null ? undefined : {{/required}}value.{{name}}.toISOString(){{/isDateTime}}{{^isDate}}{{^isDateTime}}value.{{name}}{{/isDateTime}}{{/isDate}},
120120
{{/isPrimitiveType}}
121121
{{^isPrimitiveType}}
122122
{{#isListContainer}}
123-
'{{baseName}}': {{^required}}value.{{name}} === undefined ? undefined : {{/required}}(value.{{name}} as Array<any>).map({{#items}}{{datatype}}{{/items}}ToJSON),
123+
'{{baseName}}': {{^required}}value.{{name}} == null ? undefined : {{/required}}(value.{{name}} as Array<any>).map({{#items}}{{datatype}}{{/items}}ToJSON),
124124
{{/isListContainer}}
125125
{{#isMapContainer}}
126-
'{{baseName}}': {{^required}}value.{{name}} === undefined ? undefined : {{/required}}mapValues(value.{{name}}, {{#items}}{{datatype}}{{/items}}ToJSON),
126+
'{{baseName}}': {{^required}}value.{{name}} == null ? undefined : {{/required}}mapValues(value.{{name}}, {{#items}}{{datatype}}{{/items}}ToJSON),
127127
{{/isMapContainer}}
128128
{{^isListContainer}}
129129
{{^isMapContainer}}

samples/client/petstore/typescript-fetch/builds/default/src/apis/PetApi.ts

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ export class PetApi extends runtime.BaseAPI {
9898
return new runtime.VoidApiResponse(response);
9999
}
100100

101-
/**
102-
* Add a new pet to the store
103-
*/
101+
/**
102+
* Add a new pet to the store
103+
*/
104104
async addPet(requestParameters: AddPetRequest): Promise<void> {
105105
await this.addPetRaw(requestParameters);
106106
}
@@ -140,9 +140,9 @@ export class PetApi extends runtime.BaseAPI {
140140
return new runtime.VoidApiResponse(response);
141141
}
142142

143-
/**
144-
* Deletes a pet
145-
*/
143+
/**
144+
* Deletes a pet
145+
*/
146146
async deletePet(requestParameters: DeletePetRequest): Promise<void> {
147147
await this.deletePetRaw(requestParameters);
148148
}
@@ -183,10 +183,10 @@ export class PetApi extends runtime.BaseAPI {
183183
return new runtime.JSONApiResponse(response, (jsonValue) => jsonValue.map(PetFromJSON));
184184
}
185185

186-
/**
187-
* Multiple status values can be provided with comma separated strings
188-
* Finds Pets by status
189-
*/
186+
/**
187+
* Multiple status values can be provided with comma separated strings
188+
* Finds Pets by status
189+
*/
190190
async findPetsByStatus(requestParameters: FindPetsByStatusRequest): Promise<Array<Pet>> {
191191
const response = await this.findPetsByStatusRaw(requestParameters);
192192
return await response.value();
@@ -228,10 +228,10 @@ export class PetApi extends runtime.BaseAPI {
228228
return new runtime.JSONApiResponse(response, (jsonValue) => jsonValue.map(PetFromJSON));
229229
}
230230

231-
/**
232-
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
233-
* Finds Pets by tags
234-
*/
231+
/**
232+
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
233+
* Finds Pets by tags
234+
*/
235235
async findPetsByTags(requestParameters: FindPetsByTagsRequest): Promise<Array<Pet>> {
236236
const response = await this.findPetsByTagsRaw(requestParameters);
237237
return await response.value();
@@ -264,10 +264,10 @@ export class PetApi extends runtime.BaseAPI {
264264
return new runtime.JSONApiResponse(response, (jsonValue) => PetFromJSON(jsonValue));
265265
}
266266

267-
/**
268-
* Returns a single pet
269-
* Find pet by ID
270-
*/
267+
/**
268+
* Returns a single pet
269+
* Find pet by ID
270+
*/
271271
async getPetById(requestParameters: GetPetByIdRequest): Promise<Pet> {
272272
const response = await this.getPetByIdRaw(requestParameters);
273273
return await response.value();
@@ -307,9 +307,9 @@ export class PetApi extends runtime.BaseAPI {
307307
return new runtime.VoidApiResponse(response);
308308
}
309309

310-
/**
311-
* Update an existing pet
312-
*/
310+
/**
311+
* Update an existing pet
312+
*/
313313
async updatePet(requestParameters: UpdatePetRequest): Promise<void> {
314314
await this.updatePetRaw(requestParameters);
315315
}
@@ -355,9 +355,9 @@ export class PetApi extends runtime.BaseAPI {
355355
return new runtime.VoidApiResponse(response);
356356
}
357357

358-
/**
359-
* Updates a pet in the store with form data
360-
*/
358+
/**
359+
* Updates a pet in the store with form data
360+
*/
361361
async updatePetWithForm(requestParameters: UpdatePetWithFormRequest): Promise<void> {
362362
await this.updatePetWithFormRaw(requestParameters);
363363
}
@@ -403,9 +403,9 @@ export class PetApi extends runtime.BaseAPI {
403403
return new runtime.JSONApiResponse(response, (jsonValue) => ModelApiResponseFromJSON(jsonValue));
404404
}
405405

406-
/**
407-
* uploads an image
408-
*/
406+
/**
407+
* uploads an image
408+
*/
409409
async uploadFile(requestParameters: UploadFileRequest): Promise<ModelApiResponse> {
410410
const response = await this.uploadFileRaw(requestParameters);
411411
return await response.value();

samples/client/petstore/typescript-fetch/builds/default/src/apis/StoreApi.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ export class StoreApi extends runtime.BaseAPI {
5959
return new runtime.VoidApiResponse(response);
6060
}
6161

62-
/**
63-
* For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
64-
* Delete purchase order by ID
65-
*/
62+
/**
63+
* For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
64+
* Delete purchase order by ID
65+
*/
6666
async deleteOrder(requestParameters: DeleteOrderRequest): Promise<void> {
6767
await this.deleteOrderRaw(requestParameters);
6868
}
@@ -90,10 +90,10 @@ export class StoreApi extends runtime.BaseAPI {
9090
return new runtime.JSONApiResponse<any>(response);
9191
}
9292

93-
/**
94-
* Returns a map of status codes to quantities
95-
* Returns pet inventories by status
96-
*/
93+
/**
94+
* Returns a map of status codes to quantities
95+
* Returns pet inventories by status
96+
*/
9797
async getInventory(): Promise<{ [key: string]: number; }> {
9898
const response = await this.getInventoryRaw();
9999
return await response.value();
@@ -122,10 +122,10 @@ export class StoreApi extends runtime.BaseAPI {
122122
return new runtime.JSONApiResponse(response, (jsonValue) => OrderFromJSON(jsonValue));
123123
}
124124

125-
/**
126-
* For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
127-
* Find purchase order by ID
128-
*/
125+
/**
126+
* For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
127+
* Find purchase order by ID
128+
*/
129129
async getOrderById(requestParameters: GetOrderByIdRequest): Promise<Order> {
130130
const response = await this.getOrderByIdRaw(requestParameters);
131131
return await response.value();
@@ -156,9 +156,9 @@ export class StoreApi extends runtime.BaseAPI {
156156
return new runtime.JSONApiResponse(response, (jsonValue) => OrderFromJSON(jsonValue));
157157
}
158158

159-
/**
160-
* Place an order for a pet
161-
*/
159+
/**
160+
* Place an order for a pet
161+
*/
162162
async placeOrder(requestParameters: PlaceOrderRequest): Promise<Order> {
163163
const response = await this.placeOrderRaw(requestParameters);
164164
return await response.value();

samples/client/petstore/typescript-fetch/builds/default/src/apis/UserApi.ts

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ export class UserApi extends runtime.BaseAPI {
8080
return new runtime.VoidApiResponse(response);
8181
}
8282

83-
/**
84-
* This can only be done by the logged in user.
85-
* Create user
86-
*/
83+
/**
84+
* This can only be done by the logged in user.
85+
* Create user
86+
*/
8787
async createUser(requestParameters: CreateUserRequest): Promise<void> {
8888
await this.createUserRaw(requestParameters);
8989
}
@@ -113,9 +113,9 @@ export class UserApi extends runtime.BaseAPI {
113113
return new runtime.VoidApiResponse(response);
114114
}
115115

116-
/**
117-
* Creates list of users with given input array
118-
*/
116+
/**
117+
* Creates list of users with given input array
118+
*/
119119
async createUsersWithArrayInput(requestParameters: CreateUsersWithArrayInputRequest): Promise<void> {
120120
await this.createUsersWithArrayInputRaw(requestParameters);
121121
}
@@ -145,9 +145,9 @@ export class UserApi extends runtime.BaseAPI {
145145
return new runtime.VoidApiResponse(response);
146146
}
147147

148-
/**
149-
* Creates list of users with given input array
150-
*/
148+
/**
149+
* Creates list of users with given input array
150+
*/
151151
async createUsersWithListInput(requestParameters: CreateUsersWithListInputRequest): Promise<void> {
152152
await this.createUsersWithListInputRaw(requestParameters);
153153
}
@@ -175,10 +175,10 @@ export class UserApi extends runtime.BaseAPI {
175175
return new runtime.VoidApiResponse(response);
176176
}
177177

178-
/**
179-
* This can only be done by the logged in user.
180-
* Delete user
181-
*/
178+
/**
179+
* This can only be done by the logged in user.
180+
* Delete user
181+
*/
182182
async deleteUser(requestParameters: DeleteUserRequest): Promise<void> {
183183
await this.deleteUserRaw(requestParameters);
184184
}
@@ -205,9 +205,9 @@ export class UserApi extends runtime.BaseAPI {
205205
return new runtime.JSONApiResponse(response, (jsonValue) => UserFromJSON(jsonValue));
206206
}
207207

208-
/**
209-
* Get user by user name
210-
*/
208+
/**
209+
* Get user by user name
210+
*/
211211
async getUserByName(requestParameters: GetUserByNameRequest): Promise<User> {
212212
const response = await this.getUserByNameRaw(requestParameters);
213213
return await response.value();
@@ -247,9 +247,9 @@ export class UserApi extends runtime.BaseAPI {
247247
return new runtime.TextApiResponse(response);
248248
}
249249

250-
/**
251-
* Logs user into the system
252-
*/
250+
/**
251+
* Logs user into the system
252+
*/
253253
async loginUser(requestParameters: LoginUserRequest): Promise<string> {
254254
const response = await this.loginUserRaw(requestParameters);
255255
return await response.value();
@@ -273,9 +273,9 @@ export class UserApi extends runtime.BaseAPI {
273273
return new runtime.VoidApiResponse(response);
274274
}
275275

276-
/**
277-
* Logs out current logged in user session
278-
*/
276+
/**
277+
* Logs out current logged in user session
278+
*/
279279
async logoutUser(): Promise<void> {
280280
await this.logoutUserRaw();
281281
}
@@ -310,10 +310,10 @@ export class UserApi extends runtime.BaseAPI {
310310
return new runtime.VoidApiResponse(response);
311311
}
312312

313-
/**
314-
* This can only be done by the logged in user.
315-
* Updated user
316-
*/
313+
/**
314+
* This can only be done by the logged in user.
315+
* Updated user
316+
*/
317317
async updateUser(requestParameters: UpdateUserRequest): Promise<void> {
318318
await this.updateUserRaw(requestParameters);
319319
}

samples/client/petstore/typescript-fetch/builds/default/src/models/Category.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export function CategoryFromJSONTyped(json: any, ignoreDiscriminator: boolean):
4747
};
4848
}
4949

50-
export function CategoryToJSON(value?: Category): any {
50+
export function CategoryToJSON(value?: Category | null): any {
5151
if (value === undefined) {
5252
return undefined;
5353
}

samples/client/petstore/typescript-fetch/builds/default/src/models/ModelApiResponse.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export function ModelApiResponseFromJSONTyped(json: any, ignoreDiscriminator: bo
5454
};
5555
}
5656

57-
export function ModelApiResponseToJSON(value?: ModelApiResponse): any {
57+
export function ModelApiResponseToJSON(value?: ModelApiResponse | null): any {
5858
if (value === undefined) {
5959
return undefined;
6060
}

samples/client/petstore/typescript-fetch/builds/default/src/models/Order.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export function OrderFromJSONTyped(json: any, ignoreDiscriminator: boolean): Ord
7575
};
7676
}
7777

78-
export function OrderToJSON(value?: Order): any {
78+
export function OrderToJSON(value?: Order | null): any {
7979
if (value === undefined) {
8080
return undefined;
8181
}
@@ -87,7 +87,7 @@ export function OrderToJSON(value?: Order): any {
8787
'id': value.id,
8888
'petId': value.petId,
8989
'quantity': value.quantity,
90-
'shipDate': value.shipDate === undefined ? undefined : value.shipDate.toISOString(),
90+
'shipDate': value.shipDate == null ? undefined : value.shipDate.toISOString(),
9191
'status': value.status,
9292
'complete': value.complete,
9393
};

samples/client/petstore/typescript-fetch/builds/default/src/models/Pet.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export function PetFromJSONTyped(json: any, ignoreDiscriminator: boolean): Pet {
8686
};
8787
}
8888

89-
export function PetToJSON(value?: Pet): any {
89+
export function PetToJSON(value?: Pet | null): any {
9090
if (value === undefined) {
9191
return undefined;
9292
}
@@ -99,7 +99,7 @@ export function PetToJSON(value?: Pet): any {
9999
'category': CategoryToJSON(value.category),
100100
'name': value.name,
101101
'photoUrls': value.photoUrls,
102-
'tags': value.tags === undefined ? undefined : (value.tags as Array<any>).map(TagToJSON),
102+
'tags': value.tags == null ? undefined : (value.tags as Array<any>).map(TagToJSON),
103103
'status': value.status,
104104
};
105105
}

samples/client/petstore/typescript-fetch/builds/default/src/models/Tag.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export function TagFromJSONTyped(json: any, ignoreDiscriminator: boolean): Tag {
4747
};
4848
}
4949

50-
export function TagToJSON(value?: Tag): any {
50+
export function TagToJSON(value?: Tag | null): any {
5151
if (value === undefined) {
5252
return undefined;
5353
}

samples/client/petstore/typescript-fetch/builds/default/src/models/User.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export function UserFromJSONTyped(json: any, ignoreDiscriminator: boolean): User
8989
};
9090
}
9191

92-
export function UserToJSON(value?: User): any {
92+
export function UserToJSON(value?: User | null): any {
9393
if (value === undefined) {
9494
return undefined;
9595
}

0 commit comments

Comments
 (0)