Skip to content

Commit b09d34e

Browse files
committed
fix scala test cases
1 parent a529d9d commit b09d34e

File tree

7 files changed

+70
-22
lines changed

7 files changed

+70
-22
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/ScalaClientCodegen.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public ScalaClientCodegen() {
112112
"Long",
113113
"Float",
114114
"Object",
115+
"Any",
115116
"List",
116117
"Map")
117118
);
@@ -257,4 +258,60 @@ public Map<String, Object> postProcessModels(Map<String, Object> objs) {
257258
return objs;
258259
}
259260

261+
@Override
262+
public String toVarName(String name) {
263+
// sanitize name
264+
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
265+
266+
if("_".equals(name)) {
267+
name = "_u";
268+
}
269+
270+
// if it's all uppper case, do nothing
271+
if (name.matches("^[A-Z_]*$")) {
272+
return name;
273+
}
274+
275+
// camelize (lower first character) the variable name
276+
// pet_id => petId
277+
name = camelize(name, true);
278+
279+
// for reserved word or word starting with number, append _
280+
if (isReservedWord(name) || name.matches("^\\d.*")) {
281+
name = escapeReservedWord(name);
282+
}
283+
284+
return name;
285+
}
286+
287+
@Override
288+
public String toParamName(String name) {
289+
// should be the same as variable name
290+
return toVarName(name);
291+
}
292+
293+
@Override
294+
public String toModelName(final String name) {
295+
final String sanitizedName = sanitizeName(modelNamePrefix + name + modelNameSuffix);
296+
297+
// camelize the model name
298+
// phone_number => PhoneNumber
299+
final String camelizedName = camelize(sanitizedName);
300+
301+
// model name cannot use reserved keyword, e.g. return
302+
if (isReservedWord(camelizedName)) {
303+
final String modelName = "Model" + camelizedName;
304+
LOGGER.warn(camelizedName + " (reserved word) cannot be used as model name. Renamed to " + modelName);
305+
return modelName;
306+
}
307+
308+
return camelizedName;
309+
}
310+
311+
@Override
312+
public String toModelFilename(String name) {
313+
// should be the same as the model name
314+
return toModelName(name);
315+
}
316+
260317
}

samples/client/petstore/scala/src/main/scala/io/swagger/client/api/PetApi.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.swagger.client.api
22

33
import io.swagger.client.model.Pet
4-
import io.swagger.client.model.Inline_response_200
4+
import io.swagger.client.model.InlineResponse200
55
import java.io.File
66
import io.swagger.client.ApiInvoker
77
import io.swagger.client.ApiException
@@ -321,9 +321,9 @@ class PetApi(val defBasePath: String = "http://petstore.swagger.io/v2",
321321
* Fake endpoint to test inline arbitrary object return by &#39;Find pet by ID&#39;
322322
* Returns a pet when ID &lt; 10. ID &gt; 10 or nonintegers will simulate API error conditions
323323
* @param petId ID of pet that needs to be fetched
324-
* @return Inline_response_200
324+
* @return InlineResponse200
325325
*/
326-
def getPetByIdInObject (petId: Long) : Option[Inline_response_200] = {
326+
def getPetByIdInObject (petId: Long) : Option[InlineResponse200] = {
327327
// create path and map variables
328328
val path = "/pet/{petId}?response=inline_arbitrary_object".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}",apiInvoker.escape(petId))
329329

@@ -357,7 +357,7 @@ class PetApi(val defBasePath: String = "http://petstore.swagger.io/v2",
357357
try {
358358
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match {
359359
case s: String =>
360-
Some(ApiInvoker.deserialize(s, "", classOf[Inline_response_200]).asInstanceOf[Inline_response_200])
360+
Some(ApiInvoker.deserialize(s, "", classOf[InlineResponse200]).asInstanceOf[InlineResponse200])
361361

362362
case _ => None
363363
}

samples/client/petstore/scala/src/main/scala/io/swagger/client/api/StoreApi.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.swagger.client.api
22

33
import io.swagger.client.model.Order
4-
import io.swagger.client.model.Any
54
import io.swagger.client.ApiInvoker
65
import io.swagger.client.ApiException
76

samples/client/petstore/scala/src/main/scala/io/swagger/client/model/$special[model.name].scala

Lines changed: 0 additions & 8 deletions
This file was deleted.

samples/client/petstore/scala/src/main/scala/io/swagger/client/model/Inline_response_200.scala renamed to samples/client/petstore/scala/src/main/scala/io/swagger/client/model/InlineResponse200.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package io.swagger.client.model
33

44

55

6-
case class Inline_response_200 (
6+
case class InlineResponse200 (
77
tags: List[Tag],
88
id: Long,
99
category: Any,

samples/client/petstore/scala/src/main/scala/io/swagger/client/model/Return.scala

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package io.swagger.client.model
2+
3+
4+
5+
6+
case class SpecialModelName (
7+
specialPropertyName: Long)
8+

0 commit comments

Comments
 (0)