[Scala] Default case class Option types to None for non-required fields (#6790)

* [Scala] Default case class Option types to None

* Update Petstore sample
This commit is contained in:
Greg Marzouka 2017-11-10 02:57:40 -05:00 committed by wing328
parent b404dafa02
commit f921f4f4da
10 changed files with 34 additions and 38 deletions

View File

@ -12,7 +12,7 @@ case class {{classname}} (
{{#description}}
/* {{{description}}} */
{{/description}}
{{{name}}}: {{^required}}Option[{{/required}}{{datatype}}{{^required}}]{{/required}}{{#hasMore}},{{/hasMore}}
{{{name}}}: {{^required}}Option[{{/required}}{{datatype}}{{^required}}] = None{{/required}}{{#hasMore}},{{/hasMore}}
{{/vars}}
)

View File

@ -211,7 +211,7 @@
</dependency>
<dependency>
<groupId>com.wordnik.swagger</groupId>
<artifactId>swagger-async-httpclient_2.11</artifactId>
<artifactId>swagger-async-httpclient_2.10</artifactId>
<version>${swagger-async-httpclient-version}</version>
</dependency>
</dependencies>

View File

@ -40,10 +40,8 @@ import scala.concurrent._
import scala.concurrent.duration._
import scala.util.{Failure, Success, Try}
class FakeApi(
val defBasePath: String = "https://petstore.swagger.io *_/ ' \" =end -- \\r\\n \\n \\r/v2 *_/ ' \" =end -- \\r\\n \\n \\r",
defApiInvoker: ApiInvoker = ApiInvoker
) {
class FakeApi(val defBasePath: String = "https://petstore.swagger.io *_/ ' \" =end -- \\r\\n \\n \\r/v2 *_/ ' \" =end -- \\r\\n \\n \\r",
defApiInvoker: ApiInvoker = ApiInvoker) {
implicit val formats = new org.json4s.DefaultFormats {
override def dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS+0000")
@ -55,13 +53,10 @@ class FakeApi(
implicit val stringWriter = RequestWriters.StringWriter
implicit val jsonWriter = JsonFormatsWriter
var basePath: String = defBasePath
var apiInvoker: ApiInvoker = defApiInvoker
def addHeader(key: String, value: String): mutable.HashMap[String, String] = {
apiInvoker.defaultHeaders += key -> value
}
var basePath = defBasePath
var apiInvoker = defApiInvoker
def addHeader(key: String, value: String) = apiInvoker.defaultHeaders += key -> value
val config = SwaggerConfig.forUrl(new URI(defBasePath))
val client = new RestClient(config)
val helper = new FakeApiAsyncHelper(client, config)
@ -90,6 +85,7 @@ class FakeApi(
helper.testCodeInject * &#39; &quot; &#x3D;end rn n r(testCodeInjectEndRnNR)
}
}
class FakeApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extends ApiClient(client, config) {

View File

@ -15,6 +15,6 @@ package io.swagger.client.model
case class ModelReturn (
/* property description *_/ ' \" =end -- \\r\\n \\n \\r */
_return: Option[Integer]
_return: Option[Integer] = None
)

View File

@ -14,8 +14,8 @@ package io.swagger.client.model
case class ApiResponse (
code: Option[Integer],
_type: Option[String],
message: Option[String]
code: Option[Integer] = None,
_type: Option[String] = None,
message: Option[String] = None
)

View File

@ -14,7 +14,7 @@ package io.swagger.client.model
case class Category (
id: Option[Long],
name: Option[String]
id: Option[Long] = None,
name: Option[String] = None
)

View File

@ -15,12 +15,12 @@ package io.swagger.client.model
import java.util.Date
case class Order (
id: Option[Long],
petId: Option[Long],
quantity: Option[Integer],
shipDate: Option[Date],
id: Option[Long] = None,
petId: Option[Long] = None,
quantity: Option[Integer] = None,
shipDate: Option[Date] = None,
/* Order Status */
status: Option[String],
complete: Option[Boolean]
status: Option[String] = None,
complete: Option[Boolean] = None
)

View File

@ -14,12 +14,12 @@ package io.swagger.client.model
case class Pet (
id: Option[Long],
category: Option[Category],
id: Option[Long] = None,
category: Option[Category] = None,
name: String,
photoUrls: List[String],
tags: Option[List[Tag]],
tags: Option[List[Tag]] = None,
/* pet status in the store */
status: Option[String]
status: Option[String] = None
)

View File

@ -14,7 +14,7 @@ package io.swagger.client.model
case class Tag (
id: Option[Long],
name: Option[String]
id: Option[Long] = None,
name: Option[String] = None
)

View File

@ -14,14 +14,14 @@ package io.swagger.client.model
case class User (
id: Option[Long],
username: Option[String],
firstName: Option[String],
lastName: Option[String],
email: Option[String],
password: Option[String],
phone: Option[String],
id: Option[Long] = None,
username: Option[String] = None,
firstName: Option[String] = None,
lastName: Option[String] = None,
email: Option[String] = None,
password: Option[String] = None,
phone: Option[String] = None,
/* User Status */
userStatus: Option[Integer]
userStatus: Option[Integer] = None
)