Closed OurBigAdventure closed 4 months ago
Hi @OurBigAdventure,
if you need to use more than one OpenAPI doc (either because your service implements the interface of multiple APIs, or because your service needs to talk to multiple upstream services), generate each into a separate Swift module.
For example:
- MyUpstreamService1
- openapi.yaml
- openapi-generator-config.yaml (generates a client)
- MyUpstreamService2
- openapi.yaml
- openapi-generator-config.yaml (generates a client)
- MyServiceA
- openapi.yaml
- openapi-generator-config.yaml (generates a server)
- MyServer
- depends on and imports MyUpstreamService1, MyUpstreamService2, MyServiceA
- implements the handler (conforming to `APIProtocol`) and uses the generated `MyUpstreamService1.Client` and `MyUpstreamService2.Client` to make upstream calls
Note that if you use this strategy, make sure to specify accessModifier: package
or accessModifier: public
, so that the generated code is accessible from other modules (the default is internal
).
More details:
accessModifier
: https://swiftpackageindex.com/apple/swift-openapi-generator/1.2.1/documentation/swift-openapi-generator/configuring-the-generatorInteresting, thanks for the great response!
Motivation
I have a server project that needs to interface with multiple services with OpenAPI specs. Currently I can't see a way to use more than one spec.
Proposed solution
It would be great if the spec(s) could be either grouped or specified instead of detected. A specific folder or a place to create a list of file names would be ideal.
Alternatives considered
The alternative is to pick the more complex spec and use the generator, then code all other API interfaces by hand. Or, use the OpenAPI CLI generator to just generate the code and skip using this project all together.
Additional information
No response