Skip to content

feat(core): emit warnings when unknown schemas map to JsonElement#51

Open
halotukozak wants to merge 1 commit intomasterfrom
feat/warn-unknown-schemas
Open

feat(core): emit warnings when unknown schemas map to JsonElement#51
halotukozak wants to merge 1 commit intomasterfrom
feat/warn-unknown-schemas

Conversation

@halotukozak
Copy link
Copy Markdown
Member

Summary

  • After parsing, scans the model for TypeRef.Unknown occurrences and emits a warning for each
  • Warning includes context: schema name + property, or endpoint + response/request body/parameter
  • Helps users identify silent type-safety losses where their spec produces JsonElement

Closes #37

Test plan

  • Test: spec with unresolvable type: object (no properties, no ref) emits warning mentioning schema, property, and JsonElement
  • Test: petstore spec produces no unknown-type warnings
  • ktlint passes
  • All existing tests pass

🤖 Generated with Claude Code

…ent (#37)

After parsing, scan the model for TypeRef.Unknown occurrences and emit
a warning for each one, including the schema/property or endpoint context.
This surfaces silent type-safety losses so users can fix their spec.

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:44
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

This PR adds parser-time warning reporting for places where OpenAPI schemas resolve to TypeRef.Unknown (and therefore generate JsonElement), helping users detect silent type-safety loss during code generation.

Changes:

  • Adds a post-parse scan of endpoints and schemas to emit warnings when TypeRef.Unknown is detected.
  • Threads the collected warnings into the existing ParseResult.warnings flow.
  • Adds tests ensuring unknown-type warnings appear for an unresolvable schema and do not appear for petstore.yaml.

Reviewed changes

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

File Description
core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecParser.kt Adds warnOnUnknownTypes + containsUnknown and runs it after model extraction to accumulate warnings.
core/src/test/kotlin/com/avsystem/justworks/core/parser/SpecParserTest.kt Adds tests validating presence/absence of unknown-type (JsonElement) warnings.

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

Comment on lines +459 to +465
for (schema in schemas) {
for (prop in schema.properties) {
if (containsUnknown(prop.type)) {
warn("Schema '${schema.name}', property '${prop.name}'")
}
}
}
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.

warnOnUnknownTypes only scans SchemaModel.properties, but TypeRef.Unknown can occur inside SchemaModel.underlyingType (e.g., type: object with additionalProperties: true -> Map(Unknown), or type: array with missing items -> Array(Unknown)). Those cases currently produce generated types containing JsonElement without any warning, and endpoints referencing such schemas won’t be flagged either since TypeRef.Reference is treated as non-unknown. Consider also checking schema.underlyingType (and warning at least with schema name) when containsUnknown(schema.underlyingType) is true.

Copilot uses AI. Check for mistakes.
Comment on lines +165 to +204
@Test
fun `parse spec with unresolvable schema emits warning`() {
val result = SpecParser.parse(
"""
openapi: 3.0.0
info:
title: Test
version: 1.0.0
paths: {}
components:
schemas:
Container:
type: object
properties:
data:
type: object
""".trimIndent().toTempFile(),
)
assertIs<ParseResult.Success>(result)
val warningMessages = result.warnings.map { it.message }
assertTrue(
warningMessages.any {
it.contains("Container") && it.contains("data") && it.contains("JsonElement")
},
"Expected warning about unresolvable type, got: $warningMessages",
)
}

@Test
fun `parse spec without unknown schemas has no unknown-type warnings`() {
val result = SpecParser.parse(loadResource("petstore.yaml"))
assertIs<ParseResult.Success>(result)
val unknownWarnings = result.warnings.filter {
it.message.contains("JsonElement")
}
assertTrue(
unknownWarnings.isEmpty(),
"Petstore should have no unknown-type warnings, got: $unknownWarnings",
)
}
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.

The added tests cover unknown types inside an object property, but they don’t cover unknowns that appear only via a schema’s underlyingType (e.g., additionalProperties: true or type: array without items). Adding a test for such a schema (and ideally for an endpoint referencing it via $ref) would prevent regressions for the missing-warning cases.

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.

Emit warnings when unknown schemas are mapped to JsonElement

2 participants