Skip to content

Commit

Permalink
Merge pull request #133 from icerockdev/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex009 authored May 14, 2021
2 parents 874a0e2 + 6bf6f72 commit b341b5f
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 14 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ This is a Kotlin MultiPlatform library that provide network components for iOS &
- 0.14.1
- 0.14.2
- 0.15.0
- 0.15.1

## Installation
root build.gradle
Expand All @@ -69,7 +70,7 @@ buildscript {
}
dependencies {
classpath "dev.icerock.moko:network-generator:0.15.0"
classpath "dev.icerock.moko:network-generator:0.15.1"
}
}
Expand All @@ -86,7 +87,7 @@ project build.gradle
apply plugin: "dev.icerock.mobile.multiplatform-network-generator"
dependencies {
commonMainApi("dev.icerock.moko:network:0.15.0")
commonMainApi("dev.icerock.moko:network:0.15.1")
}
```

Expand Down
4 changes: 2 additions & 2 deletions network-deps/src/main/kotlin/Deps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ object Deps {
private const val mokoMvvmVersion = "0.9.2"
private const val mokoErrorsVersion = "0.3.2"
private const val mokoTestVersion = "0.2.1"
const val mokoNetworkVersion = "0.15.0"
const val mokoNetworkVersion = "0.15.1"

private const val kbignumVersion = "1.11.0"
private const val kbignumVersion = "2.0.6"

object Android {
const val compileSdk = 30
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ internal class OpenApiProcessor {
)
}
}

if (this is ArraySchema) {
val propertyContext = SchemaContext.PropertyComponent(
schemaName = this.name,
Expand All @@ -174,6 +175,18 @@ internal class OpenApiProcessor {
)
}

if (additionalProperties != null) {
val propertyContext = SchemaContext.PropertyComponent(
schemaName = this.name,
propertyName = "additionalProperties"
)

this.additionalProperties = (this.additionalProperties as Schema<*>).processSchema(
openAPI,
SchemaContext.Child(parent = context, child = propertyContext)
)
}

return processSchemaByProcessors(
input = this,
openAPI = openAPI,
Expand Down
55 changes: 47 additions & 8 deletions sample/mpp-library/src/commonTest/kotlin/ProfileApiTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
* Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
*/

import dev.icerock.moko.network.exceptionfactory.HttpExceptionFactory
import dev.icerock.moko.network.exceptionfactory.parser.ErrorExceptionParser
import dev.icerock.moko.network.exceptionfactory.parser.ValidationExceptionParser
import dev.icerock.moko.network.features.ExceptionFeature
import dev.icerock.moko.network.generated.apis.DefaultApi
import dev.icerock.moko.network.generated.apis.ProfileApi
import dev.icerock.moko.network.generated.models.UnitActivity
Expand All @@ -15,15 +11,13 @@ import dev.icerock.moko.network.generated.models.UserSettingsNullableSchema
import dev.icerock.moko.network.generated.models.UserStateEnum
import dev.icerock.moko.network.nullable.asNullable
import dev.icerock.moko.test.runBlocking
import io.ktor.client.HttpClient
import io.ktor.client.engine.mock.MockEngine
import io.ktor.client.engine.mock.MockRequestHandler
import io.ktor.client.engine.mock.respondOk
import io.ktor.client.engine.mock.toByteArray
import io.ktor.http.HttpStatusCode
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonNull
import kotlinx.serialization.json.JsonPrimitive
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
Expand Down Expand Up @@ -470,4 +464,49 @@ class ProfileApiTest {
assertNotNull(result.stateName)
assertTrue(isTestSuccessFlow.value)
}

@Test
fun `additionalProperties oneOf success`() {
val httpClient = createMockClient { request ->
respondOk(
"""
{
"custom_field": [
null,
"value"
]
}
""".trimIndent()
)
}

json = Json {
ignoreUnknownKeys = true
}

val api = DefaultApi(
httpClient = httpClient,
json = json
)

val result = runBlocking {
api.apiGetBlogPermissionsRoles(10)
}

val field = result["custom_field"]
assertNotNull(field)

val itemsList = field.map { jsonItem ->
when (jsonItem) {
is JsonNull -> null
is JsonPrimitive -> jsonItem.content
else -> throw IllegalStateException("Wrong result data")
}
}

assertEquals(
expected = listOf(null, "value"),
actual = itemsList
)
}
}
61 changes: 61 additions & 0 deletions sample/mpp-library/src/profile_openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,30 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/UserInfoWithSet'
'/profile/get/mao/nullable':
get:
operationId: api_profile_get_map_nullable
description: Получить хэшмап со списком nullable строк
responses:
'200':
description: ''
content:
application/json:
schema:
$ref: '#/components/schemas/MapOfNullableListResponseSchema'
'/api/permissions/{blog_id}/':
get:
operationId: api_get_blog_permissions_roles
description: Получить список ролей
responses:
'200':
description: ''
content:
application/json:
schema:
$ref: '#/components/schemas/BlogPermissionsRoles'
parameters:
- $ref: '#/components/parameters/blogIdParam'
security:
- Bearer: []
components:
Expand Down Expand Up @@ -247,6 +271,13 @@ components:
format: uuid
example: e0520e34-01b3-4ddb-b08a-2735a7dfde56
description: 'Идентификатор пользователя из keycloak'
blogIdParam:
name: blog_id
in: path
description: Идентификатор
required: true
schema:
type: integer
unitIdParam:
in: path
name: unit_id
Expand Down Expand Up @@ -474,3 +505,33 @@ components:
- about_me_required_nullable
- raiting_required_nonnull
type: object
MapOfNullableListResponseSchema:
type: object
additionalProperties:
type: array
items:
oneOf:
- type: integer
- type: string
MapOfNullableListTestObjectSchema:
type: object
properties:
field1:
type: array
items:
oneOf:
- type: null
- type: string
- type: UserSettingsNullableSchema
field2:
type: array
items:
type: string
BlogPermissionsRoles:
type: object
additionalProperties:
type: array
items:
oneOf:
- type: null
- type: string
2 changes: 0 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ dependencyResolutionManagement {
mavenCentral()
google()

maven { url = uri("https://dl.bintray.com/korlibs/korlibs") }

jcenter {
content {
includeGroup("org.jetbrains.trove4j")
Expand Down

0 comments on commit b341b5f

Please sign in to comment.