是否可以在 OpenAPI 3 中引用单个路径和方法?

编程入门 行业动态 更新时间:2024-10-22 08:22:48
本文介绍了是否可以在 OpenAPI 3 中引用单个路径和方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

假设我有一个描述 API Foo 的 OpenAPI 3 文档,如下所示:

openapi: 3.0.0信息:版本:'1'书名:福路径:/foo:得到:回应:200:描述:阿福邮政:回应:201:描述:Foo 创建

在 API Bar 的另一个 OpenAPI 文档中,我想仅引用 API Foo<中的 GET/foo 操作/代码>.OpenAPI 文档稍微介绍了引用整个路径.但是,如果我执行以下操作:

openapi: 3.0.0信息:版本:'1'标题栏路径:/foo:$ref: 'foo.yaml#/paths/~1foo'

我很自然地同时获得了 API Bar 中的 GET 和 POST,因为只引用了路径,而不是方法.

我试过了:

openapi: 3.0.0信息:版本:'1'标题栏路径:/foo:得到:$ref: 'foo.yaml#/paths/~1foo/get'

但这会导致错误,例如 should NOT have additional properties additionalProperty: $ref 和 should have required property 'responses' missingProperty: answers 在各种工具中,所以它没有'似乎支持.

有没有办法做到这一点?我应该注意到,真正的请求要复杂得多,因此需要重复数据删除.如果可能的话,我想避免用单独的 $ref s 填充 get 的许多子对象.

解决方案

OpenAPI 没有办法 $ref 单个操作 (get/post/etc.),你只能$ref整个路径.

您可以在 OpenAPI 规范存储库中提出语法增强:github/OAI/OpenAPI-Specification/issues

Suppose I have an OpenAPI 3 document describing API Foo as follows:

openapi: 3.0.0 info: version: '1' title: Foo paths: /foo: get: responses: 200: description: A Foo post: responses: 201: description: Foo created

In another OpenAPI document for API Bar, I would like to reference only the GET /foo operation from API Foo. The OpenAPI docs talk a little about referencing a whole path. However, if I do the following:

openapi: 3.0.0 info: version: '1' title: Bar paths: /foo: $ref: 'foo.yaml#/paths/~1foo'

I naturally get both the GET and the POST in API Bar, since only the path is referenced, not the method.

I tried this:

openapi: 3.0.0 info: version: '1' title: Bar paths: /foo: get: $ref: 'foo.yaml#/paths/~1foo/get'

But this gives errors like should NOT have additional properties additionalProperty: $ref and should have required property 'responses' missingProperty: responses in various tools, so it doesn't seem to be supported.

Is there a way to accomplish this? I should note that the real request is much more complicated, hence the desire to de-duplicate. If possible I would like to avoid filling in many child objects of get with individual $refs.

解决方案

OpenAPI doesn't have a way to $ref an individual operation (get/post/etc.), you can only $ref an entire path.

You can propose syntax enhancements in the OpenAPI Specification repository: github/OAI/OpenAPI-Specification/issues

更多推荐

是否可以在 OpenAPI 3 中引用单个路径和方法?

本文发布于:2023-10-31 04:18:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1544980.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路径   方法   OpenAPI

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!