-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
|
||
function generateDocstringsForBlueprint(blueprint) { | ||
Check failure on line 2 in src/lib/generate-docstrings.ts GitHub Actions / Typecheck (Node.js v18)
Check failure on line 2 in src/lib/generate-docstrings.ts GitHub Actions / Typecheck (Node.js v20)
|
||
blueprint.routes.forEach(route => { | ||
Check failure on line 3 in src/lib/generate-docstrings.ts GitHub Actions / Format code
Check failure on line 3 in src/lib/generate-docstrings.ts GitHub Actions / Typecheck (Node.js v18)
Check failure on line 3 in src/lib/generate-docstrings.ts GitHub Actions / Typecheck (Node.js v20)
|
||
console.log(generateRouteDocstring(route)) | ||
route.endpoints.forEach(endpoint => { | ||
Check failure on line 5 in src/lib/generate-docstrings.ts GitHub Actions / Format code
Check failure on line 5 in src/lib/generate-docstrings.ts GitHub Actions / Typecheck (Node.js v18)
Check failure on line 5 in src/lib/generate-docstrings.ts GitHub Actions / Typecheck (Node.js v20)
|
||
console.log(generateEndpointDocstring(endpoint)) | ||
}) | ||
route.subroutes.forEach(subroute => { | ||
Check failure on line 8 in src/lib/generate-docstrings.ts GitHub Actions / Format code
Check failure on line 8 in src/lib/generate-docstrings.ts GitHub Actions / Typecheck (Node.js v18)
Check failure on line 8 in src/lib/generate-docstrings.ts GitHub Actions / Typecheck (Node.js v20)
|
||
console.log(generateRouteDocstring(subroute)) | ||
}) | ||
}) | ||
} | ||
|
||
function generateRouteDocstring(route) { | ||
Check failure on line 14 in src/lib/generate-docstrings.ts GitHub Actions / Typecheck (Node.js v18)
Check failure on line 14 in src/lib/generate-docstrings.ts GitHub Actions / Typecheck (Node.js v20)
|
||
const docstring = ` | ||
/** | ||
* ${route.name} | ||
* | ||
* Path: ${route.path} | ||
* | ||
* Description: ${route.description ?? "No description provided."} | ||
* | ||
* Namespace: ${route.namespace !== '' ? route.namespace.name : "No namespace"} | ||
* | ||
* Endpoints: | ||
* ${route.endpoints.map(endpoint => ` - ${endpoint.name}: ${endpoint.description}`).join('\n')} | ||
Check failure on line 26 in src/lib/generate-docstrings.ts GitHub Actions / Typecheck (Node.js v18)
Check failure on line 26 in src/lib/generate-docstrings.ts GitHub Actions / Typecheck (Node.js v20)
|
||
*/` | ||
|
||
return docstring | ||
} | ||
|
||
function generateEndpointDocstring(endpoint) { | ||
Check failure on line 32 in src/lib/generate-docstrings.ts GitHub Actions / Typecheck (Node.js v18)
Check failure on line 32 in src/lib/generate-docstrings.ts GitHub Actions / Typecheck (Node.js v20)
|
||
const deprecationNotice = endpoint.isDeprecated === true ? ` (Deprecated: ${endpoint.deprecationMessage})` : '' | ||
|
||
const docstring = ` | ||
/** | ||
* ${endpoint.name}${deprecationNotice} | ||
* | ||
* Path: ${endpoint.path} | ||
* | ||
* Methods: ${endpoint.methods.join(', ')} | ||
* | ||
* Description: ${endpoint.description ?? "No description provided."} | ||
* | ||
* Parameters: | ||
* ${endpoint.parameters.map(param => ` - ${param.name}: ${param.description}${param.isRequired === true ? ' (Required)' : ''}` + | ||
Check failure on line 46 in src/lib/generate-docstrings.ts GitHub Actions / Typecheck (Node.js v18)
Check failure on line 46 in src/lib/generate-docstrings.ts GitHub Actions / Typecheck (Node.js v20)
|
||
`${param.isDeprecated === true ? ` (Deprecated: ${param.deprecationMessage})` : ''}`).join('\n')} | ||
* | ||
* Request: ${endpoint.request.semanticMethod !== '' ? `Semantic Method: ${endpoint.request.semanticMethod}` : "Not specified"} | ||
* | ||
* Response: ${endpoint.response.description ?? "No description provided."} | ||
*/` | ||
|
||
return docstring | ||
} | ||
|
||
const exampleRoute = { | ||
name: "Get Devices", | ||
path: "/devices", | ||
description: "Retrieves a list of devices.", | ||
namespace: null, | ||
endpoints: [ | ||
{ | ||
name: "List Devices", | ||
path: "/devices/list", | ||
methods: ["GET"], | ||
semanticMethod: "GET", | ||
preferredMethod: "GET", | ||
description: "Lists all devices.", | ||
isDeprecated: false, | ||
deprecationMessage: "", | ||
parameters: [ | ||
{ name: "limit", isRequired: false, isDeprecated: false, deprecationMessage: "", description: "What are endpoint parameters? How are they differnet from request params?" } | ||
], | ||
request: { | ||
methods: ["GET"], | ||
semanticMethod: "GET", | ||
preferredMethod: "GET", | ||
parameters: [ | ||
{ name: "limit", isRequired: false, isDeprecated: false, deprecationMessage: "", description: "Limit the number of devices returned." } | ||
] | ||
}, | ||
response: { | ||
description: "A list of devices." | ||
} | ||
} | ||
], | ||
subroutes: [] | ||
} | ||
|
||
const blueprintExample = { | ||
name: "Device API", | ||
routes: [exampleRoute] | ||
} | ||
|
||
generateDocstringsForBlueprint(blueprintExample) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.