Skip to content

Commit 5d308bd

Browse files
authored
Merge pull request #1687 from codymikol/byte-sized
fix(kotlin): properly generate ByteArray property
2 parents 1b1e652 + 831a4d0 commit 5d308bd

File tree

4 files changed

+121
-1
lines changed

4 files changed

+121
-1
lines changed

springdoc-openapi-kotlin/src/main/java/org/springdoc/kotlin/SpringDocKotlinConfiguration.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
package org.springdoc.kotlin;
2424

2525
import com.fasterxml.jackson.module.kotlin.KotlinModule;
26+
import io.swagger.v3.oas.models.media.ByteArraySchema;
2627
import kotlin.Deprecated;
2728
import kotlin.coroutines.Continuation;
29+
import kotlin.jvm.internal.Intrinsics;
2830
import org.springdoc.core.providers.ObjectMapperProvider;
2931

3032
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
@@ -51,7 +53,9 @@ public class SpringDocKotlinConfiguration {
5153
* @param objectMapperProvider the object mapper provider
5254
*/
5355
public SpringDocKotlinConfiguration(ObjectMapperProvider objectMapperProvider) {
54-
getConfig().addRequestWrapperToIgnore(Continuation.class)
56+
getConfig()
57+
.addRequestWrapperToIgnore(Continuation.class)
58+
.replaceWithSchema(byte[].class, new ByteArraySchema())
5559
.addDeprecatedType(Deprecated.class);
5660
objectMapperProvider.jsonMapper().registerModule( new KotlinModule.Builder().build());
5761
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
*
3+
* * Copyright 2019-2022 the original author or authors.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * https://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package test.org.springdoc.api.app6
20+
21+
import org.springframework.web.bind.annotation.GetMapping
22+
import org.springframework.web.bind.annotation.RequestMapping
23+
import org.springframework.web.bind.annotation.RestController
24+
25+
data class Foo(val data: ByteArray)
26+
27+
@RestController
28+
@RequestMapping("/bytearray")
29+
class ByteArrayController {
30+
31+
@GetMapping("/")
32+
fun getByteArray(): Foo = Foo(byteArrayOf(0))
33+
34+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
*
3+
* * Copyright 2019-2020 the original author or authors.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * https://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package test.org.springdoc.api.app6
20+
21+
import org.springframework.boot.autoconfigure.SpringBootApplication
22+
import org.springframework.context.annotation.ComponentScan
23+
import test.org.springdoc.api.AbstractKotlinSpringDocTest
24+
25+
class SpringDocApp6Test : AbstractKotlinSpringDocTest() {
26+
27+
@SpringBootApplication
28+
@ComponentScan(basePackages = ["org.springdoc", "test.org.springdoc.api.app6"])
29+
open class DemoApplication
30+
31+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"openapi": "3.0.1",
3+
"info": {
4+
"title": "OpenAPI definition",
5+
"version": "v0"
6+
},
7+
"servers": [
8+
{
9+
"url": "",
10+
"description": "Generated server url"
11+
}
12+
],
13+
"paths": {
14+
"/bytearray/": {
15+
"get": {
16+
"tags": [
17+
"byte-array-controller"
18+
],
19+
"operationId": "getByteArray",
20+
"responses": {
21+
"200": {
22+
"description": "OK",
23+
"content": {
24+
"*/*": {
25+
"schema": {
26+
"$ref": "#/components/schemas/Foo"
27+
}
28+
}
29+
}
30+
}
31+
}
32+
}
33+
}
34+
},
35+
"components": {
36+
"schemas": {
37+
"Foo": {
38+
"required": [
39+
"data"
40+
],
41+
"type": "object",
42+
"properties": {
43+
"data": {
44+
"type": "string",
45+
"format": "byte"
46+
}
47+
}
48+
}
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)