forked from loafle/openapi-generator-original
* Implement generating interfaces option for api resources, closes swagger-api/swagger-codegen#5453. This commit introduces another _system property_ for typescript-angular2, called `withInterfaces` that is default to `false`. You can activate this flag by: ``` java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \ -i http://petstore.swagger.io/v2/swagger.json \ -l typescript-angular2 -o samples/server/petstore/springboot/typescript-angular2 \ -D withInterfaces=true ``` If set to `true`, generated api resource classes will be implemented with their interfaces in separate files. This change should not break and change the behaviour even though `withInterfaces` flag set to `true`. You are also welcome to create your own custom resource class by implementing those generated interfaces as they support defining new attributes with `[others: string]: any;` signature. * Fix unit test for typescript/angular2 client options for "withInterfaces" * Use double quote to follow coding standard * Respect interface naming convention for typescript/angular2 Create respectful interface names that ends with `Interface` suffix, instead of prefixing with `I` according to typescript naming convention. This is also consistent with their file names that also ends with `Interface.ts`. Also fixes the merge conflicts. * Have better explanation for the `withInterfaces` system config
This commit is contained in:
@@ -28,6 +28,7 @@ public class TypeScriptAngular2ClientCodegen extends AbstractTypeScriptClientCod
|
||||
public static final String SNAPSHOT = "snapshot";
|
||||
public static final String USE_OPAQUE_TOKEN = "useOpaqueToken";
|
||||
public static final String INJECTION_TOKEN = "injectionToken";
|
||||
public static final String WITH_INTERFACES = "withInterfaces";
|
||||
|
||||
protected String npmName = null;
|
||||
protected String npmVersion = "1.0.0";
|
||||
@@ -51,6 +52,7 @@ public class TypeScriptAngular2ClientCodegen extends AbstractTypeScriptClientCod
|
||||
this.cliOptions.add(new CliOption(NPM_REPOSITORY, "Use this property to set an url your private npmRepo in the package.json"));
|
||||
this.cliOptions.add(new CliOption(SNAPSHOT, "When setting this property to true the version will be suffixed with -SNAPSHOT.yyyyMMddHHmm", BooleanProperty.TYPE).defaultValue(Boolean.FALSE.toString()));
|
||||
this.cliOptions.add(new CliOption(USE_OPAQUE_TOKEN, "When setting this property to true, OpaqueToken is used instead of InjectionToken", BooleanProperty.TYPE).defaultValue(Boolean.FALSE.toString()));
|
||||
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()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -88,6 +90,13 @@ public class TypeScriptAngular2ClientCodegen extends AbstractTypeScriptClientCod
|
||||
this.setOpaqueToken();
|
||||
}
|
||||
additionalProperties.put(INJECTION_TOKEN, this.injectionToken);
|
||||
|
||||
if(additionalProperties.containsKey(WITH_INTERFACES)) {
|
||||
boolean withInterfaces = Boolean.parseBoolean(additionalProperties.get(WITH_INTERFACES).toString());
|
||||
if (withInterfaces) {
|
||||
apiTemplateFiles.put("apiInterface.mustache", "Interface.ts");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addNpmPackageGeneration() {
|
||||
|
||||
Reference in New Issue
Block a user