diff --git a/examples/javalin-gradle-kotlin/src/main/java/io/javalin/openapi/plugin/test/JavalinTest.java b/examples/javalin-gradle-kotlin/src/main/java/io/javalin/openapi/plugin/test/JavalinTest.java index 39bf446..d082b08 100644 --- a/examples/javalin-gradle-kotlin/src/main/java/io/javalin/openapi/plugin/test/JavalinTest.java +++ b/examples/javalin-gradle-kotlin/src/main/java/io/javalin/openapi/plugin/test/JavalinTest.java @@ -25,7 +25,7 @@ import io.javalin.openapi.OpenApiContentProperty; import io.javalin.openapi.OpenApiDescription; import io.javalin.openapi.OpenApiExample; -import io.javalin.openapi.OpenApiExampleObject; +import io.javalin.openapi.OpenApiExampleProperty; import io.javalin.openapi.OpenApiIgnore; import io.javalin.openapi.OpenApiLicense; import io.javalin.openapi.OpenApiName; @@ -331,8 +331,8 @@ public String getFormattedMessage() { // should contain examples @OpenApiExample(objects = { - @OpenApiExampleObject(value = "2022-08-14T21:13:03.546Z"), - @OpenApiExampleObject(value = "2022-08-14T21:13:03.546Z") + @OpenApiExampleProperty(value = "2022-08-14T21:13:03.546Z"), + @OpenApiExampleProperty(value = "2022-08-14T21:13:03.546Z") }) public @NotNull String[] getTimestamps() { return new String[] { timestamp }; @@ -340,9 +340,9 @@ public String getFormattedMessage() { // should contain object example @OpenApiExample(objects = { - @OpenApiExampleObject(name = "Barbie", objects = { - @OpenApiExampleObject(name = "name", value = "Margot Robbie"), - @OpenApiExampleObject(name = "link", value = "https://www.youtube.com/watch?v=dQw4w9WgXcQ") + @OpenApiExampleProperty(name = "Barbie", objects = { + @OpenApiExampleProperty(name = "name", value = "Margot Robbie"), + @OpenApiExampleProperty(name = "link", value = "https://www.youtube.com/watch?v=dQw4w9WgXcQ") }), }) public @NotNull Object[] getExampleObjects() { diff --git a/openapi-specification/src/main/kotlin/io/javalin/openapi/OpenApiAnnotations.kt b/openapi-specification/src/main/kotlin/io/javalin/openapi/OpenApiAnnotations.kt index 2e9cadd..ee823e5 100644 --- a/openapi-specification/src/main/kotlin/io/javalin/openapi/OpenApiAnnotations.kt +++ b/openapi-specification/src/main/kotlin/io/javalin/openapi/OpenApiAnnotations.kt @@ -176,15 +176,15 @@ annotation class OpenApiName( @Retention(RUNTIME) annotation class OpenApiExample( val value: String = NULL_STRING, - val objects: Array = [] + val objects: Array = [] ) @Target(ANNOTATION_CLASS) @Retention(RUNTIME) -annotation class OpenApiExampleObject( +annotation class OpenApiExampleProperty( val name: String = NULL_STRING, val value: String = NULL_STRING, - val objects: Array = [] + val objects: Array = [] ) @Target(FUNCTION, PROPERTY_GETTER, PROPERTY_SETTER) diff --git a/openapi-specification/src/main/kotlin/io/javalin/openapi/experimental/processor/generators/ExampleGenerator.kt b/openapi-specification/src/main/kotlin/io/javalin/openapi/experimental/processor/generators/ExampleGenerator.kt index 20c777c..5b151fc 100644 --- a/openapi-specification/src/main/kotlin/io/javalin/openapi/experimental/processor/generators/ExampleGenerator.kt +++ b/openapi-specification/src/main/kotlin/io/javalin/openapi/experimental/processor/generators/ExampleGenerator.kt @@ -4,7 +4,7 @@ import com.google.gson.JsonArray import com.google.gson.JsonElement import com.google.gson.JsonObject import io.javalin.openapi.NULL_STRING -import io.javalin.openapi.OpenApiExampleObject +import io.javalin.openapi.OpenApiExampleProperty object ExampleGenerator { @@ -19,7 +19,7 @@ object ExampleGenerator { } } - fun generateFromExamples(examples: Array): GeneratorResult { + fun generateFromExamples(examples: Array): GeneratorResult { if (examples.isRawList()) { val jsonArray = JsonArray() examples.forEach { jsonArray.add(it.value) } @@ -35,14 +35,14 @@ object ExampleGenerator { return GeneratorResult(null, examples.toJsonObject()) } - private fun OpenApiExampleObject.toSimpleExampleValue(): GeneratorResult = + private fun OpenApiExampleProperty.toSimpleExampleValue(): GeneratorResult = when { this.value != NULL_STRING -> GeneratorResult(this.value, null) this.objects.isNotEmpty() -> GeneratorResult(null, objects.toJsonObject()) else -> throw IllegalArgumentException("Example object must have either value or objects ($this)") } - private fun Array.toJsonObject(): JsonObject { + private fun Array.toJsonObject(): JsonObject { val jsonObject = JsonObject() this.forEach { val result = it.toSimpleExampleValue() @@ -57,10 +57,10 @@ object ExampleGenerator { return jsonObject } - private fun Array.isObjectList(): Boolean = + private fun Array.isObjectList(): Boolean = this.isNotEmpty() && this.all { it.name == NULL_STRING && it.value == NULL_STRING && it.objects.isNotEmpty() } - private fun Array.isRawList(): Boolean = + private fun Array.isRawList(): Boolean = this.isNotEmpty() && this.all { it.name == NULL_STRING && it.value != NULL_STRING && it.objects.isEmpty() } } \ No newline at end of file diff --git a/openapi-specification/src/main/kotlin/io/javalin/openapi/experimental/processor/generators/TypeSchemaGenerator.kt b/openapi-specification/src/main/kotlin/io/javalin/openapi/experimental/processor/generators/TypeSchemaGenerator.kt index 67cf974..2fd150d 100644 --- a/openapi-specification/src/main/kotlin/io/javalin/openapi/experimental/processor/generators/TypeSchemaGenerator.kt +++ b/openapi-specification/src/main/kotlin/io/javalin/openapi/experimental/processor/generators/TypeSchemaGenerator.kt @@ -11,7 +11,6 @@ import io.javalin.openapi.Nullability import io.javalin.openapi.OpenApiByFields import io.javalin.openapi.OpenApiDescription import io.javalin.openapi.OpenApiExample -import io.javalin.openapi.OpenApiExampleObject import io.javalin.openapi.OpenApiIgnore import io.javalin.openapi.OpenApiName import io.javalin.openapi.OpenApiPropertyType