Skip to content

Commit

Permalink
Fix API sample responses and request parameters (#675)
Browse files Browse the repository at this point in the history
* Fix API sample responses and request parameters

* Display typescript examples first

* Fix array-typed properties
  • Loading branch information
louis-md authored Jan 17, 2025
1 parent ce51332 commit d8e0355
Show file tree
Hide file tree
Showing 4 changed files with 1,104 additions and 153 deletions.
21 changes: 10 additions & 11 deletions .github/scripts/generateApiReference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ const generateMethodContent = (path: string, method: string) => {
method.toUpperCase()
const filePath = `./components/ApiReference/examples/${slugify(
path
)}-${method}`
)}-${method}`.replace('-api', '')
const examplePath = filePath + '.ts'
const sampleResponsePath = filePath + '.json'
const hasExample = fs.existsSync(examplePath)
Expand Down Expand Up @@ -353,23 +353,22 @@ const generateMethodContent = (path: string, method: string) => {
<CH.Section>
<CH.Code style={{boxShadow: 'none'}}>
${
hasExample && example !== 'export {}\n'
? `
\`\`\`js TypeScript
// from ${examplePath.replace('./components/ApiReference/', '')}
\`\`\`
`
: ''
}
\`\`\`bash ${hasExample && example !== 'export {}\n' ? 'curl' : ''}
${curlify({
url: pathWithParams,
method: method.toUpperCase(),
body: requestBody
})}
\`\`\`
${
hasExample && example !== 'export {}\n'
? `
\`\`\`js TypeScript
// from ./examples/${slugify(path)}-${method}.ts
\`\`\`
`
: ''
}
</CH.Code>
</CH.Section>
<NetworkNotice />
Expand Down
7 changes: 6 additions & 1 deletion components/ApiReference/Property.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ const Property: React.FC<{ property: any; required?: boolean }> = ({
? '[]'
: property.value?.type === 'object'
? ''
: property.value?.type}
: Array.isArray(property.value?.type)
? property.value?.type.join(' | ')
: (property.value?.type ??
(Array.isArray(property.value.schema?.type)
? property.value.schema?.type.join(' | ')
: property.value.schema?.type))}
</code>
<Typography
variant='body1'
Expand Down
Loading

0 comments on commit d8e0355

Please sign in to comment.