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

Feature/support generate swagge for typescript (#608) #641

Closed
wants to merge 11 commits into from
Closed

Feature/support generate swagge for typescript (#608) #641

wants to merge 11 commits into from

Conversation

yazaldefilimone
Copy link
Contributor

Checklist

@yazaldefilimone
Copy link
Contributor Author

#608

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

Thanks for sending a PR! I don't think we should add ts-node as a dependency :(, as it's too opinionated and subjected to TypeScript semver rules.
Note that the generator does not use ts-node either.

I would recommend you try a different approach:

  1. load tsconfig.json and check the outDir folder
  2. load the application from there
  3. if outDir is not built, error telling the user to build the folder
  4. adjust the typescript template to add a "swagger" script

There seems to be quite a few linting issues that are spurious. Did you enable prettier format-on-save for all files in VSCode?

util.js Outdated
requireFastifyForModule,
showHelpForCommand,
requireServerPluginFromPath
}
Copy link
Member

Choose a reason for hiding this comment

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

why this change?

util.js Outdated
fs.existsSync('/run/secrets/kubernetes.io/serviceaccount/token')
)
Copy link
Member

Choose a reason for hiding this comment

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

why this change?

@@ -94,14 +118,23 @@ function showHelpForCommand (commandName) {
console.log(fs.readFileSync(helpFilePath, 'utf8'))
exit()
} catch (e) {
exit(`unable to get help for command "${commandName}"`)
exit(`unable to get help for command '${commandName}'`)
Copy link
Member

Choose a reason for hiding this comment

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

why this change?

util.js Outdated
throw new Error(
'Async/Await plugin function should contain 2 arguments. ' +
'Refer to documentation for more information.'
)
Copy link
Member

Choose a reason for hiding this comment

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

why this change?

util.js Outdated
throw new Error(`fastify-cli cannot import plugin at '${resolvedModulePath}'. Your version of node does not support ES modules. To fix this error upgrade to Node 14 or use CommonJS syntax.`)
throw new Error(
`fastify-cli cannot import plugin at '${resolvedModulePath}'. Your version of node does not support ES modules. To fix this error upgrade to Node 14 or use CommonJS syntax.`
)
Copy link
Member

Choose a reason for hiding this comment

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

why this change?

util.js Outdated
throw new Error(`${resolvedModulePath} doesn't exist within ${process.cwd()}`)
throw new Error(
`${resolvedModulePath} doesn't exist within ${process.cwd()}`
)
Copy link
Member

Choose a reason for hiding this comment

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

why this change?

util.js Outdated
? 'module'
: commonjsPattern.test(fname)
? 'commonjs'
: packageType) || 'commonjs'
Copy link
Member

Choose a reason for hiding this comment

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

why this change?

util.js Outdated
const moduleSupport = semver.satisfies(
process.version,
'>= 14 || >= 12.17.0 < 13.0.0'
)
Copy link
Member

Choose a reason for hiding this comment

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

why this change?

@yazaldefilimone
Copy link
Contributor Author

Thanks for sending a PR! I don't think we should add ts-node as a dependency :(, as it's too opinionated and subjected to TypeScript semver rules. Note that the generator does not use ts-node either.

I would recommend you try a different approach:

  1. load tsconfig.json and check the outDir folder
  2. load the application from there
  3. if outDir is not built, error telling the user to build the folder
  4. adjust the typescript template to add a "swagger" script

There seems to be quite a few linting issues that are spurious. Did you enable prettier format-on-save for all files in VSCode?

Thanks for the feedback! I appreciate your guidance, and I've already implemented the suggested, regarding the linting issues, I've taken care of them.
I'm glad to contribute to the project's improvement, I hope I can still bring great contributions!

@mcollina
Copy link
Member

Code LGTM, a test is missing.

@yazaldefilimone
Copy link
Contributor Author

Hello, sorry for make you await, but you can tell me, how test it, i think test is about confirm if genereta ts incluede swagger script

@mcollina
Copy link
Member

mcollina commented Aug 8, 2023

Hello, sorry for make you await, but you can tell me, how test it, i think test is about confirm if genereta ts incluede swagger script

Yes.

I think you should add the required logic in https://github.com/fastify/fastify-cli/blob/master/test/generate-typescript.test.js.

I would recommend adding a test similar to

test('should finish successfully with typescript template', async (t) => {
that verifies that the file is generated for the TS app.

@yazaldefilimone
Copy link
Contributor Author

Hello, sorry for make you await, but you can tell me, how test it, i think test is about confirm if genereta ts incluede swagger script

Yes.

I think you should add the required logic in https://github.com/fastify/fastify-cli/blob/master/test/generate-typescript.test.js.

I would recommend adding a test similar to

test('should finish successfully with typescript template', async (t) => {

that verifies that the file is generated for the TS app.

Done it, thanks for explain me!

@mcollina
Copy link
Member

The test is still missing. You would want to add a new test that calls that new command that you added.

@yazaldefilimone yazaldefilimone closed this by deleting the head repository Mar 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants