Swagger(集线器)如何写某种类型

发布于 2025-02-04 15:45:18 字数 626 浏览 3 评论 0原文

我在SwaggerHub网站上,需要进行API文档。 我试图定义一个具有多个元素的对象,其中大多数是基本的,但是其中一个属性是另一个对象,而不是数组,但是该子对象可以包含一个或多个属性(所有相同类型)。

我需要制作一个看起来像数组的对象。

假设我的大对象是“用户”,给我问题的对象是“地址”:

User:
   properties:
        name: 
           type: string
        adresses:
           type: object

示例:

User:
 name: Alex
 addresses: {
                 address: {...}
                 address2: {....}
                 address3: {....}
            }

我的地址类型已定义,但是“地址”必须是一个对象(这意味着它应该看起来像JSON,并且不与[])。我如何使“地址”具有可变长度?也许有4个地址,或者只有2个。

我想在API文档中为此编写示例,我希望它具有可变的长度,因为这是API实际工作的方式,使用JSON,而不是数组。

I'm on the swaggerhub website and i need to do an API documentation.
I'm trying to define an object with multiple elements, most of which are basic, but one of the properties is another object, NOT ARRAY, but that child object can contain one or more properties (ALL OF SAME TYPE).

I need to make an object that looks like an array.

Lets say my big object is 'User', and the object that gives me problems is 'addresses':

User:
   properties:
        name: 
           type: string
        adresses:
           type: object

Example:

User:
 name: Alex
 addresses: {
                 address: {...}
                 address2: {....}
                 address3: {....}
            }

I have the Address type defined, but 'addresses' must be an object (meaning that it should look like a json, and not with []). How do i make 'addresses' have variable length?? Maybe with 4 addresses, or only 2.

I want to write examples for this in the API documentation, and i want it to be of variable length, because that's how the API actually works, with a JSON, not an array.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

慕巷 2025-02-11 15:45:18

您是否检查了OpenAPI规范页面以在编写API定义的部分时提供帮助?这是一个很好的资源,可以深入了解如何编写API的多个方面。

规格页面在这里: https://swagger.io/specification/

您可以浏览左侧的主题 - 手。这里应该有用的是规范>模式。有很多有关如何编写各种对象的信息。

Have you checked the OpenAPI Specification page for help on writing parts of your API definition? It's a great resource that goes into depth on how to write multiple aspects of your API.

Specification page is here: https://swagger.io/specification/

You can browse through topics on the left-hand side. What should be helpful here is the sections under Specification > Schema. There's a lot of information on how to write various types of objects.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文