From dabf01c3fa457928858dd4074bfb46eba71b409e Mon Sep 17 00:00:00 2001 From: Jim Schubert Date: Fri, 9 Jun 2017 03:40:18 -0400 Subject: [PATCH 01/10] [kotlin] support collection format multi (#5792) * [kotlin] support collectionFormat:multi Adds "multi" support to collections. Also changes generic lists (List) to arrays. Generic lists and nested lists can be problematic and require customized json factories. The previous implement appeared to work because the results in the test were LinkedHashMap with count greather than 0. The functional test has been updated to force serialization and verify the results. * [kotlin] Regenerate sample * [kotlin] Update model test for Array changes --- .../languages/KotlinClientCodegen.java | 9 +++-- .../main/resources/kotlin-client/api.mustache | 10 +---- .../ApiAbstractions.kt.mustache | 20 ++++++++++ .../infrastructure/ApiClient.kt.mustache | 7 +++- .../infrastructure/RequestConfig.kt.mustache | 4 +- .../kotlin/KotlinClientCodegenModelTest.java | 4 +- samples/client/petstore/kotlin/docs/Pet.md | 4 +- samples/client/petstore/kotlin/docs/PetApi.md | 20 +++++----- .../client/petstore/kotlin/docs/UserApi.md | 8 ++-- .../kotlin/io/swagger/client/apis/PetApi.kt | 40 ++++++++----------- .../kotlin/io/swagger/client/apis/StoreApi.kt | 16 ++------ .../kotlin/io/swagger/client/apis/UserApi.kt | 28 +++++-------- .../client/infrastructure/ApiAbstractions.kt | 20 ++++++++++ .../client/infrastructure/ApiClient.kt | 7 +++- .../client/infrastructure/RequestConfig.kt | 4 +- .../kotlin/io/swagger/client/models/Pet.kt | 4 +- .../swagger/client/functional/EvaluateTest.kt | 7 +++- 17 files changed, 120 insertions(+), 92 deletions(-) create mode 100644 modules/swagger-codegen/src/main/resources/kotlin-client/infrastructure/ApiAbstractions.kt.mustache create mode 100644 samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/infrastructure/ApiAbstractions.kt diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/KotlinClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/KotlinClientCodegen.java index 7e52a1c6554..2df436d195a 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/KotlinClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/KotlinClientCodegen.java @@ -125,16 +125,16 @@ public class KotlinClientCodegen extends DefaultCodegen implements CodegenConfig typeMapping.put("date-time", "java.time.LocalDateTime"); typeMapping.put("date", "java.time.LocalDateTime"); typeMapping.put("file", "java.io.File"); - typeMapping.put("array", "kotlin.collections.List"); - typeMapping.put("list", "kotlin.collections.List"); + typeMapping.put("array", "kotlin.Array"); + typeMapping.put("list", "kotlin.Array"); typeMapping.put("map", "kotlin.collections.Map"); typeMapping.put("object", "kotlin.Any"); typeMapping.put("binary", "kotlin.Array"); typeMapping.put("Date", "java.time.LocalDateTime"); typeMapping.put("DateTime", "java.time.LocalDateTime"); - instantiationTypes.put("array", "listOf"); - instantiationTypes.put("list", "listOf"); + instantiationTypes.put("array", "arrayOf"); + instantiationTypes.put("list", "arrayOf"); instantiationTypes.put("map", "mapOf"); importMapping = new HashMap(); @@ -241,6 +241,7 @@ public class KotlinClientCodegen extends DefaultCodegen implements CodegenConfig final String infrastructureFolder = (sourceFolder + File.separator + packageName + File.separator + "infrastructure").replace(".", "/"); supportingFiles.add(new SupportingFile("infrastructure/ApiClient.kt.mustache", infrastructureFolder, "ApiClient.kt")); + supportingFiles.add(new SupportingFile("infrastructure/ApiAbstractions.kt.mustache", infrastructureFolder, "ApiAbstractions.kt")); supportingFiles.add(new SupportingFile("infrastructure/ApiInfrastructureResponse.kt.mustache", infrastructureFolder, "ApiInfrastructureResponse.kt")); supportingFiles.add(new SupportingFile("infrastructure/ApplicationDelegates.kt.mustache", infrastructureFolder, "ApplicationDelegates.kt")); supportingFiles.add(new SupportingFile("infrastructure/RequestConfig.kt.mustache", infrastructureFolder, "RequestConfig.kt")); diff --git a/modules/swagger-codegen/src/main/resources/kotlin-client/api.mustache b/modules/swagger-codegen/src/main/resources/kotlin-client/api.mustache index 545cd29e691..cae4e8cb62b 100644 --- a/modules/swagger-codegen/src/main/resources/kotlin-client/api.mustache +++ b/modules/swagger-codegen/src/main/resources/kotlin-client/api.mustache @@ -19,7 +19,7 @@ class {{classname}}(basePath: kotlin.String = "{{{basePath}}}") : ApiClient(base @Suppress("UNCHECKED_CAST"){{/returnType}} fun {{operationId}}({{#allParams}}{{paramName}}: {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) : {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Unit{{/returnType}} { val localVariableBody: kotlin.Any? = {{#hasBodyParam}}{{#bodyParams}}{{paramName}}{{/bodyParams}}{{/hasBodyParam}}{{^hasBodyParam}}{{^hasFormParams}}null{{/hasFormParams}}{{#hasFormParams}}mapOf({{#formParams}}"{{{baseName}}}" to "${{paramName}}"{{#hasMore}}, {{/hasMore}}{{/formParams}}){{/hasFormParams}}{{/hasBodyParam}} - val localVariableQuery: kotlin.collections.Map = {{^hasQueryParams}}mapOf(){{/hasQueryParams}}{{#hasQueryParams}}mapOf({{#queryParams}}"{{paramName}}" to {{#isContainer}}{{paramName}}.joinToString(separator = collectionDelimiter("{{collectionFormat}}")){{/isContainer}}{{^isContainer}}{{paramName}}{{/isContainer}}{{#hasMore}}, {{/hasMore}}{{/queryParams}}){{/hasQueryParams}} + val localVariableQuery: MultiValueMap = {{^hasQueryParams}}mapOf(){{/hasQueryParams}}{{#hasQueryParams}}mapOf({{#queryParams}}"{{paramName}}" to {{#isContainer}}toMultiValue({{paramName}}.toList(), "{{collectionFormat}}"){{/isContainer}}{{^isContainer}}listOf("${{paramName}}"){{/isContainer}}{{#hasMore}}, {{/hasMore}}{{/queryParams}}){{/hasQueryParams}} val localVariableHeaders: kotlin.collections.Map = {{^headerParams}}mapOf({{#hasFormParams}}"Content-Type" to "multipart/form-data"{{/hasFormParams}}){{/headerParams}}{{#headerParams}}mapOf("{{paramName}}" to {{#isContainer}}{{paramName}}.joinToString(separator = collectionDelimiter("{{collectionFormat}}")){{/isContainer}}{{^isContainer}}{{paramName}}{{/isContainer}}){{/headerParams}} val localVariableConfig = RequestConfig( RequestMethod.{{httpMethod}}, @@ -43,13 +43,5 @@ class {{classname}}(basePath: kotlin.String = "{{{basePath}}}") : ApiClient(base } {{/operation}} - - private fun collectionDelimiter(collectionFormat: kotlin.String) = when(collectionFormat) { - "csv" -> "," - "tsv" -> "\t" - "pipes" -> "|" - "ssv" -> " " - else -> "" - } } {{/operations}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/kotlin-client/infrastructure/ApiAbstractions.kt.mustache b/modules/swagger-codegen/src/main/resources/kotlin-client/infrastructure/ApiAbstractions.kt.mustache new file mode 100644 index 00000000000..0a42ce534d3 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/kotlin-client/infrastructure/ApiAbstractions.kt.mustache @@ -0,0 +1,20 @@ +package {{packageName}}.infrastructure + +typealias MultiValueMap = Map> + +fun collectionDelimiter(collectionFormat: String) = when(collectionFormat) { + "csv" -> "," + "tsv" -> "\t" + "pipes" -> "|" + "ssv" -> " " + else -> "" +} + +val defaultMultiValueConverter: (item: Any?) -> String = { item -> "$item" } + +fun toMultiValue(items: List, collectionFormat: String, map: (item: Any?) -> String = defaultMultiValueConverter): List { + return when(collectionFormat) { + "multi" -> items.map(map) + else -> listOf(items.map(map).joinToString(separator = collectionDelimiter(collectionFormat))) + } +} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/kotlin-client/infrastructure/ApiClient.kt.mustache b/modules/swagger-codegen/src/main/resources/kotlin-client/infrastructure/ApiClient.kt.mustache index 7480a80fce9..49517bd1592 100644 --- a/modules/swagger-codegen/src/main/resources/kotlin-client/infrastructure/ApiClient.kt.mustache +++ b/modules/swagger-codegen/src/main/resources/kotlin-client/infrastructure/ApiClient.kt.mustache @@ -60,7 +60,11 @@ open class ApiClient(val baseUrl: String) { var urlBuilder = httpUrl.newBuilder() .addPathSegments(requestConfig.path.trimStart('/')) - requestConfig.query.forEach { k, v -> urlBuilder = urlBuilder.addQueryParameter(k,v) } + requestConfig.query.forEach { k, v -> + v.forEach { queryValue -> + urlBuilder = urlBuilder.addQueryParameter(k,queryValue) + } + } val url = urlBuilder.build() val headers = requestConfig.headers + defaultHeaders @@ -73,6 +77,7 @@ open class ApiClient(val baseUrl: String) { throw kotlin.IllegalStateException("Missing Accept header. This is required.") } + // TODO: support multiple contentType,accept options here. val contentType = (headers[ContentType] as String).substringBefore(";").toLowerCase() val accept = (headers[Accept] as String).substringBefore(";").toLowerCase() diff --git a/modules/swagger-codegen/src/main/resources/kotlin-client/infrastructure/RequestConfig.kt.mustache b/modules/swagger-codegen/src/main/resources/kotlin-client/infrastructure/RequestConfig.kt.mustache index 913b42b648e..58a3d605aa1 100644 --- a/modules/swagger-codegen/src/main/resources/kotlin-client/infrastructure/RequestConfig.kt.mustache +++ b/modules/swagger-codegen/src/main/resources/kotlin-client/infrastructure/RequestConfig.kt.mustache @@ -5,9 +5,11 @@ package {{packageName}}.infrastructure * NOTE: This object doesn't include 'body' because it * allows for caching of the constructed object * for many request definitions. + * NOTE: Headers is a Map because rfc2616 defines + * multi-valued headers as csv-only. */ data class RequestConfig( val method: RequestMethod, val path: String, val headers: Map = mapOf(), - val query: Map = mapOf()) \ No newline at end of file + val query: Map> = mapOf()) \ No newline at end of file diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/kotlin/KotlinClientCodegenModelTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/kotlin/KotlinClientCodegenModelTest.java index 474806638d6..23bf434bf3f 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/kotlin/KotlinClientCodegenModelTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/kotlin/KotlinClientCodegenModelTest.java @@ -104,10 +104,10 @@ public class KotlinClientCodegenModelTest { Assert.assertEquals(property.baseName, "examples"); Assert.assertEquals(property.getter, "getExamples"); Assert.assertEquals(property.setter, "setExamples"); - Assert.assertEquals(property.datatype, "kotlin.collections.List"); + Assert.assertEquals(property.datatype, "kotlin.Array"); Assert.assertEquals(property.name, "examples"); Assert.assertEquals(property.defaultValue, "null"); - Assert.assertEquals(property.baseType, "kotlin.collections.List"); + Assert.assertEquals(property.baseType, "kotlin.Array"); Assert.assertEquals(property.containerType, "array"); Assert.assertFalse(property.required); Assert.assertTrue(property.isContainer); diff --git a/samples/client/petstore/kotlin/docs/Pet.md b/samples/client/petstore/kotlin/docs/Pet.md index 73963abeb04..ec775600737 100644 --- a/samples/client/petstore/kotlin/docs/Pet.md +++ b/samples/client/petstore/kotlin/docs/Pet.md @@ -7,8 +7,8 @@ Name | Type | Description | Notes **id** | **kotlin.Long** | | [optional] **category** | [**Category**](Category.md) | | [optional] **name** | **kotlin.String** | | -**photoUrls** | **kotlin.collections.List<kotlin.String>** | | -**tags** | [**kotlin.collections.List<Tag>**](Tag.md) | | [optional] +**photoUrls** | **kotlin.Array<kotlin.String>** | | +**tags** | [**kotlin.Array<Tag>**](Tag.md) | | [optional] **status** | [**inline**](#StatusEnum) | pet status in the store | [optional] diff --git a/samples/client/petstore/kotlin/docs/PetApi.md b/samples/client/petstore/kotlin/docs/PetApi.md index 39803d4af41..29fb5bd0eeb 100644 --- a/samples/client/petstore/kotlin/docs/PetApi.md +++ b/samples/client/petstore/kotlin/docs/PetApi.md @@ -110,7 +110,7 @@ null (empty response body) # **findPetsByStatus** -> kotlin.collections.List<Pet> findPetsByStatus(status) +> kotlin.Array<Pet> findPetsByStatus(status) Finds Pets by status @@ -123,9 +123,9 @@ Multiple status values can be provided with comma separated strings //import io.swagger.client.models.* val apiInstance = PetApi() -val status : kotlin.collections.List = // kotlin.collections.List | Status values that need to be considered for filter +val status : kotlin.Array = // kotlin.Array | Status values that need to be considered for filter try { - val result : kotlin.collections.List = apiInstance.findPetsByStatus(status) + val result : kotlin.Array = apiInstance.findPetsByStatus(status) println(result) } catch (e: ClientException) { println("4xx response calling PetApi#findPetsByStatus") @@ -140,11 +140,11 @@ try { Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **status** | [**kotlin.collections.List<kotlin.String>**](kotlin.String.md)| Status values that need to be considered for filter | [enum: available, pending, sold] + **status** | [**kotlin.Array<kotlin.String>**](kotlin.String.md)| Status values that need to be considered for filter | [enum: available, pending, sold] ### Return type -[**kotlin.collections.List<Pet>**](Pet.md) +[**kotlin.Array<Pet>**](Pet.md) ### Authorization @@ -157,7 +157,7 @@ Name | Type | Description | Notes # **findPetsByTags** -> kotlin.collections.List<Pet> findPetsByTags(tags) +> kotlin.Array<Pet> findPetsByTags(tags) Finds Pets by tags @@ -170,9 +170,9 @@ Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 //import io.swagger.client.models.* val apiInstance = PetApi() -val tags : kotlin.collections.List = // kotlin.collections.List | Tags to filter by +val tags : kotlin.Array = // kotlin.Array | Tags to filter by try { - val result : kotlin.collections.List = apiInstance.findPetsByTags(tags) + val result : kotlin.Array = apiInstance.findPetsByTags(tags) println(result) } catch (e: ClientException) { println("4xx response calling PetApi#findPetsByTags") @@ -187,11 +187,11 @@ try { Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **tags** | [**kotlin.collections.List<kotlin.String>**](kotlin.String.md)| Tags to filter by | + **tags** | [**kotlin.Array<kotlin.String>**](kotlin.String.md)| Tags to filter by | ### Return type -[**kotlin.collections.List<Pet>**](Pet.md) +[**kotlin.Array<Pet>**](Pet.md) ### Authorization diff --git a/samples/client/petstore/kotlin/docs/UserApi.md b/samples/client/petstore/kotlin/docs/UserApi.md index 0974c7f83cb..d15aae23da3 100644 --- a/samples/client/petstore/kotlin/docs/UserApi.md +++ b/samples/client/petstore/kotlin/docs/UserApi.md @@ -75,7 +75,7 @@ Creates list of users with given input array //import io.swagger.client.models.* val apiInstance = UserApi() -val body : kotlin.collections.List = // kotlin.collections.List | List of user object +val body : kotlin.Array = // kotlin.Array | List of user object try { apiInstance.createUsersWithArrayInput(body) } catch (e: ClientException) { @@ -91,7 +91,7 @@ try { Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **body** | [**kotlin.collections.List<User>**](User.md)| List of user object | + **body** | [**kotlin.Array<User>**](User.md)| List of user object | ### Return type @@ -121,7 +121,7 @@ Creates list of users with given input array //import io.swagger.client.models.* val apiInstance = UserApi() -val body : kotlin.collections.List = // kotlin.collections.List | List of user object +val body : kotlin.Array = // kotlin.Array | List of user object try { apiInstance.createUsersWithListInput(body) } catch (e: ClientException) { @@ -137,7 +137,7 @@ try { Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **body** | [**kotlin.collections.List<User>**](User.md)| List of user object | + **body** | [**kotlin.Array<User>**](User.md)| List of user object | ### Return type diff --git a/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/apis/PetApi.kt b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/apis/PetApi.kt index a01400aa9d9..c716883b340 100644 --- a/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/apis/PetApi.kt @@ -26,7 +26,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli */ fun addPet(body: Pet) : Unit { val localVariableBody: kotlin.Any? = body - val localVariableQuery: kotlin.collections.Map = mapOf() + val localVariableQuery: MultiValueMap = mapOf() val localVariableHeaders: kotlin.collections.Map = mapOf() val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -58,7 +58,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli */ fun deletePet(petId: kotlin.Long, apiKey: kotlin.String) : Unit { val localVariableBody: kotlin.Any? = null - val localVariableQuery: kotlin.collections.Map = mapOf() + val localVariableQuery: MultiValueMap = mapOf() val localVariableHeaders: kotlin.collections.Map = mapOf("apiKey" to apiKey) val localVariableConfig = RequestConfig( RequestMethod.DELETE, @@ -85,12 +85,12 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli * Finds Pets by status * Multiple status values can be provided with comma separated strings * @param status Status values that need to be considered for filter - * @return kotlin.collections.List + * @return kotlin.Array */ @Suppress("UNCHECKED_CAST") - fun findPetsByStatus(status: kotlin.collections.List) : kotlin.collections.List { + fun findPetsByStatus(status: kotlin.Array) : kotlin.Array { val localVariableBody: kotlin.Any? = null - val localVariableQuery: kotlin.collections.Map = mapOf("status" to status.joinToString(separator = collectionDelimiter("csv"))) + val localVariableQuery: MultiValueMap = mapOf("status" to toMultiValue(status.toList(), "csv")) val localVariableHeaders: kotlin.collections.Map = mapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -98,13 +98,13 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli query = localVariableQuery, headers = localVariableHeaders ) - val response = request>( + val response = request>( localVariableConfig, localVariableBody ) return when (response.responseType) { - ResponseType.Success -> (response as Success<*>).data as kotlin.collections.List + ResponseType.Success -> (response as Success<*>).data as kotlin.Array ResponseType.Informational -> TODO() ResponseType.Redirection -> TODO() ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") @@ -117,12 +117,12 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli * Finds Pets by tags * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. * @param tags Tags to filter by - * @return kotlin.collections.List + * @return kotlin.Array */ @Suppress("UNCHECKED_CAST") - fun findPetsByTags(tags: kotlin.collections.List) : kotlin.collections.List { + fun findPetsByTags(tags: kotlin.Array) : kotlin.Array { val localVariableBody: kotlin.Any? = null - val localVariableQuery: kotlin.collections.Map = mapOf("tags" to tags.joinToString(separator = collectionDelimiter("csv"))) + val localVariableQuery: MultiValueMap = mapOf("tags" to toMultiValue(tags.toList(), "csv")) val localVariableHeaders: kotlin.collections.Map = mapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -130,13 +130,13 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli query = localVariableQuery, headers = localVariableHeaders ) - val response = request>( + val response = request>( localVariableConfig, localVariableBody ) return when (response.responseType) { - ResponseType.Success -> (response as Success<*>).data as kotlin.collections.List + ResponseType.Success -> (response as Success<*>).data as kotlin.Array ResponseType.Informational -> TODO() ResponseType.Redirection -> TODO() ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") @@ -154,7 +154,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli @Suppress("UNCHECKED_CAST") fun getPetById(petId: kotlin.Long) : Pet { val localVariableBody: kotlin.Any? = null - val localVariableQuery: kotlin.collections.Map = mapOf() + val localVariableQuery: MultiValueMap = mapOf() val localVariableHeaders: kotlin.collections.Map = mapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -185,7 +185,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli */ fun updatePet(body: Pet) : Unit { val localVariableBody: kotlin.Any? = body - val localVariableQuery: kotlin.collections.Map = mapOf() + val localVariableQuery: MultiValueMap = mapOf() val localVariableHeaders: kotlin.collections.Map = mapOf() val localVariableConfig = RequestConfig( RequestMethod.PUT, @@ -218,7 +218,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli */ fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String, status: kotlin.String) : Unit { val localVariableBody: kotlin.Any? = mapOf("name" to "$name", "status" to "$status") - val localVariableQuery: kotlin.collections.Map = mapOf() + val localVariableQuery: MultiValueMap = mapOf() val localVariableHeaders: kotlin.collections.Map = mapOf("Content-Type" to "multipart/form-data") val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -252,7 +252,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli @Suppress("UNCHECKED_CAST") fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String, file: java.io.File) : ApiResponse { val localVariableBody: kotlin.Any? = mapOf("additionalMetadata" to "$additionalMetadata", "file" to "$file") - val localVariableQuery: kotlin.collections.Map = mapOf() + val localVariableQuery: MultiValueMap = mapOf() val localVariableHeaders: kotlin.collections.Map = mapOf("Content-Type" to "multipart/form-data") val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -275,12 +275,4 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli } } - - private fun collectionDelimiter(collectionFormat: kotlin.String) = when(collectionFormat) { - "csv" -> "," - "tsv" -> "\t" - "pipes" -> "|" - "ssv" -> " " - else -> "" - } } diff --git a/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/apis/StoreApi.kt b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/apis/StoreApi.kt index 9dabfdb3b66..53e3813f4dc 100644 --- a/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/apis/StoreApi.kt @@ -25,7 +25,7 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC */ fun deleteOrder(orderId: kotlin.String) : Unit { val localVariableBody: kotlin.Any? = null - val localVariableQuery: kotlin.collections.Map = mapOf() + val localVariableQuery: MultiValueMap = mapOf() val localVariableHeaders: kotlin.collections.Map = mapOf() val localVariableConfig = RequestConfig( RequestMethod.DELETE, @@ -56,7 +56,7 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC @Suppress("UNCHECKED_CAST") fun getInventory() : kotlin.collections.Map { val localVariableBody: kotlin.Any? = null - val localVariableQuery: kotlin.collections.Map = mapOf() + val localVariableQuery: MultiValueMap = mapOf() val localVariableHeaders: kotlin.collections.Map = mapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -88,7 +88,7 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC @Suppress("UNCHECKED_CAST") fun getOrderById(orderId: kotlin.Long) : Order { val localVariableBody: kotlin.Any? = null - val localVariableQuery: kotlin.collections.Map = mapOf() + val localVariableQuery: MultiValueMap = mapOf() val localVariableHeaders: kotlin.collections.Map = mapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -120,7 +120,7 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC @Suppress("UNCHECKED_CAST") fun placeOrder(body: Order) : Order { val localVariableBody: kotlin.Any? = body - val localVariableQuery: kotlin.collections.Map = mapOf() + val localVariableQuery: MultiValueMap = mapOf() val localVariableHeaders: kotlin.collections.Map = mapOf() val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -143,12 +143,4 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC } } - - private fun collectionDelimiter(collectionFormat: kotlin.String) = when(collectionFormat) { - "csv" -> "," - "tsv" -> "\t" - "pipes" -> "|" - "ssv" -> " " - else -> "" - } } diff --git a/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/apis/UserApi.kt b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/apis/UserApi.kt index e703c71bcdd..d3d80fe76ab 100644 --- a/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/apis/UserApi.kt @@ -25,7 +25,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl */ fun createUser(body: User) : Unit { val localVariableBody: kotlin.Any? = body - val localVariableQuery: kotlin.collections.Map = mapOf() + val localVariableQuery: MultiValueMap = mapOf() val localVariableHeaders: kotlin.collections.Map = mapOf() val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -54,9 +54,9 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl * @param body List of user object * @return void */ - fun createUsersWithArrayInput(body: kotlin.collections.List) : Unit { + fun createUsersWithArrayInput(body: kotlin.Array) : Unit { val localVariableBody: kotlin.Any? = body - val localVariableQuery: kotlin.collections.Map = mapOf() + val localVariableQuery: MultiValueMap = mapOf() val localVariableHeaders: kotlin.collections.Map = mapOf() val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -85,9 +85,9 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl * @param body List of user object * @return void */ - fun createUsersWithListInput(body: kotlin.collections.List) : Unit { + fun createUsersWithListInput(body: kotlin.Array) : Unit { val localVariableBody: kotlin.Any? = body - val localVariableQuery: kotlin.collections.Map = mapOf() + val localVariableQuery: MultiValueMap = mapOf() val localVariableHeaders: kotlin.collections.Map = mapOf() val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -118,7 +118,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl */ fun deleteUser(username: kotlin.String) : Unit { val localVariableBody: kotlin.Any? = null - val localVariableQuery: kotlin.collections.Map = mapOf() + val localVariableQuery: MultiValueMap = mapOf() val localVariableHeaders: kotlin.collections.Map = mapOf() val localVariableConfig = RequestConfig( RequestMethod.DELETE, @@ -150,7 +150,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl @Suppress("UNCHECKED_CAST") fun getUserByName(username: kotlin.String) : User { val localVariableBody: kotlin.Any? = null - val localVariableQuery: kotlin.collections.Map = mapOf() + val localVariableQuery: MultiValueMap = mapOf() val localVariableHeaders: kotlin.collections.Map = mapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -183,7 +183,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl @Suppress("UNCHECKED_CAST") fun loginUser(username: kotlin.String, password: kotlin.String) : kotlin.String { val localVariableBody: kotlin.Any? = null - val localVariableQuery: kotlin.collections.Map = mapOf("username" to username, "password" to password) + val localVariableQuery: MultiValueMap = mapOf("username" to listOf("$username"), "password" to listOf("$password")) val localVariableHeaders: kotlin.collections.Map = mapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -213,7 +213,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl */ fun logoutUser() : Unit { val localVariableBody: kotlin.Any? = null - val localVariableQuery: kotlin.collections.Map = mapOf() + val localVariableQuery: MultiValueMap = mapOf() val localVariableHeaders: kotlin.collections.Map = mapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -245,7 +245,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl */ fun updateUser(username: kotlin.String, body: User) : Unit { val localVariableBody: kotlin.Any? = body - val localVariableQuery: kotlin.collections.Map = mapOf() + val localVariableQuery: MultiValueMap = mapOf() val localVariableHeaders: kotlin.collections.Map = mapOf() val localVariableConfig = RequestConfig( RequestMethod.PUT, @@ -268,12 +268,4 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl } } - - private fun collectionDelimiter(collectionFormat: kotlin.String) = when(collectionFormat) { - "csv" -> "," - "tsv" -> "\t" - "pipes" -> "|" - "ssv" -> " " - else -> "" - } } diff --git a/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/infrastructure/ApiAbstractions.kt b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/infrastructure/ApiAbstractions.kt new file mode 100644 index 00000000000..87cc13d045b --- /dev/null +++ b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/infrastructure/ApiAbstractions.kt @@ -0,0 +1,20 @@ +package io.swagger.client.infrastructure + +typealias MultiValueMap = Map> + +fun collectionDelimiter(collectionFormat: String) = when(collectionFormat) { + "csv" -> "," + "tsv" -> "\t" + "pipes" -> "|" + "ssv" -> " " + else -> "" +} + +val defaultMultiValueConverter: (item: Any?) -> String = { item -> "$item" } + +fun toMultiValue(items: List, collectionFormat: String, map: (item: Any?) -> String = defaultMultiValueConverter): List { + return when(collectionFormat) { + "multi" -> items.map(map) + else -> listOf(items.map(map).joinToString(separator = collectionDelimiter(collectionFormat))) + } +} \ No newline at end of file diff --git a/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/infrastructure/ApiClient.kt index 05ff12c0f94..40d771e475d 100644 --- a/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/infrastructure/ApiClient.kt @@ -60,7 +60,11 @@ open class ApiClient(val baseUrl: String) { var urlBuilder = httpUrl.newBuilder() .addPathSegments(requestConfig.path.trimStart('/')) - requestConfig.query.forEach { k, v -> urlBuilder = urlBuilder.addQueryParameter(k,v) } + requestConfig.query.forEach { k, v -> + v.forEach { queryValue -> + urlBuilder = urlBuilder.addQueryParameter(k,queryValue) + } + } val url = urlBuilder.build() val headers = requestConfig.headers + defaultHeaders @@ -73,6 +77,7 @@ open class ApiClient(val baseUrl: String) { throw kotlin.IllegalStateException("Missing Accept header. This is required.") } + // TODO: support multiple contentType,accept options here. val contentType = (headers[ContentType] as String).substringBefore(";").toLowerCase() val accept = (headers[Accept] as String).substringBefore(";").toLowerCase() diff --git a/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/infrastructure/RequestConfig.kt b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/infrastructure/RequestConfig.kt index 1df8b769db5..3825588ce4a 100644 --- a/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/infrastructure/RequestConfig.kt +++ b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/infrastructure/RequestConfig.kt @@ -5,9 +5,11 @@ package io.swagger.client.infrastructure * NOTE: This object doesn't include 'body' because it * allows for caching of the constructed object * for many request definitions. + * NOTE: Headers is a Map because rfc2616 defines + * multi-valued headers as csv-only. */ data class RequestConfig( val method: RequestMethod, val path: String, val headers: Map = mapOf(), - val query: Map = mapOf()) \ No newline at end of file + val query: Map> = mapOf()) \ No newline at end of file diff --git a/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/models/Pet.kt b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/models/Pet.kt index 5fe800afe77..68ee9be1b4b 100644 --- a/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/models/Pet.kt +++ b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/models/Pet.kt @@ -25,10 +25,10 @@ import io.swagger.client.models.Tag */ data class Pet ( val name: kotlin.String, - val photoUrls: kotlin.collections.List, + val photoUrls: kotlin.Array, val id: kotlin.Long? = null, val category: Category? = null, - val tags: kotlin.collections.List? = null, + val tags: kotlin.Array? = null, /* pet status in the store */ val status: Pet.Status? = null ) { diff --git a/samples/client/petstore/kotlin/src/test/kotlin/io/swagger/client/functional/EvaluateTest.kt b/samples/client/petstore/kotlin/src/test/kotlin/io/swagger/client/functional/EvaluateTest.kt index 955560fb798..db40b04f2ef 100644 --- a/samples/client/petstore/kotlin/src/test/kotlin/io/swagger/client/functional/EvaluateTest.kt +++ b/samples/client/petstore/kotlin/src/test/kotlin/io/swagger/client/functional/EvaluateTest.kt @@ -2,16 +2,21 @@ package io.swagger.client.functional import io.kotlintest.matchers.should import io.kotlintest.matchers.beGreaterThan +import io.kotlintest.matchers.shouldEqual import io.kotlintest.specs.ShouldSpec import io.swagger.client.apis.PetApi +import io.swagger.client.models.Pet class EvaluateTest : ShouldSpec() { init { should("query against pet statuses") { val api = PetApi() - val results = api.findPetsByStatus(listOf("sold")) + val results = api.findPetsByStatus(arrayOf("sold")) results.size should beGreaterThan(1) + + // Pet is lazily deserialized here. Need to iterate to verify all "sold" statuses. + results.all { it.status == Pet.Status.sold } shouldEqual true } // TODO: Handle default (200) response From 8f7e2a1563a98ee72e494af612555a4d689180fe Mon Sep 17 00:00:00 2001 From: Mads Hvelplund Date: Fri, 9 Jun 2017 10:09:27 +0200 Subject: [PATCH 02/10] Allow overriding the service delegate (#5662) * Added support for injecting service implementations via web.xml * Updated samples --- .../src/main/resources/JavaJaxRS/api.mustache | 24 ++++++++++++++++++- .../src/gen/java/io/swagger/api/FakeApi.java | 24 ++++++++++++++++++- .../src/gen/java/io/swagger/api/PetApi.java | 24 ++++++++++++++++++- .../src/gen/java/io/swagger/api/StoreApi.java | 24 ++++++++++++++++++- .../src/gen/java/io/swagger/api/UserApi.java | 24 ++++++++++++++++++- 5 files changed, 115 insertions(+), 5 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/api.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/api.mustache index 4e2560932c1..20cd3c87db5 100644 --- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/api.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/api.mustache @@ -18,6 +18,7 @@ import java.io.InputStream; import org.glassfish.jersey.media.multipart.FormDataContentDisposition; import org.glassfish.jersey.media.multipart.FormDataParam; +import javax.servlet.ServletConfig; import javax.ws.rs.core.Context; import javax.ws.rs.core.Response; import javax.ws.rs.core.SecurityContext; @@ -33,7 +34,28 @@ import javax.validation.constraints.*; {{>generatedAnnotation}} {{#operations}} public class {{classname}} { - private final {{classname}}Service delegate = {{classname}}ServiceFactory.get{{classname}}(); + private final {{classname}}Service delegate; + + public {{classname}}(@Context ServletConfig servletContext) { + {{classname}}Service delegate = null; + + if (servletContext != null) { + String implClass = servletContext.getInitParameter("{{classname}}.implementation"); + if (implClass != null && !"".equals(implClass.trim())) { + try { + delegate = ({{classname}}Service) Class.forName(implClass).newInstance(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + } + + if (delegate == null) { + delegate = {{classname}}ServiceFactory.get{{classname}}(); + } + + this.delegate = delegate; + } {{#operation}} @{{httpMethod}} diff --git a/samples/server/petstore/jaxrs/jersey2/src/gen/java/io/swagger/api/FakeApi.java b/samples/server/petstore/jaxrs/jersey2/src/gen/java/io/swagger/api/FakeApi.java index c57513ff09a..6b9497fde67 100644 --- a/samples/server/petstore/jaxrs/jersey2/src/gen/java/io/swagger/api/FakeApi.java +++ b/samples/server/petstore/jaxrs/jersey2/src/gen/java/io/swagger/api/FakeApi.java @@ -20,6 +20,7 @@ import java.io.InputStream; import org.glassfish.jersey.media.multipart.FormDataContentDisposition; import org.glassfish.jersey.media.multipart.FormDataParam; +import javax.servlet.ServletConfig; import javax.ws.rs.core.Context; import javax.ws.rs.core.Response; import javax.ws.rs.core.SecurityContext; @@ -32,7 +33,28 @@ import javax.validation.constraints.*; @io.swagger.annotations.Api(description = "the fake API") public class FakeApi { - private final FakeApiService delegate = FakeApiServiceFactory.getFakeApi(); + private final FakeApiService delegate; + + public FakeApi(@Context ServletConfig servletContext) { + FakeApiService delegate = null; + + if (servletContext != null) { + String implClass = servletContext.getInitParameter("FakeApi.implementation"); + if (implClass != null && !"".equals(implClass.trim())) { + try { + delegate = (FakeApiService) Class.forName(implClass).newInstance(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + } + + if (delegate == null) { + delegate = FakeApiServiceFactory.getFakeApi(); + } + + this.delegate = delegate; + } @POST @Path("/outer/boolean") diff --git a/samples/server/petstore/jaxrs/jersey2/src/gen/java/io/swagger/api/PetApi.java b/samples/server/petstore/jaxrs/jersey2/src/gen/java/io/swagger/api/PetApi.java index 6e5089e40d5..30b1eece3c8 100644 --- a/samples/server/petstore/jaxrs/jersey2/src/gen/java/io/swagger/api/PetApi.java +++ b/samples/server/petstore/jaxrs/jersey2/src/gen/java/io/swagger/api/PetApi.java @@ -19,6 +19,7 @@ import java.io.InputStream; import org.glassfish.jersey.media.multipart.FormDataContentDisposition; import org.glassfish.jersey.media.multipart.FormDataParam; +import javax.servlet.ServletConfig; import javax.ws.rs.core.Context; import javax.ws.rs.core.Response; import javax.ws.rs.core.SecurityContext; @@ -31,7 +32,28 @@ import javax.validation.constraints.*; @io.swagger.annotations.Api(description = "the pet API") public class PetApi { - private final PetApiService delegate = PetApiServiceFactory.getPetApi(); + private final PetApiService delegate; + + public PetApi(@Context ServletConfig servletContext) { + PetApiService delegate = null; + + if (servletContext != null) { + String implClass = servletContext.getInitParameter("PetApi.implementation"); + if (implClass != null && !"".equals(implClass.trim())) { + try { + delegate = (PetApiService) Class.forName(implClass).newInstance(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + } + + if (delegate == null) { + delegate = PetApiServiceFactory.getPetApi(); + } + + this.delegate = delegate; + } @POST diff --git a/samples/server/petstore/jaxrs/jersey2/src/gen/java/io/swagger/api/StoreApi.java b/samples/server/petstore/jaxrs/jersey2/src/gen/java/io/swagger/api/StoreApi.java index b2b9e2a4323..18c5a14979c 100644 --- a/samples/server/petstore/jaxrs/jersey2/src/gen/java/io/swagger/api/StoreApi.java +++ b/samples/server/petstore/jaxrs/jersey2/src/gen/java/io/swagger/api/StoreApi.java @@ -18,6 +18,7 @@ import java.io.InputStream; import org.glassfish.jersey.media.multipart.FormDataContentDisposition; import org.glassfish.jersey.media.multipart.FormDataParam; +import javax.servlet.ServletConfig; import javax.ws.rs.core.Context; import javax.ws.rs.core.Response; import javax.ws.rs.core.SecurityContext; @@ -30,7 +31,28 @@ import javax.validation.constraints.*; @io.swagger.annotations.Api(description = "the store API") public class StoreApi { - private final StoreApiService delegate = StoreApiServiceFactory.getStoreApi(); + private final StoreApiService delegate; + + public StoreApi(@Context ServletConfig servletContext) { + StoreApiService delegate = null; + + if (servletContext != null) { + String implClass = servletContext.getInitParameter("StoreApi.implementation"); + if (implClass != null && !"".equals(implClass.trim())) { + try { + delegate = (StoreApiService) Class.forName(implClass).newInstance(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + } + + if (delegate == null) { + delegate = StoreApiServiceFactory.getStoreApi(); + } + + this.delegate = delegate; + } @DELETE @Path("/order/{order_id}") diff --git a/samples/server/petstore/jaxrs/jersey2/src/gen/java/io/swagger/api/UserApi.java b/samples/server/petstore/jaxrs/jersey2/src/gen/java/io/swagger/api/UserApi.java index 50d97a56825..1a0225db3c2 100644 --- a/samples/server/petstore/jaxrs/jersey2/src/gen/java/io/swagger/api/UserApi.java +++ b/samples/server/petstore/jaxrs/jersey2/src/gen/java/io/swagger/api/UserApi.java @@ -18,6 +18,7 @@ import java.io.InputStream; import org.glassfish.jersey.media.multipart.FormDataContentDisposition; import org.glassfish.jersey.media.multipart.FormDataParam; +import javax.servlet.ServletConfig; import javax.ws.rs.core.Context; import javax.ws.rs.core.Response; import javax.ws.rs.core.SecurityContext; @@ -30,7 +31,28 @@ import javax.validation.constraints.*; @io.swagger.annotations.Api(description = "the user API") public class UserApi { - private final UserApiService delegate = UserApiServiceFactory.getUserApi(); + private final UserApiService delegate; + + public UserApi(@Context ServletConfig servletContext) { + UserApiService delegate = null; + + if (servletContext != null) { + String implClass = servletContext.getInitParameter("UserApi.implementation"); + if (implClass != null && !"".equals(implClass.trim())) { + try { + delegate = (UserApiService) Class.forName(implClass).newInstance(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + } + + if (delegate == null) { + delegate = UserApiServiceFactory.getUserApi(); + } + + this.delegate = delegate; + } @POST From 7e98e59e53465f425e8f71d185f1df8aa6d6beeb Mon Sep 17 00:00:00 2001 From: wing328 Date: Fri, 9 Jun 2017 16:11:34 +0800 Subject: [PATCH 03/10] move swift/objc test to the end --- pom.xml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index aa562ff427f..afa94fd6d1f 100644 --- a/pom.xml +++ b/pom.xml @@ -791,17 +791,12 @@ + + samples/server/petstore/scalatra + - samples/client/petstore/ruby - samples/client/petstore/swift3/default/SwaggerClientTests - samples/client/petstore/swift3/promisekit/SwaggerClientTests - samples/client/petstore/swift3/rxswift/SwaggerClientTests - samples/client/petstore/swift/default/SwaggerClientTests - samples/client/petstore/swift/promisekit/SwaggerClientTests - samples/client/petstore/swift/rxswift/SwaggerClientTests - samples/client/petstore/objc/default/SwaggerClientTests - samples/client/petstore/objc/core-data/SwaggerClientTests + samples/client/petstore/ruby samples/client/petstore/scala samples/client/petstore/akka-scala samples/client/petstore/javascript @@ -813,9 +808,14 @@ samples/client/petstore/typescript-angular samples/client/petstore/typescript-node/npm samples/client/petstore/typescript-jquery/npm - - samples/server/petstore/scalatra - + samples/client/petstore/swift3/default/SwaggerClientTests + samples/client/petstore/swift3/promisekit/SwaggerClientTests + samples/client/petstore/swift3/rxswift/SwaggerClientTests + samples/client/petstore/swift/default/SwaggerClientTests + samples/client/petstore/swift/promisekit/SwaggerClientTests + samples/client/petstore/swift/rxswift/SwaggerClientTests + samples/client/petstore/objc/default/SwaggerClientTests + samples/client/petstore/objc/core-data/SwaggerClientTests From e9a0d7ea8367aee9322838c7d78ed5a2ae9ac74a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Petersen?= Date: Fri, 9 Jun 2017 10:16:53 +0200 Subject: [PATCH 04/10] Add android dependency to pom if 'parcelableModel' is set (#5801) (#5802) * Add android dependency to pom if 'parcelableModel' is set * Update java-okhttp-gson-parcelableModel sample --- .../Java/libraries/okhttp-gson/pom.mustache | 9 ++ .../Java/libraries/retrofit/pom.mustache | 10 ++ .../Java/libraries/retrofit2/pom.mustache | 10 ++ .../src/main/resources/Java/pom.mustache | 11 ++ .../okhttp-gson-parcelableModel/README.md | 47 ++++--- .../docs/FakeclassnametagsApi.md | 52 -------- .../java/okhttp-gson-parcelableModel/pom.xml | 7 + .../swagger/client/ProgressRequestBody.java | 8 +- .../io/swagger/client/api/FakeApiTest.java | 123 ++++++++++++++---- .../client/api/FakeclassnametagsApiTest.java | 61 --------- .../io/swagger/client/api/PetApiTest.java | 34 ++--- .../io/swagger/client/api/StoreApiTest.java | 24 +--- .../io/swagger/client/api/UserApiTest.java | 32 ++--- 13 files changed, 205 insertions(+), 223 deletions(-) delete mode 100644 samples/client/petstore/java/okhttp-gson-parcelableModel/docs/FakeclassnametagsApi.md delete mode 100644 samples/client/petstore/java/okhttp-gson-parcelableModel/src/test/java/io/swagger/client/api/FakeclassnametagsApiTest.java diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/pom.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/pom.mustache index 40ec4f345e3..d8086d4550f 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/pom.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/pom.mustache @@ -218,6 +218,15 @@ 2.2 {{/performBeanValidation}} + {{#parcelableModel}} + + + com.google.android + android + 4.1.1.4 + provided + + {{/parcelableModel}} junit diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/pom.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/pom.mustache index b5b7a535a4f..13f1ac3282b 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/pom.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/pom.mustache @@ -203,6 +203,16 @@ ${jodatime-version} + {{#parcelableModel}} + + + com.google.android + android + 4.1.1.4 + provided + + {{/parcelableModel}} + junit diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/pom.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/pom.mustache index 2bcbdd3fa11..92002db838e 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/pom.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/pom.mustache @@ -260,6 +260,16 @@ {{/usePlay24WS}} + {{#parcelableModel}} + + + com.google.android + android + 4.1.1.4 + provided + + {{/parcelableModel}} + junit diff --git a/modules/swagger-codegen/src/main/resources/Java/pom.mustache b/modules/swagger-codegen/src/main/resources/Java/pom.mustache index 67d4ba4d2ac..9a292b9ddc4 100644 --- a/modules/swagger-codegen/src/main/resources/Java/pom.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/pom.mustache @@ -272,6 +272,17 @@ provided {{/useBeanValidation}} + + {{#parcelableModel}} + + + com.google.android + android + 4.1.1.4 + provided + + {{/parcelableModel}} + junit diff --git a/samples/client/petstore/java/okhttp-gson-parcelableModel/README.md b/samples/client/petstore/java/okhttp-gson-parcelableModel/README.md index ce4c6f54fa4..8e55bbc51a2 100644 --- a/samples/client/petstore/java/okhttp-gson-parcelableModel/README.md +++ b/samples/client/petstore/java/okhttp-gson-parcelableModel/README.md @@ -71,22 +71,12 @@ public class FakeApiExample { public static void main(String[] args) { FakeApi apiInstance = new FakeApi(); - BigDecimal number = new BigDecimal(); // BigDecimal | None - Double _double = 3.4D; // Double | None - String string = "string_example"; // String | None - byte[] _byte = B; // byte[] | None - Integer integer = 56; // Integer | None - Integer int32 = 56; // Integer | None - Long int64 = 789L; // Long | None - Float _float = 3.4F; // Float | None - byte[] binary = B; // byte[] | None - LocalDate date = new LocalDate(); // LocalDate | None - DateTime dateTime = new DateTime(); // DateTime | None - String password = "password_example"; // String | None + Boolean body = true; // Boolean | Input boolean as post body try { - apiInstance.testEndpointParameters(number, _double, string, _byte, integer, int32, int64, _float, binary, date, dateTime, password); + Boolean result = apiInstance.fakeOuterBooleanSerialize(body); + System.out.println(result); } catch (ApiException e) { - System.err.println("Exception when calling FakeApi#testEndpointParameters"); + System.err.println("Exception when calling FakeApi#fakeOuterBooleanSerialize"); e.printStackTrace(); } } @@ -96,12 +86,17 @@ public class FakeApiExample { ## Documentation for API Endpoints -All URIs are relative to *http://petstore.swagger.io/v2* +All URIs are relative to *http://petstore.swagger.io:80/v2* Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- +*FakeApi* | [**fakeOuterBooleanSerialize**](docs/FakeApi.md#fakeOuterBooleanSerialize) | **POST** /fake/outer/boolean | +*FakeApi* | [**fakeOuterCompositeSerialize**](docs/FakeApi.md#fakeOuterCompositeSerialize) | **POST** /fake/outer/composite | +*FakeApi* | [**fakeOuterNumberSerialize**](docs/FakeApi.md#fakeOuterNumberSerialize) | **POST** /fake/outer/number | +*FakeApi* | [**fakeOuterStringSerialize**](docs/FakeApi.md#fakeOuterStringSerialize) | **POST** /fake/outer/string | +*FakeApi* | [**testClientModel**](docs/FakeApi.md#testClientModel) | **PATCH** /fake | To test \"client\" model *FakeApi* | [**testEndpointParameters**](docs/FakeApi.md#testEndpointParameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 -*FakeApi* | [**testEnumQueryParameters**](docs/FakeApi.md#testEnumQueryParameters) | **GET** /fake | To test enum query parameters +*FakeApi* | [**testEnumParameters**](docs/FakeApi.md#testEnumParameters) | **GET** /fake | To test enum parameters *PetApi* | [**addPet**](docs/PetApi.md#addPet) | **POST** /pet | Add a new pet to the store *PetApi* | [**deletePet**](docs/PetApi.md#deletePet) | **DELETE** /pet/{petId} | Deletes a pet *PetApi* | [**findPetsByStatus**](docs/PetApi.md#findPetsByStatus) | **GET** /pet/findByStatus | Finds Pets by status @@ -110,9 +105,9 @@ Class | Method | HTTP request | Description *PetApi* | [**updatePet**](docs/PetApi.md#updatePet) | **PUT** /pet | Update an existing pet *PetApi* | [**updatePetWithForm**](docs/PetApi.md#updatePetWithForm) | **POST** /pet/{petId} | Updates a pet in the store with form data *PetApi* | [**uploadFile**](docs/PetApi.md#uploadFile) | **POST** /pet/{petId}/uploadImage | uploads an image -*StoreApi* | [**deleteOrder**](docs/StoreApi.md#deleteOrder) | **DELETE** /store/order/{orderId} | Delete purchase order by ID +*StoreApi* | [**deleteOrder**](docs/StoreApi.md#deleteOrder) | **DELETE** /store/order/{order_id} | Delete purchase order by ID *StoreApi* | [**getInventory**](docs/StoreApi.md#getInventory) | **GET** /store/inventory | Returns pet inventories by status -*StoreApi* | [**getOrderById**](docs/StoreApi.md#getOrderById) | **GET** /store/order/{orderId} | Find purchase order by ID +*StoreApi* | [**getOrderById**](docs/StoreApi.md#getOrderById) | **GET** /store/order/{order_id} | Find purchase order by ID *StoreApi* | [**placeOrder**](docs/StoreApi.md#placeOrder) | **POST** /store/order | Place an order for a pet *UserApi* | [**createUser**](docs/UserApi.md#createUser) | **POST** /user | Create user *UserApi* | [**createUsersWithArrayInput**](docs/UserApi.md#createUsersWithArrayInput) | **POST** /user/createWithArray | Creates list of users with given input array @@ -132,9 +127,11 @@ Class | Method | HTTP request | Description - [ArrayOfArrayOfNumberOnly](docs/ArrayOfArrayOfNumberOnly.md) - [ArrayOfNumberOnly](docs/ArrayOfNumberOnly.md) - [ArrayTest](docs/ArrayTest.md) - - [Cat](docs/Cat.md) + - [Capitalization](docs/Capitalization.md) - [Category](docs/Category.md) - - [Dog](docs/Dog.md) + - [ClassModel](docs/ClassModel.md) + - [Client](docs/Client.md) + - [EnumArrays](docs/EnumArrays.md) - [EnumClass](docs/EnumClass.md) - [EnumTest](docs/EnumTest.md) - [FormatTest](docs/FormatTest.md) @@ -147,11 +144,15 @@ Class | Method | HTTP request | Description - [Name](docs/Name.md) - [NumberOnly](docs/NumberOnly.md) - [Order](docs/Order.md) + - [OuterComposite](docs/OuterComposite.md) + - [OuterEnum](docs/OuterEnum.md) - [Pet](docs/Pet.md) - [ReadOnlyFirst](docs/ReadOnlyFirst.md) - [SpecialModelName](docs/SpecialModelName.md) - [Tag](docs/Tag.md) - [User](docs/User.md) + - [Cat](docs/Cat.md) + - [Dog](docs/Dog.md) ## Documentation for Authorization @@ -163,6 +164,10 @@ Authentication schemes defined for the API: - **API key parameter name**: api_key - **Location**: HTTP header +### http_basic_test + +- **Type**: HTTP basic authentication + ### petstore_auth - **Type**: OAuth @@ -175,7 +180,7 @@ Authentication schemes defined for the API: ## Recommendation -It's recommended to create an instance of `ApiClient` per thread in a multithreaded environment to avoid any potential issue. +It's recommended to create an instance of `ApiClient` per thread in a multithreaded environment to avoid any potential issues. ## Author diff --git a/samples/client/petstore/java/okhttp-gson-parcelableModel/docs/FakeclassnametagsApi.md b/samples/client/petstore/java/okhttp-gson-parcelableModel/docs/FakeclassnametagsApi.md deleted file mode 100644 index f8ec0768e1f..00000000000 --- a/samples/client/petstore/java/okhttp-gson-parcelableModel/docs/FakeclassnametagsApi.md +++ /dev/null @@ -1,52 +0,0 @@ -# FakeclassnametagsApi - -All URIs are relative to *http://petstore.swagger.io/v2* - -Method | HTTP request | Description -------------- | ------------- | ------------- -[**testClassname**](FakeclassnametagsApi.md#testClassname) | **PATCH** /fake_classname_test | To test class name in snake case - - - -# **testClassname** -> Client testClassname(body) - -To test class name in snake case - -### Example -```java -// Import classes: -//import io.swagger.client.ApiException; -//import io.swagger.client.api.FakeclassnametagsApi; - - -FakeclassnametagsApi apiInstance = new FakeclassnametagsApi(); -Client body = new Client(); // Client | client model -try { - Client result = apiInstance.testClassname(body); - System.out.println(result); -} catch (ApiException e) { - System.err.println("Exception when calling FakeclassnametagsApi#testClassname"); - e.printStackTrace(); -} -``` - -### Parameters - -Name | Type | Description | Notes -------------- | ------------- | ------------- | ------------- - **body** | [**Client**](Client.md)| client model | - -### Return type - -[**Client**](Client.md) - -### Authorization - -No authorization required - -### HTTP request headers - - - **Content-Type**: application/json - - **Accept**: application/json - diff --git a/samples/client/petstore/java/okhttp-gson-parcelableModel/pom.xml b/samples/client/petstore/java/okhttp-gson-parcelableModel/pom.xml index 26751c4e3af..751d978c946 100644 --- a/samples/client/petstore/java/okhttp-gson-parcelableModel/pom.xml +++ b/samples/client/petstore/java/okhttp-gson-parcelableModel/pom.xml @@ -194,6 +194,13 @@ joda-time ${jodatime-version} + + + com.google.android + android + 4.1.1.4 + provided + junit diff --git a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/io/swagger/client/ProgressRequestBody.java b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/io/swagger/client/ProgressRequestBody.java index a06ea04a4d0..d6d76e7de98 100644 --- a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/io/swagger/client/ProgressRequestBody.java +++ b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/io/swagger/client/ProgressRequestBody.java @@ -34,8 +34,6 @@ public class ProgressRequestBody extends RequestBody { private final ProgressRequestListener progressListener; - private BufferedSink bufferedSink; - public ProgressRequestBody(RequestBody requestBody, ProgressRequestListener progressListener) { this.requestBody = requestBody; this.progressListener = progressListener; @@ -53,13 +51,9 @@ public class ProgressRequestBody extends RequestBody { @Override public void writeTo(BufferedSink sink) throws IOException { - if (bufferedSink == null) { - bufferedSink = Okio.buffer(sink(sink)); - } - + BufferedSink bufferedSink = Okio.buffer(sink(sink)); requestBody.writeTo(bufferedSink); bufferedSink.flush(); - } private Sink sink(Sink sink) { diff --git a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/test/java/io/swagger/client/api/FakeApiTest.java b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/test/java/io/swagger/client/api/FakeApiTest.java index 5a7d2e5aa80..169209bd418 100644 --- a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/test/java/io/swagger/client/api/FakeApiTest.java +++ b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/test/java/io/swagger/client/api/FakeApiTest.java @@ -1,4 +1,4 @@ -/** +/* * Swagger Petstore * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ * @@ -8,28 +8,19 @@ * NOTE: This class is auto generated by the swagger code generator program. * https://github.com/swagger-api/swagger-codegen.git * Do not edit the class manually. - * - * 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. */ package io.swagger.client.api; import io.swagger.client.ApiException; -import org.joda.time.LocalDate; -import org.joda.time.DateTime; import java.math.BigDecimal; +import io.swagger.client.model.Client; +import org.joda.time.DateTime; +import org.joda.time.LocalDate; +import io.swagger.client.model.OuterComposite; import org.junit.Test; +import org.junit.Ignore; import java.util.ArrayList; import java.util.HashMap; @@ -39,11 +30,92 @@ import java.util.Map; /** * API tests for FakeApi */ +@Ignore public class FakeApiTest { private final FakeApi api = new FakeApi(); + /** + * + * + * Test serialization of outer boolean types + * + * @throws ApiException + * if the Api call fails + */ + @Test + public void fakeOuterBooleanSerializeTest() throws ApiException { + Boolean body = null; + Boolean response = api.fakeOuterBooleanSerialize(body); + + // TODO: test validations + } + + /** + * + * + * Test serialization of object with outer number type + * + * @throws ApiException + * if the Api call fails + */ + @Test + public void fakeOuterCompositeSerializeTest() throws ApiException { + OuterComposite body = null; + OuterComposite response = api.fakeOuterCompositeSerialize(body); + + // TODO: test validations + } + + /** + * + * + * Test serialization of outer number types + * + * @throws ApiException + * if the Api call fails + */ + @Test + public void fakeOuterNumberSerializeTest() throws ApiException { + BigDecimal body = null; + BigDecimal response = api.fakeOuterNumberSerialize(body); + + // TODO: test validations + } + + /** + * + * + * Test serialization of outer string types + * + * @throws ApiException + * if the Api call fails + */ + @Test + public void fakeOuterStringSerializeTest() throws ApiException { + String body = null; + String response = api.fakeOuterStringSerialize(body); + + // TODO: test validations + } + + /** + * To test \"client\" model + * + * To test \"client\" model + * + * @throws ApiException + * if the Api call fails + */ + @Test + public void testClientModelTest() throws ApiException { + Client body = null; + Client response = api.testClientModel(body); + + // TODO: test validations + } + /** * Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 * @@ -56,35 +128,42 @@ public class FakeApiTest { public void testEndpointParametersTest() throws ApiException { BigDecimal number = null; Double _double = null; - String string = null; + String patternWithoutDelimiter = null; byte[] _byte = null; Integer integer = null; Integer int32 = null; Long int64 = null; Float _float = null; + String string = null; byte[] binary = null; LocalDate date = null; DateTime dateTime = null; String password = null; - // api.testEndpointParameters(number, _double, string, _byte, integer, int32, int64, _float, binary, date, dateTime, password); + String paramCallback = null; + api.testEndpointParameters(number, _double, patternWithoutDelimiter, _byte, integer, int32, int64, _float, string, binary, date, dateTime, password, paramCallback); // TODO: test validations } /** - * To test enum query parameters + * To test enum parameters * - * + * To test enum parameters * * @throws ApiException * if the Api call fails */ @Test - public void testEnumQueryParametersTest() throws ApiException { + public void testEnumParametersTest() throws ApiException { + List enumFormStringArray = null; + String enumFormString = null; + List enumHeaderStringArray = null; + String enumHeaderString = null; + List enumQueryStringArray = null; String enumQueryString = null; - BigDecimal enumQueryInteger = null; + Integer enumQueryInteger = null; Double enumQueryDouble = null; - // api.testEnumQueryParameters(enumQueryString, enumQueryInteger, enumQueryDouble); + api.testEnumParameters(enumFormStringArray, enumFormString, enumHeaderStringArray, enumHeaderString, enumQueryStringArray, enumQueryString, enumQueryInteger, enumQueryDouble); // TODO: test validations } diff --git a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/test/java/io/swagger/client/api/FakeclassnametagsApiTest.java b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/test/java/io/swagger/client/api/FakeclassnametagsApiTest.java deleted file mode 100644 index 0d9a4c99b27..00000000000 --- a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/test/java/io/swagger/client/api/FakeclassnametagsApiTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Swagger Petstore - * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ - * - * OpenAPI spec version: 1.0.0 - * Contact: apiteam@swagger.io - * - * NOTE: This class is auto generated by the swagger code generator program. - * https://github.com/swagger-api/swagger-codegen.git - * Do not edit the class manually. - * - * 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. - */ - - -package io.swagger.client.api; - -import io.swagger.client.ApiException; -import io.swagger.client.model.Client; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * API tests for FakeclassnametagsApi - */ -public class FakeclassnametagsApiTest { - - private final FakeclassnametagsApi api = new FakeclassnametagsApi(); - - - /** - * To test class name in snake case - * - * - * - * @throws ApiException - * if the Api call fails - */ - @Test - public void testClassnameTest() throws ApiException { - Client body = null; - // Client response = api.testClassname(body); - - // TODO: test validations - } - -} diff --git a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/test/java/io/swagger/client/api/PetApiTest.java b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/test/java/io/swagger/client/api/PetApiTest.java index 373f7d287ad..349a55d93dc 100644 --- a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/test/java/io/swagger/client/api/PetApiTest.java +++ b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/test/java/io/swagger/client/api/PetApiTest.java @@ -1,4 +1,4 @@ -/** +/* * Swagger Petstore * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ * @@ -8,28 +8,17 @@ * NOTE: This class is auto generated by the swagger code generator program. * https://github.com/swagger-api/swagger-codegen.git * Do not edit the class manually. - * - * 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. */ package io.swagger.client.api; import io.swagger.client.ApiException; -import io.swagger.client.model.Pet; import java.io.File; import io.swagger.client.model.ModelApiResponse; +import io.swagger.client.model.Pet; import org.junit.Test; +import org.junit.Ignore; import java.util.ArrayList; import java.util.HashMap; @@ -39,6 +28,7 @@ import java.util.Map; /** * API tests for PetApi */ +@Ignore public class PetApiTest { private final PetApi api = new PetApi(); @@ -55,7 +45,7 @@ public class PetApiTest { @Test public void addPetTest() throws ApiException { Pet body = null; - // api.addPet(body); + api.addPet(body); // TODO: test validations } @@ -72,7 +62,7 @@ public class PetApiTest { public void deletePetTest() throws ApiException { Long petId = null; String apiKey = null; - // api.deletePet(petId, apiKey); + api.deletePet(petId, apiKey); // TODO: test validations } @@ -88,7 +78,7 @@ public class PetApiTest { @Test public void findPetsByStatusTest() throws ApiException { List status = null; - // List response = api.findPetsByStatus(status); + List response = api.findPetsByStatus(status); // TODO: test validations } @@ -104,7 +94,7 @@ public class PetApiTest { @Test public void findPetsByTagsTest() throws ApiException { List tags = null; - // List response = api.findPetsByTags(tags); + List response = api.findPetsByTags(tags); // TODO: test validations } @@ -120,7 +110,7 @@ public class PetApiTest { @Test public void getPetByIdTest() throws ApiException { Long petId = null; - // Pet response = api.getPetById(petId); + Pet response = api.getPetById(petId); // TODO: test validations } @@ -136,7 +126,7 @@ public class PetApiTest { @Test public void updatePetTest() throws ApiException { Pet body = null; - // api.updatePet(body); + api.updatePet(body); // TODO: test validations } @@ -154,7 +144,7 @@ public class PetApiTest { Long petId = null; String name = null; String status = null; - // api.updatePetWithForm(petId, name, status); + api.updatePetWithForm(petId, name, status); // TODO: test validations } @@ -172,7 +162,7 @@ public class PetApiTest { Long petId = null; String additionalMetadata = null; File file = null; - // ModelApiResponse response = api.uploadFile(petId, additionalMetadata, file); + ModelApiResponse response = api.uploadFile(petId, additionalMetadata, file); // TODO: test validations } diff --git a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/test/java/io/swagger/client/api/StoreApiTest.java b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/test/java/io/swagger/client/api/StoreApiTest.java index 4bcdcbf8338..bef0884a2da 100644 --- a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/test/java/io/swagger/client/api/StoreApiTest.java +++ b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/test/java/io/swagger/client/api/StoreApiTest.java @@ -1,4 +1,4 @@ -/** +/* * Swagger Petstore * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ * @@ -8,18 +8,6 @@ * NOTE: This class is auto generated by the swagger code generator program. * https://github.com/swagger-api/swagger-codegen.git * Do not edit the class manually. - * - * 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. */ @@ -28,6 +16,7 @@ package io.swagger.client.api; import io.swagger.client.ApiException; import io.swagger.client.model.Order; import org.junit.Test; +import org.junit.Ignore; import java.util.ArrayList; import java.util.HashMap; @@ -37,6 +26,7 @@ import java.util.Map; /** * API tests for StoreApi */ +@Ignore public class StoreApiTest { private final StoreApi api = new StoreApi(); @@ -53,7 +43,7 @@ public class StoreApiTest { @Test public void deleteOrderTest() throws ApiException { String orderId = null; - // api.deleteOrder(orderId); + api.deleteOrder(orderId); // TODO: test validations } @@ -68,7 +58,7 @@ public class StoreApiTest { */ @Test public void getInventoryTest() throws ApiException { - // Map response = api.getInventory(); + Map response = api.getInventory(); // TODO: test validations } @@ -84,7 +74,7 @@ public class StoreApiTest { @Test public void getOrderByIdTest() throws ApiException { Long orderId = null; - // Order response = api.getOrderById(orderId); + Order response = api.getOrderById(orderId); // TODO: test validations } @@ -100,7 +90,7 @@ public class StoreApiTest { @Test public void placeOrderTest() throws ApiException { Order body = null; - // Order response = api.placeOrder(body); + Order response = api.placeOrder(body); // TODO: test validations } diff --git a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/test/java/io/swagger/client/api/UserApiTest.java b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/test/java/io/swagger/client/api/UserApiTest.java index 832748dbb45..4455b3920b9 100644 --- a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/test/java/io/swagger/client/api/UserApiTest.java +++ b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/test/java/io/swagger/client/api/UserApiTest.java @@ -1,4 +1,4 @@ -/** +/* * Swagger Petstore * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ * @@ -8,18 +8,6 @@ * NOTE: This class is auto generated by the swagger code generator program. * https://github.com/swagger-api/swagger-codegen.git * Do not edit the class manually. - * - * 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. */ @@ -28,6 +16,7 @@ package io.swagger.client.api; import io.swagger.client.ApiException; import io.swagger.client.model.User; import org.junit.Test; +import org.junit.Ignore; import java.util.ArrayList; import java.util.HashMap; @@ -37,6 +26,7 @@ import java.util.Map; /** * API tests for UserApi */ +@Ignore public class UserApiTest { private final UserApi api = new UserApi(); @@ -53,7 +43,7 @@ public class UserApiTest { @Test public void createUserTest() throws ApiException { User body = null; - // api.createUser(body); + api.createUser(body); // TODO: test validations } @@ -69,7 +59,7 @@ public class UserApiTest { @Test public void createUsersWithArrayInputTest() throws ApiException { List body = null; - // api.createUsersWithArrayInput(body); + api.createUsersWithArrayInput(body); // TODO: test validations } @@ -85,7 +75,7 @@ public class UserApiTest { @Test public void createUsersWithListInputTest() throws ApiException { List body = null; - // api.createUsersWithListInput(body); + api.createUsersWithListInput(body); // TODO: test validations } @@ -101,7 +91,7 @@ public class UserApiTest { @Test public void deleteUserTest() throws ApiException { String username = null; - // api.deleteUser(username); + api.deleteUser(username); // TODO: test validations } @@ -117,7 +107,7 @@ public class UserApiTest { @Test public void getUserByNameTest() throws ApiException { String username = null; - // User response = api.getUserByName(username); + User response = api.getUserByName(username); // TODO: test validations } @@ -134,7 +124,7 @@ public class UserApiTest { public void loginUserTest() throws ApiException { String username = null; String password = null; - // String response = api.loginUser(username, password); + String response = api.loginUser(username, password); // TODO: test validations } @@ -149,7 +139,7 @@ public class UserApiTest { */ @Test public void logoutUserTest() throws ApiException { - // api.logoutUser(); + api.logoutUser(); // TODO: test validations } @@ -166,7 +156,7 @@ public class UserApiTest { public void updateUserTest() throws ApiException { String username = null; User body = null; - // api.updateUser(username, body); + api.updateUser(username, body); // TODO: test validations } From 53bd931f5c57eeb805ef38e47a880d73e3dbdc5d Mon Sep 17 00:00:00 2001 From: Brendan Burns Date: Fri, 9 Jun 2017 01:47:38 -0700 Subject: [PATCH 05/10] Add JSON-patch as a JSON mime-type (#5764) --- .../resources/Java/libraries/okhttp-gson/ApiClient.mustache | 2 +- .../okhttp-gson/src/main/java/io/swagger/client/ApiClient.java | 2 +- .../okhttp-gson/src/main/java/io/swagger/client/ApiClient.java | 2 +- .../src/test/java/io/swagger/client/ApiClientTest.java | 2 ++ 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache index b9da0cc4a4c..b3cb0221ac6 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache @@ -744,7 +744,7 @@ public class ApiClient { */ public boolean isJsonMime(String mime) { String jsonMime = "(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$"; - return mime != null && mime.matches(jsonMime); + return mime != null && (mime.matches(jsonMime) || mime.equalsIgnoreCase("application/json-patch+json")); } /** diff --git a/samples/client/petstore-security-test/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore-security-test/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java index 365c87ff45e..ba8bdfbc253 100644 --- a/samples/client/petstore-security-test/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore-security-test/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java @@ -750,7 +750,7 @@ public class ApiClient { */ public boolean isJsonMime(String mime) { String jsonMime = "(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$"; - return mime != null && mime.matches(jsonMime); + return mime != null && (mime.matches(jsonMime) || mime.equalsIgnoreCase("application/json-patch+json")); } /** diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java index 7af43d0eafc..21729ee04b2 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java @@ -751,7 +751,7 @@ public class ApiClient { */ public boolean isJsonMime(String mime) { String jsonMime = "(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$"; - return mime != null && mime.matches(jsonMime); + return mime != null && (mime.matches(jsonMime) || mime.equalsIgnoreCase("application/json-patch+json")); } /** diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/io/swagger/client/ApiClientTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/io/swagger/client/ApiClientTest.java index bec38b44d98..294deff5c4b 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/io/swagger/client/ApiClientTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/io/swagger/client/ApiClientTest.java @@ -99,6 +99,8 @@ public class ApiClientTest { assertTrue(apiClient.isJsonMime("example/foo+json;x;y")); assertTrue(apiClient.isJsonMime("example/foo+json\t;")); assertTrue(apiClient.isJsonMime("Example/fOO+JSON")); + + assertTrue(apiClient.isJsonMime("application/json-patch+json")); } @Test From 7cddd17acc4718653e450e208d5ba98d2c7debe1 Mon Sep 17 00:00:00 2001 From: wing328 Date: Fri, 9 Jun 2017 21:46:40 +0800 Subject: [PATCH 06/10] [Java] Add JSON-patch support to other Java API clients (#5808) * add JSON-patch support to other Java API clients * minor fix to java jersey1 json check --- .../swagger-codegen/src/main/resources/Java/ApiClient.mustache | 2 +- .../main/resources/Java/libraries/jersey2/ApiClient.mustache | 2 +- samples/client/petstore/java/jersey1/pom.xml | 2 ++ .../java/jersey1/src/main/java/io/swagger/client/ApiClient.java | 2 +- .../src/main/java/io/swagger/client/ApiClient.java | 2 +- .../src/main/java/io/swagger/client/ApiClient.java | 2 +- .../java/jersey2/src/main/java/io/swagger/client/ApiClient.java | 2 +- .../src/main/java/io/swagger/client/ApiClient.java | 2 +- samples/client/petstore/java/retrofit/pom.xml | 1 + samples/client/petstore/java/retrofit2-play24/pom.xml | 1 + samples/client/petstore/java/retrofit2/pom.xml | 1 + samples/client/petstore/java/retrofit2rx/pom.xml | 1 + samples/client/petstore/java/retrofit2rx2/pom.xml | 1 + 13 files changed, 14 insertions(+), 7 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/Java/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/Java/ApiClient.mustache index 6668c30d8bf..9fe8d556135 100644 --- a/modules/swagger-codegen/src/main/resources/Java/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/ApiClient.mustache @@ -465,7 +465,7 @@ public class ApiClient { */ public boolean isJsonMime(String mime) { String jsonMime = "(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$"; - return mime != null && mime.matches(jsonMime); + return mime != null && (mime.matches(jsonMime) || mime.equalsIgnoreCase("application/json-patch+json")); } /** diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/ApiClient.mustache index 759e6708aa1..b8a5f95d9d1 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/ApiClient.mustache @@ -443,7 +443,7 @@ public class ApiClient { */ public boolean isJsonMime(String mime) { String jsonMime = "(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$"; - return mime != null && mime.matches(jsonMime); + return mime != null && (mime.matches(jsonMime) || mime.equalsIgnoreCase("application/json-patch+json")); } /** diff --git a/samples/client/petstore/java/jersey1/pom.xml b/samples/client/petstore/java/jersey1/pom.xml index f15b614e1aa..2347df728d3 100644 --- a/samples/client/petstore/java/jersey1/pom.xml +++ b/samples/client/petstore/java/jersey1/pom.xml @@ -235,6 +235,8 @@ 2.2 + + junit diff --git a/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/ApiClient.java index b9dbb9117b5..7c98c2d74a8 100644 --- a/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/ApiClient.java @@ -466,7 +466,7 @@ public class ApiClient { */ public boolean isJsonMime(String mime) { String jsonMime = "(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$"; - return mime != null && mime.matches(jsonMime); + return mime != null && (mime.matches(jsonMime) || mime.equalsIgnoreCase("application/json-patch+json")); } /** diff --git a/samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/ApiClient.java index 31c5d60d626..938b7521e6f 100644 --- a/samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/ApiClient.java @@ -437,7 +437,7 @@ public class ApiClient { */ public boolean isJsonMime(String mime) { String jsonMime = "(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$"; - return mime != null && mime.matches(jsonMime); + return mime != null && (mime.matches(jsonMime) || mime.equalsIgnoreCase("application/json-patch+json")); } /** diff --git a/samples/client/petstore/java/jersey2-java8/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/jersey2-java8/src/main/java/io/swagger/client/ApiClient.java index d3e9924e8eb..0995fbc3df7 100644 --- a/samples/client/petstore/java/jersey2-java8/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/jersey2-java8/src/main/java/io/swagger/client/ApiClient.java @@ -438,7 +438,7 @@ public class ApiClient { */ public boolean isJsonMime(String mime) { String jsonMime = "(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$"; - return mime != null && mime.matches(jsonMime); + return mime != null && (mime.matches(jsonMime) || mime.equalsIgnoreCase("application/json-patch+json")); } /** diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/ApiClient.java index d3e9924e8eb..0995fbc3df7 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/ApiClient.java @@ -438,7 +438,7 @@ public class ApiClient { */ public boolean isJsonMime(String mime) { String jsonMime = "(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$"; - return mime != null && mime.matches(jsonMime); + return mime != null && (mime.matches(jsonMime) || mime.equalsIgnoreCase("application/json-patch+json")); } /** diff --git a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/io/swagger/client/ApiClient.java index 7af43d0eafc..21729ee04b2 100644 --- a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/io/swagger/client/ApiClient.java @@ -751,7 +751,7 @@ public class ApiClient { */ public boolean isJsonMime(String mime) { String jsonMime = "(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$"; - return mime != null && mime.matches(jsonMime); + return mime != null && (mime.matches(jsonMime) || mime.equalsIgnoreCase("application/json-patch+json")); } /** diff --git a/samples/client/petstore/java/retrofit/pom.xml b/samples/client/petstore/java/retrofit/pom.xml index 069c8bb3ed2..cb50ddea34d 100644 --- a/samples/client/petstore/java/retrofit/pom.xml +++ b/samples/client/petstore/java/retrofit/pom.xml @@ -203,6 +203,7 @@ ${jodatime-version} + junit diff --git a/samples/client/petstore/java/retrofit2-play24/pom.xml b/samples/client/petstore/java/retrofit2-play24/pom.xml index a1e7f6eeff2..6693f615e65 100644 --- a/samples/client/petstore/java/retrofit2-play24/pom.xml +++ b/samples/client/petstore/java/retrofit2-play24/pom.xml @@ -232,6 +232,7 @@ ${play-version} + junit diff --git a/samples/client/petstore/java/retrofit2/pom.xml b/samples/client/petstore/java/retrofit2/pom.xml index ae1a4b573d8..ee302c6300d 100644 --- a/samples/client/petstore/java/retrofit2/pom.xml +++ b/samples/client/petstore/java/retrofit2/pom.xml @@ -201,6 +201,7 @@ + junit diff --git a/samples/client/petstore/java/retrofit2rx/pom.xml b/samples/client/petstore/java/retrofit2rx/pom.xml index 668d38623fc..1498dc252f8 100644 --- a/samples/client/petstore/java/retrofit2rx/pom.xml +++ b/samples/client/petstore/java/retrofit2rx/pom.xml @@ -211,6 +211,7 @@ + junit diff --git a/samples/client/petstore/java/retrofit2rx2/pom.xml b/samples/client/petstore/java/retrofit2rx2/pom.xml index cd806e757b0..34d054b1fdc 100644 --- a/samples/client/petstore/java/retrofit2rx2/pom.xml +++ b/samples/client/petstore/java/retrofit2rx2/pom.xml @@ -211,6 +211,7 @@ + junit From 21bf3a5a5e1218bd15a44df898427ff559ff8f0c Mon Sep 17 00:00:00 2001 From: harishchoragudi Date: Fri, 9 Jun 2017 19:50:40 -0500 Subject: [PATCH 07/10] Create README.md (#5813) Added GE in the list of companies using swagger-codegen --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 25c9de19665..c45194e0fff 100644 --- a/README.md +++ b/README.md @@ -742,6 +742,7 @@ Here are some companies/projects using Swagger Codegen in production. To add you - [FH Münster - University of Applied Sciences](http://www.fh-muenster.de) - [Fotition](https://www.fotition.com/) - [Gear Zero Network](https://www.gearzero.ca) +- [General Electric](https://www.ge.com/) - [Germin8](http://www.germin8.com) - [GigaSpaces](http://www.gigaspaces.com) - [goTransverse](http://www.gotransverse.com/api) From c5335081ea9750fa06036abb4fb086ee047ebc2d Mon Sep 17 00:00:00 2001 From: manuc66 Date: Sun, 11 Jun 2017 09:34:09 +0200 Subject: [PATCH 08/10] fix the mustache file (#5736) --- .../main/resources/JavaInflector/typeInfoAnnotation.mustache | 2 +- .../src/main/resources/JavaJaxRS/typeInfoAnnotation.mustache | 2 +- .../resources/JavaPlayFramework/typeInfoAnnotation.mustache | 2 +- .../src/main/resources/JavaSpring/typeInfoAnnotation.mustache | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/JavaInflector/typeInfoAnnotation.mustache b/modules/swagger-codegen/src/main/resources/JavaInflector/typeInfoAnnotation.mustache index b3083e788d9..2d7983d0101 100644 --- a/modules/swagger-codegen/src/main/resources/JavaInflector/typeInfoAnnotation.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaInflector/typeInfoAnnotation.mustache @@ -2,6 +2,6 @@ @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{discriminator}}", visible = true ) @JsonSubTypes({ {{#children}} - @JsonSubTypes.Type(value = {{name}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}"), + @JsonSubTypes.Type(value = {{classname}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}"), {{/children}} }){{/jackson}} diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/typeInfoAnnotation.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/typeInfoAnnotation.mustache index b3083e788d9..2d7983d0101 100644 --- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/typeInfoAnnotation.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/typeInfoAnnotation.mustache @@ -2,6 +2,6 @@ @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{discriminator}}", visible = true ) @JsonSubTypes({ {{#children}} - @JsonSubTypes.Type(value = {{name}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}"), + @JsonSubTypes.Type(value = {{classname}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}"), {{/children}} }){{/jackson}} diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/typeInfoAnnotation.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/typeInfoAnnotation.mustache index b3083e788d9..2d7983d0101 100644 --- a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/typeInfoAnnotation.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/typeInfoAnnotation.mustache @@ -2,6 +2,6 @@ @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{discriminator}}", visible = true ) @JsonSubTypes({ {{#children}} - @JsonSubTypes.Type(value = {{name}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}"), + @JsonSubTypes.Type(value = {{classname}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}"), {{/children}} }){{/jackson}} diff --git a/modules/swagger-codegen/src/main/resources/JavaSpring/typeInfoAnnotation.mustache b/modules/swagger-codegen/src/main/resources/JavaSpring/typeInfoAnnotation.mustache index b3083e788d9..2d7983d0101 100644 --- a/modules/swagger-codegen/src/main/resources/JavaSpring/typeInfoAnnotation.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaSpring/typeInfoAnnotation.mustache @@ -2,6 +2,6 @@ @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{discriminator}}", visible = true ) @JsonSubTypes({ {{#children}} - @JsonSubTypes.Type(value = {{name}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}"), + @JsonSubTypes.Type(value = {{classname}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}"), {{/children}} }){{/jackson}} From f163fdb980d156a604d2478927fd0d231ce476ef Mon Sep 17 00:00:00 2001 From: wing328 Date: Sun, 11 Jun 2017 15:39:08 +0800 Subject: [PATCH 09/10] update spring samples --- .../main/java/io/swagger/model/OuterComposite.java | 9 +++++++++ .../main/java/io/swagger/model/OuterComposite.java | 9 +++++++++ .../main/java/io/swagger/model/OuterComposite.java | 9 +++++++++ .../main/java/io/swagger/model/OuterComposite.java | 9 +++++++++ .../main/java/io/swagger/model/OuterComposite.java | 9 +++++++++ .../src/main/java/io/swagger/api/PetApi.java | 12 ++++++------ .../src/main/java/io/swagger/api/StoreApi.java | 8 ++++---- .../src/main/java/io/swagger/api/UserApi.java | 6 +++--- .../main/java/io/swagger/model/OuterComposite.java | 9 +++++++++ 9 files changed, 67 insertions(+), 13 deletions(-) diff --git a/samples/server/petstore/spring-mvc-j8-async/src/main/java/io/swagger/model/OuterComposite.java b/samples/server/petstore/spring-mvc-j8-async/src/main/java/io/swagger/model/OuterComposite.java index 2502d28ab57..bd384f3dcd2 100644 --- a/samples/server/petstore/spring-mvc-j8-async/src/main/java/io/swagger/model/OuterComposite.java +++ b/samples/server/petstore/spring-mvc-j8-async/src/main/java/io/swagger/model/OuterComposite.java @@ -6,7 +6,9 @@ import com.fasterxml.jackson.annotation.JsonCreator; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import java.math.BigDecimal; +import javax.validation.Valid; import javax.validation.constraints.*; + /** * OuterComposite */ @@ -31,6 +33,9 @@ public class OuterComposite { * @return myNumber **/ @ApiModelProperty(value = "") + + @Valid + public BigDecimal getMyNumber() { return myNumber; } @@ -49,6 +54,8 @@ public class OuterComposite { * @return myString **/ @ApiModelProperty(value = "") + + public String getMyString() { return myString; } @@ -67,6 +74,8 @@ public class OuterComposite { * @return myBoolean **/ @ApiModelProperty(value = "") + + public Boolean getMyBoolean() { return myBoolean; } diff --git a/samples/server/petstore/spring-mvc/src/main/java/io/swagger/model/OuterComposite.java b/samples/server/petstore/spring-mvc/src/main/java/io/swagger/model/OuterComposite.java index 2502d28ab57..bd384f3dcd2 100644 --- a/samples/server/petstore/spring-mvc/src/main/java/io/swagger/model/OuterComposite.java +++ b/samples/server/petstore/spring-mvc/src/main/java/io/swagger/model/OuterComposite.java @@ -6,7 +6,9 @@ import com.fasterxml.jackson.annotation.JsonCreator; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import java.math.BigDecimal; +import javax.validation.Valid; import javax.validation.constraints.*; + /** * OuterComposite */ @@ -31,6 +33,9 @@ public class OuterComposite { * @return myNumber **/ @ApiModelProperty(value = "") + + @Valid + public BigDecimal getMyNumber() { return myNumber; } @@ -49,6 +54,8 @@ public class OuterComposite { * @return myString **/ @ApiModelProperty(value = "") + + public String getMyString() { return myString; } @@ -67,6 +74,8 @@ public class OuterComposite { * @return myBoolean **/ @ApiModelProperty(value = "") + + public Boolean getMyBoolean() { return myBoolean; } diff --git a/samples/server/petstore/springboot-beanvalidation/src/main/java/io/swagger/model/OuterComposite.java b/samples/server/petstore/springboot-beanvalidation/src/main/java/io/swagger/model/OuterComposite.java index 2502d28ab57..bd384f3dcd2 100644 --- a/samples/server/petstore/springboot-beanvalidation/src/main/java/io/swagger/model/OuterComposite.java +++ b/samples/server/petstore/springboot-beanvalidation/src/main/java/io/swagger/model/OuterComposite.java @@ -6,7 +6,9 @@ import com.fasterxml.jackson.annotation.JsonCreator; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import java.math.BigDecimal; +import javax.validation.Valid; import javax.validation.constraints.*; + /** * OuterComposite */ @@ -31,6 +33,9 @@ public class OuterComposite { * @return myNumber **/ @ApiModelProperty(value = "") + + @Valid + public BigDecimal getMyNumber() { return myNumber; } @@ -49,6 +54,8 @@ public class OuterComposite { * @return myString **/ @ApiModelProperty(value = "") + + public String getMyString() { return myString; } @@ -67,6 +74,8 @@ public class OuterComposite { * @return myBoolean **/ @ApiModelProperty(value = "") + + public Boolean getMyBoolean() { return myBoolean; } diff --git a/samples/server/petstore/springboot-delegate-j8/src/main/java/io/swagger/model/OuterComposite.java b/samples/server/petstore/springboot-delegate-j8/src/main/java/io/swagger/model/OuterComposite.java index 2502d28ab57..bd384f3dcd2 100644 --- a/samples/server/petstore/springboot-delegate-j8/src/main/java/io/swagger/model/OuterComposite.java +++ b/samples/server/petstore/springboot-delegate-j8/src/main/java/io/swagger/model/OuterComposite.java @@ -6,7 +6,9 @@ import com.fasterxml.jackson.annotation.JsonCreator; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import java.math.BigDecimal; +import javax.validation.Valid; import javax.validation.constraints.*; + /** * OuterComposite */ @@ -31,6 +33,9 @@ public class OuterComposite { * @return myNumber **/ @ApiModelProperty(value = "") + + @Valid + public BigDecimal getMyNumber() { return myNumber; } @@ -49,6 +54,8 @@ public class OuterComposite { * @return myString **/ @ApiModelProperty(value = "") + + public String getMyString() { return myString; } @@ -67,6 +74,8 @@ public class OuterComposite { * @return myBoolean **/ @ApiModelProperty(value = "") + + public Boolean getMyBoolean() { return myBoolean; } diff --git a/samples/server/petstore/springboot-delegate/src/main/java/io/swagger/model/OuterComposite.java b/samples/server/petstore/springboot-delegate/src/main/java/io/swagger/model/OuterComposite.java index 2502d28ab57..bd384f3dcd2 100644 --- a/samples/server/petstore/springboot-delegate/src/main/java/io/swagger/model/OuterComposite.java +++ b/samples/server/petstore/springboot-delegate/src/main/java/io/swagger/model/OuterComposite.java @@ -6,7 +6,9 @@ import com.fasterxml.jackson.annotation.JsonCreator; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import java.math.BigDecimal; +import javax.validation.Valid; import javax.validation.constraints.*; + /** * OuterComposite */ @@ -31,6 +33,9 @@ public class OuterComposite { * @return myNumber **/ @ApiModelProperty(value = "") + + @Valid + public BigDecimal getMyNumber() { return myNumber; } @@ -49,6 +54,8 @@ public class OuterComposite { * @return myString **/ @ApiModelProperty(value = "") + + public String getMyString() { return myString; } @@ -67,6 +74,8 @@ public class OuterComposite { * @return myBoolean **/ @ApiModelProperty(value = "") + + public Boolean getMyBoolean() { return myBoolean; } diff --git a/samples/server/petstore/springboot-implicitHeaders/src/main/java/io/swagger/api/PetApi.java b/samples/server/petstore/springboot-implicitHeaders/src/main/java/io/swagger/api/PetApi.java index 22458048873..0b1b331425d 100644 --- a/samples/server/petstore/springboot-implicitHeaders/src/main/java/io/swagger/api/PetApi.java +++ b/samples/server/petstore/springboot-implicitHeaders/src/main/java/io/swagger/api/PetApi.java @@ -64,8 +64,8 @@ public interface PetApi { }) }, tags={ "pet", }) @ApiResponses(value = { - @ApiResponse(code = 200, message = "successful operation", response = Pet.class), - @ApiResponse(code = 400, message = "Invalid status value", response = Pet.class) }) + @ApiResponse(code = 200, message = "successful operation", response = Pet.class, responseContainer = "List"), + @ApiResponse(code = 400, message = "Invalid status value", response = Void.class) }) @ApiImplicitParams({ }) @@ -82,8 +82,8 @@ public interface PetApi { }) }, tags={ "pet", }) @ApiResponses(value = { - @ApiResponse(code = 200, message = "successful operation", response = Pet.class), - @ApiResponse(code = 400, message = "Invalid tag value", response = Pet.class) }) + @ApiResponse(code = 200, message = "successful operation", response = Pet.class, responseContainer = "List"), + @ApiResponse(code = 400, message = "Invalid tag value", response = Void.class) }) @ApiImplicitParams({ }) @@ -98,8 +98,8 @@ public interface PetApi { }, tags={ "pet", }) @ApiResponses(value = { @ApiResponse(code = 200, message = "successful operation", response = Pet.class), - @ApiResponse(code = 400, message = "Invalid ID supplied", response = Pet.class), - @ApiResponse(code = 404, message = "Pet not found", response = Pet.class) }) + @ApiResponse(code = 400, message = "Invalid ID supplied", response = Void.class), + @ApiResponse(code = 404, message = "Pet not found", response = Void.class) }) @ApiImplicitParams({ }) diff --git a/samples/server/petstore/springboot-implicitHeaders/src/main/java/io/swagger/api/StoreApi.java b/samples/server/petstore/springboot-implicitHeaders/src/main/java/io/swagger/api/StoreApi.java index c620cbd1812..38ed7c35bc4 100644 --- a/samples/server/petstore/springboot-implicitHeaders/src/main/java/io/swagger/api/StoreApi.java +++ b/samples/server/petstore/springboot-implicitHeaders/src/main/java/io/swagger/api/StoreApi.java @@ -38,7 +38,7 @@ public interface StoreApi { @Authorization(value = "api_key") }, tags={ "store", }) @ApiResponses(value = { - @ApiResponse(code = 200, message = "successful operation", response = Integer.class) }) + @ApiResponse(code = 200, message = "successful operation", response = Integer.class, responseContainer = "Map") }) @ApiImplicitParams({ }) @@ -51,8 +51,8 @@ public interface StoreApi { @ApiOperation(value = "Find purchase order by ID", notes = "For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions", response = Order.class, tags={ "store", }) @ApiResponses(value = { @ApiResponse(code = 200, message = "successful operation", response = Order.class), - @ApiResponse(code = 400, message = "Invalid ID supplied", response = Order.class), - @ApiResponse(code = 404, message = "Order not found", response = Order.class) }) + @ApiResponse(code = 400, message = "Invalid ID supplied", response = Void.class), + @ApiResponse(code = 404, message = "Order not found", response = Void.class) }) @ApiImplicitParams({ }) @@ -65,7 +65,7 @@ public interface StoreApi { @ApiOperation(value = "Place an order for a pet", notes = "", response = Order.class, tags={ "store", }) @ApiResponses(value = { @ApiResponse(code = 200, message = "successful operation", response = Order.class), - @ApiResponse(code = 400, message = "Invalid Order", response = Order.class) }) + @ApiResponse(code = 400, message = "Invalid Order", response = Void.class) }) @ApiImplicitParams({ }) diff --git a/samples/server/petstore/springboot-implicitHeaders/src/main/java/io/swagger/api/UserApi.java b/samples/server/petstore/springboot-implicitHeaders/src/main/java/io/swagger/api/UserApi.java index 39777fe0e9d..edd23956cc1 100644 --- a/samples/server/petstore/springboot-implicitHeaders/src/main/java/io/swagger/api/UserApi.java +++ b/samples/server/petstore/springboot-implicitHeaders/src/main/java/io/swagger/api/UserApi.java @@ -73,8 +73,8 @@ public interface UserApi { @ApiOperation(value = "Get user by user name", notes = "", response = User.class, tags={ "user", }) @ApiResponses(value = { @ApiResponse(code = 200, message = "successful operation", response = User.class), - @ApiResponse(code = 400, message = "Invalid username supplied", response = User.class), - @ApiResponse(code = 404, message = "User not found", response = User.class) }) + @ApiResponse(code = 400, message = "Invalid username supplied", response = Void.class), + @ApiResponse(code = 404, message = "User not found", response = Void.class) }) @ApiImplicitParams({ }) @@ -87,7 +87,7 @@ public interface UserApi { @ApiOperation(value = "Logs user into the system", notes = "", response = String.class, tags={ "user", }) @ApiResponses(value = { @ApiResponse(code = 200, message = "successful operation", response = String.class), - @ApiResponse(code = 400, message = "Invalid username/password supplied", response = String.class) }) + @ApiResponse(code = 400, message = "Invalid username/password supplied", response = Void.class) }) @ApiImplicitParams({ }) diff --git a/samples/server/petstore/springboot/src/main/java/io/swagger/model/OuterComposite.java b/samples/server/petstore/springboot/src/main/java/io/swagger/model/OuterComposite.java index 2502d28ab57..bd384f3dcd2 100644 --- a/samples/server/petstore/springboot/src/main/java/io/swagger/model/OuterComposite.java +++ b/samples/server/petstore/springboot/src/main/java/io/swagger/model/OuterComposite.java @@ -6,7 +6,9 @@ import com.fasterxml.jackson.annotation.JsonCreator; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import java.math.BigDecimal; +import javax.validation.Valid; import javax.validation.constraints.*; + /** * OuterComposite */ @@ -31,6 +33,9 @@ public class OuterComposite { * @return myNumber **/ @ApiModelProperty(value = "") + + @Valid + public BigDecimal getMyNumber() { return myNumber; } @@ -49,6 +54,8 @@ public class OuterComposite { * @return myString **/ @ApiModelProperty(value = "") + + public String getMyString() { return myString; } @@ -67,6 +74,8 @@ public class OuterComposite { * @return myBoolean **/ @ApiModelProperty(value = "") + + public Boolean getMyBoolean() { return myBoolean; } From dc7c1f8cb92712d88c6732982fb90b677f80f185 Mon Sep 17 00:00:00 2001 From: Cliffano Subagio Date: Sun, 11 Jun 2017 23:42:36 +1000 Subject: [PATCH 10/10] [JS] Fix JavaScript string return type (#5819) * [javascript] Fix response body when return type is String. * [javascript] Regenerate javascript petstores with fixed String return type. * [javascript-es6] Fix response body when return type is string. --- .../src/main/resources/Javascript-es6/ApiClient.mustache | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/swagger-codegen/src/main/resources/Javascript-es6/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/Javascript-es6/ApiClient.mustache index 785945752b5..22cd56bd12c 100644 --- a/modules/swagger-codegen/src/main/resources/Javascript-es6/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/Javascript-es6/ApiClient.mustache @@ -434,6 +434,8 @@ export default class ApiClient { if (returnType === 'Blob') { request.responseType('blob'); + } else if (returnType === 'String') { + request.responseType('string'); } // Attach previously saved cookies, if enabled