diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractTypeScriptClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractTypeScriptClientCodegen.java index d676f4a342c..a8d57989892 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractTypeScriptClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractTypeScriptClientCodegen.java @@ -27,6 +27,7 @@ import io.swagger.models.properties.Property; import io.swagger.models.properties.StringProperty; public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen implements CodegenConfig { + private static final String X_DISCRIMINATOR_TYPE = "x-discriminator-value"; private static final String UNDEFINED_VALUE = "undefined"; protected String modelPropertyNaming= "camelCase"; @@ -330,7 +331,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp if (p instanceof StringProperty) { StringProperty sp = (StringProperty) p; if (sp.getDefault() != null) { - return "\"" + sp.getDefault() + "\""; + return "'" + sp.getDefault() + "'"; } return UNDEFINED_VALUE; } else if (p instanceof BooleanProperty) { @@ -495,17 +496,44 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp Map mo = (Map) _mo; CodegenModel cm = (CodegenModel) mo.get("model"); cm.imports = new TreeSet(cm.imports); + // name enum with model name, e.g. StatusEnum => Pet.StatusEnum for (CodegenProperty var : cm.vars) { - // name enum with model name, e.g. StatuEnum => Pet.StatusEnum if (Boolean.TRUE.equals(var.isEnum)) { var.datatypeWithEnum = var.datatypeWithEnum.replace(var.enumName, cm.classname + "." + var.enumName); } } + if (cm.parent != null) { + for (CodegenProperty var : cm.allVars) { + if (Boolean.TRUE.equals(var.isEnum)) { + var.datatypeWithEnum = var.datatypeWithEnum + .replace(var.enumName, cm.classname + "." + var.enumName); + } + } + } } return objs; } + @Override + public Map postProcessAllModels(Map objs) { + Map result = super.postProcessAllModels(objs); + + for (Map.Entry entry : result.entrySet()) { + Map inner = (Map) entry.getValue(); + List> models = (List>) inner.get("models"); + for (Map mo : models) { + CodegenModel cm = (CodegenModel) mo.get("model"); + if (cm.discriminator != null && cm.children != null) { + for (CodegenModel child : cm.children) { + this.setDiscriminatorValue(child, cm.discriminator, this.getDiscriminatorValue(child)); + } + } + } + } + return result; + } + public void setSupportsES6(Boolean value) { supportsES6 = value; } @@ -514,6 +542,25 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp return supportsES6; } + private void setDiscriminatorValue(CodegenModel model, String baseName, String value) { + for (CodegenProperty prop : model.allVars) { + if (prop.baseName.equals(baseName)) { + prop.discriminatorValue = value; + } + } + if (model.children != null) { + final boolean newDiscriminator = model.discriminator != null; + for (CodegenModel child : model.children) { + this.setDiscriminatorValue(child, baseName, newDiscriminator ? value : this.getDiscriminatorValue(child)); + } + } + } + + private String getDiscriminatorValue(CodegenModel model) { + return model.vendorExtensions.containsKey(X_DISCRIMINATOR_TYPE) ? + (String) model.vendorExtensions.get(X_DISCRIMINATOR_TYPE) : model.classname; + } + @Override public String escapeQuotationMark(String input) { // remove ', " to avoid code injection diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngularClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngularClientCodegen.java index 0ca5848f7ff..526fe1e2a94 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngularClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngularClientCodegen.java @@ -21,18 +21,22 @@ import io.swagger.models.properties.*; public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCodegen { private static final SimpleDateFormat SNAPSHOT_SUFFIX_FORMAT = new SimpleDateFormat("yyyyMMddHHmm"); + private static final String X_DISCRIMINATOR_TYPE = "x-discriminator-value"; public static final String NPM_NAME = "npmName"; public static final String NPM_VERSION = "npmVersion"; public static final String NPM_REPOSITORY = "npmRepository"; public static final String SNAPSHOT = "snapshot"; public static final String WITH_INTERFACES = "withInterfaces"; + public static final String TAGGED_UNIONS ="taggedUnions"; public static final String NG_VERSION = "ngVersion"; protected String npmName = null; protected String npmVersion = "1.0.0"; protected String npmRepository = null; + private boolean taggedUnions = false; + public TypeScriptAngularClientCodegen() { super(); this.outputFolder = "generated-code/typescript-angular"; @@ -55,6 +59,9 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode this.cliOptions.add(new CliOption(WITH_INTERFACES, "Setting this property to true will generate interfaces next to the default class implementations.", BooleanProperty.TYPE).defaultValue(Boolean.FALSE.toString())); + this.cliOptions.add(new CliOption(TAGGED_UNIONS, + "Use discriminators to create tagged unions instead of extending interfaces.", + BooleanProperty.TYPE).defaultValue(Boolean.FALSE.toString())); this.cliOptions.add(new CliOption(NG_VERSION, "The version of Angular. Default is '4.3'")); } @@ -101,6 +108,10 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode } } + if (additionalProperties.containsKey(TAGGED_UNIONS)) { + taggedUnions = Boolean.parseBoolean(additionalProperties.get(TAGGED_UNIONS).toString()); + } + // determine NG version SemVer ngVersion; if (additionalProperties.containsKey(NG_VERSION)) { @@ -295,14 +306,33 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode public Map postProcessModels(Map objs) { Map result = super.postProcessModels(objs); - // Add additional filename information for imports - List models = (List) postProcessModelsEnum(result).get("models"); - for (Object _mo : models) { - Map mo = (Map) _mo; - CodegenModel cm = (CodegenModel) mo.get("model"); - mo.put("tsImports", toTsImports(cm, cm.imports)); - } + return postProcessModelsEnum(result); + } + @Override + public Map postProcessAllModels(Map objs) { + Map result = super.postProcessAllModels(objs); + + for (Map.Entry entry : result.entrySet()) { + Map inner = (Map) entry.getValue(); + List> models = (List>) inner.get("models"); + for (Map mo : models) { + CodegenModel cm = (CodegenModel) mo.get("model"); + if (taggedUnions) { + mo.put(TAGGED_UNIONS, true); + if (cm.discriminator != null && cm.children != null) { + for (CodegenModel child : cm.children) { + cm.imports.add(child.classname); + } + } + if (cm.parent != null) { + cm.imports.remove(cm.parent); + } + } + // Add additional filename information for imports + mo.put("tsImports", toTsImports(cm, cm.imports)); + } + } return result; } diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular/model.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular/model.mustache index 0d5cf4c146e..0b93ad2998f 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular/model.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular/model.mustache @@ -11,6 +11,6 @@ import { {{classname}} } from './{{filename}}'; * {{{description}}} */ {{/description}} -{{#isEnum}}{{>modelEnum}}{{/isEnum}}{{^isEnum}}{{>modelGeneric}}{{/isEnum}} +{{#isEnum}}{{>modelEnum}}{{/isEnum}}{{^isEnum}}{{#isAlias}}{{>modelAlias}}{{/isAlias}}{{^isAlias}}{{#taggedUnions}}{{>modelTaggedUnion}}{{/taggedUnions}}{{^taggedUnions}}{{>modelGeneric}}{{/taggedUnions}}{{/isAlias}}{{/isEnum}} {{/model}} {{/models}} diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular/modelAlias.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular/modelAlias.mustache new file mode 100644 index 00000000000..c1c6bf7a5da --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/typescript-angular/modelAlias.mustache @@ -0,0 +1 @@ +export type {{classname}} = {{dataType}}; \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular/modelGeneric.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular/modelGeneric.mustache index 34e35255d5a..a4248ea3da0 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular/modelGeneric.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular/modelGeneric.mustache @@ -1,28 +1,10 @@ -export interface {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{ -{{#additionalPropertiesType}} - [key: string]: {{{additionalPropertiesType}}}{{#hasVars}} | any{{/hasVars}}; - -{{/additionalPropertiesType}} +export interface {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{ {{>modelGenericAdditionalProperties}} {{#vars}} {{#description}} /** * {{{description}}} */ {{/description}} - {{name}}{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}}; + {{#isReadOnly}}readonly {{/isReadOnly}}{{name}}{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}}; {{/vars}} -}{{#hasEnums}} -export namespace {{classname}} { -{{#vars}} - {{#isEnum}} - export type {{enumName}} = {{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}} | {{/-last}}{{/enumVars}}{{/allowableValues}}; - export const {{enumName}} = { - {{#allowableValues}} - {{#enumVars}} - {{name}}: {{{value}}} as {{enumName}}{{^-last}},{{/-last}} - {{/enumVars}} - {{/allowableValues}} - } - {{/isEnum}} -{{/vars}} -}{{/hasEnums}} \ No newline at end of file +}{{>modelGenericEnums}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular/modelGenericAdditionalProperties.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular/modelGenericAdditionalProperties.mustache new file mode 100644 index 00000000000..e6499ce9d63 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/typescript-angular/modelGenericAdditionalProperties.mustache @@ -0,0 +1,5 @@ +{{#additionalPropertiesType}} + + [key: string]: {{{additionalPropertiesType}}}{{#hasVars}} | any{{/hasVars}}; + +{{/additionalPropertiesType}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular/modelGenericEnums.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular/modelGenericEnums.mustache new file mode 100644 index 00000000000..432020b726f --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/typescript-angular/modelGenericEnums.mustache @@ -0,0 +1,16 @@ +{{#hasEnums}} + +export namespace {{classname}} { +{{#vars}} + {{#isEnum}} + export type {{enumName}} = {{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}} | {{/-last}}{{/enumVars}}{{/allowableValues}}; + export const {{enumName}} = { + {{#allowableValues}} + {{#enumVars}} + {{name}}: {{{value}}} as {{enumName}}{{^-last}},{{/-last}} + {{/enumVars}} + {{/allowableValues}} + } + {{/isEnum}} +{{/vars}} +}{{/hasEnums}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular/modelTaggedUnion.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular/modelTaggedUnion.mustache new file mode 100644 index 00000000000..cd7d1c8b936 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/typescript-angular/modelTaggedUnion.mustache @@ -0,0 +1,21 @@ +{{#discriminator}} +export type {{classname}} = {{#children}}{{^-first}} | {{/-first}}{{classname}}{{/children}}; +{{/discriminator}} +{{^discriminator}} +{{#parent}} +export interface {{classname}} { {{>modelGenericAdditionalProperties}} +{{#allVars}} + {{#description}} + /** + * {{{description}}} + */ + {{/description}} + {{name}}{{^required}}?{{/required}}: {{#discriminatorValue}}'{{discriminatorValue}}'{{/discriminatorValue}}{{^discriminatorValue}}{{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}}{{/discriminatorValue}}; +{{/allVars}} +} +{{>modelGenericEnums}} +{{/parent}} +{{^parent}} +{{>modelGeneric}} +{{/parent}} +{{/discriminator}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/TypeScriptAngularClientOptionsProvider.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/TypeScriptAngularClientOptionsProvider.java index d0e53eaeb21..c39586131b6 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/TypeScriptAngularClientOptionsProvider.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/TypeScriptAngularClientOptionsProvider.java @@ -35,6 +35,7 @@ public class TypeScriptAngularClientOptionsProvider implements OptionsProvider { .put(TypeScriptAngularClientCodegen.NPM_VERSION, NMP_VERSION) .put(TypeScriptAngularClientCodegen.SNAPSHOT, Boolean.FALSE.toString()) .put(TypeScriptAngularClientCodegen.WITH_INTERFACES, Boolean.FALSE.toString()) + .put(TypeScriptAngularClientCodegen.TAGGED_UNIONS, Boolean.FALSE.toString()) .put(TypeScriptAngularClientCodegen.NPM_REPOSITORY, NPM_REPOSITORY) .put(TypeScriptAngularClientCodegen.NG_VERSION, NG_VERSION) .put(CodegenConstants.ALLOW_UNICODE_IDENTIFIERS, ALLOW_UNICODE_IDENTIFIERS_VALUE) diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/typescriptangular/TypeScriptAngularClientOptionsTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/typescriptangular/TypeScriptAngularClientOptionsTest.java index 6dd88157eb1..bc363ea58c4 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/typescriptangular/TypeScriptAngularClientOptionsTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/typescriptangular/TypeScriptAngularClientOptionsTest.java @@ -4,7 +4,6 @@ import io.swagger.codegen.AbstractOptionsTest; import io.swagger.codegen.CodegenConfig; import io.swagger.codegen.languages.TypeScriptAngularClientCodegen; import io.swagger.codegen.options.TypeScriptAngularClientOptionsProvider; -import io.swagger.codegen.options.TypeScriptAngularClientOptionsProvider; import mockit.Expectations; import mockit.Tested; diff --git a/samples/client/petstore-security-test/typescript-angular/.swagger-codegen/VERSION b/samples/client/petstore-security-test/typescript-angular/.swagger-codegen/VERSION index f9f7450d135..cc6612c36e0 100644 --- a/samples/client/petstore-security-test/typescript-angular/.swagger-codegen/VERSION +++ b/samples/client/petstore-security-test/typescript-angular/.swagger-codegen/VERSION @@ -1 +1 @@ -2.3.0-SNAPSHOT \ No newline at end of file +2.3.0 \ No newline at end of file diff --git a/samples/client/petstore-security-test/typescript-angular/api.module.ts b/samples/client/petstore-security-test/typescript-angular/api.module.ts index c3bde487bc4..77fac0cd707 100644 --- a/samples/client/petstore-security-test/typescript-angular/api.module.ts +++ b/samples/client/petstore-security-test/typescript-angular/api.module.ts @@ -1,21 +1,28 @@ -import { NgModule, ModuleWithProviders } from '@angular/core'; +import { NgModule, ModuleWithProviders, SkipSelf, Optional } from '@angular/core'; import { CommonModule } from '@angular/common'; -import { HttpModule } from '@angular/http'; +import { HttpClientModule } from '@angular/common/http'; import { Configuration } from './configuration'; import { FakeService } from './api/fake.service'; @NgModule({ - imports: [ CommonModule, HttpModule ], + imports: [ CommonModule, HttpClientModule ], declarations: [], exports: [], - providers: [ FakeService ] + providers: [ + FakeService ] }) export class ApiModule { - public static forConfig(configurationFactory: () => Configuration): ModuleWithProviders { + public static forRoot(configurationFactory: () => Configuration): ModuleWithProviders { return { ngModule: ApiModule, - providers: [ {provide: Configuration, useFactory: configurationFactory}] + providers: [ { provide: Configuration, useFactory: configurationFactory } ] + } + } + + constructor( @Optional() @SkipSelf() parentModule: ApiModule) { + if (parentModule) { + throw new Error('ApiModule is already loaded. Import your base AppModule only.'); } } } diff --git a/samples/client/petstore-security-test/typescript-angular/api/fake.service.ts b/samples/client/petstore-security-test/typescript-angular/api/fake.service.ts index ec51d332251..d0047d78bee 100644 --- a/samples/client/petstore-security-test/typescript-angular/api/fake.service.ts +++ b/samples/client/petstore-security-test/typescript-angular/api/fake.service.ts @@ -9,19 +9,18 @@ * https://github.com/swagger-api/swagger-codegen.git * Do not edit the class manually. */ - /* tslint:disable:no-unused-variable member-ordering */ import { Inject, Injectable, Optional } from '@angular/core'; -import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; +import { HttpClient, HttpHeaders, HttpParams, + HttpResponse, HttpEvent } from '@angular/common/http'; +import { CustomHttpUrlEncodingCodec } from '../encoder'; import { Observable } from 'rxjs/Observable'; -import '../rxjs-operators'; import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; import { Configuration } from '../configuration'; -import { CustomHttpUrlEncodingCodec } from '../encoder'; @Injectable() @@ -56,21 +55,36 @@ export class FakeService { } - /** * To test code injection *_/ ' \" =end -- \\r\\n \\n \\r * - * @param test code inject * ' " =end rn n r To test code injection *_/ ' \" =end -- \\r\\n \\n \\r + * @param testCodeInjectEndRnNR To test code injection *_/ ' \" =end -- \\r\\n \\n \\r + * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. + * @param reportProgress flag to report request and response progress. */ - public testCodeInjectEndRnNR(test code inject * ' " =end rn n r?: string): Observable<{}> { + public testCodeInjectEndRnNR(testCodeInjectEndRnNR?: string, observe?: 'body', reportProgress?: boolean): Observable; + public testCodeInjectEndRnNR(testCodeInjectEndRnNR?: string, observe?: 'response', reportProgress?: boolean): Observable>; + public testCodeInjectEndRnNR(testCodeInjectEndRnNR?: string, observe?: 'events', reportProgress?: boolean): Observable>; + public testCodeInjectEndRnNR(testCodeInjectEndRnNR?: string, observe: any = 'body', reportProgress: boolean = false ): Observable { let headers = this.defaultHeaders; + // to determine the Accept header + let httpHeaderAccepts: string[] = [ + 'application/json', + '*_/ =end -- ' + ]; + let httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); + if (httpHeaderAcceptSelected != undefined) { + headers = headers.set("Accept", httpHeaderAcceptSelected); + } + // to determine the Content-Type header let consumes: string[] = [ 'application/json', '*_/ =end -- ' ]; + const canConsumeForm = this.canConsumeForm(consumes); let formParams: { append(param: string, value: any): void; }; @@ -82,17 +96,19 @@ export class FakeService { formParams = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()}); } - - - if (test code inject * ' " =end rn n r !== undefined) { - formParams = formParams.append('test code inject */ ' " =end -- \r\n \n \r', test code inject * ' " =end rn n r) || formParams; + if (testCodeInjectEndRnNR !== undefined) { + formParams = formParams.append('test code inject */ ' " =end -- \r\n \n \r', testCodeInjectEndRnNR) || formParams; } - return this.httpClient.put(`${this.basePath}/fake`, - convertFormParamsToString ? formParams.toString() : formParams, { - headers: headers, - withCredentials: this.configuration.withCredentials, - }); + return this.httpClient.put(`${this.basePath}/fake`, + convertFormParamsToString ? formParams.toString() : formParams, + { + withCredentials: this.configuration.withCredentials, + headers: headers, + observe: observe, + reportProgress: reportProgress + } + ); } } diff --git a/samples/client/petstore-security-test/typescript-angular/configuration.ts b/samples/client/petstore-security-test/typescript-angular/configuration.ts index 005c3a26df3..2ee1824f5f7 100644 --- a/samples/client/petstore-security-test/typescript-angular/configuration.ts +++ b/samples/client/petstore-security-test/typescript-angular/configuration.ts @@ -23,4 +23,57 @@ export class Configuration { this.basePath = configurationParameters.basePath; this.withCredentials = configurationParameters.withCredentials; } + + /** + * Select the correct content-type to use for a request. + * Uses {@link Configuration#isJsonMime} to determine the correct content-type. + * If no content type is found return the first found type if the contentTypes is not empty + * @param {string[]} contentTypes - the array of content types that are available for selection + * @returns {string} the selected content-type or undefined if no selection could be made. + */ + public selectHeaderContentType (contentTypes: string[]): string | undefined { + if (contentTypes.length == 0) { + return undefined; + } + + let type = contentTypes.find(x => this.isJsonMime(x)); + if (type === undefined) { + return contentTypes[0]; + } + return type; + } + + /** + * Select the correct accept content-type to use for a request. + * Uses {@link Configuration#isJsonMime} to determine the correct accept content-type. + * If no content type is found return the first found type if the contentTypes is not empty + * @param {string[]} accepts - the array of content types that are available for selection. + * @returns {string} the selected content-type or undefined if no selection could be made. + */ + public selectHeaderAccept(accepts: string[]): string | undefined { + if (accepts.length == 0) { + return undefined; + } + + let type = accepts.find(x => this.isJsonMime(x)); + if (type === undefined) { + return accepts[0]; + } + return type; + } + + /** + * Check if the given MIME is a JSON MIME. + * JSON MIME examples: + * application/json + * application/json; charset=UTF8 + * APPLICATION/JSON + * application/vnd.company+json + * @param {string} mime - MIME (Multipurpose Internet Mail Extensions) + * @return {boolean} True if the given MIME is JSON, false otherwise. + */ + public isJsonMime(mime: string): boolean { + const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i'); + return mime != null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json'); + } } diff --git a/samples/client/petstore-security-test/typescript-angular/git_push.sh b/samples/client/petstore-security-test/typescript-angular/git_push.sh index ed374619b13..ae01b182ae9 100644 --- a/samples/client/petstore-security-test/typescript-angular/git_push.sh +++ b/samples/client/petstore-security-test/typescript-angular/git_push.sh @@ -36,7 +36,7 @@ git_remote=`git remote` if [ "$git_remote" = "" ]; then # git remote not defined if [ "$GIT_TOKEN" = "" ]; then - echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git crediential in your environment." + echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment." git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git else git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git diff --git a/samples/client/petstore-security-test/typescript-angular/model/modelReturn.ts b/samples/client/petstore-security-test/typescript-angular/model/modelReturn.ts new file mode 100644 index 00000000000..515aa6eff6a --- /dev/null +++ b/samples/client/petstore-security-test/typescript-angular/model/modelReturn.ts @@ -0,0 +1,22 @@ +/** + * Swagger Petstore *_/ ' \" =end -- \\r\\n \\n \\r + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end -- + * + * OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r + * Contact: apiteam@swagger.io *_/ ' \" =end -- \\r\\n \\n \\r + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + + +/** + * Model for testing reserved words *_/ ' \" =end -- \\r\\n \\n \\r + */ +export interface ModelReturn { + /** + * property description *_/ ' \" =end -- \\r\\n \\n \\r + */ + _return?: number; +} diff --git a/samples/client/petstore/typescript-angular-v2/default/model/apiResponse.ts b/samples/client/petstore/typescript-angular-v2/default/model/apiResponse.ts new file mode 100644 index 00000000000..af5590c3d85 --- /dev/null +++ b/samples/client/petstore/typescript-angular-v2/default/model/apiResponse.ts @@ -0,0 +1,21 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + + +/** + * Describes the result of uploading an image resource + */ +export interface ApiResponse { + code?: number; + type?: string; + message?: string; +} diff --git a/samples/client/petstore/typescript-angular-v2/default/model/category.ts b/samples/client/petstore/typescript-angular-v2/default/model/category.ts index 5040d1db915..093bd438a38 100644 --- a/samples/client/petstore/typescript-angular-v2/default/model/category.ts +++ b/samples/client/petstore/typescript-angular-v2/default/model/category.ts @@ -14,7 +14,7 @@ /** * A category for a pet */ -export interface Category { +export interface Category { id?: number; name?: string; } diff --git a/samples/client/petstore/typescript-angular-v2/default/model/order.ts b/samples/client/petstore/typescript-angular-v2/default/model/order.ts index 33b60bb6e16..6a1e1fd6bcf 100644 --- a/samples/client/petstore/typescript-angular-v2/default/model/order.ts +++ b/samples/client/petstore/typescript-angular-v2/default/model/order.ts @@ -14,7 +14,7 @@ /** * An order for a pets from the pet store */ -export interface Order { +export interface Order { id?: number; petId?: number; quantity?: number; diff --git a/samples/client/petstore/typescript-angular-v2/default/model/pet.ts b/samples/client/petstore/typescript-angular-v2/default/model/pet.ts index 342ab5f8e75..b8b659008af 100644 --- a/samples/client/petstore/typescript-angular-v2/default/model/pet.ts +++ b/samples/client/petstore/typescript-angular-v2/default/model/pet.ts @@ -16,7 +16,7 @@ import { Tag } from './tag'; /** * A pet for sale in the pet store */ -export interface Pet { +export interface Pet { id?: number; category?: Category; name: string; diff --git a/samples/client/petstore/typescript-angular-v2/default/model/tag.ts b/samples/client/petstore/typescript-angular-v2/default/model/tag.ts index c7524000357..e35232df691 100644 --- a/samples/client/petstore/typescript-angular-v2/default/model/tag.ts +++ b/samples/client/petstore/typescript-angular-v2/default/model/tag.ts @@ -14,7 +14,7 @@ /** * A tag for a pet */ -export interface Tag { +export interface Tag { id?: number; name?: string; } diff --git a/samples/client/petstore/typescript-angular-v2/default/model/user.ts b/samples/client/petstore/typescript-angular-v2/default/model/user.ts index a0261a6f37d..e8788de129c 100644 --- a/samples/client/petstore/typescript-angular-v2/default/model/user.ts +++ b/samples/client/petstore/typescript-angular-v2/default/model/user.ts @@ -14,7 +14,7 @@ /** * A User who is purchasing from the pet store */ -export interface User { +export interface User { id?: number; username?: string; firstName?: string; diff --git a/samples/client/petstore/typescript-angular-v2/npm/model/apiResponse.ts b/samples/client/petstore/typescript-angular-v2/npm/model/apiResponse.ts new file mode 100644 index 00000000000..af5590c3d85 --- /dev/null +++ b/samples/client/petstore/typescript-angular-v2/npm/model/apiResponse.ts @@ -0,0 +1,21 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + + +/** + * Describes the result of uploading an image resource + */ +export interface ApiResponse { + code?: number; + type?: string; + message?: string; +} diff --git a/samples/client/petstore/typescript-angular-v2/npm/model/category.ts b/samples/client/petstore/typescript-angular-v2/npm/model/category.ts index 5040d1db915..093bd438a38 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/model/category.ts +++ b/samples/client/petstore/typescript-angular-v2/npm/model/category.ts @@ -14,7 +14,7 @@ /** * A category for a pet */ -export interface Category { +export interface Category { id?: number; name?: string; } diff --git a/samples/client/petstore/typescript-angular-v2/npm/model/order.ts b/samples/client/petstore/typescript-angular-v2/npm/model/order.ts index 33b60bb6e16..6a1e1fd6bcf 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/model/order.ts +++ b/samples/client/petstore/typescript-angular-v2/npm/model/order.ts @@ -14,7 +14,7 @@ /** * An order for a pets from the pet store */ -export interface Order { +export interface Order { id?: number; petId?: number; quantity?: number; diff --git a/samples/client/petstore/typescript-angular-v2/npm/model/pet.ts b/samples/client/petstore/typescript-angular-v2/npm/model/pet.ts index 342ab5f8e75..b8b659008af 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/model/pet.ts +++ b/samples/client/petstore/typescript-angular-v2/npm/model/pet.ts @@ -16,7 +16,7 @@ import { Tag } from './tag'; /** * A pet for sale in the pet store */ -export interface Pet { +export interface Pet { id?: number; category?: Category; name: string; diff --git a/samples/client/petstore/typescript-angular-v2/npm/model/tag.ts b/samples/client/petstore/typescript-angular-v2/npm/model/tag.ts index c7524000357..e35232df691 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/model/tag.ts +++ b/samples/client/petstore/typescript-angular-v2/npm/model/tag.ts @@ -14,7 +14,7 @@ /** * A tag for a pet */ -export interface Tag { +export interface Tag { id?: number; name?: string; } diff --git a/samples/client/petstore/typescript-angular-v2/npm/model/user.ts b/samples/client/petstore/typescript-angular-v2/npm/model/user.ts index a0261a6f37d..e8788de129c 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/model/user.ts +++ b/samples/client/petstore/typescript-angular-v2/npm/model/user.ts @@ -14,7 +14,7 @@ /** * A User who is purchasing from the pet store */ -export interface User { +export interface User { id?: number; username?: string; firstName?: string; diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/model/apiResponse.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/model/apiResponse.ts index eac4208f022..af5590c3d85 100644 --- a/samples/client/petstore/typescript-angular-v2/with-interfaces/model/apiResponse.ts +++ b/samples/client/petstore/typescript-angular-v2/with-interfaces/model/apiResponse.ts @@ -14,7 +14,7 @@ /** * Describes the result of uploading an image resource */ -export interface ApiResponse { +export interface ApiResponse { code?: number; type?: string; message?: string; diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/model/category.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/model/category.ts new file mode 100644 index 00000000000..093bd438a38 --- /dev/null +++ b/samples/client/petstore/typescript-angular-v2/with-interfaces/model/category.ts @@ -0,0 +1,20 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + + +/** + * A category for a pet + */ +export interface Category { + id?: number; + name?: string; +} diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/model/order.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/model/order.ts new file mode 100644 index 00000000000..6a1e1fd6bcf --- /dev/null +++ b/samples/client/petstore/typescript-angular-v2/with-interfaces/model/order.ts @@ -0,0 +1,35 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + + +/** + * An order for a pets from the pet store + */ +export interface Order { + id?: number; + petId?: number; + quantity?: number; + shipDate?: Date; + /** + * Order Status + */ + status?: Order.StatusEnum; + complete?: boolean; +} +export namespace Order { + export type StatusEnum = 'placed' | 'approved' | 'delivered'; + export const StatusEnum = { + Placed: 'placed' as StatusEnum, + Approved: 'approved' as StatusEnum, + Delivered: 'delivered' as StatusEnum + } +} diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/model/pet.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/model/pet.ts new file mode 100644 index 00000000000..b8b659008af --- /dev/null +++ b/samples/client/petstore/typescript-angular-v2/with-interfaces/model/pet.ts @@ -0,0 +1,37 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ +import { Category } from './category'; +import { Tag } from './tag'; + + +/** + * A pet for sale in the pet store + */ +export interface Pet { + id?: number; + category?: Category; + name: string; + photoUrls: Array; + tags?: Array; + /** + * pet status in the store + */ + status?: Pet.StatusEnum; +} +export namespace Pet { + export type StatusEnum = 'available' | 'pending' | 'sold'; + export const StatusEnum = { + Available: 'available' as StatusEnum, + Pending: 'pending' as StatusEnum, + Sold: 'sold' as StatusEnum + } +} diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/model/tag.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/model/tag.ts new file mode 100644 index 00000000000..e35232df691 --- /dev/null +++ b/samples/client/petstore/typescript-angular-v2/with-interfaces/model/tag.ts @@ -0,0 +1,20 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + + +/** + * A tag for a pet + */ +export interface Tag { + id?: number; + name?: string; +} diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/model/user.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/model/user.ts new file mode 100644 index 00000000000..e8788de129c --- /dev/null +++ b/samples/client/petstore/typescript-angular-v2/with-interfaces/model/user.ts @@ -0,0 +1,29 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + + +/** + * A User who is purchasing from the pet store + */ +export interface User { + id?: number; + username?: string; + firstName?: string; + lastName?: string; + email?: string; + password?: string; + phone?: string; + /** + * User Status + */ + userStatus?: number; +} diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/model/apiResponse.ts b/samples/client/petstore/typescript-angular-v4.3/npm/model/apiResponse.ts index eac4208f022..af5590c3d85 100644 --- a/samples/client/petstore/typescript-angular-v4.3/npm/model/apiResponse.ts +++ b/samples/client/petstore/typescript-angular-v4.3/npm/model/apiResponse.ts @@ -14,7 +14,7 @@ /** * Describes the result of uploading an image resource */ -export interface ApiResponse { +export interface ApiResponse { code?: number; type?: string; message?: string; diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/model/category.ts b/samples/client/petstore/typescript-angular-v4.3/npm/model/category.ts index 5040d1db915..093bd438a38 100644 --- a/samples/client/petstore/typescript-angular-v4.3/npm/model/category.ts +++ b/samples/client/petstore/typescript-angular-v4.3/npm/model/category.ts @@ -14,7 +14,7 @@ /** * A category for a pet */ -export interface Category { +export interface Category { id?: number; name?: string; } diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/model/order.ts b/samples/client/petstore/typescript-angular-v4.3/npm/model/order.ts index 33b60bb6e16..6a1e1fd6bcf 100644 --- a/samples/client/petstore/typescript-angular-v4.3/npm/model/order.ts +++ b/samples/client/petstore/typescript-angular-v4.3/npm/model/order.ts @@ -14,7 +14,7 @@ /** * An order for a pets from the pet store */ -export interface Order { +export interface Order { id?: number; petId?: number; quantity?: number; diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/model/pet.ts b/samples/client/petstore/typescript-angular-v4.3/npm/model/pet.ts index 342ab5f8e75..b8b659008af 100644 --- a/samples/client/petstore/typescript-angular-v4.3/npm/model/pet.ts +++ b/samples/client/petstore/typescript-angular-v4.3/npm/model/pet.ts @@ -16,7 +16,7 @@ import { Tag } from './tag'; /** * A pet for sale in the pet store */ -export interface Pet { +export interface Pet { id?: number; category?: Category; name: string; diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/model/tag.ts b/samples/client/petstore/typescript-angular-v4.3/npm/model/tag.ts index c7524000357..e35232df691 100644 --- a/samples/client/petstore/typescript-angular-v4.3/npm/model/tag.ts +++ b/samples/client/petstore/typescript-angular-v4.3/npm/model/tag.ts @@ -14,7 +14,7 @@ /** * A tag for a pet */ -export interface Tag { +export interface Tag { id?: number; name?: string; } diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/model/user.ts b/samples/client/petstore/typescript-angular-v4.3/npm/model/user.ts index a0261a6f37d..e8788de129c 100644 --- a/samples/client/petstore/typescript-angular-v4.3/npm/model/user.ts +++ b/samples/client/petstore/typescript-angular-v4.3/npm/model/user.ts @@ -14,7 +14,7 @@ /** * A User who is purchasing from the pet store */ -export interface User { +export interface User { id?: number; username?: string; firstName?: string; diff --git a/samples/client/petstore/typescript-angular-v4/npm/model/apiResponse.ts b/samples/client/petstore/typescript-angular-v4/npm/model/apiResponse.ts index eac4208f022..af5590c3d85 100644 --- a/samples/client/petstore/typescript-angular-v4/npm/model/apiResponse.ts +++ b/samples/client/petstore/typescript-angular-v4/npm/model/apiResponse.ts @@ -14,7 +14,7 @@ /** * Describes the result of uploading an image resource */ -export interface ApiResponse { +export interface ApiResponse { code?: number; type?: string; message?: string; diff --git a/samples/client/petstore/typescript-angular-v4/npm/model/category.ts b/samples/client/petstore/typescript-angular-v4/npm/model/category.ts index 5040d1db915..093bd438a38 100644 --- a/samples/client/petstore/typescript-angular-v4/npm/model/category.ts +++ b/samples/client/petstore/typescript-angular-v4/npm/model/category.ts @@ -14,7 +14,7 @@ /** * A category for a pet */ -export interface Category { +export interface Category { id?: number; name?: string; } diff --git a/samples/client/petstore/typescript-angular-v4/npm/model/order.ts b/samples/client/petstore/typescript-angular-v4/npm/model/order.ts index 33b60bb6e16..6a1e1fd6bcf 100644 --- a/samples/client/petstore/typescript-angular-v4/npm/model/order.ts +++ b/samples/client/petstore/typescript-angular-v4/npm/model/order.ts @@ -14,7 +14,7 @@ /** * An order for a pets from the pet store */ -export interface Order { +export interface Order { id?: number; petId?: number; quantity?: number; diff --git a/samples/client/petstore/typescript-angular-v4/npm/model/pet.ts b/samples/client/petstore/typescript-angular-v4/npm/model/pet.ts index 342ab5f8e75..b8b659008af 100644 --- a/samples/client/petstore/typescript-angular-v4/npm/model/pet.ts +++ b/samples/client/petstore/typescript-angular-v4/npm/model/pet.ts @@ -16,7 +16,7 @@ import { Tag } from './tag'; /** * A pet for sale in the pet store */ -export interface Pet { +export interface Pet { id?: number; category?: Category; name: string; diff --git a/samples/client/petstore/typescript-angular-v4/npm/model/tag.ts b/samples/client/petstore/typescript-angular-v4/npm/model/tag.ts index c7524000357..e35232df691 100644 --- a/samples/client/petstore/typescript-angular-v4/npm/model/tag.ts +++ b/samples/client/petstore/typescript-angular-v4/npm/model/tag.ts @@ -14,7 +14,7 @@ /** * A tag for a pet */ -export interface Tag { +export interface Tag { id?: number; name?: string; } diff --git a/samples/client/petstore/typescript-angular-v4/npm/model/user.ts b/samples/client/petstore/typescript-angular-v4/npm/model/user.ts index a0261a6f37d..e8788de129c 100644 --- a/samples/client/petstore/typescript-angular-v4/npm/model/user.ts +++ b/samples/client/petstore/typescript-angular-v4/npm/model/user.ts @@ -14,7 +14,7 @@ /** * A User who is purchasing from the pet store */ -export interface User { +export interface User { id?: number; username?: string; firstName?: string;