-
Notifications
You must be signed in to change notification settings - Fork 1
OpenAPI data model, parser, and validator #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
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 98bc12d
feat: add OpenAPI data model, parser, and validator
halotukozak ddfe68f
Merge branch 'feat/gradle-plugin' into feat/model-parser
halotukozak 9e75f7a
Merge branch 'feat/ktlint' into feat/model-parser
halotukozak fb05a75
chore: update Gradle properties and adjust ktlint rules
halotukozak 2b64c3b
feat: enhance OpenAPI parser with Arrow library and refactor validation
halotukozak 1c5dce3
refactor: improve SpecParser readability and streamline schema handling
halotukozak e8cb61f
refactor: replace `ParseResult` with functional error handling using …
halotukozak 106f69a
chore: update ktlint configuration and clean up SpecParser
halotukozak 9929001
fix: align tests with Arrow-based ParseResult API and fix null-safe a…
halotukozak 2ba35ba
refactor: improve null-safe schema handling and consolidate property …
halotukozak 67b18dd
refactor: reorder SpecParser definitions by responsibility
halotukozak 27d5d52
refactor: remove redundant comments and improve SpecParser formatting
halotukozak 821834f
refactor: simplify test cases by using direct ParseResult references
halotukozak 9282e80
refactor(01-01): review and clean up parser and model code
halotukozak b79f705
refactor(01-01): verify and clean up parser test conventions
halotukozak 863dae8
refactor: remove unused `isEnum` field and simplify schema handling i…
halotukozak 0a9b36c
refactor: improve property extraction and type resolution in SpecParser
halotukozak 5d80666
refactor: add HttpMethod parsing and enhance SpecParser for endpoint …
halotukozak 3b6774e
refactor: simplify test helpers and remove redundant code
halotukozak 4b3063e
refactor: fix enum and schema model extraction order in SpecParser
halotukozak dfc9dda
test: remove redundant blank line in SpecParserPolymorphicTest
halotukozak 7a2bd0d
fix: add missing SpecParserTestBase extracted in previous refactor
halotukozak 6cfb44d
refactor: replace asSequence with toMap for schema processing in Spec…
halotukozak d3a101c
Refactor `SpecParserTest` to reuse a single `petstore` object initial…
halotukozak b7a9790
Refactor `SpecParser` to simplify schema folding logic and improve ty…
halotukozak 0933c73
fmt
halotukozak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
core/src/main/kotlin/com/avsystem/justworks/core/model/ApiSpec.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
|
|
||
| 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
21
core/src/main/kotlin/com/avsystem/justworks/core/model/TypeRef.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.