Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JavaScript] fix index.js, ApiClient.js and test files generated to incorrect location (invokerPackage) #2511

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo

final String[][] JAVASCRIPT_SUPPORTING_FILES = new String[][]{
new String[]{"package.mustache", "package.json"},
new String[]{"index.mustache", "src/index.js"},
new String[]{"ApiClient.mustache", "src/ApiClient.js"},
// new String[]{"index.mustache", "src/index.js", },
// new String[]{"ApiClient.mustache", "src/ApiClient.js"},
new String[]{"git_push.sh.mustache", "git_push.sh"},
new String[]{"README.mustache", "README.md"},
new String[]{"mocha.opts", "mocha.opts"},
Expand All @@ -61,8 +61,8 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo

final String[][] JAVASCRIPT_ES6_SUPPORTING_FILES = new String[][]{
new String[]{"package.mustache", "package.json"},
new String[]{"index.mustache", "src/index.js"},
new String[]{"ApiClient.mustache", "src/ApiClient.js"},
// new String[]{"index.mustache", "src/index.js"},
// new String[]{"ApiClient.mustache", "src/ApiClient.js"},
new String[]{"git_push.sh.mustache", "git_push.sh"},
new String[]{"README.mustache", "README.md"},
new String[]{"mocha.opts", "mocha.opts"},
Expand All @@ -85,7 +85,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
protected String modelDocPath = "docs/";
protected String apiTestPath = "api/";
protected String modelTestPath = "model/";
protected boolean useES6 = true; // default is ES5
protected boolean useES6 = true; // default is ES6
private String modelPropertyNaming = "camelCase";

public JavascriptClientCodegen() {
Expand Down Expand Up @@ -337,6 +337,9 @@ public void preprocessOpenAPI(OpenAPI openAPI) {
for (String[] supportingTemplateFile : supportingTemplateFiles) {
supportingFiles.add(new SupportingFile(supportingTemplateFile[0], "", supportingTemplateFile[1]));
}

supportingFiles.add(new SupportingFile("index.mustache", createPath(sourceFolder, invokerPackage), "index.js"));
supportingFiles.add(new SupportingFile("ApiClient.mustache", createPath(sourceFolder, invokerPackage), "ApiClient.js"));
}

@Override
Expand Down Expand Up @@ -373,12 +376,12 @@ private String createPath(String... segments) {

@Override
public String apiTestFileFolder() {
return (outputFolder + "/test/" + apiTestPath).replace('/', File.separatorChar);
return createPath(outputFolder, "test", invokerPackage, apiTestPath);
}

@Override
public String modelTestFileFolder() {
return (outputFolder + "/test/" + modelTestPath).replace('/', File.separatorChar);
return createPath(outputFolder, "test", invokerPackage, modelTestPath);
}

@Override
Expand Down Expand Up @@ -788,7 +791,7 @@ protected String setPropertyExampleValue(CodegenProperty p) {
* @param type Primitive type
* @return Normalized type
*/
public String normalizeType(String type) {
private String normalizeType(String type) {
return type.replaceAll("\\b(Boolean|Integer|Number|String|Date|Blob)\\b", "'$1'");
}

Expand Down Expand Up @@ -867,10 +870,11 @@ public CodegenModel fromModel(String name, Schema model) {
return codegenModel;
}

/*
private String sanitizePath(String p) {
//prefer replace a ', instead of a fuLL URL encode for readability
return p.replaceAll("'", "%27");
}
}*/

private String trimBrackets(String s) {
if (s != null) {
Expand Down Expand Up @@ -959,7 +963,7 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o
if (operations != null) {
List<CodegenOperation> ops = (List<CodegenOperation>) operations.get("operation");
for (CodegenOperation operation : ops) {
List<String> argList = new ArrayList<String>();
List<String> argList = new ArrayList<>();
boolean hasOptionalParams = false;
for (CodegenParameter p : operation.allParams) {
if (p.required) {
Expand Down Expand Up @@ -1014,7 +1018,7 @@ public Map<String, Object> postProcessModels(Map<String, Object> objs) {
// NOTE: can't use 'mandatory' as it is built from ModelImpl.getRequired(), which sorts names
// alphabetically and in any case the document order of 'required' and 'properties' can differ.
List<CodegenProperty> required = new ArrayList<>();
List<CodegenProperty> allRequired = supportsInheritance || supportsMixins ? new ArrayList<CodegenProperty>() : required;
List<CodegenProperty> allRequired = supportsInheritance || supportsMixins ? new ArrayList<>() : required;
cm.vendorExtensions.put("x-required", required);
cm.vendorExtensions.put("x-all-required", allRequired);

Expand Down Expand Up @@ -1120,6 +1124,7 @@ private static CodegenModel reconcileInlineEnums(CodegenModel codegenModel, Code
return codegenModel;
}

/*
private static String sanitizePackageName(String packageName) { // FIXME parameter should not be assigned. Also declare it as "final"
packageName = packageName.trim();
packageName = packageName.replaceAll("[^a-zA-Z0-9_\\.]", "_");
Expand All @@ -1128,6 +1133,7 @@ private static String sanitizePackageName(String packageName) { // FIXME paramet
}
return packageName;
}
*/

@Override
public String toEnumName(CodegenProperty property) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD.
define(['expect.js', '../../src/index'], factory);
define(['expect.js', process.cwd()+'/src/{{#invokerPackage}}{{invokerPackage}}/{{/invokerPackage}}index'], factory);
} else if (typeof module === 'object' && module.exports) {
// CommonJS-like environments that support module.exports, like Node.
factory(require('expect.js'), require('../../src/index'));
factory(require('expect.js'), require(process.cwd()+'/src/{{#invokerPackage}}{{invokerPackage}}/{{/invokerPackage}}index'));
} else {
// Browser globals (root is window)
factory(root.expect, root.{{moduleName}});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD.
define(['expect.js', '../../src/index'], factory);
define(['expect.js', process.cwd()+'/src/{{#invokerPackage}}{{invokerPackage}}/{{/invokerPackage}}index'], factory);
} else if (typeof module === 'object' && module.exports) {
// CommonJS-like environments that support module.exports, like Node.
factory(require('expect.js'), require('../../src/index'));
factory(require('expect.js'), require(process.cwd()+'/src/{{#invokerPackage}}{{invokerPackage}}/{{/invokerPackage}}index'));
} else {
// Browser globals (root is window)
factory(root.expect, root.{{moduleName}});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD.
define(['expect.js', '../../src/index'], factory);
define(['expect.js', process.cwd()+'/src/{{#invokerPackage}}{{invokerPackage}}/{{/invokerPackage}}index'], factory);
} else if (typeof module === 'object' && module.exports) {
// CommonJS-like environments that support module.exports, like Node.
factory(require('expect.js'), require('../../src/index'));
factory(require('expect.js'), require(process.cwd()+'/src/{{#invokerPackage}}{{invokerPackage}}/{{/invokerPackage}}index'));
} else {
// Browser globals (root is window)
factory(root.expect, root.{{moduleName}});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
"babel-core": "6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-stage-0": "^6.24.1",
"expect.js": "~0.3.1",
"expect.js": "^0.3.1",
"mocha": "^5.2.0",
"sinon": "1.17.3"
"sinon": "^7.2.0"
},
"files": [
"dist"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD.
define(['expect.js', '../../src/index'], factory);
define(['expect.js', process.cwd()+'/src/{{#invokerPackage}}{{invokerPackage}}/{{/invokerPackage}}index'], factory);
} else if (typeof module === 'object' && module.exports) {
// CommonJS-like environments that support module.exports, like Node.
factory(require('expect.js'), require('../../src/index'));
factory(require('expect.js'), require(process.cwd()+'/src/{{#invokerPackage}}{{invokerPackage}}/{{/invokerPackage}}index'));
} else {
// Browser globals (root is window)
factory(root.expect, root.{{moduleName}});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "{{licenseName}}",
"main": "{{sourceFolder}}{{#invokerPackage}}/{{invokerPackage}}{{/invokerPackage}}/index.js",
"scripts": {
"test": "./node_modules/mocha/bin/mocha --recursive"
"test": "mocha --recursive"
},
"browser": {
"fs": false
Expand All @@ -14,8 +14,8 @@
"superagent": "3.7.0"
},
"devDependencies": {
"expect.js": "~0.3.1",
"expect.js": "^0.3.1",
"mocha": "^5.2.0",
"sinon": "1.17.3"
"sinon": "^7.2.0"
}
}
7 changes: 0 additions & 7 deletions samples/client/petstore/javascript-es6/docs/AnimalFarm.md

This file was deleted.

This file was deleted.

7 changes: 0 additions & 7 deletions samples/client/petstore/javascript-es6/docs/OuterBoolean.md

This file was deleted.

7 changes: 0 additions & 7 deletions samples/client/petstore/javascript-es6/docs/OuterNumber.md

This file was deleted.

7 changes: 0 additions & 7 deletions samples/client/petstore/javascript-es6/docs/OuterString.md

This file was deleted.

This file was deleted.

4 changes: 2 additions & 2 deletions samples/client/petstore/javascript-es6/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
"babel-core": "6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-stage-0": "^6.24.1",
"expect.js": "~0.3.1",
"expect.js": "^0.3.1",
"mocha": "^5.2.0",
"sinon": "1.17.3"
"sinon": "^7.2.0"
},
"files": [
"dist"
Expand Down
70 changes: 0 additions & 70 deletions samples/client/petstore/javascript-es6/src/model/AnimalFarm.js

This file was deleted.

Loading