在同一段中有多个变量有效的OpenAPI路径是否有效?

发布于 2025-01-26 21:40:10 字数 444 浏览 1 评论 0 原文

以下是有效的吗?

获取image/{id}/{palette}。{file_extension}

我希望能够做这样的事情: 示例:

GET image/1/falsecolor.jpg
GET image/4/alternative.png
GET image/9/falsecolor.tiff

基本上,调色板定义了图像的颜色(调色板),并且扩展名是更适合您的应用程序的文件格式(使用一种文件格式,网络最佳的移动交易,带有另一种文件的网络等),所有我尝试过的OpenAPI Linters做验证它,我在OpenAPI的文档中找不到任何东西,它说这不是一个有效的方法,但是当我将其上传到Postman中时,它却无法识别,加载了调色板和文件扩展名,变量而不是API属性,据说Postman符合OpenAPI/兼容,因此我想知道这实际上是不合格的路径参数。

Is the following valid?

GET image/{id}/{palette}.{file_extension}

I want to be able to do something like this:
example:

GET image/1/falsecolor.jpg
GET image/4/alternative.png
GET image/9/falsecolor.tiff

Basically, the palette defines how is the image is colored (color palette) and the extension is the file format better suited for your application (mobile deals best with one file format, web with another, etc), all OpenAPI linters I tried do validate it, there is nothing that I can find in the documentation for the OpenAPI that says that this is not a valid approach, but when I uploaded this to Postman, it borked beyond recognition, loading the palette and the file extension both as collection variables instead of API properties, and Postman is supposedly OpenAPI compliant/compatible, so I am wondering if this is actually a non-compliant path parameter.

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

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

发布评论

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

评论(2

戏蝶舞 2025-02-02 21:40:10

是的,部分路径参数在OpenAPI中有效。

但是,他们可以导致模棱两可的解析如果参数值包含分隔符值。例如,给定路径模板/{palette}。{file_extension} 和请求url /false.color.color.jpg ,服务器应该假设什么值?

  • Palette = “ false”

    file_extension = “ color.jpg”

  • palette = “ false.color”

    file_extension = “ jpg”

一些工具(尤其是/{foo}/{bar} ,但不/{foo} .json >或/{foo} - {bar} )。

Yes, partial path parameters are valid in OpenAPI.

However, they can result in ambiguous parsing if the parameter value contains the separator character. For example, given the path template /{palette}.{file_extension} and the request URL /false.color.jpg, what values should the server assume?

  • palette="false"
    file_extension="color.jpg"
  • palette="false.color"
    file_extension="jpg"

Some tools (notably AWS API Gateway) choose not to support partial path parameters and require that path parameters occupy the entire path segment (that is, /{foo}/{bar} but not /{foo}.json or /{foo}-{bar}).

私藏温柔 2025-02-02 21:40:10

Postman发送了一个证实行为的答案,这是他们实施的当前限制。

我们当前的收集格式存在局限性,例如,该格式在路径段中不允许多个路径变量 - 例如 -/files/{file -id}。路径段的内容不能被界定为路径变量,例如 -/file。{format} 。为了克服此当前限制,我们使用集合变量来表示此路径变量。这不会打破任何行为,但同时,预计OpenAPI的信息损失。话虽如此,用户可以依靠没有这些限制并保留用户配置的路径参数的模式文档。


他们还说,这是他们将来想改变的事情,目前没有ETA。

我要感谢所有花时间回答这个问题的人,这有助于很多。

Postman has sent an answer confirming the behavior, it is a current limitation in their implementation.

There are limitations to our current collection format, which does not allow more than one path variable within a path segment for example - /files/{file-id}.{format} and also parts of the path segment can't be delimited as a path variable for example - /file.{format}. In order to overcome this current limitation, we use collection variables to represent this path variable. This will not break any behavior but at the same time, information loss from OpenAPI is expected. Having said that users can rely on schema documentation which doesn't have these limitations and preserve the path parameters as configured by the users.

They also said this is something they want to change in the future, just no ETA on that for the moment.

I'd like to thank everyone that put their time to answer this question, it helped alot.

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