Skip to content

Commit 213512f

Browse files
committed
GH-193 Rename OpenApiExampleObject to OpenApiExampleProperty
1 parent f6d3baa commit 213512f

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

examples/javalin-gradle-kotlin/src/main/java/io/javalin/openapi/plugin/test/JavalinTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import io.javalin.openapi.OpenApiContentProperty;
2626
import io.javalin.openapi.OpenApiDescription;
2727
import io.javalin.openapi.OpenApiExample;
28-
import io.javalin.openapi.OpenApiExampleObject;
28+
import io.javalin.openapi.OpenApiExampleProperty;
2929
import io.javalin.openapi.OpenApiIgnore;
3030
import io.javalin.openapi.OpenApiLicense;
3131
import io.javalin.openapi.OpenApiName;
@@ -331,18 +331,18 @@ public String getFormattedMessage() {
331331

332332
// should contain examples
333333
@OpenApiExample(objects = {
334-
@OpenApiExampleObject(value = "2022-08-14T21:13:03.546Z"),
335-
@OpenApiExampleObject(value = "2022-08-14T21:13:03.546Z")
334+
@OpenApiExampleProperty(value = "2022-08-14T21:13:03.546Z"),
335+
@OpenApiExampleProperty(value = "2022-08-14T21:13:03.546Z")
336336
})
337337
public @NotNull String[] getTimestamps() {
338338
return new String[] { timestamp };
339339
}
340340

341341
// should contain object example
342342
@OpenApiExample(objects = {
343-
@OpenApiExampleObject(name = "Barbie", objects = {
344-
@OpenApiExampleObject(name = "name", value = "Margot Robbie"),
345-
@OpenApiExampleObject(name = "link", value = "https://www.youtube.com/watch?v=dQw4w9WgXcQ")
343+
@OpenApiExampleProperty(name = "Barbie", objects = {
344+
@OpenApiExampleProperty(name = "name", value = "Margot Robbie"),
345+
@OpenApiExampleProperty(name = "link", value = "https://www.youtube.com/watch?v=dQw4w9WgXcQ")
346346
}),
347347
})
348348
public @NotNull Object[] getExampleObjects() {

openapi-specification/src/main/kotlin/io/javalin/openapi/OpenApiAnnotations.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,15 @@ annotation class OpenApiName(
176176
@Retention(RUNTIME)
177177
annotation class OpenApiExample(
178178
val value: String = NULL_STRING,
179-
val objects: Array<OpenApiExampleObject> = []
179+
val objects: Array<OpenApiExampleProperty> = []
180180
)
181181

182182
@Target(ANNOTATION_CLASS)
183183
@Retention(RUNTIME)
184-
annotation class OpenApiExampleObject(
184+
annotation class OpenApiExampleProperty(
185185
val name: String = NULL_STRING,
186186
val value: String = NULL_STRING,
187-
val objects: Array<OpenApiExampleObject> = []
187+
val objects: Array<OpenApiExampleProperty> = []
188188
)
189189

190190
@Target(FUNCTION, PROPERTY_GETTER, PROPERTY_SETTER)

openapi-specification/src/main/kotlin/io/javalin/openapi/experimental/processor/generators/ExampleGenerator.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import com.google.gson.JsonArray
44
import com.google.gson.JsonElement
55
import com.google.gson.JsonObject
66
import io.javalin.openapi.NULL_STRING
7-
import io.javalin.openapi.OpenApiExampleObject
7+
import io.javalin.openapi.OpenApiExampleProperty
88

99
object ExampleGenerator {
1010

@@ -19,7 +19,7 @@ object ExampleGenerator {
1919
}
2020
}
2121

22-
fun generateFromExamples(examples: Array<OpenApiExampleObject>): GeneratorResult {
22+
fun generateFromExamples(examples: Array<OpenApiExampleProperty>): GeneratorResult {
2323
if (examples.isRawList()) {
2424
val jsonArray = JsonArray()
2525
examples.forEach { jsonArray.add(it.value) }
@@ -35,14 +35,14 @@ object ExampleGenerator {
3535
return GeneratorResult(null, examples.toJsonObject())
3636
}
3737

38-
private fun OpenApiExampleObject.toSimpleExampleValue(): GeneratorResult =
38+
private fun OpenApiExampleProperty.toSimpleExampleValue(): GeneratorResult =
3939
when {
4040
this.value != NULL_STRING -> GeneratorResult(this.value, null)
4141
this.objects.isNotEmpty() -> GeneratorResult(null, objects.toJsonObject())
4242
else -> throw IllegalArgumentException("Example object must have either value or objects ($this)")
4343
}
4444

45-
private fun Array<OpenApiExampleObject>.toJsonObject(): JsonObject {
45+
private fun Array<OpenApiExampleProperty>.toJsonObject(): JsonObject {
4646
val jsonObject = JsonObject()
4747
this.forEach {
4848
val result = it.toSimpleExampleValue()
@@ -57,10 +57,10 @@ object ExampleGenerator {
5757
return jsonObject
5858
}
5959

60-
private fun Array<OpenApiExampleObject>.isObjectList(): Boolean =
60+
private fun Array<OpenApiExampleProperty>.isObjectList(): Boolean =
6161
this.isNotEmpty() && this.all { it.name == NULL_STRING && it.value == NULL_STRING && it.objects.isNotEmpty() }
6262

63-
private fun Array<OpenApiExampleObject>.isRawList(): Boolean =
63+
private fun Array<OpenApiExampleProperty>.isRawList(): Boolean =
6464
this.isNotEmpty() && this.all { it.name == NULL_STRING && it.value != NULL_STRING && it.objects.isEmpty() }
6565

6666
}

openapi-specification/src/main/kotlin/io/javalin/openapi/experimental/processor/generators/TypeSchemaGenerator.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import io.javalin.openapi.Nullability
1111
import io.javalin.openapi.OpenApiByFields
1212
import io.javalin.openapi.OpenApiDescription
1313
import io.javalin.openapi.OpenApiExample
14-
import io.javalin.openapi.OpenApiExampleObject
1514
import io.javalin.openapi.OpenApiIgnore
1615
import io.javalin.openapi.OpenApiName
1716
import io.javalin.openapi.OpenApiPropertyType

0 commit comments

Comments
 (0)