Skip to content

Commit

Permalink
feat: allow dereferencing references that are circular
Browse files Browse the repository at this point in the history
fixes #1276
  • Loading branch information
domoritz committed Mar 3, 2023
1 parent b692d84 commit 8d550bb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/Type/ReferenceType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export class ReferenceType extends BaseType {
return this.type;
}

public hasType(): boolean {
return this.type != null;
}

public setType(type: BaseType): void {
this.type = type;
this.setId(type.getId());
Expand Down
13 changes: 7 additions & 6 deletions src/Utils/derefType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import { BaseType } from "../Type/BaseType";
import { DefinitionType } from "../Type/DefinitionType";
import { ReferenceType } from "../Type/ReferenceType";

/**
* Dereference the type as far as possible.
*/
export function derefType(type: BaseType): BaseType {
if (
type instanceof ReferenceType ||
type instanceof DefinitionType ||
type instanceof AliasType ||
type instanceof AnnotatedType
) {
if (type instanceof DefinitionType || type instanceof AliasType || type instanceof AnnotatedType) {
return derefType(type.getType());
}
if (type instanceof ReferenceType && type.hasType()) {
return derefType(type.getType());
}

Expand Down

0 comments on commit 8d550bb

Please sign in to comment.