-
Notifications
You must be signed in to change notification settings - Fork 0
feat(core): emit warnings when unknown schemas map to JsonElement #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
32326f3
a45bfc9
cf70788
f466152
bcee685
8e5ad00
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -160,6 +160,49 @@ class SpecParserTest : SpecParserTestBase() { | |
| assertEquals("Pet", itemType.schemaName) | ||
| } | ||
|
|
||
| // -- SPEC-01b: Warnings for unknown schemas -- | ||
|
|
||
| @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", | ||
| ) | ||
| } | ||
|
Comment on lines
+165
to
+204
|
||
|
|
||
| // -- SPEC-02: $ref resolution -- | ||
|
|
||
| @Test | ||
|
|
||
There was a problem hiding this comment.
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: objectwithadditionalProperties: true-> Map(Unknown), ortype: arraywith 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 checkingschema.underlyingType(and warning at least with schema name) whencontainsUnknown(schema.underlyingType)is true.