[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}}} */ /* {{{description}}} */
{{/description}} {{/description}}
{{{name}}}: {{^required}}Option[{{/required}}{{datatype}}{{^required}}]{{/required}}{{#hasMore}},{{/hasMore}} {{{name}}}: {{^required}}Option[{{/required}}{{datatype}}{{^required}}] = None{{/required}}{{#hasMore}},{{/hasMore}}
{{/vars}} {{/vars}}
) )

View File

@ -211,7 +211,7 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.wordnik.swagger</groupId> <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> <version>${swagger-async-httpclient-version}</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

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

View File

@ -15,6 +15,6 @@ package io.swagger.client.model
case class ModelReturn ( case class ModelReturn (
/* property description *_/ ' \" =end -- \\r\\n \\n \\r */ /* 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 ( case class ApiResponse (
code: Option[Integer], code: Option[Integer] = None,
_type: Option[String], _type: Option[String] = None,
message: Option[String] message: Option[String] = None
) )

View File

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

View File

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

View File

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

View File

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