-
-
Notifications
You must be signed in to change notification settings - Fork 0
Circular refs #19
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
Circular refs #19
Changes from all commits
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 | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -49,6 +49,7 @@ class JsonSchemaParser { | |||||||||||||||||||||||||
| private readonly types = new Map<string, Type>(); | ||||||||||||||||||||||||||
| private readonly enums = new Map<string, Enum>(); | ||||||||||||||||||||||||||
| private readonly unions = new Map<string, Union>(); | ||||||||||||||||||||||||||
| private readonly resolvingRefs = new Set<string>(); | ||||||||||||||||||||||||||
| private readonly violations: Violation[] = []; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| parse(): { service: Service; violations: Violation[] } { | ||||||||||||||||||||||||||
|
|
@@ -208,25 +209,48 @@ class JsonSchemaParser { | |||||||||||||||||||||||||
| loc: string | undefined, | ||||||||||||||||||||||||||
| ): { memberValue: MemberValue; inheritedDescription: StringLiteral[] } { | ||||||||||||||||||||||||||
| if (schema.ref) { | ||||||||||||||||||||||||||
| const resolved = resolve( | ||||||||||||||||||||||||||
| this.source.node, | ||||||||||||||||||||||||||
| schema.ref.value, | ||||||||||||||||||||||||||
| AST.SchemaNode, | ||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||
| if (this.resolvingRefs.has(schema.ref.value)) { | ||||||||||||||||||||||||||
| const resolved = resolve( | ||||||||||||||||||||||||||
| this.source.node, | ||||||||||||||||||||||||||
| schema.ref.value, | ||||||||||||||||||||||||||
| AST.SchemaNode, | ||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||
| const typeName = this.parseTypeName(resolved); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if (resolved) { | ||||||||||||||||||||||||||
| return this.parseType(resolved, loc); | ||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||
| const { range, sourceIndex } = decodeRange( | ||||||||||||||||||||||||||
| encodeRange(0, schema.ref.loc), | ||||||||||||||||||||||||||
| if (typeName) { | ||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||
| memberValue: { kind: 'ComplexValue', typeName, rules: [] }, | ||||||||||||||||||||||||||
| inheritedDescription: [], | ||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| const { range, sourceIndex } = decodeRange( | |
| encodeRange(0, schema.ref.loc), | |
| ); | |
| this.violations.push({ | |
| code: 'PARSER_ERROR', | |
| message: `Circular ref '${schema.ref.value}' does not resolve to a concrete type`, | |
| severity: 'error', | |
| range, | |
| sourcePath: this.sourcePaths[sourceIndex], | |
| }); |
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.
This test only asserts that
serviceis truthy, so it won't catch cases where circular refs no longer overflow but still produce an invalid/partially-parsed service (e.g., missing type declarations or parser violations). It would be stronger to also validate the returned service (and/or assert no parser violations) and check that the expected types are present (e.g.AandB).