带括号和变量名的 OpenAPI 参数

编程入门 行业动态 更新时间:2024-10-14 08:27:24
本文介绍了带括号和变量名的 OpenAPI 参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在开发一个允许使用以下 URL 进行搜索的 API:

I am working on an API which allows searching with URLs like:

GET example/api/data?search[field1]=value1 GET example/api/data?search[field2]=value2 GET example/api/data?search[field1]=value1&search[field2]=value2

基本上,您可以通过将字段名称放在括号中来搜索一个或多个字段值.问题是,字段名称是由用户在其设置中定义的.字段名称将是一个字符串,但在全球范围内无法提前知道.

Basically, you can search for one or more field values by putting a field name in brackets. The problem is, the field names are defined by the user in their settings. The field name will be a string, but otherwise is not known ahead of time at a global level.

这个答案几乎就是我想要做的,我只是找不到定义值的方法括号内为任何字符串",而不是已知名称列表.

This answer is almost what I am looking to do, I just can't find a way to define the value inside the brackets to be "any string" rather than a list of known names.

推荐答案

search 参数可以定义为 deepObject 序列化的">自由形式对象style 和 minProperties: 1 强制搜索查询中至少存在一个字段.

The search parameter can be defined as a free-form object with the deepObject serialization style and minProperties: 1 to enforce the presence of at least one field in the search query.

确保您使用 OpenAPI 3.0 (openapi: 3.0.x) 而不是 OpenAPI 2.0 (swagger: "2.0");后者不支持查询字符串中的对象.

Make sure you use OpenAPI 3.0 (openapi: 3.0.x) and not OpenAPI 2.0 (swagger: "2.0"); the latter does not support objects in query strings.

openapi: 3.0.2 ... paths: /api/data: get: parameters: - in: query name: search required: true schema: type: object additionalProperties: true # Default value, may be omitted minProperties: 1 # Optional example to use as a starting value for "try it out" in Swagger UI example: > { "field1": "value1", "field2": "value2" } style: deepObject explode: true responses: 200: description: OK

更多推荐

带括号和变量名的 OpenAPI 参数

本文发布于:2023-11-26 02:33:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1632301.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:括号   变量名   参数   OpenAPI

发布评论

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

>www.elefans.com

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