Skip to content

Commit 1a5d392

Browse files
authored
Javascript Generator: two small sanitization changes 🦠 (#13268)
* Javascript Generator: small sanitization changes Sanitize module name, do not sanitize description. If we set the project name to "@myorg/mypackage" (scoped package[1]), running `npm test` will fail, as it will generate faulty code due to the module name including the '@' symbol, which is not a valid JS identifier. Additionally, we don't need to sanitize the description - spaces and special characters are fine. We just need to make sure they are escaped, which we're already doing by invoking escapeText() on line 329 [1]anitize module name, do not sanitize description * update JS samples
1 parent b9a6be0 commit 1a5d392

File tree

5 files changed

+6
-6
lines changed

5 files changed

+6
-6
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavascriptClientCodegen.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ public void preprocessOpenAPI(OpenAPI openAPI) {
296296
if (StringUtils.isEmpty(info.getDescription())) {
297297
projectDescription = "JS API client generated by OpenAPI Generator";
298298
} else {
299-
projectDescription = sanitizeName(info.getDescription());
299+
projectDescription = info.getDescription();
300300
}
301301
}
302302

@@ -312,7 +312,7 @@ public void preprocessOpenAPI(OpenAPI openAPI) {
312312
projectName = "openapi-js-client";
313313
}
314314
if (StringUtils.isBlank(moduleName)) {
315-
moduleName = camelize(underscore(projectName));
315+
moduleName = camelize(underscore(sanitizeName(projectName)));
316316
}
317317
if (StringUtils.isBlank(projectVersion)) {
318318
projectVersion = "1.0.0";

samples/client/petstore/javascript-es6/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "open_api_petstore",
33
"version": "1.0.0",
4-
"description": "This_spec_is_mainly_for_testing_Petstore_server_and_contains_fake_endpoints_models__Please_do_not_use_this_for_any_other_purpose__Special_characters___",
4+
"description": "This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\",
55
"license": "Apache-2.0",
66
"main": "dist/index.js",
77
"scripts": {

samples/client/petstore/javascript-es6/src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ import UserApi from './api/UserApi';
6969

7070

7171
/**
72-
* This_spec_is_mainly_for_testing_Petstore_server_and_contains_fake_endpoints_models__Please_do_not_use_this_for_any_other_purpose__Special_characters___.<br>
72+
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \&quot; \\.<br>
7373
* The <code>index</code> module provides access to constructors for all the classes which comprise the public API.
7474
* <p>
7575
* An AMD (recommended!) or CommonJS application will generally do something equivalent to the following:

samples/client/petstore/javascript-promise-es6/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "open_api_petstore",
33
"version": "1.0.0",
4-
"description": "This_spec_is_mainly_for_testing_Petstore_server_and_contains_fake_endpoints_models__Please_do_not_use_this_for_any_other_purpose__Special_characters___",
4+
"description": "This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\",
55
"license": "Apache-2.0",
66
"main": "dist/index.js",
77
"scripts": {

samples/client/petstore/javascript-promise-es6/src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ import UserApi from './api/UserApi';
6969

7070

7171
/**
72-
* This_spec_is_mainly_for_testing_Petstore_server_and_contains_fake_endpoints_models__Please_do_not_use_this_for_any_other_purpose__Special_characters___.<br>
72+
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \&quot; \\.<br>
7373
* The <code>index</code> module provides access to constructors for all the classes which comprise the public API.
7474
* <p>
7575
* An AMD (recommended!) or CommonJS application will generally do something equivalent to the following:

0 commit comments

Comments
 (0)