Skip to content

Commit 7c8ff57

Browse files
authored
Referenced descriptions (#113)
1 parent 15cf9e4 commit 7c8ff57

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+62807
-17612
lines changed

build.gradle.kts

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ subprojects {
4242
ktfmt().kotlinlangStyle().configure {
4343
it.setBlockIndent(2)
4444
it.setContinuationIndent(2)
45-
it.setRemoveUnusedImport(true)
45+
it.setRemoveUnusedImports(true)
46+
it.setManageTrailingCommas(true)
4647
}
4748
}
4849
}

generation/src/main/kotlin/io/github/nomisrev/openapi/APIs.kt

+7-7
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ fun configure(defaults: Boolean) =
2323
"configure",
2424
LambdaTypeName.get(
2525
receiver = ClassName("io.ktor.client.request", "HttpRequestBuilder"),
26-
returnType = Unit::class.asTypeName()
27-
)
26+
returnType = Unit::class.asTypeName(),
27+
),
2828
) {
2929
if (defaults) defaultValue("{}")
3030
}
@@ -190,7 +190,7 @@ private fun API.toImplementation(context: NamingContext? = null): TypeSpec {
190190
addModifiers(KModifier.OVERRIDE)
191191
initializer(
192192
"%T(client)",
193-
toClassName(Nested(Named(it.name + "Ktor"), className.toContext()))
193+
toClassName(Nested(Named(it.name + "Ktor"), className.toContext())),
194194
)
195195
}
196196
}
@@ -222,7 +222,7 @@ private fun Route.addFunction(implemented: Boolean) {
222222
.addStatement("}")
223223
.addStatement(
224224
"return response.%M()",
225-
MemberName(`package`, "bodyOrThrow", isExtension = true)
225+
MemberName(`package`, "bodyOrThrow", isExtension = true),
226226
)
227227
.build()
228228
)
@@ -245,7 +245,7 @@ fun Route.addPathAndContent() {
245245
addStatement(
246246
"url { %M(%S$replace) }",
247247
MemberName("io.ktor.http", "path", isExtension = true),
248-
path
248+
path,
249249
)
250250
addContentType(body)
251251
}
@@ -305,7 +305,7 @@ fun Route.params(defaults: Boolean): List<ParameterSpec> =
305305
input.map { input ->
306306
ParameterSpec(
307307
toParamName(Named(input.name)),
308-
input.type.toTypeName().copy(nullable = !input.isRequired)
308+
input.type.toTypeName().copy(nullable = !input.isRequired),
309309
) {
310310
input.description?.let { addKdoc(it) }
311311
if (defaults) {
@@ -335,7 +335,7 @@ fun Route.requestBody(defaults: Boolean): List<ParameterSpec> {
335335
toParamName(Named(parameter.name)),
336336
parameter.type,
337337
!body.required,
338-
parameter.type.description
338+
parameter.type.description,
339339
)
340340
}
341341
})

generation/src/main/kotlin/io/github/nomisrev/openapi/Default.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ context(OpenAPIContext)
4343
private fun default(
4444
model: Collection,
4545
builder: String,
46-
default: List<String>?
46+
default: List<String>?,
4747
): Pair<String, List<Any>>? =
4848
when {
4949
default == null -> null

generation/src/main/kotlin/io/github/nomisrev/openapi/Interceptors.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ interface APIInterceptor {
2828

2929
override fun OpenAPIContext.modifyInterface(
3030
api: API,
31-
typeSpec: TypeSpec.Builder
31+
typeSpec: TypeSpec.Builder,
3232
): TypeSpec.Builder = typeSpec
3333

3434
override fun OpenAPIContext.modifyImplementation(
3535
api: API,
36-
typeSpec: TypeSpec.Builder
36+
typeSpec: TypeSpec.Builder,
3737
): TypeSpec.Builder = typeSpec
3838
}
3939
}

generation/src/main/kotlin/io/github/nomisrev/openapi/KotlinPoetExt.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ fun ParameterSpec.Builder.description(kdoc: String?): ParameterSpec.Builder = ap
5757
fun TypeSpec.Companion.dataClass(
5858
className: ClassName,
5959
parameters: List<ParameterSpec>,
60-
configure: TypeSpec.Builder.() -> Unit = {}
60+
configure: TypeSpec.Builder.() -> Unit = {},
6161
): TypeSpec {
6262
val sorted = parameters.sorted()
6363
return classBuilder(className)
@@ -76,14 +76,14 @@ fun PropertySpec(
7676
name: String,
7777
type: TypeName,
7878
vararg modifiers: KModifier,
79-
configure: PropertySpec.Builder.() -> Unit = {}
79+
configure: PropertySpec.Builder.() -> Unit = {},
8080
): PropertySpec = PropertySpec.builder(name, type, *modifiers).apply(configure).build()
8181

8282
fun ParameterSpec(
8383
name: String,
8484
type: TypeName,
8585
vararg modifiers: KModifier,
86-
configure: ParameterSpec.Builder.() -> Unit = {}
86+
configure: ParameterSpec.Builder.() -> Unit = {},
8787
): ParameterSpec = ParameterSpec.builder(name, type, *modifiers).apply(configure).build()
8888

8989
private fun List<ParameterSpec>.sorted(): List<ParameterSpec> {

generation/src/main/kotlin/io/github/nomisrev/openapi/Main.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ data class GenerationConfig(
99
val output: String,
1010
val `package`: String,
1111
val name: String,
12-
val isK2: Boolean
12+
val isK2: Boolean,
1313
)
1414

1515
@JvmOverloads

generation/src/main/kotlin/io/github/nomisrev/openapi/Models.kt

+18-18
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,15 @@ private fun Model.Union.toTypeSpec(): TypeSpec {
146146
"%M(%S, %T.SEALED) {\n",
147147
MemberName("kotlinx.serialization.descriptors", "buildSerialDescriptor"),
148148
toClassName(context).simpleNames.joinToString("."),
149-
PolymorphicKind::class
149+
PolymorphicKind::class,
150150
)
151151
.withIndent {
152152
cases.forEach { case ->
153153
val (placeholder, values) = case.model.serializer()
154154
add(
155155
"element(%S, $placeholder.descriptor)\n",
156156
toCaseClassName(case.model).simpleNames.joinToString("."),
157-
*values
157+
*values,
158158
)
159159
}
160160
}
@@ -177,7 +177,7 @@ private fun Model.Union.toTypeSpec(): TypeSpec {
177177
addStatement(
178178
"is %T -> encoder.encodeSerializableValue($placeholder, value.value)",
179179
toCaseClassName(case.model),
180-
*values
180+
*values,
181181
)
182182
}
183183
}
@@ -195,12 +195,12 @@ private fun Model.Union.toTypeSpec(): TypeSpec {
195195
CodeBlock.builder()
196196
.addStatement(
197197
"val value = decoder.decodeSerializableValue(%T.serializer())",
198-
JsonElement::class.asTypeName()
198+
JsonElement::class.asTypeName(),
199199
)
200200
.addStatement(
201201
"val json = requireNotNull(decoder as? %T) { %S }.json",
202202
JsonDecoder::class.asTypeName(),
203-
"Currently only supporting Json"
203+
"Currently only supporting Json",
204204
)
205205
.addStatement("return attemptDeserialize(value,")
206206
.withIndent {
@@ -211,7 +211,7 @@ private fun Model.Union.toTypeSpec(): TypeSpec {
211211
"Pair(%T::class) { %T(json.decodeFromJsonElement($placeholder, value)) },\n",
212212
caseClassName,
213213
caseClassName,
214-
*values
214+
*values,
215215
)
216216
}
217217
}
@@ -239,7 +239,7 @@ private fun Model.Object.toTypeSpec(): TypeSpec =
239239
if (prop.isRequired && hasDefault) addAnnotation(annotationSpec<Required>())
240240
else if (!prop.isRequired && !hasDefault && prop.isNullable) defaultValue("null")
241241
}
242-
}
242+
},
243243
) {
244244
// Cannot serialize binary, these are used for multipart requests.
245245
// This occurs when request bodies are defined using top-level schemas.
@@ -273,7 +273,7 @@ private fun Iterable<Model.Object.Property>.requirements(): List<Requirement> =
273273
Requirement(
274274
property,
275275
"$paramName.size <= ${constraint.maxItems}",
276-
"$paramName should have at most ${constraint.maxItems} elements"
276+
"$paramName should have at most ${constraint.maxItems} elements",
277277
)
278278
)
279279
}
@@ -284,15 +284,15 @@ private fun Iterable<Model.Object.Property>.requirements(): List<Requirement> =
284284
Requirement(
285285
property,
286286
"$paramName.size >= ${constraint.minItems}",
287-
"$paramName should have at least ${constraint.minItems} elements"
287+
"$paramName should have at least ${constraint.minItems} elements",
288288
)
289289
)
290290
else ->
291291
listOf(
292292
Requirement(
293293
property,
294294
"$paramName.size in ${constraint.minItems}..${constraint.maxItems}",
295-
"$paramName should have between ${constraint.minItems} and ${constraint.maxItems} elements"
295+
"$paramName should have between ${constraint.minItems} and ${constraint.maxItems} elements",
296296
)
297297
)
298298
}
@@ -325,7 +325,7 @@ private fun Iterable<Model.Object.Property>.requirements(): List<Requirement> =
325325
Requirement(
326326
property,
327327
"$paramName.${"length"} <= ${constraint.maxLength}",
328-
"$paramName should have a ${"length"} of at most ${constraint.maxLength}"
328+
"$paramName should have a ${"length"} of at most ${constraint.maxLength}",
329329
)
330330
}
331331
else ->
@@ -334,13 +334,13 @@ private fun Iterable<Model.Object.Property>.requirements(): List<Requirement> =
334334
Requirement(
335335
property,
336336
"$paramName.${"length"} >= ${constraint.minLength}",
337-
"$paramName should have a ${"length"} of at least ${constraint.minLength}"
337+
"$paramName should have a ${"length"} of at least ${constraint.minLength}",
338338
)
339339
else ->
340340
Requirement(
341341
property,
342342
"$paramName.${"length"} in ${constraint.minLength}..${constraint.maxLength}",
343-
"$paramName should have a ${"length"} between ${constraint.minLength} and ${constraint.maxLength}"
343+
"$paramName should have a ${"length"} between ${constraint.minLength} and ${constraint.maxLength}",
344344
)
345345
}
346346
}
@@ -412,7 +412,7 @@ private fun Model.Object.Property.intRequirement(constraint: Constraints.Number)
412412
context(OpenAPIContext)
413413
private fun Model.Object.Property.numberRequirement(
414414
constraint: Constraints.Number,
415-
transform: (Double) -> Number
415+
transform: (Double) -> Number,
416416
): Requirement? {
417417
val paramName = toParamName(Named(baseName))
418418
val minimum = transform(constraint.minimum)
@@ -435,7 +435,7 @@ private fun Model.Object.Property.numberRequirement(
435435
Requirement(
436436
this,
437437
"$minimum $min $paramName && $paramName $max $maximum",
438-
"$paramName should be $minM $minimum and should be $maxM ${maximum}"
438+
"$paramName should be $minM $minimum and should be $maxM ${maximum}",
439439
)
440440
}
441441
}
@@ -470,7 +470,7 @@ private fun Model.Enum.Closed.toTypeSpec(): TypeSpec {
470470
)
471471
}
472472
.addSuperclassConstructorParameter("\"$rawName\"")
473-
.build()
473+
.build(),
474474
)
475475
}
476476
}
@@ -554,7 +554,7 @@ private fun Model.Enum.Open.toTypeSpec(): TypeSpec {
554554
"%M(%S, %T.STRING)",
555555
PrimitiveSerialDescriptor,
556556
enumName,
557-
PrimitiveKind::class.asTypeName()
557+
PrimitiveKind::class.asTypeName(),
558558
)
559559
.build()
560560
)
@@ -582,7 +582,7 @@ private fun Model.Enum.Open.toTypeSpec(): TypeSpec {
582582
val nested = NamingContext.Nested(Named(name), context)
583583
addStatement(
584584
"Pair(%T::class) { defined.find { it.value == value } },",
585-
toClassName(nested)
585+
toClassName(nested),
586586
)
587587
}
588588
}

generation/src/main/kotlin/io/github/nomisrev/openapi/Naming.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ private class Nam(private val `package`: String) : Naming {
4444
WordSplitterConfig(
4545
boundaries = setOf(' ', '-', '_', '.', '/'),
4646
handleCase = true,
47-
treatDigitsAsUppercase = true
47+
treatDigitsAsUppercase = true,
4848
)
4949
)
5050

@@ -69,13 +69,13 @@ private class Nam(private val `package`: String) : Naming {
6969
`package`,
7070
// $OuterClass$MyOperation$Param, this allows for multiple custom objects in a single
7171
// operation
72-
"${context.operationId.toPascalCase()}${context.name.toPascalCase()}".dropArraySyntax()
72+
"${context.operationId.toPascalCase()}${context.name.toPascalCase()}".dropArraySyntax(),
7373
)
7474
}
7575
is NamingContext.RouteBody ->
7676
ClassName(
7777
`package`,
78-
"${context.name.toPascalCase()}${context.postfix.toPascalCase()}".dropArraySyntax()
78+
"${context.name.toPascalCase()}${context.postfix.toPascalCase()}".dropArraySyntax(),
7979
)
8080
}
8181

0 commit comments

Comments
 (0)