feat: multipart/form-data and form-urlencoded content type generation#23
Open
halotukozak wants to merge 9 commits intomasterfrom
Open
feat: multipart/form-data and form-urlencoded content type generation#23halotukozak wants to merge 9 commits intomasterfrom
halotukozak wants to merge 9 commits intomasterfrom
Conversation
…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>
Contributor
There was a problem hiding this comment.
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
SpecParserrequestBody content-type resolution with priority multipart > form-urlencoded > JSON. - Add Ktor forms/multipart KotlinPoet name constants in
Names.kt. - Extend
ClientGeneratorto generatesubmitFormWithBinaryData/submitFormrequest 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.
core/src/main/kotlin/com/avsystem/justworks/core/gen/ClientGenerator.kt
Outdated
Show resolved
Hide resolved
core/src/test/kotlin/com/avsystem/justworks/core/gen/ClientGeneratorTest.kt
Show resolved
Hide resolved
core/src/main/kotlin/com/avsystem/justworks/core/gen/ClientGenerator.kt
Outdated
Show resolved
Hide resolved
core/src/main/kotlin/com/avsystem/justworks/core/gen/ClientGenerator.kt
Outdated
Show resolved
Hide resolved
Coverage Report
|
- 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.
Contributor
There was a problem hiding this comment.
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.
core/src/main/kotlin/com/avsystem/justworks/core/gen/ClientGenerator.kt
Outdated
Show resolved
Hide resolved
core/src/main/kotlin/com/avsystem/justworks/core/gen/ClientGenerator.kt
Outdated
Show resolved
Hide resolved
…rameter naming in ClientGenerator
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
SpecParserto resolve content types with priority: multipart > form-urlencoded > JSONNames.ktbuildMultipartBodyinClientGenerator:submitFormWithBinaryData+formData {}builder,ChannelProviderfor file params,ContentDispositionheadersbuildFormUrlEncodedBody:submitForm+parameters {}builder, individual typed params withtoString()conversionTest plan
🤖 Generated with Claude Code