forked from loafle/openapi-generator-original
Feature/es6 angular (#5495)
* module code added for es6-angular client code generation * typescript wiped out the core gitignore file * added USE_ES6 cli option to javascript-closure-angular, will use the javascript-es6-angular templates instead * fixed issue with module file * added annotations to the templates * moved default output folder declaration * moved es6 template folder under closure-angular
This commit is contained in:
parent
ba4ecea408
commit
85850b2846
1
.gitignore
vendored
1
.gitignore
vendored
@ -158,4 +158,3 @@ samples/client/petstore/typescript-node/npm/npm-debug.log
|
|||||||
|
|
||||||
# aspnetcore
|
# aspnetcore
|
||||||
samples/server/petstore/aspnetcore/.vs/
|
samples/server/petstore/aspnetcore/.vs/
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package io.swagger.codegen.languages;
|
|||||||
import io.swagger.codegen.CodegenModel;
|
import io.swagger.codegen.CodegenModel;
|
||||||
import io.swagger.codegen.*;
|
import io.swagger.codegen.*;
|
||||||
import io.swagger.models.properties.*;
|
import io.swagger.models.properties.*;
|
||||||
|
import io.swagger.models.Swagger;
|
||||||
|
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -11,8 +12,14 @@ import java.io.File;
|
|||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
public class JavascriptClosureAngularClientCodegen extends DefaultCodegen implements CodegenConfig {
|
public class JavascriptClosureAngularClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||||
|
|
||||||
|
public static final String USE_ES6 = "useEs6";
|
||||||
|
|
||||||
|
protected boolean useEs6;
|
||||||
|
|
||||||
public JavascriptClosureAngularClientCodegen() {
|
public JavascriptClosureAngularClientCodegen() {
|
||||||
super();
|
super();
|
||||||
|
outputFolder = "generated-code/javascript-closure-angular";
|
||||||
|
|
||||||
supportsInheritance = false;
|
supportsInheritance = false;
|
||||||
setReservedWordsLowerCase(Arrays.asList("abstract",
|
setReservedWordsLowerCase(Arrays.asList("abstract",
|
||||||
@ -64,15 +71,11 @@ public class JavascriptClosureAngularClientCodegen extends DefaultCodegen implem
|
|||||||
|
|
||||||
typeMapping.put("binary", "string");
|
typeMapping.put("binary", "string");
|
||||||
|
|
||||||
outputFolder = "generated-code/javascript-closure-angular";
|
|
||||||
modelTemplateFiles.put("model.mustache", ".js");
|
|
||||||
apiTemplateFiles.put("api.mustache", ".js");
|
|
||||||
embeddedTemplateDir = templateDir = "Javascript-Closure-Angular";
|
|
||||||
apiPackage = "API.Client";
|
|
||||||
modelPackage = "API.Client";
|
|
||||||
|
|
||||||
cliOptions.add(new CliOption(CodegenConstants.HIDE_GENERATION_TIMESTAMP, "hides the timestamp when files were generated")
|
cliOptions.add(new CliOption(CodegenConstants.HIDE_GENERATION_TIMESTAMP, "hides the timestamp when files were generated")
|
||||||
.defaultValue(Boolean.TRUE.toString()));
|
.defaultValue(Boolean.TRUE.toString()));
|
||||||
|
cliOptions.add(new CliOption(USE_ES6,
|
||||||
|
"use ES6 templates")
|
||||||
|
.defaultValue(Boolean.FALSE.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -83,6 +86,28 @@ public class JavascriptClosureAngularClientCodegen extends DefaultCodegen implem
|
|||||||
if (!additionalProperties.containsKey(CodegenConstants.HIDE_GENERATION_TIMESTAMP)) {
|
if (!additionalProperties.containsKey(CodegenConstants.HIDE_GENERATION_TIMESTAMP)) {
|
||||||
additionalProperties.put(CodegenConstants.HIDE_GENERATION_TIMESTAMP, Boolean.TRUE.toString());
|
additionalProperties.put(CodegenConstants.HIDE_GENERATION_TIMESTAMP, Boolean.TRUE.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (additionalProperties.containsKey(USE_ES6)) {
|
||||||
|
setUseEs6(convertPropertyToBooleanAndWriteBack(USE_ES6));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void preprocessSwagger(Swagger swagger) {
|
||||||
|
super.preprocessSwagger(swagger);
|
||||||
|
|
||||||
|
if (useEs6) {
|
||||||
|
embeddedTemplateDir = templateDir = "Javascript-Closure-Angular/es6";
|
||||||
|
apiPackage = "resources";
|
||||||
|
apiTemplateFiles.put("api.mustache", ".js");
|
||||||
|
supportingFiles.add(new SupportingFile("module.mustache", "", "module.js"));
|
||||||
|
} else {
|
||||||
|
modelTemplateFiles.put("model.mustache", ".js");
|
||||||
|
apiTemplateFiles.put("api.mustache", ".js");
|
||||||
|
embeddedTemplateDir = templateDir = "Javascript-Closure-Angular";
|
||||||
|
apiPackage = "API.Client";
|
||||||
|
modelPackage = "API.Client";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -273,4 +298,7 @@ public class JavascriptClosureAngularClientCodegen extends DefaultCodegen implem
|
|||||||
return input.replace("*/", "*_/").replace("/*", "/_*");
|
return input.replace("*/", "*_/").replace("/*", "/_*");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setUseEs6(boolean useEs6) {
|
||||||
|
this.useEs6 = useEs6;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,64 @@
|
|||||||
|
/**
|
||||||
|
* @fileoverview AUTOMATICALLY GENERATED service for {{package}}.{{classname}}.
|
||||||
|
* Do not edit this file by hand or your changes will be lost next time it is
|
||||||
|
* generated.{{#appDescription}}
|
||||||
|
*
|
||||||
|
* {{ appDescription }}{{/appDescription}}{{#version}}
|
||||||
|
* Version: {{version}}{{/version}}{{#appContact}}
|
||||||
|
* Contact: {{appContact}}{{/appContact}}
|
||||||
|
{{^hideGenerationTimestamp}}
|
||||||
|
* Generated at: {{generatedDate}}
|
||||||
|
{{/hideGenerationTimestamp}}
|
||||||
|
* Generated by: {{generatorClass}}
|
||||||
|
*/{{#licenseInfo}}
|
||||||
|
/**
|
||||||
|
* @license {{licenseInfo}}{{#licenseUrl}}
|
||||||
|
* {{licenseUrl}}{{/licenseUrl}}
|
||||||
|
*/
|
||||||
|
{{/licenseInfo}}
|
||||||
|
|
||||||
|
{{#operations}}
|
||||||
|
|
||||||
|
export default class {{classname}} {
|
||||||
|
|
||||||
|
/**
|
||||||
|
{{#description}}
|
||||||
|
* {{&description}}
|
||||||
|
{{/description}}
|
||||||
|
* @constructor
|
||||||
|
* @param {!angular.$resource} $resource
|
||||||
|
* @ngInject
|
||||||
|
*/
|
||||||
|
constructor($resource) {
|
||||||
|
this.basePath = '{{basePath}}';
|
||||||
|
|
||||||
|
return $resource(null, {}, {
|
||||||
|
{{#operation}}
|
||||||
|
'{{operationId}}': this.{{operationId}}(),
|
||||||
|
{{/operation}}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
{{#operation}}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {{summary}}
|
||||||
|
* {{notes}} {{#pathParams}}
|
||||||
|
* @param {object} { {{paramName}} : !{{{dataType}}}{{^required}}={{/required}} } path parameters required by resource {{/pathParams}}{{#bodyParams}}
|
||||||
|
* @param {object} { {{paramName}} : !{{{dataType}}}{{^required}}={{/required}} } postData required by resource {{/bodyParams}}
|
||||||
|
* @param {function} Success Callback
|
||||||
|
* @param {function} Error Callback
|
||||||
|
* @return {object}
|
||||||
|
*/
|
||||||
|
{{operationId}}() {
|
||||||
|
return {
|
||||||
|
method: '{{httpMethod}}',
|
||||||
|
url: this.basePath + '{{path}}'
|
||||||
|
{{#pathParams}}
|
||||||
|
.replace('{' + '{{baseName}}' + '}', ':{{paramName}}')
|
||||||
|
{{/pathParams}}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{{/operation}}
|
||||||
|
}
|
||||||
|
{{/operations}}
|
@ -0,0 +1,18 @@
|
|||||||
|
{{#apiInfo}}
|
||||||
|
{{#apis}}
|
||||||
|
{{#operations}}
|
||||||
|
import {{classname}} from './resources/{{classname}}';
|
||||||
|
{{/operations}}
|
||||||
|
{{/apis}}
|
||||||
|
|
||||||
|
let moduleName = '{{appName}}'.toLowerCase().replace(/\s/g, '.');
|
||||||
|
|
||||||
|
export default angular
|
||||||
|
.module(moduleName, [])
|
||||||
|
{{#apis}}
|
||||||
|
{{#operations}}
|
||||||
|
.service('{{classname}}', {{classname}})
|
||||||
|
{{/operations}}
|
||||||
|
{{/apis}};
|
||||||
|
|
||||||
|
{{/apiInfo}}
|
Loading…
x
Reference in New Issue
Block a user