Skip to content
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

only a body parameter has a schema and body parameters aren't parsed here #1147

Merged
merged 1 commit into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/server/dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class Dispatcher {
}

for (const parameter of parameters) {
const type = parameter.schema?.type ?? parameter?.type;
const type = parameter?.type;

if (type !== undefined) {
types[parameter.in][parameter.name] =
Expand Down
106 changes: 0 additions & 106 deletions test/server/dispatcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@
req: { path: "/a" },
});

if (!("headers" in response)) {

Check warning on line 271 in test/server/dispatcher.test.ts

View workflow job for this annotation

GitHub Actions / CI Checks (ubuntu-latest)

[jest/no-conditional-in-test] Avoid having conditionals in tests
// TypeScript thinks the response object might not have a headers property. Can't figure out why.
throw new Error("response.headers not defined");
}
Expand Down Expand Up @@ -312,7 +312,7 @@
registry.add("/a", {
GET({ tools }) {
return {
body: tools.accepts("text/html") ? "acceptable" : "unacceptable",

Check warning on line 315 in test/server/dispatcher.test.ts

View workflow job for this annotation

GitHub Actions / CI Checks (ubuntu-latest)

[jest/no-conditional-in-test] Avoid having conditionals in tests
};
},
});
Expand Down Expand Up @@ -562,112 +562,6 @@
it("converts query, path, and header parameters to numbers if necessary", async () => {
const registry = new Registry();

registry.add("/a/{integerInPath}/{stringInPath}", {
// @ts-expect-error - not obvious how to make TS happy here, and it's just a unit test
GET({ headers, path, query, response }) {
if (path === undefined) {
throw new Error("path is undefined");
}

return response["200"]?.text({
integerInPath: path.integerInPath,
numberInHeader: headers.numberInHeader,
numberInQuery: query.numberInQuery,
stringInHeader: headers.stringInHeader,
stringInPath: path.stringInPath,
stringInQuery: query.stringInQuery,
});
},
});

const openApiDocument: OpenApiDocument = {
paths: {
"/a/{integerInPath}/{stringInPath}": {
get: {
parameters: [
{
in: "path",
name: "integerInPath",
schema: { type: "integer" },
},
{ in: "path", name: "stringInPath", schema: { type: "string" } },
{
in: "query",
name: "numberInQuery",
schema: { type: "number" },
},
{
in: "query",
name: "stringInQuery",
schema: { type: "string" },
},
{
in: "header",
name: "numberInHeader",
schema: { type: "number" },
},
{
in: "header",
name: "stringInHeader",
schema: { type: "string" },
},
],

responses: {
200: {
content: {
"application/json": {
schema: {
integerInPath: "number",
stringInPath: "string",
},
},
},
},
},
},
},
},
};

const dispatcher = new Dispatcher(
registry,
new ContextRegistry(),
openApiDocument,
);
const htmlResponse = await dispatcher.request({
body: "",

headers: {
numberInHeader: "5",
stringInHeader: "6",
},

method: "GET",

path: "/a/1/2",

query: {
numberInQuery: "3",
stringInQuery: "4",
},

req: { path: "/a/1/2" },
});

expect(htmlResponse.body).toStrictEqual({
integerInPath: 1,
numberInHeader: 5,
numberInQuery: 3,
stringInHeader: "6",
stringInPath: "2",
stringInQuery: "4",
});
});

it("converts query, path, and header parameters to numbers if necessary (Swagger v2)", async () => {
const registry = new Registry();

registry.add("/a/{integerInPath}/{stringInPath}", {
// @ts-expect-error - not obvious how to make TS happy here, and it's just a unit test
GET({ headers, path, query, response }) {
Expand Down
Loading