Skip to content

Commit

Permalink
GH-128 Make OpenApi & JsonSchema annotations visible in runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
dzikoysk committed Dec 20, 2022
1 parent 6fcee6a commit 51d2405
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.javalin.openapi

import java.io.InputStream
import java.util.function.Supplier
import kotlin.annotation.AnnotationRetention.BINARY
import kotlin.annotation.AnnotationRetention.RUNTIME
import kotlin.annotation.AnnotationTarget.ANNOTATION_CLASS
import kotlin.annotation.AnnotationTarget.CLASS
import kotlin.annotation.AnnotationTarget.FIELD
Expand All @@ -12,7 +12,7 @@ import kotlin.annotation.AnnotationTarget.PROPERTY_SETTER
import kotlin.reflect.KClass

@Target(CLASS)
@Retention(BINARY)
@Retention(RUNTIME)
annotation class JsonSchema(
/**
* By default, each usage of @JsonSchema annotation results in generated `/json-schemas/{type qualifier}` resource file.
Expand All @@ -27,29 +27,29 @@ annotation class JsonSchema(
)

@Target(FUNCTION, PROPERTY_GETTER, PROPERTY_SETTER, FIELD, CLASS)
@Retention(BINARY)
@Retention(RUNTIME)
annotation class OneOf(
/** List of associated classes to list */
vararg val value: KClass<*>
)

@Target(FUNCTION, PROPERTY_GETTER, PROPERTY_SETTER, FIELD, CLASS)
@Retention(BINARY)
@Retention(RUNTIME)
annotation class AnyOf(
/** List of associated classes to list */
vararg val value: KClass<*>
)

@Target(FUNCTION, PROPERTY_GETTER, PROPERTY_SETTER, FIELD, CLASS)
@Retention(BINARY)
@Retention(RUNTIME)
annotation class AllOf(
/** List of associated classes to list */
vararg val value: KClass<*>
)

/** Allows you to add custom properties to your schemes */
@Target(FUNCTION, PROPERTY_GETTER, PROPERTY_SETTER, FIELD)
@Retention(BINARY)
@Retention(RUNTIME)
@Repeatable
annotation class Custom(
/* Define name of key for custom property */
Expand All @@ -60,7 +60,7 @@ annotation class Custom(

/** Allows you to create custom annotations for a group of custom properties */
@Target(ANNOTATION_CLASS)
@Retention(BINARY)
@Retention(RUNTIME)
annotation class CustomAnnotation

enum class Combinator(val propertyName: String, val type: KClass<*>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import io.javalin.openapi.HttpMethod.GET
import io.javalin.openapi.Visibility.PUBLIC
import java.lang.annotation.Repeatable
import kotlin.annotation.AnnotationRetention.BINARY
import kotlin.annotation.AnnotationRetention.RUNTIME
import kotlin.annotation.AnnotationTarget.CLASS
import kotlin.annotation.AnnotationTarget.FIELD
import kotlin.annotation.AnnotationTarget.FUNCTION
Expand All @@ -22,7 +23,7 @@ import kotlin.reflect.KClass
*/
@Repeatable(value = OpenApis::class)
@Target(CLASS, FIELD, FUNCTION)
@Retention(BINARY)
@Retention(RUNTIME)
annotation class OpenApi(
/** The described path */
val path: String,
Expand Down Expand Up @@ -80,21 +81,21 @@ fun OpenApi.getFormattedPath(): String =

/** Utility annotation to aggregate multiple [OpenApi] instances */
@Target(CLASS, FIELD, FUNCTION)
@Retention(BINARY)
@Retention(RUNTIME)
annotation class OpenApis(
val value: Array<OpenApi> = []
)

@Target()
@Retention(BINARY)
@Retention(RUNTIME)
annotation class OpenApiResponse(
val status: String,
val content: Array<OpenApiContent> = [],
val description: String = NULL_STRING
)

@Target()
@Retention(BINARY)
@Retention(RUNTIME)
annotation class OpenApiParam(
val name: String,
val type: KClass<*> = String::class,
Expand All @@ -107,7 +108,7 @@ annotation class OpenApiParam(
)

@Target()
@Retention(BINARY)
@Retention(RUNTIME)
annotation class OpenApiRequestBody(
val content: Array<OpenApiContent>,
val required: Boolean = false,
Expand All @@ -124,7 +125,7 @@ annotation class OpenApiRequestBody(
//)

@Target()
@Retention(BINARY)
@Retention(RUNTIME)
annotation class OpenApiContent(
val from: KClass<*> = NULL_CLASS::class,
val mimeType: String = ContentType.AUTODETECT,
Expand All @@ -134,7 +135,7 @@ annotation class OpenApiContent(
)

@Target()
@Retention(BINARY)
@Retention(RUNTIME)
annotation class OpenApiContentProperty(
val name: String,
val isArray: Boolean = false,
Expand All @@ -143,30 +144,30 @@ annotation class OpenApiContentProperty(
)

@Target()
@Retention(BINARY)
@Retention(RUNTIME)
annotation class OpenApiSecurity(
val name: String,
val scopes: Array<String> = []
)

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

@Target(CLASS, FUNCTION, PROPERTY_GETTER, PROPERTY_SETTER)
@Retention(BINARY)
@Retention(RUNTIME)
annotation class OpenApiName(
val value: String
)

@Target(FUNCTION, PROPERTY_GETTER, PROPERTY_SETTER)
@Retention(BINARY)
@Retention(RUNTIME)
annotation class OpenApiExample(
val value: String
)

@Target(CLASS, FUNCTION, PROPERTY_GETTER, PROPERTY_SETTER)
@Retention(BINARY)
@Retention(RUNTIME)
annotation class OpenApiPropertyType(
val definedBy: KClass<*>
)
Expand All @@ -179,7 +180,7 @@ enum class Visibility(val priority: Int) {
}

@Target(CLASS)
@Retention(BINARY)
@Retention(RUNTIME)
annotation class OpenApiByFields(
val value: Visibility = PUBLIC
)
Expand Down

0 comments on commit 51d2405

Please sign in to comment.