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

Generate OpenAPI spec during compile #1279

Draft
wants to merge 46 commits into
base: master
Choose a base branch
from
Draft

Conversation

adamw
Copy link
Member

@adamw adamw commented Aug 6, 2024

No description provided.

@adamw adamw marked this pull request as draft August 6, 2024 15:29
@@ -18,11 +18,13 @@
"@types/react-router-bootstrap": "^0.26.6",
"@types/react-router-dom": "^5.3.3",
"@types/yup": "^0.32.0",
"axios": "^1.6.5",
"axios": "0.27.2",
Copy link
Contributor

Choose a reason for hiding this comment

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

I was getting an error like described here: openapistack/openapi-client-axios#172
Turns out, this is an incompatibility issue related to create-react-app.

I had it fixed by downgrading axios' version, as suggested here: facebook/create-react-app#12823 (comment)

In the long run, we might think about migrating this project out of CRA and into Vite-backed codebase, as suggested in the first link.

Copy link
Member Author

Choose a reason for hiding this comment

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

hm that's from 2022, shouldn't we be concerned that we're using such an old dependency? CRA maybe needs to be updated?

Copy link
Member Author

Choose a reason for hiding this comment

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

ah you write about that. Probably this vite thing should happen sooner rather than later?

ui/README.md Outdated
@@ -12,6 +12,12 @@ Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
The page will reload if you make edits.<br />
You will also see any lint errors in the console.

#### API client & associated types

Before running `yarn start`, make sure to run `sbt "backend/generateOpenAPISpec"` in the project's root directory. This command will generate the `<project_root>/backend/target/openapi.yaml` file.
Copy link
Member Author

Choose a reason for hiding this comment

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

ok so I did yarn start after pulling these changes, and the terminal hangs on:

[~/projects/bootzooka/ui]% yarn start
yarn run v1.22.19
$ yarn generate:openapi-types && concurrently "react-scripts start" "yarn watch:openapi"
$ npx openapicmd typegen ../backend/target/openapi.yaml > src/api-client/openapi.d.ts

While in src/api-client/openapi.d.ts I got:

Need to install the following packages:
  openapicmd
Ok to proceed? (y) 

this probably should go to the terminal? ;)

Copy link
Member Author

Choose a reason for hiding this comment

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

After answering "y" to the (hidden) question, I got:

/bin/sh: concurrently: command not found
error Command failed with exit code 127.

probably some setup that I'm missing?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok so running ./frontend-start.sh, which does yarn install helped ;) Maybe consolidating the READMEs would be a good idea?

Copy link
Member Author

Choose a reason for hiding this comment

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

Now I got:

error @oclif/[email protected]: The engine "node" is incompatible with this module. Expected version ">=18.0.0". Got "16.15.1"
error Found incompatible module.

node 16 is specified as the minimum in package.json. Maybe this should be updated?

@adamw
Copy link
Member Author

adamw commented Sep 5, 2024

Somewhat unrelated to the core task, but maybe https://softwaremill.github.io/bootzooka/stack.html would be good to extend with the main libraries used on the frontend - there are things like Formik or Yup (and possibly others) which I might guess as to why they are used, but it would be good to describe it too

@adamw
Copy link
Member Author

adamw commented Sep 5, 2024

@katekozlowska @belfz ^

@adamw
Copy link
Member Author

adamw commented Sep 5, 2024

After starting I get a warning:

[0] Browserslist: caniuse-lite is outdated. Please run:
[0]   npx update-browserslist-db@latest
[0]   Why you should do it regularly: https://github.com/browserslist/update-db#readme
[0] (node:38772) [DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE] DeprecationWarning: 'onAfterSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.
[0] (Use `node --trace-deprecation ...` to show where the warning was created)
[0] (node:38772) [DEP_WEBPACK_DEV_SERVER_ON_BEFORE_SETUP_MIDDLEWARE] DeprecationWarning: 'onBeforeSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.
[0] Starting the development server...
[0]
[0] Browserslist: caniuse-lite is outdated. Please run:
[0]   npx update-browserslist-db@latest
[0]   Why you should do it regularly: https://github.com/browserslist/update-db#readme
[0] Compiled with warnings.

Another thing to update probably?

@adamw
Copy link
Member Author

adamw commented Sep 5, 2024

More warnings, these seem to be connected to the client generation:

[0] WARNING in ./node_modules/openapi-client-axios/client.js
[0] Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
[0] Failed to parse source map from '/Users/adamw/projects/bootzooka/ui/node_modules/openapi-client-axios/src/client.ts' file: Error: ENOENT: no such file or directory, open '/Users/adamw/projects/bootzooka/ui/node_modules/openapi-client-axios/src/client.ts'
[0]
[0] WARNING in ./node_modules/openapi-client-axios/index.js
[0] Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
[0] Failed to parse source map from '/Users/adamw/projects/bootzooka/ui/node_modules/openapi-client-axios/src/index.ts' file: Error: ENOENT: no such file or directory, open '/Users/adamw/projects/bootzooka/ui/node_modules/openapi-client-axios/src/index.ts'
[0]
[0] WARNING in ./node_modules/openapi-client-axios/types/client.js
[0] Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
[0] Failed to parse source map from '/Users/adamw/projects/bootzooka/ui/node_modules/openapi-client-axios/src/types/client.ts' file: Error: ENOENT: no such file or directory, open '/Users/adamw/projects/bootzooka/ui/node_modules/openapi-client-axios/src/types/client.ts'

@katekozlowska

@adamw
Copy link
Member Author

adamw commented Sep 5, 2024

But despite the warnings, the UI works :)

.then((client) => client.postUserLogin(null, { ...params, apiKeyValidHours: 1 }))
.then(({ data }) => apiKeySchema.validate(data));

export const register = (payload: RegisterParamsPayload) =>
Copy link
Member Author

Choose a reason for hiding this comment

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

can we generate these values as well? they seem to follow the same pattern, and that they can be fully computed from the API spec? this applies to the validation as well, doesn't it exactly follow what's in the OpenAPI schema?

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.

3 participants