Skip to content

feat: add KDoc generation for properties, enum constants, and endpoints#32

Merged
halotukozak merged 14 commits intomasterfrom
docs/kdoc
Apr 2, 2026
Merged

feat: add KDoc generation for properties, enum constants, and endpoints#32
halotukozak merged 14 commits intomasterfrom
docs/kdoc

Conversation

@halotukozak
Copy link
Copy Markdown
Member

Summary

  • Add description field to Endpoint, valueDescriptions to EnumModel
  • Parser extracts operation.description and x-enum-descriptions
  • ModelGenerator adds KDoc to properties with descriptions and per-constant KDoc from valueDescriptions
  • ClientGenerator generates KDoc with summary/description/@param/@return for endpoints
  • Tests verify all KDoc generation scenarios

Test plan

  • Unit tests for property KDoc presence/absence
  • Unit tests for enum constant KDoc from valueDescriptions
  • Unit tests for endpoint KDoc with summary, description, params, return

🤖 Generated with Claude Code

- Add description field to Endpoint, valueDescriptions to EnumModel
- Parser extracts operation.description and x-enum-descriptions
- ModelGenerator adds KDoc to properties and enum constants
- ClientGenerator adds KDoc with summary/description/@param/@return
- Tests verify all KDoc generation scenarios

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 25, 2026 12:55
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 25, 2026

Coverage Report

Overall Project 96.03% -0.34% 🍏
Files changed 92.38% 🍏

File Coverage
ClientGenerator.kt 99.63% -0.37% 🍏
NameUtils.kt 97.92% 🍏
ApiSpec.kt 97.68% 🍏
ModelGenerator.kt 96.72% -1.35%
SpecParser.kt 94.03% -0.13% 🍏

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

Adds richer documentation support to the OpenAPI-to-Kotlin codegen pipeline by carrying more descriptive metadata through the parsed model and emitting it as KDoc in generated model/client code.

Changes:

  • Extend intermediate model: Endpoint.description and EnumModel.valueDescriptions.
  • Parse operation.description and x-enum-descriptions into the intermediate model.
  • Generate KDoc for schema properties, enum constants, and client endpoint functions; add unit tests for the new KDoc behaviors.

Reviewed changes

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

Show a summary per file
File Description
core/src/main/kotlin/com/avsystem/justworks/core/model/ApiSpec.kt Adds fields to intermediate model to carry endpoint/enum documentation.
core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecParser.kt Extracts endpoint descriptions and enum value descriptions from OpenAPI/extensions.
core/src/main/kotlin/com/avsystem/justworks/core/gen/ModelGenerator.kt Emits property and enum-constant KDoc based on descriptions/valueDescriptions.
core/src/main/kotlin/com/avsystem/justworks/core/gen/ClientGenerator.kt Emits endpoint KDoc including summary/description/params/return.
core/src/test/kotlin/com/avsystem/justworks/core/gen/ModelGeneratorTest.kt Adds tests for property and enum-constant KDoc generation.
core/src/test/kotlin/com/avsystem/justworks/core/gen/ClientGeneratorTest.kt Adds tests for endpoint KDoc generation scenarios.

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

- Update EnumModel to use structured `Value` objects instead of raw strings.
- Adjust ModelGenerator and SpecParser for new `Value` format.
- Refactor related tests to validate `Value` usage and associated descriptions.
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

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.


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

…ndpoints

- Introduced `sanitizeKdoc()` to clean input before adding to KDoc.
- Updated ModelGenerator and ClientGenerator to apply sanitization.
- Removed unused `simpleTypeName()` helper from Client
- Escapes comment terminators (`*/`, `/*`) to prevent broken Kotlin source generation.
- Ensure key-value consistency when mapping `x-enum-descriptions` extensions.
- Replace invalid map entries with `emptyMap` for
@halotukozak halotukozak self-assigned this Mar 25, 2026
@halotukozak halotukozak changed the base branch from master to feat/content-types March 30, 2026 15:19
halotukozak and others added 2 commits March 30, 2026 17:32
Port KDoc generation to refactored client/ClientGenerator.kt,
preserve x-enum-descriptions support and EnumModel.Value in SpecParser,
fix test compilation after merge.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
# Conflicts:
#	core/src/main/kotlin/com/avsystem/justworks/core/gen/client/ClientGenerator.kt
#	core/src/main/kotlin/com/avsystem/justworks/core/gen/model/ModelGenerator.kt
#	core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecParser.kt
Base automatically changed from feat/content-types to master March 31, 2026 10:31
# Conflicts:
#	core/src/main/kotlin/com/avsystem/justworks/core/gen/model/ModelGenerator.kt
Copy link
Copy Markdown
Collaborator

@janwawszczak janwawszczak left a comment

Choose a reason for hiding this comment

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

The new code correctly uses sanitizeKdoc() everywhere, but there are 3 pre-existing places in ModelGenerator that also emit descriptions into KDoc without sanitization (generateSealedInterface:248, generateDataClass:428, generateTypeAlias:647). Since this PR is already adding sanitization across the board, could you include these 3 lines as well for consistency?

Without this, if an OpenAPI schema description contains */, the generated Kotlin file will have a broken KDoc comment — the / will prematurely close the comment block, causing everything after it to be treated as code, resulting in a compilation error in the generated sources. Similarly, a stray / in a description could open an unexpected comment block that swallows the following generated code.

…r tests

- Add `sanitizeKdoc` to handle special characters in schema descriptions.
- Replace `${'$'}ref` with `$ref` in test specifications for better consistency.
…dability

- Add `description = null` field in multiple test cases for improved APISpec coverage.
- Refactor tests to use `assert` for clearer error messaging.
- Fix minor formatting issues in `PropertyModel` and test comments.
- Replace `filterIsInstance<com.squareup.kotlinpoet.TypeSpec>` with `filterIsInstance<TypeSpec>` for consistency.
Copy link
Copy Markdown
Collaborator

@janwawszczak janwawszczak left a comment

Choose a reason for hiding this comment

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

Good job! Thx for changes :)

@halotukozak halotukozak merged commit 34d4621 into master Apr 2, 2026
1 check passed
@halotukozak halotukozak deleted the docs/kdoc branch April 2, 2026 14:21
@halotukozak halotukozak added this to the 0.0.2 milestone Apr 2, 2026
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.

3 participants