Skip to content

fix(kotlin): properly generate ByteArray property #1687

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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))

}
Original file line number Diff line number Diff line change
@@ -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

}
51 changes: 51 additions & 0 deletions springdoc-openapi-kotlin/src/test/resources/results/app6.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
}
}