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

fix: Return proper void response in JS code samples #94

Merged
merged 3 commits into from
Sep 26, 2024
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/lib/code-sample/javascript.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { camelCase } from 'change-case'

import { createJsonResponse } from './create-json-response.js'
import { createJsonResponse } from './json.js'
import type { CodeSampleDefinition, Context } from './schema.js'

export const createJavascriptRequest = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ export const createJsonResponse = (
context: Context,
): string => {
const { endpoint } = context
if (endpoint.response.responseType === 'void') return 'void'
if (endpoint.response.responseType === 'void') {
return JSON.stringify({})
}
const { responseKey } = endpoint.response
const data = response?.body?.[responseKey]
if (data == null) {
Expand Down
7 changes: 5 additions & 2 deletions src/lib/code-sample/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,16 @@ export const createCodeSample = async (
codeSampleDefinition: CodeSampleDefinition,
context: Context,
): Promise<CodeSample> => {
const isVoidResponse = context.endpoint.response.responseType === 'void'
const code: Code = {
javascript: {
title: 'JavaScript',
request: createJavascriptRequest(codeSampleDefinition, context),
response: createJavascriptResponse(codeSampleDefinition, context),
response: isVoidResponse
? '// void'
: createJavascriptResponse(codeSampleDefinition, context),
request_syntax: 'javascript',
response_syntax: 'json',
response_syntax: isVoidResponse ? 'javascript' : 'json',
},
python: {
title: 'Python',
Expand Down
2 changes: 1 addition & 1 deletion src/lib/code-sample/seam-cli.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { kebabCase } from 'change-case'

import { createJsonResponse } from './create-json-response.js'
import { createJsonResponse } from './json.js'
import type { CodeSampleDefinition, Context } from './schema.js'

export const createSeamCliRequest = (
Expand Down
42 changes: 21 additions & 21 deletions test/snapshots/blueprint.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -1481,8 +1481,8 @@ Generated by [AVA](https://avajs.dev).
javascript: {
request: 'await seam.deprecated.undocumented.endpoint()',
request_syntax: 'javascript',
response: 'void',
response_syntax: 'json',
response: '// void',
response_syntax: 'javascript',
title: 'JavaScript',
},
php: {
Expand Down Expand Up @@ -1510,7 +1510,7 @@ Generated by [AVA](https://avajs.dev).
seam_cli: {
request: 'seam deprecated undocumented endpoint ',
request_syntax: 'bash',
response: 'void',
response: '{}',
response_syntax: 'json',
title: 'Seam CLI',
},
Expand Down Expand Up @@ -1553,8 +1553,8 @@ Generated by [AVA](https://avajs.dev).
javascript: {
request: 'await seam.deprecated.undocumented.endpoint()',
request_syntax: 'javascript',
response: 'void',
response_syntax: 'json',
response: '// void',
response_syntax: 'javascript',
title: 'JavaScript',
},
php: {
Expand Down Expand Up @@ -1582,7 +1582,7 @@ Generated by [AVA](https://avajs.dev).
seam_cli: {
request: 'seam deprecated undocumented endpoint ',
request_syntax: 'bash',
response: 'void',
response: '{}',
response_syntax: 'json',
title: 'Seam CLI',
},
Expand Down Expand Up @@ -1625,8 +1625,8 @@ Generated by [AVA](https://avajs.dev).
javascript: {
request: 'await seam.deprecated.undocumented.endpoint()',
request_syntax: 'javascript',
response: 'void',
response_syntax: 'json',
response: '// void',
response_syntax: 'javascript',
title: 'JavaScript',
},
php: {
Expand Down Expand Up @@ -1654,7 +1654,7 @@ Generated by [AVA](https://avajs.dev).
seam_cli: {
request: 'seam deprecated undocumented endpoint ',
request_syntax: 'bash',
response: 'void',
response: '{}',
response_syntax: 'json',
title: 'Seam CLI',
},
Expand Down Expand Up @@ -3334,9 +3334,9 @@ Generated by [AVA](https://avajs.dev).
request: `// javascript␊
await seam.deprecated.undocumented.endpoint()`,
request_syntax: 'javascript',
response: `// json
void`,
response_syntax: 'json',
response: `// javascript
// void`,
response_syntax: 'javascript',
title: 'JavaScript',
},
php: {
Expand Down Expand Up @@ -3372,7 +3372,7 @@ Generated by [AVA](https://avajs.dev).
seam deprecated undocumented endpoint `,
request_syntax: 'bash',
response: `// json␊
void`,
{}`,
response_syntax: 'json',
title: 'Seam CLI',
},
Expand Down Expand Up @@ -3416,9 +3416,9 @@ Generated by [AVA](https://avajs.dev).
request: `// javascript␊
await seam.deprecated.undocumented.endpoint()`,
request_syntax: 'javascript',
response: `// json
void`,
response_syntax: 'json',
response: `// javascript
// void`,
response_syntax: 'javascript',
title: 'JavaScript',
},
php: {
Expand Down Expand Up @@ -3454,7 +3454,7 @@ Generated by [AVA](https://avajs.dev).
seam deprecated undocumented endpoint `,
request_syntax: 'bash',
response: `// json␊
void`,
{}`,
response_syntax: 'json',
title: 'Seam CLI',
},
Expand Down Expand Up @@ -3498,9 +3498,9 @@ Generated by [AVA](https://avajs.dev).
request: `// javascript␊
await seam.deprecated.undocumented.endpoint()`,
request_syntax: 'javascript',
response: `// json
void`,
response_syntax: 'json',
response: `// javascript
// void`,
response_syntax: 'javascript',
title: 'JavaScript',
},
php: {
Expand Down Expand Up @@ -3536,7 +3536,7 @@ Generated by [AVA](https://avajs.dev).
seam deprecated undocumented endpoint `,
request_syntax: 'bash',
response: `// json␊
void`,
{}`,
response_syntax: 'json',
title: 'Seam CLI',
},
Expand Down
Binary file modified test/snapshots/blueprint.test.ts.snap
Binary file not shown.