Skip to content

feat(core): support HEAD, OPTIONS and TRACE HTTP methods#49

Open
halotukozak wants to merge 1 commit intomasterfrom
feat/head-options-trace-methods
Open

feat(core): support HEAD, OPTIONS and TRACE HTTP methods#49
halotukozak wants to merge 1 commit intomasterfrom
feat/head-options-trace-methods

Conversation

@halotukozak
Copy link
Copy Markdown
Member

Summary

  • Adds HEAD, OPTIONS, TRACE to HttpMethod enum so SpecParser no longer silently drops these operations
  • HEAD and OPTIONS use dedicated Ktor client functions (head(), options())
  • TRACE uses the generic request() builder with explicit HttpMethod("TRACE") since Ktor has no trace() shorthand

Closes #35

Test plan

  • Parser test: inline spec with HEAD/OPTIONS/TRACE endpoints parses correctly
  • Generator test: supports all HTTP methods extended to cover all 8 methods
  • All existing tests pass

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings April 9, 2026 18:36
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, TRACE to the HttpMethod model so SpecParser recognizes these operations.
  • Update client request-body generation to use Ktor head()/options() shorthands and request { 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.

Comment on lines +196 to +199
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)
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines 81 to +84
beginControlFlow("$CLIENT.%M(%L)", httpMethodFun, urlString)
if (endpoint.method == HttpMethod.TRACE) {
addStatement("method = %T(%S)", HTTP_METHOD_CLASS, "TRACE")
}
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support HEAD, OPTIONS, and TRACE HTTP methods

2 participants