Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7cab983
feat: add Gradle build configuration with core module and CI
halotukozak Mar 11, 2026
98bc12d
feat: add OpenAPI data model, parser, and validator
halotukozak Mar 11, 2026
ddfe68f
Merge branch 'feat/gradle-plugin' into feat/model-parser
halotukozak Mar 11, 2026
9e75f7a
Merge branch 'feat/ktlint' into feat/model-parser
halotukozak Mar 11, 2026
fb05a75
chore: update Gradle properties and adjust ktlint rules
halotukozak Mar 11, 2026
2b64c3b
feat: enhance OpenAPI parser with Arrow library and refactor validation
halotukozak Mar 11, 2026
1c5dce3
refactor: improve SpecParser readability and streamline schema handling
halotukozak Mar 11, 2026
e8cb61f
refactor: replace `ParseResult` with functional error handling using …
halotukozak Mar 11, 2026
106f69a
chore: update ktlint configuration and clean up SpecParser
halotukozak Mar 11, 2026
9929001
fix: align tests with Arrow-based ParseResult API and fix null-safe a…
halotukozak Mar 11, 2026
2ba35ba
refactor: improve null-safe schema handling and consolidate property …
halotukozak Mar 11, 2026
67b18dd
refactor: reorder SpecParser definitions by responsibility
halotukozak Mar 11, 2026
27d5d52
refactor: remove redundant comments and improve SpecParser formatting
halotukozak Mar 11, 2026
821834f
refactor: simplify test cases by using direct ParseResult references
halotukozak Mar 11, 2026
9282e80
refactor(01-01): review and clean up parser and model code
halotukozak Mar 12, 2026
b79f705
refactor(01-01): verify and clean up parser test conventions
halotukozak Mar 12, 2026
863dae8
refactor: remove unused `isEnum` field and simplify schema handling i…
halotukozak Mar 12, 2026
0a9b36c
refactor: improve property extraction and type resolution in SpecParser
halotukozak Mar 12, 2026
5d80666
refactor: add HttpMethod parsing and enhance SpecParser for endpoint …
halotukozak Mar 13, 2026
3b6774e
refactor: simplify test helpers and remove redundant code
halotukozak Mar 13, 2026
4b3063e
refactor: fix enum and schema model extraction order in SpecParser
halotukozak Mar 13, 2026
dfc9dda
test: remove redundant blank line in SpecParserPolymorphicTest
halotukozak Mar 13, 2026
7a2bd0d
fix: add missing SpecParserTestBase extracted in previous refactor
halotukozak Mar 13, 2026
6cfb44d
refactor: replace asSequence with toMap for schema processing in Spec…
halotukozak Mar 13, 2026
d3a101c
Refactor `SpecParserTest` to reuse a single `petstore` object initial…
halotukozak Mar 16, 2026
b7a9790
Refactor `SpecParser` to simplify schema folding logic and improve ty…
halotukozak Mar 16, 2026
0933c73
fmt
halotukozak Mar 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm")
`maven-publish`
Expand All @@ -8,10 +10,17 @@ kotlin {
jvmToolchain(21)
}

// todo: remove when https://github.com/JLLeitschuh/ktlint-gradle/issues/912 resolved
ktlint {
version.set("1.8.0")
}


dependencies {
implementation("io.swagger.parser.v3:swagger-parser:2.1.39")
implementation("com.squareup:kotlinpoet:2.2.0")
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.7.1")
implementation("io.arrow-kt:arrow-core:2.2.1.1")
testImplementation(kotlin("test"))
}

Expand All @@ -26,3 +35,7 @@ publishing {
}
}
}
val compileKotlin: KotlinCompile by tasks
compileKotlin.compilerOptions {
freeCompilerArgs.add("-Xcontext-parameters")
}
107 changes: 107 additions & 0 deletions core/src/main/kotlin/com/avsystem/justworks/core/model/ApiSpec.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package com.avsystem.justworks.core.model

/**
* Intermediate model representing a fully parsed OpenAPI specification.
*
* Produced by [com.avsystem.justworks.core.parser.SpecParser] and consumed by the
* code generators. Bridges the raw Swagger Parser OAS model and the generated
* Kotlin client/model source files.
*/
data class ApiSpec(
val title: String,
val version: String,
val endpoints: List<Endpoint>,
val schemas: List<SchemaModel>,
val enums: List<EnumModel>,
)

data class Endpoint(
val path: String,
val method: HttpMethod,
val operationId: String,
val summary: String?,
val tags: List<String>,
val parameters: List<Parameter>,
val requestBody: RequestBody?,
val responses: Map<String, Response>,
)

enum class HttpMethod {
GET,
POST,
PUT,
DELETE,
PATCH;

companion object {
fun parse(name: String): HttpMethod? = entries.find { it.name.equals(name, true) }
}
}

data class Parameter(
val name: String,
val location: ParameterLocation,
val required: Boolean,
val schema: TypeRef,
val description: String?,
)

// todo: add cookie
enum class ParameterLocation {
PATH,
QUERY,
HEADER;
Comment thread
halotukozak marked this conversation as resolved.

companion object {
fun parse(name: String): ParameterLocation? = entries.find { it.name.equals(name, true) }
}
}

data class RequestBody(
val required: Boolean,
val contentType: String,
val schema: TypeRef,
)

data class Response(
val statusCode: String,
val description: String?,
val schema: TypeRef?,
)

data class SchemaModel(
val name: String,
val description: String?,
val properties: List<PropertyModel>,
val requiredProperties: Set<String>,
val allOf: List<TypeRef>?,
val oneOf: List<TypeRef>?,
val anyOf: List<TypeRef>?,
val discriminator: Discriminator?,
)

data class PropertyModel(
val name: String,
val type: TypeRef,
val description: String?,
val nullable: Boolean,
val defaultValue: Any? = null,
)

data class EnumModel(
val name: String,
val description: String?,
val type: EnumBackingType,
val values: List<String>,
)

enum class EnumBackingType {
STRING,
INTEGER;

companion object {
fun parse(name: String): EnumBackingType? = entries.find { it.name.equals(name, true) }
}
}

data class Discriminator(val propertyName: String, val mapping: Map<String, String>)
21 changes: 21 additions & 0 deletions core/src/main/kotlin/com/avsystem/justworks/core/model/TypeRef.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.avsystem.justworks.core.model

sealed interface TypeRef {
data class Primitive(val type: PrimitiveType) : TypeRef

data class Array(val items: TypeRef) : TypeRef

data class Reference(val schemaName: String) : TypeRef

data class Map(val valueType: TypeRef) : TypeRef

data class Inline(
val properties: List<PropertyModel>,
val requiredProperties: Set<String>,
val contextHint: String, // "request"|"response"|property name for context-aware naming
) : TypeRef

data object Unknown : TypeRef
}

enum class PrimitiveType { STRING, INT, LONG, DOUBLE, FLOAT, BOOLEAN, BYTE_ARRAY, DATE_TIME, DATE }
Loading
Loading