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

ENG-1497 Feat: Codegen implementation in api package #33

Merged
merged 25 commits into from
May 23, 2024

Conversation

rahulr8
Copy link
Contributor

@rahulr8 rahulr8 commented May 13, 2024

Affected Packages

  • portal
  • 1ui
  • protocol
  • api

Overview

This PR setups a library under packages/api/api-client that contains the Typescript client to interface with the backend. There are two generated files that are of particular importance

  1. services.gen.ts - All API calls to the backend wrapped in functions and using axios
  2. types.gen.ts - TypeScript interfaces to model data from the backend

These can be imported into any app or package in the mono-repo in order to better facilitate seamless interfacing with the backend.

Testing

Run pnpm install to install latest dependencies.

For testing, I created a test route which you can hit. It has the following loader. You can go to localhost:3000/test to access it and check your server logs.

  OpenAPI.BASE = 'https://dev.api.intuition.systems'
  const { accessToken } = await requireAuthedUser(request)
  const headers = getAuthHeaders(accessToken !== null ? accessToken : '')
  OpenAPI.HEADERS = headers as Record<string, string>

  const test = await IdentitiesService.getIdentities({
    paging: {
      page: 1,
      limit: 10,
      offset: 0,
    },
    sort: {
      sortBy: 'IdentityId',
      direction: 'asc',
    },
  })

  console.log('test api call response', test)

  return json({
    hello: 'world',
  })
}

You should see the following logs

image

Declaration

  • I hereby declare that I have abided by the rules and regulations as outlined in the CONTRIBUTING.md

Copy link

linear bot commented May 13, 2024

ENG-1497 [Spike] Setup codegen with OpenAPI

TLDR:

Use the openapi.json to generate models, types, and API calls on the front-end

Context

https://intuition-systems.slack.com/archives/C070UVDVB5X/p1715355180943489

@rahulr8 rahulr8 changed the title ENG-1497: Codegen proof of concept ENG-1497 Feat: Codegen proof of concept May 13, 2024
@simonas-notcat
Copy link
Member

@rahulr8 is the plan to eventually move this to packages/api as described in #15 ?

@rahulr8 rahulr8 changed the title ENG-1497 Feat: Codegen proof of concept ENG-1497 Feat: Codegen implementation in api package May 22, 2024
@rahulr8 rahulr8 marked this pull request as ready for review May 22, 2024 18:51
@rahulr8 rahulr8 merged commit 138dccf into main May 23, 2024
6 checks passed
@rahulr8 rahulr8 deleted the ENG-1497-codegen-setup branch May 23, 2024 16:08
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