I’m working on a project where we deal with multiple Spring Boot microservices and one Angular front end application. We are using OpenAPI to generate some code for us (Java classes for the back end, TypeScript files for the front). But we have an issue.
In API A and API B, we have some common components. Let’s say we have a component ContactInfo
like this, in both API:
When we generate the TypeScript files, we end up with a contactInfo.ts
from API A and a contactInfo.ts
from API B. That does not sound like a good practice.
But how could we deal with that? Having only one API for both microservices?
This will be usefull in the longterm. What if only API A will change the contactInfo? So only the generated files of that part of your angular application will need changes.
Currently I have the same setup with multiple api’s and 1 angular app. In my opinion this can be usefull long-term.
2
Personally I would work in a monorepo with the generated types in a shared library used by API A and API B
Like :
my-project/
├── packages/
│ ├── shared-types/
│ │ ├── src/
│ │ │ └── models/
│ │ │ └── ContactInfo.ts
│ │ ├── package.json
│ │ └── tsconfig.json
│ ├── api-a/
│ │ ├── src/
│ │ ├── package.json
│ │ └── tsconfig.json
│ └── api-b/
│ ├── src/
│ ├── package.json
│ └── tsconfig.json
├── package.json
└── tsconfig.json