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

Create example docstrings #115

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions .github/workflows/generate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ jobs:
jq '.peerDependencies."@seamapi/types" = "^" + .devDependencies."@seamapi/types"' package.json | sponge package.json
- name: Normalize package-lock.json
run: npm install
- name: Generate code
run: npm run generate
# - name: Generate code
# run: npm run generate
- name: Commit
uses: stefanzweifel/git-auto-commit-action@v5
with:
Expand Down
116 changes: 116 additions & 0 deletions src/lib/generate-docstrings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
function generateDocstringsForBlueprint(blueprint) {

Check failure on line 1 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Format code

Missing return type on function

Check failure on line 1 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Lint (Node.js v18)

Missing return type on function

Check failure on line 1 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Typecheck (Node.js v18)

Parameter 'blueprint' implicitly has an 'any' type.

Check failure on line 1 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Lint (Node.js v20)

Missing return type on function

Check failure on line 1 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Typecheck (Node.js v20)

Parameter 'blueprint' implicitly has an 'any' type.

Check failure on line 1 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Build / Package

Parameter 'blueprint' implicitly has an 'any' type.
blueprint.routes.forEach((route) => {

Check failure on line 2 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Typecheck (Node.js v18)

Parameter 'route' implicitly has an 'any' type.

Check failure on line 2 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Typecheck (Node.js v20)

Parameter 'route' implicitly has an 'any' type.

Check failure on line 2 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Build / Package

Parameter 'route' implicitly has an 'any' type.
console.log(generateRouteDocstring(route))

Check failure on line 3 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Format code

Unexpected console statement

Check failure on line 3 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Lint (Node.js v18)

Unexpected console statement

Check failure on line 3 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Lint (Node.js v20)

Unexpected console statement
route.endpoints.forEach((endpoint) => {

Check failure on line 4 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Typecheck (Node.js v18)

Parameter 'endpoint' implicitly has an 'any' type.

Check failure on line 4 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Typecheck (Node.js v20)

Parameter 'endpoint' implicitly has an 'any' type.

Check failure on line 4 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Build / Package

Parameter 'endpoint' implicitly has an 'any' type.
console.log(generateEndpointDocstring(endpoint))

Check failure on line 5 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Format code

Unexpected console statement

Check failure on line 5 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Lint (Node.js v18)

Unexpected console statement

Check failure on line 5 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Lint (Node.js v20)

Unexpected console statement
})
route.subroutes.forEach((subroute) => {

Check failure on line 7 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Typecheck (Node.js v18)

Parameter 'subroute' implicitly has an 'any' type.

Check failure on line 7 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Typecheck (Node.js v20)

Parameter 'subroute' implicitly has an 'any' type.

Check failure on line 7 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Build / Package

Parameter 'subroute' implicitly has an 'any' type.
console.log(generateRouteDocstring(subroute))

Check failure on line 8 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Format code

Unexpected console statement

Check failure on line 8 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Lint (Node.js v18)

Unexpected console statement

Check failure on line 8 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Lint (Node.js v20)

Unexpected console statement
})
})
}

function generateRouteDocstring(route) {

Check failure on line 13 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Format code

Missing return type on function

Check failure on line 13 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Lint (Node.js v18)

Missing return type on function

Check failure on line 13 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Typecheck (Node.js v18)

Parameter 'route' implicitly has an 'any' type.

Check failure on line 13 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Lint (Node.js v20)

Missing return type on function

Check failure on line 13 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Typecheck (Node.js v20)

Parameter 'route' implicitly has an 'any' type.

Check failure on line 13 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Build / Package

Parameter 'route' implicitly has an 'any' type.
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 25 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Typecheck (Node.js v18)

Parameter 'endpoint' implicitly has an 'any' type.

Check failure on line 25 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Typecheck (Node.js v20)

Parameter 'endpoint' implicitly has an 'any' type.

Check failure on line 25 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Build / Package

Parameter 'endpoint' implicitly has an 'any' type.
*/`

return docstring
}

function generateEndpointDocstring(endpoint) {

Check failure on line 31 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Format code

Missing return type on function

Check failure on line 31 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Lint (Node.js v18)

Missing return type on function

Check failure on line 31 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Typecheck (Node.js v18)

Parameter 'endpoint' implicitly has an 'any' type.

Check failure on line 31 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Lint (Node.js v20)

Missing return type on function

Check failure on line 31 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Typecheck (Node.js v20)

Parameter 'endpoint' implicitly has an 'any' type.

Check failure on line 31 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Build / Package

Parameter 'endpoint' implicitly has an 'any' type.
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) =>

Check failure on line 50 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Typecheck (Node.js v18)

Parameter 'param' implicitly has an 'any' type.

Check failure on line 50 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Typecheck (Node.js v20)

Parameter 'param' implicitly has an 'any' type.

Check failure on line 50 in src/lib/generate-docstrings.ts

View workflow job for this annotation

GitHub Actions / Build / Package

Parameter 'param' implicitly has an 'any' type.
` - ${param.name}: ${param.description}${param.isRequired === true ? ' (Required)' : ''}` +
`${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)
Loading