Skip to content

Commit

Permalink
GH-181 Support @OpenApiRequired (Resolve #181)
Browse files Browse the repository at this point in the history
  • Loading branch information
dzikoysk committed Apr 26, 2023
1 parent e26c056 commit 45bf946
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ annotation class OpenApiSecurity(
@Retention(RUNTIME)
annotation class OpenApiIgnore

@Target(FUNCTION, PROPERTY_GETTER, PROPERTY_SETTER)
@Retention(RUNTIME)
annotation class OpenApiRequired

@Target(CLASS, FUNCTION, PROPERTY_GETTER, PROPERTY_SETTER)
@Retention(RUNTIME)
annotation class OpenApiName(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import io.javalin.openapi.OpenApiExample
import io.javalin.openapi.OpenApiIgnore
import io.javalin.openapi.OpenApiName
import io.javalin.openapi.OpenApiPropertyType
import io.javalin.openapi.OpenApiRequired
import io.javalin.openapi.Visibility
import io.javalin.openapi.experimental.AnnotationProcessorContext
import io.javalin.openapi.experimental.ClassDefinition
Expand Down Expand Up @@ -266,12 +267,17 @@ internal fun ClassDefinition.findAllProperties(requireNonNulls: Boolean): Collec
else -> false
}

val required = when {
property.getAnnotation(OpenApiRequired::class.java) != null -> true
else -> requireNonNulls && isNotNull
}

properties.add(
Property(
name = name,
type = propertyType.toClassDefinition(),
composition = findCompositionInElement(context, property),
required = requireNonNulls && isNotNull,
required = required,
extra = property.findExtra(context)
)
)
Expand Down

0 comments on commit 45bf946

Please sign in to comment.