Skip to content

chore: implement Orval to generate API fetch functions and types - #1159

Open
GuillaumeKESTEMAN wants to merge 12 commits into
developfrom
chore/implement-orval-to-generate-api-fetch-functions-and-types
Open

chore: implement Orval to generate API fetch functions and types#1159
GuillaumeKESTEMAN wants to merge 12 commits into
developfrom
chore/implement-orval-to-generate-api-fetch-functions-and-types

Conversation

@GuillaumeKESTEMAN

@GuillaumeKESTEMAN GuillaumeKESTEMAN commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

Title: Implement Orval to generate API fetch functions and types from Swagger

Type of Pull Request:

  • New feature
  • Bug fix
  • Documentation
  • Other (specify):

Associated Issue:
Closes #278

Context:
Currently, API types and fetch functions are manually maintained in the frontend, causing sync issues between the backend OpenAPI/Swagger specification and frontend implementations. This PR introduces Orval as an automated code generation tool to sync TypeScript types and API client functions directly from the backend's Swagger specification, reducing manual maintenance and ensuring consistency.

Proposed Changes:

  • Setup Orval & Swagger Normalization:

    • Added orval.config.ts with configuration for generating API clients using the fetch client and custom mutator
    • Created prepare-swagger.mjs script to normalize the Swagger spec: removes non-standard security definitions and strips the /api prefix from paths to enable dynamic backend URL injection
    • Updated Makefile and npm scripts to run npm run generate:api during frontend startup
    • Updated .gitignore to exclude generated API files (/src/api/generated/, swagger.json)
  • Custom Fetch Mutator:

    • Implemented fetchApiMutator.ts to integrate Orval-generated clients with existing error handling and token refresh logic
    • Handles 498 (expired token) responses by refreshing and retrying requests
    • Supports dynamic backend URL injection via environment variables
  • Refactored Authentication APIs:

    • Removed manual API files (authStatusApi.ts, refreshTokenApi.ts) now generated by Orval
    • Updated signUpApi.ts to use generated postV1Account function
    • Updated authentication context (useCheckAuthentication) to use generated getV1AuthStatus function
    • Updated signup hook (useSignUp) to use generated mutation functions
  • Type Consolidation:

    • Removed duplicate error response classes (AuthStatusErrorResponse.ts)
    • Updated fixture files to use generated types from slotFinderAPI.schemas
    • Updated MSW browser setup to include generated auth status handler
  • Dependencies:

    • Added orval@^8.22.0 as dev dependency with all required sub-packages

Checklist:

  • I have verified that my changes work as expected
  • I have updated the documentation if necessary
  • I have thought to rebase my branch
  • I have applied the correct label according to the type of PR (bug/feature/documentation)

Additional Information:

  • The Swagger specification is normalized during build: non-standard security definitions are removed to avoid parser crashes, and the /api prefix is stripped to support dynamic backend URL injection (/mocked-api, /api, etc.)
  • The username field is accepted by the real API but is absent from the OpenAPI spec; the generated code accepts it without casting via structural subtyping
  • Generated files in src/api/generated/ are gitignored and regenerated on every build

@GuillaumeKESTEMAN
GuillaumeKESTEMAN requested a review from nekeo as a code owner July 18, 2026 10:57
@GuillaumeKESTEMAN GuillaumeKESTEMAN self-assigned this Jul 18, 2026
@GuillaumeKESTEMAN
GuillaumeKESTEMAN force-pushed the chore/implement-orval-to-generate-api-fetch-functions-and-types branch from e7f3b20 to 62b5b30 Compare July 18, 2026 11:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Confidence: 98%.

This PR introduces Orval-based OpenAPI client generation for the frontend, replacing hand-written API wrappers/types with generated fetch clients and a shared custom mutator (including token refresh + error handling) to keep the frontend aligned with the backend Swagger contract.

Changes:

  • Added Orval configuration + Swagger preparation script and wired generate:api into local dev and CI setup.
  • Implemented a custom Orval fetch mutator and refactored authentication/signup flows to use generated endpoints.
  • Updated mocks/fixtures and documentation, and removed legacy manual API wrappers/types.

Reviewed changes

Copilot reviewed 23 out of 24 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
Makefile Runs npm run generate:api during make start / make front.
front/src/types/Authentication/tokenRefresh/tokenRefresh.types.ts Removes unused TokenRefreshResponseType alias; keeps error code typing.
front/src/types/Authentication/authStatus/AuthStatusErrorResponse.ts Removes legacy custom error response class.
front/src/types/Authentication/authStatus/authStatus.types.ts Removes unused AuthStatusResponseType alias; keeps error code typing.
front/src/pages/Authentication/SignUp/useSignUp.ts Updates React Query mutation typing/error type to shared ErrorResponse; aligns with generated signup call.
front/src/contexts/AuthenticationContext/useCheckAuthentication.ts Switches auth status call to generated getV1AuthStatus and shared ErrorResponse typing.
front/src/api/README.md Updates API layer docs to describe Orval-generated structure and workflow.
front/src/api/orval/fetchApiMutator.ts Adds Orval mutator implementing shared fetch behavior + token refresh retry.
front/src/api/fetchApi.ts Removes legacy custom fetch wrapper.
front/src/api/constant.ts Removes now-unused HTTP method/MIME enums; keeps header constants.
front/src/api/authentication/signUpApi.ts Switches signup to generated postV1Account and builds DTO expected by API.
front/src/api/authentication/refreshTokenApi.ts Removes legacy refresh API wrapper.
front/src/api/authentication/authStatusApi.ts Removes legacy auth status API wrapper.
front/scripts/prepare-swagger.mjs Adds Swagger normalization step (remove securityDefinitions, strip /api prefix).
front/README.md Documents Orval API generation workflow.
front/package.json Adds generate:api script and Orval dev dependency.
front/package-lock.json Locks Orval and its transitive deps.
front/orval.config.ts Adds Orval config targeting fetch client with custom mutator.
front/mocks/fixtures/tokenRefreshFixtures.ts Adjusts fixtures after removing response type alias.
front/mocks/fixtures/authStatusFixtures.ts Switches fixtures to generated schema error type.
front/mocks/fixtures/accountFixtures.ts Updates error fixture typing; keeps “real API returns token” fixture shape.
front/mocks/browser.ts Registers a generated auth status handler in the MSW worker.
front/.gitignore Ignores generated Orval output and prepared swagger JSON.
.github/actions/setup-node/action.yaml Extends setup-node composite action to run API generation.
Files not reviewed (1)
  • front/package-lock.json: Generated file

Comment thread front/src/api/orval/fetchApiMutator.ts
Comment thread front/src/api/orval/fetchApiMutator.ts Outdated
Comment thread .github/actions/setup-node/action.yaml Outdated
@GuillaumeKESTEMAN

Copy link
Copy Markdown
Collaborator Author

Utiliser un script postinstall plutôt que de le définir manuellement dans le makefile et workflow

@GuillaumeKESTEMAN
GuillaumeKESTEMAN force-pushed the chore/implement-orval-to-generate-api-fetch-functions-and-types branch from 545d0e8 to 42db0fb Compare July 21, 2026 17:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 24 out of 25 changed files in this pull request and generated 1 comment.

Comment thread .github/actions/setup-node/action.yaml Outdated
@GuillaumeKESTEMAN
GuillaumeKESTEMAN force-pushed the chore/implement-orval-to-generate-api-fetch-functions-and-types branch 2 times, most recently from 7fc0709 to 573cad3 Compare July 22, 2026 19:38
GuillaumeKESTEMAN and others added 9 commits July 25, 2026 09:35
…tion

- added script to prepare Swagger for Orval code generation
- replaced custom API calls with Orval-generated functions for authentication
- removed obsolete API files and error response classes
- updated authentication context and sign-up logic to use new API structure
- introduced custom fetch mutator for handling token refresh and error responses
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Refactor the setup-node action and Makefile to remove the API generation step.
Update the postinstall script in package.json to ensure API generation occurs
after initializing MSW and installing dependencies.
…ckage-lock.json

Includes updates to the signUpApi to utilize Temporal for time zone handling.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@GuillaumeKESTEMAN
GuillaumeKESTEMAN force-pushed the chore/implement-orval-to-generate-api-fetch-functions-and-types branch from 573cad3 to 287fe28 Compare July 25, 2026 09:38
Enhance the CI workflow to check for changes in both front-end and back-end files.
This includes updating job names and conditions for installation, linting, testing, and building.
@GuillaumeKESTEMAN
GuillaumeKESTEMAN force-pushed the chore/implement-orval-to-generate-api-fetch-functions-and-types branch from 7a0a86d to 380b262 Compare July 25, 2026 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chore(front,back): implement orval to sync swagger

2 participants