Skip to content

Commit

Permalink
Merge pull request #1147 from pmcelhaney/clean-up-1139
Browse files Browse the repository at this point in the history
only a body parameter has a schema and body parameters aren't parsed here
  • Loading branch information
pmcelhaney authored Jan 1, 2025
2 parents 943e89f + 26ec969 commit 9ce28fc
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 107 deletions.
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 @@ -562,112 +562,6 @@ describe("a dispatcher", () => {
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

0 comments on commit 9ce28fc

Please sign in to comment.