Skip to content

Issue 5978 #6431

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 @@ -487,8 +487,17 @@ public String toModelTestFilename(String name) {
@Override
public String toVarName(String name) {
// sanitize name

// var name starts with number
if (name.matches("^\\d.*")) {
String varName = "var" + name; // e.g. 200data => var200Data (after camelize)
LOGGER.warn(name + " (variable name starts with number) cannot be used as variable name. Renamed to " + varName);
name = varName;
}

name = sanitizeName(name); // FIXME parameter should not be assigned. Also declare it as "final"


if("_".equals(name)) {
name = "_u";
}
Expand All @@ -500,7 +509,7 @@ public String toVarName(String name) {

// camelize (lower first character) the variable name
// pet_id => petId
name = camelize(name, true);
//name = camelize(name, true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CodeNinjai Commenting out camelize will probably impact JS ES5 output as well. Shall we keep it as it's?

cc @frol @cliffano

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CodeNinjai Given the code style guides for JS, camel-case should be used for variable and method names. Please, bring it back.

Also, it seems that the custom name.matches(...) should be simply placed into sanitizeName once instead of copy-pasting.


// for reserved word or word starting with number, append _
if (isReservedWord(name) || name.matches("^\\d.*")) {
Expand Down Expand Up @@ -623,6 +632,14 @@ public String toDefaultValue(Property p) {
@Override
public String toDefaultValueWithParam(String name, Property p) {
String type = normalizeType(getTypeDeclaration(p));
// TODO
if (name.matches("^\\d.*")) {
String varName = "var" + name; // e.g. 200data => var200Data (after camelize)
LOGGER.warn(name + " (variable name starts with number) cannot be used as variable name. Renamed to " + varName);
name = varName;
}

name = this.sanitizeName(name);
if (p instanceof RefProperty) {
return " = " + type + ".constructFromObject(data['" + name + "']);";
} else {
Expand Down Expand Up @@ -723,6 +740,12 @@ public String toOperationId(String operationId) {
throw new RuntimeException("Empty method/operation name (operationId) not allowed");
}

if (operationId.matches("^\\d.*")) {
String varName = "var" + operationId; // e.g. 200data => var200Data (after camelize)
LOGGER.warn(operationId + " (operationId starts with number) cannot be used as operationId. Renamed to " + varName);
operationId = varName;
}

operationId = camelize(sanitizeName(operationId), true);

// method name cannot use reserved keyword, e.g. return
Expand Down Expand Up @@ -1042,6 +1065,8 @@ public String toEnumVarName(String value, String datatype) {
return "empty";
}

value = sanitizeName(value);

// for symbol, e.g. $, #
if (getSymbolName(value) != null) {
return (getSymbolName(value)).toUpperCase();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
{{>licenseInfo}}
import expect, { createSpy, spyOn, isSpy } from 'expect';

(function(root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD.
define(['expect.js', '../../src/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'));
} else {
// Browser globals (root is window)
factory(root.expect, root.{{moduleName}});
}

}(this, function(expect, {{moduleName}}) {
'use strict';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
{{>licenseInfo}}
import expect, { createSpy, spyOn, isSpy } from 'expect';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any use of these.


(function(root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD.
define(['expect.js', '../../src/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'));
} else {
// Browser globals (root is window)
factory(root.expect, root.{{moduleName}});
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this going to work? The module will be empty since the factory isn't called.

}(this, function(expect, {{moduleName}}) {
'use strict';

var instance;
let instance;

beforeEach(function() {
{{#models}}
Expand All @@ -25,15 +18,15 @@
{{/models}}
});

var getProperty = function(object, getter, property) {
let getProperty = function(object, getter, property) {
// Use getter method if present; otherwise, get the property directly.
if (typeof object[getter] === 'function')
return object[getter]();
else
return object[property];
}

var setProperty = function(object, setter, property, value) {
let setProperty = function(object, setter, property, value) {
// Use setter method if present; otherwise, set the property directly.
if (typeof object[setter] === 'function')
object[setter](value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default class {{classname}} {{#parent}}{{^parentModel}}{{#vendorExtension
* @member {{=< >=}}{<&vendorExtensions.x-jsdoc-type>}<={{ }}=> {{baseName}}{{#defaultValue}}
* @default {{{defaultValue}}}{{/defaultValue}}
*/{{/emitJSDoc}}
{{baseName}} = {{#defaultValue}}{{{defaultValue}}}{{/defaultValue}}{{^defaultValue}}undefined{{/defaultValue}};
{{name}} = {{#defaultValue}}{{{defaultValue}}}{{/defaultValue}}{{^defaultValue}}undefined{{/defaultValue}};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CodeNinjai I still think this should be {{name}} instead of {{baseName}}

e.g. {{baseName}} (original name specified in the spec) can be "modified-date" while {{name}} is the variable name following JS style guide (e.g. modified_date)

cc @cliffano @frol

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wing328 So that what the change does, doesn't it? It changes {{ baseName }} to {{ name }}.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@frol ah sorry. You're right. I misread.

{{/vars}}

{{#useInheritance}}{{#interfaceModels}}
Expand All @@ -75,7 +75,7 @@ export default class {{classname}} {{#parent}}{{^parentModel}}{{#vendorExtension
* @member {{=< >=}}{<&vendorExtensions.x-jsdoc-type>}<={{ }}=> {{baseName}}{{#defaultValue}}
* @default {{{defaultValue}}}{{/defaultValue}}
*/{{/emitJSDoc}}
{{baseName}} = {{#defaultValue}}{{{defaultValue}}}{{/defaultValue}}{{^defaultValue}}undefined{{/defaultValue}};
{{name}} = {{#defaultValue}}{{{defaultValue}}}{{/defaultValue}}{{^defaultValue}}undefined{{/defaultValue}};
{{/allVars}}
{{/interfaceModels}}{{/useInheritance}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public void enumModelValueTest() {
one.put("name", "1");
one.put("value", "1");
HashMap<String, String> minusOne = new HashMap<String, String>();
minusOne.put("name", "-1");
minusOne.put("name", "_1");
minusOne.put("value", "-1");
Assert.assertEquals(prope.allowableValues.get("enumVars"), Arrays.asList(one, minusOne));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ public void hyphensTest() {
Assert.assertEquals(property.baseName, "created-at");
Assert.assertEquals(property.getter, "getCreatedAt");
Assert.assertEquals(property.setter, "setCreatedAt");
Assert.assertEquals(property.name, "createdAt");
Assert.assertEquals(property.name, "created_at");
}

@Test(description = "convert query[password] to queryPassword")
Expand All @@ -394,7 +394,7 @@ public void squareBracketsTest() {
Assert.assertEquals(property.baseName, "query[password]");
Assert.assertEquals(property.getter, "getQueryPassword");
Assert.assertEquals(property.setter, "setQueryPassword");
Assert.assertEquals(property.name, "queryPassword");
Assert.assertEquals(property.name, "query_password");
}

@Test(description = "properly escape names per 567")
Expand Down Expand Up @@ -446,7 +446,7 @@ public void invalidParamNameTest() {
Assert.assertEquals(property.getter, "getU");
Assert.assertEquals(property.setter, "setU");
Assert.assertEquals(property.datatype, "String");
Assert.assertEquals(property.name, "u");
Assert.assertEquals(property.name, "_u");
Assert.assertEquals(property.defaultValue, null);
Assert.assertEquals(property.baseType, "String");
Assert.assertFalse(property.hasMore);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**mapProperty** | **{String: String}** | | [optional]
**mapOfMapProperty** | **{String: {String: String}}** | | [optional]
**map_property** | **{String: String}** | | [optional]
**map_of_map_property** | **{String: {String: String}}** | | [optional]


Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**arrayArrayNumber** | **[[Number]]** | | [optional]
**ArrayArrayNumber** | **[[Number]]** | | [optional]


Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**arrayNumber** | **[Number]** | | [optional]
**ArrayNumber** | **[Number]** | | [optional]


6 changes: 3 additions & 3 deletions samples/client/petstore/javascript-es6/docs/ArrayTest.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**arrayOfString** | **[String]** | | [optional]
**arrayArrayOfInteger** | **[[Number]]** | | [optional]
**arrayArrayOfModel** | **[[ReadOnlyFirst]]** | | [optional]
**array_of_string** | **[String]** | | [optional]
**array_array_of_integer** | **[[Number]]** | | [optional]
**array_array_of_model** | **[[ReadOnlyFirst]]** | | [optional]


8 changes: 4 additions & 4 deletions samples/client/petstore/javascript-es6/docs/Capitalization.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**smallCamel** | **String** | | [optional]
**capitalCamel** | **String** | | [optional]
**smallSnake** | **String** | | [optional]
**capitalSnake** | **String** | | [optional]
**sCAETHFlowPoints** | **String** | | [optional]
**CapitalCamel** | **String** | | [optional]
**small_Snake** | **String** | | [optional]
**Capital_Snake** | **String** | | [optional]
**SCA_ETH_Flow_Points** | **String** | | [optional]
**ATT_NAME** | **String** | Name of the pet | [optional]


8 changes: 4 additions & 4 deletions samples/client/petstore/javascript-es6/docs/EnumArrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**justSymbol** | **String** | | [optional]
**arrayEnum** | **[String]** | | [optional]
**just_symbol** | **String** | | [optional]
**array_enum** | **[String]** | | [optional]


<a name="JustSymbolEnum"></a>
## Enum: JustSymbolEnum


* `GREATER_THAN_OR_EQUAL_TO` (value: `">="`)
* `` (value: `">="`)

* `DOLLAR` (value: `"$"`)
* `value` (value: `"$"`)



Expand Down
4 changes: 2 additions & 2 deletions samples/client/petstore/javascript-es6/docs/EnumClass.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

* `_abc` (value: `"_abc"`)

* `-efg` (value: `"-efg"`)
* `_efg` (value: `"-efg"`)

* `(xyz)` (value: `"(xyz)"`)
* `_xyz` (value: `"(xyz)"`)


12 changes: 6 additions & 6 deletions samples/client/petstore/javascript-es6/docs/EnumTest.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**enumString** | **String** | | [optional]
**enumInteger** | **Number** | | [optional]
**enumNumber** | **Number** | | [optional]
**enum_string** | **String** | | [optional]
**enum_integer** | **Number** | | [optional]
**enum_number** | **Number** | | [optional]
**outerEnum** | [**OuterEnum**](OuterEnum.md) | | [optional]


Expand All @@ -28,7 +28,7 @@ Name | Type | Description | Notes

* `1` (value: `1`)

* `-1` (value: `-1`)
* `_1` (value: `-1`)



Expand All @@ -37,9 +37,9 @@ Name | Type | Description | Notes
## Enum: EnumNumberEnum


* `1.1` (value: `1.1`)
* `1_1` (value: `1.1`)

* `-1.2` (value: `-1.2`)
* `_1_2` (value: `-1.2`)



Expand Down
40 changes: 20 additions & 20 deletions samples/client/petstore/javascript-es6/docs/FakeApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ No authorization required

<a name="testEndpointParameters"></a>
# **testEndpointParameters**
> testEndpointParameters(_number, _double, patternWithoutDelimiter, _byte, opts)
> testEndpointParameters(_number, _double, pattern_without_delimiter, _byte, opts)

Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트

Expand All @@ -267,7 +267,7 @@ let _number = 3.4; // Number | None

let _double = 1.2; // Number | None

let patternWithoutDelimiter = "patternWithoutDelimiter_example"; // String | None
let pattern_without_delimiter = "pattern_without_delimiter_example"; // String | None

let _byte = _byte_example; // Blob | None

Expand All @@ -284,7 +284,7 @@ let opts = {
'callback': "callback_example" // String | None
};

apiInstance.testEndpointParameters(_number, _double, patternWithoutDelimiter, _byte, opts, (error, data, response) => {
apiInstance.testEndpointParameters(_number, _double, pattern_without_delimiter, _byte, opts, (error, data, response) => {
if (error) {
console.error(error);
} else {
Expand All @@ -299,7 +299,7 @@ Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**_number** | **Number**| None |
**_double** | **Number**| None |
**patternWithoutDelimiter** | **String**| None |
**pattern_without_delimiter** | **String**| None |
**_byte** | **Blob**| None |
**integer** | **Number**| None | [optional]
**int32** | **Number**| None | [optional]
Expand Down Expand Up @@ -340,14 +340,14 @@ import SwaggerPetstore from 'swagger_petstore';
let apiInstance = new SwaggerPetstore.FakeApi();

let opts = {
'enumFormStringArray': ["enumFormStringArray_example"], // [String] | Form parameter enum test (string array)
'enumFormString': "-efg", // String | Form parameter enum test (string)
'enumHeaderStringArray': ["enumHeaderStringArray_example"], // [String] | Header parameter enum test (string array)
'enumHeaderString': "-efg", // String | Header parameter enum test (string)
'enumQueryStringArray': ["enumQueryStringArray_example"], // [String] | Query parameter enum test (string array)
'enumQueryString': "-efg", // String | Query parameter enum test (string)
'enumQueryInteger': 56, // Number | Query parameter enum test (double)
'enumQueryDouble': 1.2 // Number | Query parameter enum test (double)
'enum_form_string_array': ["enum_form_string_array_example"], // [String] | Form parameter enum test (string array)
'enum_form_string': "-efg", // String | Form parameter enum test (string)
'enum_header_string_array': ["enum_header_string_array_example"], // [String] | Header parameter enum test (string array)
'enum_header_string': "-efg", // String | Header parameter enum test (string)
'enum_query_string_array': ["enum_query_string_array_example"], // [String] | Query parameter enum test (string array)
'enum_query_string': "-efg", // String | Query parameter enum test (string)
'enum_query_integer': 56, // Number | Query parameter enum test (double)
'enum_query_double': 1.2 // Number | Query parameter enum test (double)
};

apiInstance.testEnumParameters(opts, (error, data, response) => {
Expand All @@ -363,14 +363,14 @@ apiInstance.testEnumParameters(opts, (error, data, response) => {

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**enumFormStringArray** | [**[String]**](String.md)| Form parameter enum test (string array) | [optional]
**enumFormString** | **String**| Form parameter enum test (string) | [optional] [default to -efg]
**enumHeaderStringArray** | [**[String]**](String.md)| Header parameter enum test (string array) | [optional]
**enumHeaderString** | **String**| Header parameter enum test (string) | [optional] [default to -efg]
**enumQueryStringArray** | [**[String]**](String.md)| Query parameter enum test (string array) | [optional]
**enumQueryString** | **String**| Query parameter enum test (string) | [optional] [default to -efg]
**enumQueryInteger** | **Number**| Query parameter enum test (double) | [optional]
**enumQueryDouble** | **Number**| Query parameter enum test (double) | [optional]
**enum_form_string_array** | [**[String]**](String.md)| Form parameter enum test (string array) | [optional]
**enum_form_string** | **String**| Form parameter enum test (string) | [optional] [default to -efg]
**enum_header_string_array** | [**[String]**](String.md)| Header parameter enum test (string array) | [optional]
**enum_header_string** | **String**| Header parameter enum test (string) | [optional] [default to -efg]
**enum_query_string_array** | [**[String]**](String.md)| Query parameter enum test (string array) | [optional]
**enum_query_string** | **String**| Query parameter enum test (string) | [optional] [default to -efg]
**enum_query_integer** | **Number**| Query parameter enum test (double) | [optional]
**enum_query_double** | **Number**| Query parameter enum test (double) | [optional]

### Return type

Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/javascript-es6/docs/List.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**_123List** | **String** | | [optional]
**var123_list** | **String** | | [optional]


4 changes: 2 additions & 2 deletions samples/client/petstore/javascript-es6/docs/MapTest.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**mapMapOfString** | **{String: {String: String}}** | | [optional]
**mapOfEnumString** | **{String: String}** | | [optional]
**map_map_of_string** | **{String: {String: String}}** | | [optional]
**map_of_enum_string** | **{String: String}** | | [optional]


<a name="{String: String}"></a>
Expand Down
Loading