feat(core): support HEAD, OPTIONS and TRACE HTTP methods#49
feat(core): support HEAD, OPTIONS and TRACE HTTP methods#49halotukozak wants to merge 1 commit intomasterfrom
Conversation
Add HEAD, OPTIONS and TRACE to HttpMethod enum so the parser no longer silently drops operations using these methods. HEAD and OPTIONS use dedicated Ktor client functions; TRACE uses the generic request builder since Ktor has no trace() shorthand. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Extends the core OpenAPI model + code generation pipeline to fully support OpenAPI operations using HEAD, OPTIONS, and TRACE, ensuring these endpoints are parsed and emitted into the generated Ktor client rather than being silently dropped.
Changes:
- Add
HEAD,OPTIONS,TRACEto theHttpMethodmodel soSpecParserrecognizes these operations. - Update client request-body generation to use Ktor
head()/options()shorthands andrequest { method = HttpMethod("TRACE") }for TRACE. - Extend parser + generator tests to cover parsing and generation behavior for the new methods.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| core/src/main/kotlin/com/avsystem/justworks/core/model/ApiSpec.kt | Extends HttpMethod enum with HEAD/OPTIONS/TRACE. |
| core/src/main/kotlin/com/avsystem/justworks/core/gen/Names.kt | Adds KotlinPoet MemberNames for head, options, and generic request. |
| core/src/main/kotlin/com/avsystem/justworks/core/gen/client/BodyGenerator.kt | Maps new methods to appropriate Ktor calls; adds explicit TRACE method setting. |
| core/src/test/kotlin/com/avsystem/justworks/core/parser/SpecParserTest.kt | Adds regression test ensuring HEAD/OPTIONS/TRACE endpoints are parsed. |
| core/src/test/kotlin/com/avsystem/justworks/core/gen/ClientGeneratorTest.kt | Extends HTTP method coverage test to include HEAD/OPTIONS/TRACE generation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| assertEquals(3, spec.endpoints.size) | ||
| assertEquals(HttpMethod.HEAD, spec.endpoints.find { it.operationId == "healthHead" }?.method) | ||
| assertEquals(HttpMethod.OPTIONS, spec.endpoints.find { it.operationId == "healthOptions" }?.method) | ||
| assertEquals(HttpMethod.TRACE, spec.endpoints.find { it.operationId == "healthTrace" }?.method) |
There was a problem hiding this comment.
In this test, using find { ... }?.method means a missing endpoint will fail with a less-informative expected <METHOD> but was null. Consider using ?: fail("<opId> endpoint not found") (as done elsewhere in this file) to make failures easier to diagnose.
| beginControlFlow("$CLIENT.%M(%L)", httpMethodFun, urlString) | ||
| if (endpoint.method == HttpMethod.TRACE) { | ||
| addStatement("method = %T(%S)", HTTP_METHOD_CLASS, "TRACE") | ||
| } |
There was a problem hiding this comment.
TRACE method assignment is hard-coded as the string literal "TRACE" here (and also in addHttpMethodIfNeeded). To avoid duplication and keep behavior consistent if the enum/value changes, consider deriving it from endpoint.method.name or extracting a small helper for setting custom methods.
Summary
HEAD,OPTIONS,TRACEtoHttpMethodenum soSpecParserno longer silently drops these operationshead(),options())request()builder with explicitHttpMethod("TRACE")since Ktor has notrace()shorthandCloses #35
Test plan
supports all HTTP methodsextended to cover all 8 methods🤖 Generated with Claude Code