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

Gen docs in js actions #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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/gen/js/genOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function renderOperation(spec: ApiSpec, op: ApiOperation, options: ClientOptions
return lines
}

function renderOperationDocs(op: ApiOperation): string[] {
export function renderOperationDocs(op: ApiOperation): string[] {
const lines = []
lines.push(`/**`)
join(lines, renderDocDescription(op))
Expand Down
7 changes: 5 additions & 2 deletions src/gen/js/genReduxActions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { writeFileSync, join, groupOperationsByGroupName, camelToUppercase, getBestResponse } from '../util'
import { DOC, SP, ST, getDocType, getTSParamType } from './support'
import { renderParamSignature, renderOperationGroup } from './genOperations'
import {renderParamSignature, renderOperationGroup, renderOperationDocs} from './genOperations'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spacing consistency

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, right. The block was formatted by the code editor on import.
Should have payed more attention before commit and submit the PR


export default function genReduxActions(spec: ApiSpec, operations: ApiOperation[], options: ClientOptions) {
const files = genReduxActionGroupFiles(spec, operations, options)
Expand Down Expand Up @@ -48,14 +48,17 @@ function renderReduxActionBlock(spec: ApiSpec, op: ApiOperation, options: Client
if (required.length) params += ', options'
else params = 'options'
}

const docsArray=renderOperationDocs(op)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gets you most of the way there, but the promise returned from redux action creators are not the same as the promise returned from the raw service call. This means there's incorrect promise typings being gen'd.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohhh yes you are right, didn't tough about that as mostly i only wanted to get completion in action's arguments.

So probably this needs more work, can't just use the same gen docs from the other methods.

docsArray.splice(docsArray.length-2, 0, `${DOC}@param {object} [info]`)
const docs=docsArray.join('\n')
const response = getBestResponse(op)
const returnType = response ? getTSParamType(response) : 'any'
return `
export const ${actionStart} = 's/${op.group}/${actionStart}'${ST}
export const ${actionComplete} = 's/${op.group}/${actionComplete}'${ST}
${isTs ? `export type ${actionComplete} = ${returnType}${ST}`: ''}

${docs}
export function ${op.id}(${paramSignature})${isTs? ': any' : ''} {
return dispatch => {
dispatch({ type: ${actionStart}, meta: { info } })${ST}
Expand Down
1 change: 1 addition & 0 deletions src/gen/js/genTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ function renderTypeDoc(name: string, def: any): string[] {
if (propLines.length) lines.push(`${DOC}`)
join(lines, propLines)
lines.push(' */')
lines.push(`const ${name}=null`)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify this one? It's not need to add code in my testing. Also setting to null causes issues for people not allowing null's in their code base.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not really needed. For what i see the Types.js file is not really used anywhere.
It does not contain any code
It's there just to give code completion.
My problem was that some CodeEditor's would not find the @typedef and won't give code completion as they assume that typedef is not defined.
But this probably a problem to be solved in code editors, not in code gen, thought it does not hurt anyone

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if it is removed by code minification, but potentially it can hurt "anyone" because you're potentially shipping more bytes through the wire.

lines.push('')
return lines
}
Expand Down