Skip to content

Commit

Permalink
Merge pull request #892 from pmcelhaney/fix-recursive-types
Browse files Browse the repository at this point in the history
fix recursive types (#890)
  • Loading branch information
pmcelhaney authored May 6, 2024
2 parents 84a421d + b731a44 commit 19c756f
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 148 deletions.
5 changes: 5 additions & 0 deletions .changeset/little-wolves-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"counterfact": patch
---

fix invalid TypeScript generated for recursive types
5 changes: 4 additions & 1 deletion openapi-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ paths:
content:
application/json:
schema:
type: string
$ref: "#/components/schemas/Recursive"
"400":
$ref: "#/components/responses/BadRequest"

Expand All @@ -94,6 +94,9 @@ components:
description: A detailed description of the error
required:
- message
Recursive:
oneOf:
- { $ref: "#/components/schemas/Recursive" }

securitySchemes:
basicAuth:
Expand Down
6 changes: 2 additions & 4 deletions src/typescript-generator/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class Script {

firstUniqueName(coder) {
for (const name of coder.names()) {
if (!this.imports.has(name) && !this.exports.has(name)) {
if (!this.imports.has(name)) {
return name;
}
}
Expand All @@ -36,9 +36,7 @@ export class Script {
}

export(coder, isType = false, isDefault = false) {
const cacheKey = isDefault
? "default"
: `${coder.id}@${nodePath}:${isType}`;
const cacheKey = isDefault ? "default" : `${coder.id}:${isType}`;

if (this.cache.has(cacheKey)) {
return this.cache.get(cacheKey);
Expand Down
Loading

0 comments on commit 19c756f

Please sign in to comment.