Skip to content

Commit

Permalink
impr: OpenAPI generates requestBody for every POST request
Browse files Browse the repository at this point in the history
  • Loading branch information
hajnalben committed May 29, 2019
1 parent f7e4ece commit d02deb6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/open-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export function OpenAPI({
url: path,
operation: info.document,
schema,
useRequestBody: info.method === 'POST',
});
},
get() {
Expand Down
7 changes: 4 additions & 3 deletions src/open-api/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@ export function buildPathFromOperation({
url,
schema,
operation,
useRequestBody,
}: {
url: string;
schema: GraphQLSchema;
operation: DocumentNode;
useRequestBody: boolean;
}) {
const info = getOperationInfo(operation)!;
const isQuery = info.operation.operation === 'query';

return {
operationId: info.name,
parameters: isQuery
parameters: !useRequestBody
? resolveParameters(url, info.operation.variableDefinitions)
: [],
requestBody: !isQuery
requestBody: useRequestBody
? {
content: {
'application/json': {
Expand Down
2 changes: 2 additions & 0 deletions tests/open-api/operations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ test('handle query', async () => {
url: '/api/feed',
operation,
schema,
useRequestBody: false,
});

expect(result.operationId).toEqual('feedQuery');
Expand Down Expand Up @@ -70,6 +71,7 @@ test('handle mutation', async () => {
url: '/api/add-post',
operation,
schema,
useRequestBody: true,
});

// id
Expand Down

0 comments on commit d02deb6

Please sign in to comment.