openAPI3的@Parameter中参数列表分别代表什么意思,并且为每个参数生成一个实例代码
时间: 2024-05-08 17:15:48 浏览: 57
1. name:参数名称,必须是一个字符串。示例代码:
```
@Parameter(name = "id", description = "用户ID", required = true, schema = @Schema(type = "integer", format = "int64"))
```
2. in:参数在请求中的位置,必须是下列之一:path、query、header、cookie。示例代码:
```
@Parameter(name = "Authorization", description = "身份认证信息", in = Header, required = true, schema = @Schema(type = "string"))
```
3. description:参数的描述信息。示例代码:
```
@Parameter(name = "id", description = "用户ID", required = true, schema = @Schema(type = "integer", format = "int64"))
```
4. required:参数是否必须。示例代码:
```
@Parameter(name = "id", description = "用户ID", required = true, schema = @Schema(type = "integer", format = "int64"))
```
5. schema:参数的数据类型,是一个Schema对象。示例代码:
```
@Parameter(name = "id", description = "用户ID", required = true, schema = @Schema(type = "integer", format = "int64"))
```
生成的实例代码:
```java
Parameter idParameter = new Parameter();
idParameter.setName("id");
idParameter.setDescription("用户ID");
idParameter.setRequired(true);
Schema idSchema = new Schema();
idSchema.setType("integer");
idSchema.setFormat("int64");
idParameter.setSchema(idSchema);
```
6. deprecated:参数是否已经过时。示例代码:
```
@Parameter(name = "id", description = "用户ID", required = true, schema = @Schema(type = "integer", format = "int64"), deprecated = true)
```
生成的实例代码:
```java
Parameter idParameter = new Parameter();
idParameter.setName("id");
idParameter.setDescription("用户ID");
idParameter.setRequired(true);
Schema idSchema = new Schema();
idSchema.setType("integer");
idSchema.setFormat("int64");
idParameter.setSchema(idSchema);
idParameter.setDeprecated(true);
```
阅读全文