Skip to content
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 @@ -361,7 +361,7 @@ public String toVarName(String name) {
// sanitize name
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.

if ("class".equals(name.toLowerCase())) {
if (name.toLowerCase().matches("^_*class$")) {
return "propertyClass";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,11 @@ public void toEnumVarNameShouldNotShortenUnderScore() throws Exception {
Assert.assertEquals("__", fakeJavaCodegen.toEnumVarName("_,.", "String"));
}

@Test
public void toVarNameShouldAvoidOverloadingGetClassMethod() throws Exception {
Assert.assertEquals("propertyClass", fakeJavaCodegen.toVarName("class"));
Assert.assertEquals("propertyClass", fakeJavaCodegen.toVarName("_class"));
Assert.assertEquals("propertyClass", fakeJavaCodegen.toVarName("__class"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -522,4 +522,29 @@ public void modelNameTest(String name, String expectedName) {
Assert.assertEquals(cm.name, name);
Assert.assertEquals(cm.classname, expectedName);
}

@DataProvider(name = "classProperties")
public static Object[][] classProperties() {
return new Object[][] {
{"class", "getPropertyClass", "setPropertyClass", "propertyClass"},
{"_class", "getPropertyClass", "setPropertyClass", "propertyClass"},
{"__class", "getPropertyClass", "setPropertyClass", "propertyClass"}
};
}

@Test(dataProvider = "classProperties", description = "handle 'class' properties")
public void classPropertyTest(String baseName, String getter, String setter, String name) {
final Model model = new ModelImpl()
.description("a sample model")
.property(baseName, new StringProperty());
final DefaultCodegen codegen = new JavaClientCodegen();
final CodegenModel cm = codegen.fromModel("sample", model);

final CodegenProperty property = cm.vars.get(0);
Assert.assertEquals(property.baseName, baseName);
Assert.assertEquals(property.getter, getter);
Assert.assertEquals(property.setter, setter);
Assert.assertEquals(property.name, name);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -958,9 +958,14 @@ definitions:
type: integer
format: int32
class:
type: string
type: string
xml:
name: Name
ClassModel:
description: Model for testing model with "_class" property
properties:
_class:
type: string
Dog:
allOf:
- $ref: '#/definitions/Animal'
Expand Down
12 changes: 0 additions & 12 deletions samples/client/petstore-security-test/java/okhttp-gson/.travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
#
# Generated by: https://github.com/swagger-api/swagger-codegen.git
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
language: java
jdk:
- oraclejdk8
Expand Down
201 changes: 0 additions & 201 deletions samples/client/petstore-security-test/java/okhttp-gson/LICENSE

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# FakeApi

All URIs are relative to *https://petstore.swagger.io ' \" =end/v2 ' \" =end*
All URIs are relative to *https://petstore.swagger.io *_/ ' \" =end -- \\r\\n \\n \\r/v2 *_/ ' \" =end -- \\r\\n \\n \\r*

Method | HTTP request | Description
------------- | ------------- | -------------
[**testCodeInjectEnd**](FakeApi.md#testCodeInjectEnd) | **PUT** /fake | To test code injection ' \" =end
[**testCodeInjectEndRnNR**](FakeApi.md#testCodeInjectEndRnNR) | **PUT** /fake | To test code injection *_/ ' \" =end -- \\r\\n \\n \\r


<a name="testCodeInjectEnd"></a>
# **testCodeInjectEnd**
> testCodeInjectEnd(testCodeInjectEnd)
<a name="testCodeInjectEndRnNR"></a>
# **testCodeInjectEndRnNR**
> testCodeInjectEndRnNR(testCodeInjectEndRnNR)

To test code injection &#39; \&quot; &#x3D;end
To test code injection *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r

### Example
```java
Expand All @@ -21,11 +21,11 @@ To test code injection &#39; \&quot; &#x3D;end


FakeApi apiInstance = new FakeApi();
String testCodeInjectEnd = "testCodeInjectEnd_example"; // String | To test code injection ' \" =end
String testCodeInjectEndRnNR = "testCodeInjectEndRnNR_example"; // String | To test code injection *_/ ' \" =end -- \\r\\n \\n \\r
try {
apiInstance.testCodeInjectEnd(testCodeInjectEnd);
apiInstance.testCodeInjectEndRnNR(testCodeInjectEndRnNR);
} catch (ApiException e) {
System.err.println("Exception when calling FakeApi#testCodeInjectEnd");
System.err.println("Exception when calling FakeApi#testCodeInjectEndRnNR");
e.printStackTrace();
}
```
Expand All @@ -34,7 +34,7 @@ try {

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**testCodeInjectEnd** | **String**| To test code injection &#39; \&quot; &#x3D;end | [optional]
**testCodeInjectEndRnNR** | **String**| To test code injection *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r | [optional]

### Return type

Expand All @@ -46,6 +46,6 @@ No authorization required

### HTTP request headers

- **Content-Type**: application/json, */ ' =end
- **Accept**: application/json, */ ' =end
- **Content-Type**: application/json, *_/ ' =end --
- **Accept**: application/json, *_/ ' =end --

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**_return** | **Integer** | property description &#39; \&quot; &#x3D;end | [optional]
**_return** | **Integer** | property description *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r | [optional]



Loading