Skip to content

Commit

Permalink
fix response and request type (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
ferozco authored Jun 20, 2018
1 parent 7aff077 commit 7ca501a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
25 changes: 25 additions & 0 deletions src/commands/generate/__tests__/serviceGeneratorTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,31 @@ describe("serviceGenerator", () => {
});

it("handles binary body and return types", async () => {
await generateService(
{
endpoints: [
{
args: [],
endpointName: "foo",
httpMethod: HttpMethod.GET,
httpPath: "/bar",
markers: [],
returns: { primitive: PrimitiveType.BINARY, type: "primitive" },
},
],
serviceName: { name: "MyService", package: "com.palantir.services" },
},
new Map(),
simpleAst,
);
const outFile = path.join(outDir, "services/myService.ts");
const contents = fs.readFileSync(outFile, "utf8");
expect(contents).toContain("foo(): Promise<any>;");
expect(contents).toContain(`requestMediaType: MediaType.APPLICATION_JSON`);
expect(contents).toContain(`responseMediaType: MediaType.APPLICATION_OCTET_STREAM`);
});

it("handle binary return and json request types", async () => {
await generateService(
{
endpoints: [
Expand Down
4 changes: 2 additions & 2 deletions src/commands/generate/serviceGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ function generateEndpointBody(
}
return `"${paramId}": ${argDefinition.argName},`;
});
const requestMediaType = mediaType(returnType);
const responseMediaType = mediaType(bodyType);
const requestMediaType = mediaType(bodyType);
const responseMediaType = mediaType(returnType);

return writer => {
writer.write(`return this.${BRIDGE}.callEndpoint<${returnTsType}>(`).inlineBlock(() => {
Expand Down

0 comments on commit 7ca501a

Please sign in to comment.