OpenAPI:缩放强大的API套件的最佳方法
我具有相同的对象,需要在多个SDK上使用。
说servicea
包含object1
的yaml文件,我想在serviceb
yaml文件中使用它。
在serviceb
文件中,我很容易引用object1
with $ ref:./service-a.yaml#/components/schemas/schemas/object1
,但是当为每种服务生成SDK,分别有两个不同的对象。 。
- (这是可以的
com.example.sdk.serviceb.models.object1
在应用程序中使用此时servicea
service> serviceb 我无法传递servicea.models.object1
进入serviceb
api,因为它会丢弃类型错误。它期望serviceb.models.object1
。
为此,我知道两种方法:
创建扩展功能以将
servicea.models.object1
转换为service> serviceb.models.object1
。如果在许多服务中都有许多可重复使用的对象,则不会很好地扩展。将所有路径导入单个文件,然后生成主文件。这是一个规模,但有两个问题。
i。将SDK导入应用程序时,我正在导入所有API(超过300多个),因此导入大得多。
ii。我必须为每个API创建两个路径,一个在服务文件中,一个在主文件中。
问题:是否有更合适的方法来解决这个问题?
I have the same object that needs to be used across multiple SDKs.
Say the yaml file for ServiceA
contains Object1
and I want to use it in the ServiceB
yaml file.
In the ServiceB
file I easily reference Object1
with $ref: ./service-a.yaml#/components/schemas/Object1
, however when generating the SDKs for each service separately there are two different objects. (This is expected.)
com.example.sdk.serviceA.models.Object1
com.example.sdk.serviceB.models.Object1
When using this in an application where serviceA
calls serviceB
I can't pass serviceA.models.Object1
into the serviceB
API because it will throw a type error. It is expecting serviceB.models.Object1
.
To solve for this I know of two approaches:
Create extension functions to convert
serviceA.models.Object1
toserviceB.models.Object1
. This doesn't scale nicely if one has many reusable objects across many services.Import all the paths into a single file and just generate the main file. This scales but there are two concerns.
i. When importing the SDK into an application I am importing all APIs (over 300+), as a result the import is a lot larger then it should to be.
ii. I have to create two paths for each API, one in the service file and one in the main file.
Question: Is there a more appropriate way to solve for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论