feat(core): emit warnings when unknown schemas map to JsonElement#51
feat(core): emit warnings when unknown schemas map to JsonElement#51halotukozak wants to merge 1 commit intomasterfrom
Conversation
…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>
There was a problem hiding this comment.
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.Unknownis detected. - Threads the collected warnings into the existing
ParseResult.warningsflow. - 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.
| for (schema in schemas) { | ||
| for (prop in schema.properties) { | ||
| if (containsUnknown(prop.type)) { | ||
| warn("Schema '${schema.name}', property '${prop.name}'") | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
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.
| @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", | ||
| ) | ||
| } |
There was a problem hiding this comment.
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.
Summary
TypeRef.Unknownoccurrences and emits a warning for eachJsonElementCloses #37
Test plan
type: object(no properties, no ref) emits warning mentioning schema, property, and JsonElement🤖 Generated with Claude Code