diff --git a/springdoc-openapi-kotlin/src/main/java/org/springdoc/kotlin/SpringDocKotlinConfiguration.java b/springdoc-openapi-kotlin/src/main/java/org/springdoc/kotlin/SpringDocKotlinConfiguration.java index 6bb79f35d..6f8dffb75 100644 --- a/springdoc-openapi-kotlin/src/main/java/org/springdoc/kotlin/SpringDocKotlinConfiguration.java +++ b/springdoc-openapi-kotlin/src/main/java/org/springdoc/kotlin/SpringDocKotlinConfiguration.java @@ -23,8 +23,10 @@ package org.springdoc.kotlin; import com.fasterxml.jackson.module.kotlin.KotlinModule; +import io.swagger.v3.oas.models.media.ByteArraySchema; import kotlin.Deprecated; import kotlin.coroutines.Continuation; +import kotlin.jvm.internal.Intrinsics; import org.springdoc.core.providers.ObjectMapperProvider; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -51,7 +53,9 @@ public class SpringDocKotlinConfiguration { * @param objectMapperProvider the object mapper provider */ public SpringDocKotlinConfiguration(ObjectMapperProvider objectMapperProvider) { - getConfig().addRequestWrapperToIgnore(Continuation.class) + getConfig() + .addRequestWrapperToIgnore(Continuation.class) + .replaceWithSchema(byte[].class, new ByteArraySchema()) .addDeprecatedType(Deprecated.class); objectMapperProvider.jsonMapper().registerModule( new KotlinModule.Builder().build()); } diff --git a/springdoc-openapi-kotlin/src/test/kotlin/test/org/springdoc/api/app6/ByteArrayController.kt b/springdoc-openapi-kotlin/src/test/kotlin/test/org/springdoc/api/app6/ByteArrayController.kt new file mode 100644 index 000000000..2437acda9 --- /dev/null +++ b/springdoc-openapi-kotlin/src/test/kotlin/test/org/springdoc/api/app6/ByteArrayController.kt @@ -0,0 +1,34 @@ +/* + * + * * Copyright 2019-2022 the original author or authors. + * * + * * 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 + * * + * * https://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 test.org.springdoc.api.app6 + +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController + +data class Foo(val data: ByteArray) + +@RestController +@RequestMapping("/bytearray") +class ByteArrayController { + + @GetMapping("/") + fun getByteArray(): Foo = Foo(byteArrayOf(0)) + +} diff --git a/springdoc-openapi-kotlin/src/test/kotlin/test/org/springdoc/api/app6/SpringDocApp6Test.kt b/springdoc-openapi-kotlin/src/test/kotlin/test/org/springdoc/api/app6/SpringDocApp6Test.kt new file mode 100644 index 000000000..2197721dc --- /dev/null +++ b/springdoc-openapi-kotlin/src/test/kotlin/test/org/springdoc/api/app6/SpringDocApp6Test.kt @@ -0,0 +1,31 @@ +/* + * + * * Copyright 2019-2020 the original author or authors. + * * + * * 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 + * * + * * https://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 test.org.springdoc.api.app6 + +import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.context.annotation.ComponentScan +import test.org.springdoc.api.AbstractKotlinSpringDocTest + +class SpringDocApp6Test : AbstractKotlinSpringDocTest() { + + @SpringBootApplication + @ComponentScan(basePackages = ["org.springdoc", "test.org.springdoc.api.app6"]) + open class DemoApplication + +} \ No newline at end of file diff --git a/springdoc-openapi-kotlin/src/test/resources/results/app6.json b/springdoc-openapi-kotlin/src/test/resources/results/app6.json new file mode 100644 index 000000000..907da4426 --- /dev/null +++ b/springdoc-openapi-kotlin/src/test/resources/results/app6.json @@ -0,0 +1,51 @@ +{ + "openapi": "3.0.1", + "info": { + "title": "OpenAPI definition", + "version": "v0" + }, + "servers": [ + { + "url": "", + "description": "Generated server url" + } + ], + "paths": { + "/bytearray/": { + "get": { + "tags": [ + "byte-array-controller" + ], + "operationId": "getByteArray", + "responses": { + "200": { + "description": "OK", + "content": { + "*/*": { + "schema": { + "$ref": "#/components/schemas/Foo" + } + } + } + } + } + } + } + }, + "components": { + "schemas": { + "Foo": { + "required": [ + "data" + ], + "type": "object", + "properties": { + "data": { + "type": "string", + "format": "byte" + } + } + } + } + } +} \ No newline at end of file