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
feat(cli): Add the new frontend command #1043
Conversation
75a88b7
to
0e11b55
Compare
Signed-off-by: Stefano Magni <nori.ste.magni@gmail.com>
Signed-off-by: Stefano Magni <nori.ste.magni@gmail.com>
Signed-off-by: Stefano Magni <nori.ste.magni@gmail.com>
Signed-off-by: Stefano Magni <nori.ste.magni@gmail.com>
0dbb424
to
884931c
Compare
Signed-off-by: Stefano Magni <nori.ste.magni@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job! Tnx! Some comments, nothing blocking. But I would try to have the platformatic version of the frontend template updated "automatically" (with the script see the comment) If too complex, just update to latest platformatic, we will fix in another PR.
const { method, path } = operation | ||
|
||
// Only dealing with success responses | ||
const successResponses = Object.entries(responses).filter(([s]) => s.startsWith('2')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why startsWith
'2'
? Maybe this worth a comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree! Let me give some context:
- The
hen-openapi.mjs
module is a fork of the already existing client-cli one. The above lines come from thereplatformatic/packages/client-cli/lib/gen-openapi.mjs
Lines 117 to 124 in f2bdb5c
// Only dealing with success responses const successResponses = Object.entries(responses).filter(([s]) => s.startsWith('2')) // The following block it's impossible to happen with well-formed // OpenAPI. /* c8 ignore next 3 */ if (successResponses.length === 0) { throw new Error(`Could not find a 200 level response for ${operationId}`) } - The mentioned code has been added here by @gunjam client-cli: set response types to undefined for 204 responses, support 201 and empty objects #958
- In general, I preferred to keep the "fork" as much aligned as possible to the original implementation
In the code, I could link to the PR or comment with something like "Non-2xx responses lack the response body and would make the rest of the code generation throw", WDYT?
@@ -0,0 +1,66 @@ | |||
// import type { PlaywrightTestConfig } from '@playwright/test'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should remove this comment? Or it's here because is a template? (like the dotenv
one below, I guess)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, I removed either of them from the various PlayWright config
"fastify": "^4.17.0" | ||
}, | ||
"dependencies": { | ||
"platformatic": "^0.22.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we are at 0.26.0 now. Maybe we should update this like we do for all other package.json
? Currently we are using this script, but this updates only the package.json of the packages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"platformatic": "^0.22.0" | |
"platformatic": "workspace:*" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, thank you! I committed the change suggested by @mcollina!
One more thing than can be improved @NoriSte (maybe in another PR).
We should check explicitly that the mandatory parameters are present and validate them. In this case should say something like |
Signed-off-by: Stefano Magni <nori.ste.magni@gmail.com>
Signed-off-by: Stefano Magni <nori.ste.magni@gmail.com>
I totally agree, thanks for pointing it out! I'll work on it as soon as I can! |
Signed-off-by: Stefano Magni <nori.ste.magni@gmail.com>
@marcopiraccini look at the latest commit with the solution I implemented. Tha approach now is:
I show the main
Then, if the users passed either the parameters but the URL is not valid I show the
Then , the WDYT? |
This PR Introduces the new
platformatic frontend
CLI command that generated the frontend code to consume the Rest APIs.New package
A dedicated package, called
frontend-template
is now available in the monorepo and includesTests
The new command is tested through a single E2E test that checks that the Viter application works after the frontend code have been generated.
platformatic frontend
commandWhere:
url
is the URL of the Platformatic DB applanguage
can bets
orjs
The command generates two files:
api.d.ts
that includes all the API typesapi.ts
orapi.js
that includes all the TS (or vanilla JS) functions that consume the REST APIsErrors
The new command reports the errors to the users for all the expected edge cases.
Docs
This PR includes the new "Generate Front-end Code to Consume Platformatic REST API" guide. Please note that the new guide should be added to the Docusaurus' sidebar here
https://github.com/platformatic/oss/blob/3fc45b08e30eff5cc0d388888bd0953186367f11/sidebars.js#L70
in order to show up in the sidebar when the docs are published.
I already opened a dedicated PR here for it.