Skip to content

Commit

Permalink
Merge branch 'main' into 1083-url-encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
pmcelhaney authored Jan 18, 2025
2 parents 3b4c9ea + 3b0bab4 commit 74b85ca
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/cool-emus-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"counterfact": patch
---

follow $refs in parameters (fixes #1105)
18 changes: 10 additions & 8 deletions src/typescript-generator/parameters-type-coder.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@ export class ParametersTypeCoder extends TypeCoder {

writeCode(script) {
const typeDefinitions = (this.requirement?.data ?? [])
.filter((parameter) => parameter.in === this.placement)
.map((parameter, index) => {
const requirement = this.requirement.get(String(index));

const { name, required } = parameter;
.map((_, index) => {
return this.requirement.get(index);
})
.filter((parameter) => parameter.get("in").data === this.placement)
.map((parameter) => {
const name = parameter.get("name")?.data;
const required = parameter.get("required")?.data;

const optionalFlag = required ? "" : "?";

const schema = requirement.has("schema")
? requirement.get("schema")
: requirement;
const schema = parameter.has("schema")
? parameter.get("schema")
: parameter;

return `"${name}"${optionalFlag}: ${new SchemaTypeCoder(schema).write(
script,
Expand Down
6 changes: 3 additions & 3 deletions test/typescript-generator/__snapshots__/generate.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ export type HTTP_GET = (
export type HTTP_POST = (
$: OmitValueWhenNever<{
query: { name?: number; status?: string };
query: { name?: string; status?: string };
path: { petId: number };
headers: never;
body: never;
Expand All @@ -398,7 +398,7 @@ export type HTTP_POST = (
export type HTTP_DELETE = (
$: OmitValueWhenNever<{
query: never;
path: { petId: string };
path: { petId: number };
headers: { api_key?: string };
body: never;
context: Context;
Expand Down Expand Up @@ -446,7 +446,7 @@ import type { ApiResponse } from "../../../components/schemas/ApiResponse.js";
export type HTTP_POST = (
$: OmitValueWhenNever<{
query: { additionalMetadata?: number };
query: { additionalMetadata?: string };
path: { petId: number };
headers: never;
body: never;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ exports[`a ParametersTypeCoder generates types for parameters (OAS2): path 1`] =
`;

exports[`a ParametersTypeCoder generates types for parameters (OAS2): query 1`] = `
"type TestType = { name?: string; age?: string };
"type TestType = { name?: string; age?: number };
"
`;

Expand All @@ -31,6 +31,6 @@ exports[`a ParametersTypeCoder generates types for parameters: path 1`] = `
`;

exports[`a ParametersTypeCoder generates types for parameters: query 1`] = `
"type TestType = { name?: string; age?: string };
"type TestType = { name?: string; age?: number };
"
`;

0 comments on commit 74b85ca

Please sign in to comment.