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

Orval generator POC #2724

Merged
merged 25 commits into from
Jan 5, 2023
Merged

Orval generator POC #2724

merged 25 commits into from
Jan 5, 2023

Conversation

Tymek
Copy link
Member

@Tymek Tymek commented Dec 21, 2022

About the changes

POC for #2715

Important files

  • frontend/orval.config.js
  • frontend/src/openapi/fetcher.ts

@vercel
Copy link

vercel bot commented Dec 21, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
unleash-monorepo-frontend ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Jan 5, 2023 at 10:25AM (UTC)
1 Ignored Deployment
Name Status Preview Comments Updated
unleash-docs ⬜️ Ignored (Inspect) Jan 5, 2023 at 10:25AM (UTC)

@kwasniew
Copy link
Contributor

Can we put this (the actual usage) behind a feature flag so that we can turn it on/off at any time. This is a very dangerous change so I'd like to be on the safe side.

Copy link
Contributor

@FredrikOseberg FredrikOseberg left a comment

Choose a reason for hiding this comment

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

I think this makes sense. For types I'm happy to start right away. For the API integration I think we should wait until we can validate properly and over time. We can for example try the fetchers on new features, put them behind feature flags and try it out as we are developing instead of modifying existing endpoints.

This way, we'll find edge cases while we are developing, and we can figure out if the generator provides a pleasant experience, or if we are just moving around the technical debt.

@Tymek
Copy link
Member Author

Tymek commented Dec 30, 2022

@FredrikOseberg @kwasniew About putting it behind a flag: I only substituted 2 OpenAPI getters that where used before (get features and get features archive). All model/Schema names where compatible. We still have frontend/src/interfaces written by hand (that IMHO we should mostly deprecate).

Files that where using previous auto-generated fetcher that I refactored:

  • frontend/src/component/archive/ProjectFeaturesArchiveTable.tsx
  • frontend/src/hooks/api/actions/useFeatureApi/useFeatureApi.ts
  • frontend/src/hooks/api/getters/useFeaturesArchive/useFeaturesArchive.ts

[strategyId, uiConfig.flags],
fetchSegments,
url,
() => (uiConfig.flags?.SE ? fetchSegments(url) : []),
Copy link
Contributor

Choose a reason for hiding this comment

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

We tried this approach in change requests and it didn't work. Please check SWR recommended approach: https://swr.vercel.app/docs/conditional-fetching. We have our own hook useConditionalSWR encapsulating the logic.

Copy link
Contributor

@FredrikOseberg FredrikOseberg left a comment

Choose a reason for hiding this comment

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

Nice! Can be merged after addressing comments.

@sjaanus
Copy link
Contributor

sjaanus commented Jan 5, 2023

Couple of questions to cover everything.

  1. Do we have example how we regenerate the schema, when we add new endpoint to the backend?
  2. If I understand correctly, for useFeatureApi we are now using Orval. When looking at that file, does this mean, we still need to know the path and http method by heart? Orval does not generate that?

@Tymek
Copy link
Member Author

Tymek commented Jan 5, 2023

@sjaanus

Couple of questions to cover everything.

  1. Do we have example how we regenerate the schema, when we add new endpoint to the backend?

There is a comment in orval.config.js. Scripts in package.json are fairly easy to understand:

"gen:api": "orval --config orval.config.js",
"gen:api:demo": "UNLEASH_OPENAPI_URL=https://app.unleash-hosted.com/demo/docs/openapi.json yarn run gen:api",
  1. If I understand correctly, for useFeatureApi we are now using Orval. When looking at that file, does this mean, we still need to know the path and http method by heart? Orval does not generate that?

We don't use methods/actions yet. For now we only use generated types.

@Tymek Tymek merged commit 1653b04 into main Jan 5, 2023
@Tymek Tymek deleted the tymek/1-519-openapi-generator-for-frontend branch January 5, 2023 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

4 participants