Skip to content

feat: multipart/form-data and form-urlencoded content type generation#23

Open
halotukozak wants to merge 9 commits intomasterfrom
feat/content-types
Open

feat: multipart/form-data and form-urlencoded content type generation#23
halotukozak wants to merge 9 commits intomasterfrom
feat/content-types

Conversation

@halotukozak
Copy link
Member

Summary

  • Extend SpecParser to resolve content types with priority: multipart > form-urlencoded > JSON
  • Add 10 Ktor form/multipart constants to Names.kt
  • Implement buildMultipartBody in ClientGenerator: submitFormWithBinaryData + formData {} builder, ChannelProvider for file params, ContentDisposition headers
  • Implement buildFormUrlEncodedBody: submitForm + parameters {} builder, individual typed params with toString() conversion
  • Verify CONT-03: 201 Created returns typed body, 204 No Content returns Unit

Test plan

  • Parser content type resolution tests
  • CONT-03 verification: 201 typed response + 204/200 priority
  • Multipart: single file, mixed text+file, multiple files, ChannelProvider params
  • Form-urlencoded: basic form, typed params, optional fields, non-POST method override
  • Manual: test against real specs with multipart/form endpoints

🤖 Generated with Claude Code

halotukozak and others added 5 commits March 23, 2026 10:19
…multipart constants

- SpecParser resolves requestBody content type with priority: multipart > form-urlencoded > json
- Add MULTIPART_FORM_DATA and FORM_URL_ENCODED constants to SpecParser
- Add Ktor Forms & Multipart MemberName/ClassName constants to Names.kt

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Test 201 Created with schema returns typed response (not Unit)
- Test mixed 200/204 responses uses 200 schema type

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- multipart endpoint generates submitFormWithBinaryData call
- ChannelProvider param for binary fields
- text fields use simple append
- binary fields include ContentDisposition header
- existing JSON requestBody still generates setBody pattern

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Branch buildFunctionBody on content type (multipart/form/json)
- buildMultipartBody generates submitFormWithBinaryData with formData builder
- Binary fields generate ChannelProvider + fileName + contentType params
- Text fields use simple append(key, value) pattern
- ContentDisposition header with filename for binary parts
- Extract buildUrlString, addHeaderParams, addQueryParams helpers
- Add HEADERS_CLASS constant to Names.kt

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- form-urlencoded endpoint generates submitForm with parameters builder
- non-string params use toString() conversion
- string params do NOT use toString()
- optional fields generate nullable params with null guard

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 23, 2026 09:34
Copy link
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

Adds multipart/form-data and application/x-www-form-urlencoded support to the OpenAPI → Ktor client generation pipeline, spanning parsing (content-type selection), name constants, client codegen, and tests.

Changes:

  • Update SpecParser requestBody content-type resolution with priority multipart > form-urlencoded > JSON.
  • Add Ktor forms/multipart KotlinPoet name constants in Names.kt.
  • Extend ClientGenerator to generate submitFormWithBinaryData / submitForm request bodies and corresponding parameters; add tests for the new behaviors.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 8 comments.

File Description
core/src/test/kotlin/com/avsystem/justworks/core/gen/ClientGeneratorTest.kt Adds tests for response code typing and basic multipart/form-urlencoded generation behavior.
core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecParser.kt Chooses requestBody media type by priority and stores the chosen contentType on RequestBody.
core/src/main/kotlin/com/avsystem/justworks/core/gen/Names.kt Introduces KotlinPoet MemberName/ClassName constants for Ktor forms/multipart APIs.
core/src/main/kotlin/com/avsystem/justworks/core/gen/ClientGenerator.kt Implements multipart and form-urlencoded request generation and parameter shaping; refactors URL/header/query helpers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link

github-actions bot commented Mar 24, 2026

Coverage Report

Overall Project 93.82% -0.55% 🍏
Files changed 95.03% 🍏

File Coverage
Names.kt 100% 🍏
ClientGenerator.kt 96.86% -2.85% 🍏
TypeRef.kt 94.96% -5.04%
SpecParser.kt 89.93% -0.13% 🍏

- Simplify handling of request body parameters by consolidating logic.
- Leverage schema's `properties` and `requiredProperties` directly, removing redundant helper methods.
- Adjust related builder functions for improved clarity and conciseness.
Copy link
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

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@halotukozak halotukozak requested a review from MattK97 March 25, 2026 15:10
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.

2 participants