Skip to content

Commit

Permalink
skip more default values from upgraded swagger annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
angryziber committed Aug 25, 2023
1 parent 532f340 commit b1a907c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions openapi/src/OpenAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.Parameter
import io.swagger.v3.oas.annotations.enums.ParameterIn
import io.swagger.v3.oas.annotations.info.Info
import io.swagger.v3.oas.annotations.media.Schema.AccessMode
import io.swagger.v3.oas.annotations.media.Schema.*
import io.swagger.v3.oas.annotations.parameters.RequestBody
import io.swagger.v3.oas.annotations.responses.ApiResponse
import io.swagger.v3.oas.annotations.security.SecurityRequirement
Expand Down Expand Up @@ -161,7 +161,7 @@ private fun List<SecurityRequirement>.toSecurity() = map { mapOf(it.name to it.s
internal fun <T: Annotation> T.toNonEmptyValues(filter: (KProperty1<T, *>) -> Boolean = { true }): MutableMap<String, Any?> = HashMap<String, Any?>().also { map ->
publicProperties.filter(filter).forEach { p ->
when(val v = p.valueOf(this)) {
"", false, 0, Int.MAX_VALUE, Int.MIN_VALUE, 0.0, Void::class.java, AccessMode.AUTO -> null
"", false, 0, Int.MAX_VALUE, Int.MIN_VALUE, 0.0, Void::class.java, AccessMode.AUTO, RequiredMode.AUTO, AdditionalPropertiesValue.USE_ADDITIONAL_PROPERTIES_ANNOTATION -> null
is Enum<*> -> v.takeIf { v.name != "DEFAULT" }
is Annotation -> v.toNonEmptyValues().takeIf { it.isNotEmpty() }
is Array<*> -> v.map { (it as? Annotation)?.toNonEmptyValues() ?: it }.takeIf { it.isNotEmpty() }
Expand Down

0 comments on commit b1a907c

Please sign in to comment.