Skip to content

Commit a2aa802

Browse files
committed
refactor: add toInlinedName utility and replace inline schema name sanitization logic
- Introduced `toInlinedName` to simplify dot separator replacement with underscores. - Replaced redundant sanitization logic in `TypeMapping` and `ModelGenerator` with the new utility.
1 parent d3df0f3 commit a2aa802

3 files changed

Lines changed: 10 additions & 9 deletions

File tree

core/src/main/kotlin/com/avsystem/justworks/core/gen/ModelGenerator.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.avsystem.justworks.core.gen
22

33
import arrow.core.raise.catch
4-
import arrow.core.tail
54
import com.avsystem.justworks.core.model.ApiSpec
65
import com.avsystem.justworks.core.model.EnumModel
76
import com.avsystem.justworks.core.model.PrimitiveType
@@ -457,11 +456,9 @@ class ModelGenerator(private val modelPackage: String) {
457456
return visited.toList()
458457
}
459458

460-
context(hierarchy: HierarchyInfo)
461-
private fun generateNestedInlineClass(schema: SchemaModel): FileSpec {
462-
val sanitizedName = schema.name.replace(".", "")
463-
return generateDataClass(schema.copy(name = sanitizedName))
464-
}
459+
context(_: HierarchyInfo)
460+
private fun generateNestedInlineClass(schema: SchemaModel): FileSpec =
461+
generateDataClass(schema.copy(name = schema.name.toInlinedName()))
465462

466463
private val SchemaModel.isPrimitiveOnly: Boolean
467464
get() = properties.isEmpty() && allOf == null && oneOf == null && anyOf == null

core/src/main/kotlin/com/avsystem/justworks/core/gen/NameUtils.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ fun String.toEnumConstantName(): String {
3838
}
3939
}
4040

41+
/**
42+
* Sanitizes a nested inline schema name by removing dot separators.
43+
* E.g. "Pet.Address" becomes "Pet_Address".
44+
*/
45+
fun String.toInlinedName(): String = replace(".", "_")
46+
4147
/**
4248
* Generates a PascalCase operation name from HTTP method and path.
4349
* Path parameters like {id} become "ById", {userId} becomes "ByUserId".

core/src/main/kotlin/com/avsystem/justworks/core/gen/TypeMapping.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ object TypeMapping {
4848
}
4949

5050
is TypeRef.Inline -> {
51-
// For nested inline classes (e.g., "Pet.Address"), sanitize to "PetAddress"
52-
val sanitizedName = typeRef.contextHint.replace(".", "")
53-
ClassName(modelPackage, sanitizedName)
51+
ClassName(modelPackage, typeRef.contextHint.toInlinedName())
5452
}
5553

5654
is TypeRef.Unknown -> {

0 commit comments

Comments
 (0)