OpenAPI:缩放强大的API套件的最佳方法

发布于 2025-01-31 04:07:20 字数 968 浏览 3 评论 0原文

我具有相同的对象,需要在多个SDK上使用。

servicea包含object1的yaml文件,我想在serviceb yaml文件中使用它。

serviceb文件中,我很容易引用object1 with $ ref:./service-a.yaml#/components/schemas/schemas/object1 ,但是当为每种服务生成SDK,分别有两个不同的对象。 。

  1. (这是可以的
  2. com.example.sdk.serviceb.models.object1

在应用程序中使用此时servicea service> serviceb 我无法传递servicea.models.object1进入serviceb api,因为它会丢弃类型错误。它期望serviceb.models.object1

为此,我知道两种方法:

  1. 创建扩展功能以将servicea.models.object1转换为service> serviceb.models.object1。如果在许多服务中都有许多可重复使用的对象,则不会很好地扩展。

  2. 将所有路径导入单个文件,然后生成主文件。这是一个规模,但有两个问题。

    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.)

  1. com.example.sdk.serviceA.models.Object1

  2. 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:

  1. Create extension functions to convert serviceA.models.Object1 to serviceB.models.Object1. This doesn't scale nicely if one has many reusable objects across many services.

  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文