From c8650d0e34790e4ca1fa8e0d578ed63d3470db00 Mon Sep 17 00:00:00 2001 From: Ben Wells Date: Sat, 31 Mar 2018 05:12:06 +0100 Subject: [PATCH] Make optional properties in models optional parameters (#7859) * Make optional properties in models optional parameters Move incorrect location of typescript-node client * Add typescript node package.json to swagger ignore --- .../resources/typescript-node/api.mustache | 2 +- .../petstore/typescript-node/default/api.ts | 50 +++++++++---------- .../npm/.swagger-codegen-ignore | 4 ++ .../petstore/typescript-node/npm/api.d.ts | 50 +++++++++---------- .../petstore/typescript-node/npm/api.ts | 50 +++++++++---------- 5 files changed, 80 insertions(+), 76 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/typescript-node/api.mustache b/modules/swagger-codegen/src/main/resources/typescript-node/api.mustache index f86a148db80..d95cbbbddb8 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-node/api.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-node/api.mustache @@ -141,7 +141,7 @@ export class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{ * {{{description}}} */ {{/description}} - '{{name}}': {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}}; + '{{name}}'{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}}; {{/vars}} {{#discriminator}} diff --git a/samples/client/petstore/typescript-node/default/api.ts b/samples/client/petstore/typescript-node/default/api.ts index 24bc1ef3841..2a41b799bea 100644 --- a/samples/client/petstore/typescript-node/default/api.ts +++ b/samples/client/petstore/typescript-node/default/api.ts @@ -140,9 +140,9 @@ class ObjectSerializer { * Describes the result of uploading an image resource */ export class ApiResponse { - 'code': number; - 'type': string; - 'message': string; + 'code'?: number; + 'type'?: string; + 'message'?: string; static discriminator = undefined; @@ -172,8 +172,8 @@ export class ApiResponse { * A category for a pet */ export class Category { - 'id': number; - 'name': string; + 'id'?: number; + 'name'?: string; static discriminator = undefined; @@ -198,15 +198,15 @@ export class Category { * An order for a pets from the pet store */ export class Order { - 'id': number; - 'petId': number; - 'quantity': number; - 'shipDate': Date; + 'id'?: number; + 'petId'?: number; + 'quantity'?: number; + 'shipDate'?: Date; /** * Order Status */ - 'status': Order.StatusEnum; - 'complete': boolean; + 'status'?: Order.StatusEnum; + 'complete'?: boolean; static discriminator = undefined; @@ -258,15 +258,15 @@ export namespace Order { * A pet for sale in the pet store */ export class Pet { - 'id': number; - 'category': Category; + 'id'?: number; + 'category'?: Category; 'name': string; 'photoUrls': Array; - 'tags': Array; + 'tags'?: Array; /** * pet status in the store */ - 'status': Pet.StatusEnum; + 'status'?: Pet.StatusEnum; static discriminator = undefined; @@ -318,8 +318,8 @@ export namespace Pet { * A tag for a pet */ export class Tag { - 'id': number; - 'name': string; + 'id'?: number; + 'name'?: string; static discriminator = undefined; @@ -344,17 +344,17 @@ export class Tag { * A User who is purchasing from the pet store */ export class User { - 'id': number; - 'username': string; - 'firstName': string; - 'lastName': string; - 'email': string; - 'password': string; - 'phone': string; + 'id'?: number; + 'username'?: string; + 'firstName'?: string; + 'lastName'?: string; + 'email'?: string; + 'password'?: string; + 'phone'?: string; /** * User Status */ - 'userStatus': number; + 'userStatus'?: number; static discriminator = undefined; diff --git a/samples/client/petstore/typescript-node/npm/.swagger-codegen-ignore b/samples/client/petstore/typescript-node/npm/.swagger-codegen-ignore index e69de29bb2d..f521f812824 100644 --- a/samples/client/petstore/typescript-node/npm/.swagger-codegen-ignore +++ b/samples/client/petstore/typescript-node/npm/.swagger-codegen-ignore @@ -0,0 +1,4 @@ +# Do not overwrite package.json file when re-generating typescript-node client +# as the package file as been modified to include dependencies required for +# testing the generated client. +package.json diff --git a/samples/client/petstore/typescript-node/npm/api.d.ts b/samples/client/petstore/typescript-node/npm/api.d.ts index aaa337c017f..535a6c528d7 100644 --- a/samples/client/petstore/typescript-node/npm/api.d.ts +++ b/samples/client/petstore/typescript-node/npm/api.d.ts @@ -5,9 +5,9 @@ import localVarRequest = require('request'); import http = require('http'); import Promise = require('bluebird'); export declare class ApiResponse { - 'code': number; - 'type': string; - 'message': string; + 'code'?: number; + 'type'?: string; + 'message'?: string; static discriminator: undefined; static attributeTypeMap: Array<{ name: string; @@ -21,8 +21,8 @@ export declare class ApiResponse { }[]; } export declare class Category { - 'id': number; - 'name': string; + 'id'?: number; + 'name'?: string; static discriminator: undefined; static attributeTypeMap: Array<{ name: string; @@ -36,12 +36,12 @@ export declare class Category { }[]; } export declare class Order { - 'id': number; - 'petId': number; - 'quantity': number; - 'shipDate': Date; - 'status': Order.StatusEnum; - 'complete': boolean; + 'id'?: number; + 'petId'?: number; + 'quantity'?: number; + 'shipDate'?: Date; + 'status'?: Order.StatusEnum; + 'complete'?: boolean; static discriminator: undefined; static attributeTypeMap: Array<{ name: string; @@ -62,12 +62,12 @@ export declare namespace Order { } } export declare class Pet { - 'id': number; - 'category': Category; + 'id'?: number; + 'category'?: Category; 'name': string; 'photoUrls': Array; - 'tags': Array; - 'status': Pet.StatusEnum; + 'tags'?: Array; + 'status'?: Pet.StatusEnum; static discriminator: undefined; static attributeTypeMap: Array<{ name: string; @@ -88,8 +88,8 @@ export declare namespace Pet { } } export declare class Tag { - 'id': number; - 'name': string; + 'id'?: number; + 'name'?: string; static discriminator: undefined; static attributeTypeMap: Array<{ name: string; @@ -103,14 +103,14 @@ export declare class Tag { }[]; } export declare class User { - 'id': number; - 'username': string; - 'firstName': string; - 'lastName': string; - 'email': string; - 'password': string; - 'phone': string; - 'userStatus': number; + 'id'?: number; + 'username'?: string; + 'firstName'?: string; + 'lastName'?: string; + 'email'?: string; + 'password'?: string; + 'phone'?: string; + 'userStatus'?: number; static discriminator: undefined; static attributeTypeMap: Array<{ name: string; diff --git a/samples/client/petstore/typescript-node/npm/api.ts b/samples/client/petstore/typescript-node/npm/api.ts index 24bc1ef3841..2a41b799bea 100644 --- a/samples/client/petstore/typescript-node/npm/api.ts +++ b/samples/client/petstore/typescript-node/npm/api.ts @@ -140,9 +140,9 @@ class ObjectSerializer { * Describes the result of uploading an image resource */ export class ApiResponse { - 'code': number; - 'type': string; - 'message': string; + 'code'?: number; + 'type'?: string; + 'message'?: string; static discriminator = undefined; @@ -172,8 +172,8 @@ export class ApiResponse { * A category for a pet */ export class Category { - 'id': number; - 'name': string; + 'id'?: number; + 'name'?: string; static discriminator = undefined; @@ -198,15 +198,15 @@ export class Category { * An order for a pets from the pet store */ export class Order { - 'id': number; - 'petId': number; - 'quantity': number; - 'shipDate': Date; + 'id'?: number; + 'petId'?: number; + 'quantity'?: number; + 'shipDate'?: Date; /** * Order Status */ - 'status': Order.StatusEnum; - 'complete': boolean; + 'status'?: Order.StatusEnum; + 'complete'?: boolean; static discriminator = undefined; @@ -258,15 +258,15 @@ export namespace Order { * A pet for sale in the pet store */ export class Pet { - 'id': number; - 'category': Category; + 'id'?: number; + 'category'?: Category; 'name': string; 'photoUrls': Array; - 'tags': Array; + 'tags'?: Array; /** * pet status in the store */ - 'status': Pet.StatusEnum; + 'status'?: Pet.StatusEnum; static discriminator = undefined; @@ -318,8 +318,8 @@ export namespace Pet { * A tag for a pet */ export class Tag { - 'id': number; - 'name': string; + 'id'?: number; + 'name'?: string; static discriminator = undefined; @@ -344,17 +344,17 @@ export class Tag { * A User who is purchasing from the pet store */ export class User { - 'id': number; - 'username': string; - 'firstName': string; - 'lastName': string; - 'email': string; - 'password': string; - 'phone': string; + 'id'?: number; + 'username'?: string; + 'firstName'?: string; + 'lastName'?: string; + 'email'?: string; + 'password'?: string; + 'phone'?: string; /** * User Status */ - 'userStatus': number; + 'userStatus'?: number; static discriminator = undefined;