Skip to content

Commit

Permalink
Fix: no duplicates in Path type generated by Integration (#2251)
Browse files Browse the repository at this point in the history
Found this one during my work on #2226
  • Loading branch information
RobinTail authored Dec 11, 2024
1 parent 6e23748 commit 098bcb8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

### v21.6.1

- `node-mocks-http` version is `^1.16.2`.
- `node-mocks-http` version is `^1.16.2`;
- Fixed possible duplicates in the `Path` type generated by `Integration`:
- Duplicates used to be possible when using `DependsOnMethod` instance within specified `routing`.

### v21.6.0

Expand Down
8 changes: 5 additions & 3 deletions src/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class Integration {
ReturnType<typeof quoteProp>, // method+path
Record<IOKind, string> & { isJson: boolean; tags: ReadonlyArray<string> }
>();
protected paths: string[] = [];
protected paths = new Set<string>();
protected aliases = new Map<z.ZodTypeAny, ts.TypeAliasDeclaration>();
protected ids = {
pathType: f.createIdentifier("Path"),
Expand Down Expand Up @@ -209,7 +209,7 @@ export class Integration {
negativeResponse,
genericResponse,
);
this.paths.push(path);
this.paths.add(path);
const isJson = endpoint
.getResponses("positive")
.some(({ mimeTypes }) => mimeTypes?.includes(contentTypes.json));
Expand All @@ -226,7 +226,9 @@ export class Integration {
this.program.unshift(...this.aliases.values());

// export type Path = "/v1/user/retrieve" | ___;
this.program.push(makePublicLiteralType(this.ids.pathType, this.paths));
this.program.push(
makePublicLiteralType(this.ids.pathType, Array.from(this.paths)),
);

// export type Method = "get" | "post" | "put" | "delete" | "patch";
this.program.push(makePublicLiteralType(this.ids.methodType, methods));
Expand Down

0 comments on commit 098bcb8

Please sign in to comment.