我在 API 端点中有一个 multipart/form-data POST,它需要一些键/值字符串,并通过 key 上传文件files。
我相信我已经在 OpenAPI 中正确定义了它;
"requestBody": {
"required": true,
"content": {
"multipart/form-data": {
"schema": {
"properties": {
"file": {
"type": "array",
"items": {
"type": "string",
"format": "binary"
}
},
"myKey1": {
"type": "string"
},
"myKey2": {
"type": "string"
}
}
},
"examples": {
"value": ?
}
}
}
},
Run Code Online (Sandbox Code Playgroud)
但是,我不确定如何描述该领域的多部分/表单数据的示例examples。
我认为我不需要表示文件(尽管这将是一个额外的好处),而只需表示myKey1键myKey2和值。
您好,我需要从结构推断 json 架构 (github.com/go-openapi/spec.Schema):
type Testcase struct {
Id string `json:"id,omitempty"` // id of this test case
Name string `json:"name,omitempty"` // name of this test case
CreationDate time.Time `json:"creation_date,omitempty"` // timestamp when the scenario was first created
UpdateDate time.Time `json:"update_date,omitempty"` // last update timestamp
Steps []Step `json:"steps,omitempty"` // list of steps type:"[]StepCcs"
}
Run Code Online (Sandbox Code Playgroud)
我找不到简单的方法来做到这一点。我想这是许多从代码生成开放 API 规范的 REST 框架的先决条件。
有人可以向我指出包含此类助手的包吗:即
func toSchema(obj interface{}) (spec.Schema, error)
Run Code Online (Sandbox Code Playgroud) 我有一个新的 .NET6 Azure Functions 应用程序。我使用 OpenAPI 规范创建了一些 HTTP 函数。
我的 swagger 页面工作正常,除了 POST 功能。
我想在此页面上显示一个最小的正文请求作为示例。
我已经IOpenApiExample按照https://github.com/Azure/azure-functions-openapi-extension/blob/main/docs/openapi-core.md#openapirequestbodyattribute
中提到的方式实现了
,但未使用该示例。它不断显示整个模型,没有任何样本值。
这是我的相关代码:
[FunctionName("PostHistoryEvent")]
[OpenApiOperation(operationId: "PostHistoryEvent", tags: new[] { "Post HistoryEvent" })]
[OpenApiSecurity("function_key", SecuritySchemeType.ApiKey, Name = "code", In = OpenApiSecurityLocationType.Query)]
[OpenApiRequestBody("application/json", typeof(HistoryEvent), Required = true, Description = "Description of OpenApiRequestBody", Example = typeof(HistoryEventOpenApiExample))]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.Created, contentType: "application/json", bodyType: typeof(HistoryEvent), Description = "The created History Event")]
public async Task<IActionResult> PostHistoryEvent(...){...}
public class HistoryEventOpenApiExample : OpenApiExample<HistoryEvent>
{
public override IOpenApiExample<HistoryEvent> Build(NamingStrategy namingStrategy = …Run Code Online (Sandbox Code Playgroud) 我需要 JSON 方案中的一个字段为日期或日期时间。它可以具有这些格式中的任何一种。使用该format属性,是否可以使用两种格式?
我正在使用带有 Spring Boot 的 OpenAPI+OpenAPI-generator,并尝试使用oneof如下架构:
这是 requests.yaml 文件中的配置:
...
requestBody:
name: request
required: true
content:
application/json:
schema:
oneOf:
- $ref: 'components.yaml#/Request'
- $ref: 'components.yaml#/ComplexRequest'
...
Run Code Online (Sandbox Code Playgroud)
这是 Components.yaml 文件中的相关配置:
Request:
allOf:
- $ref: '#/BaseInfo'
- type: object
properties:
should_create:
type: boolean
enum: [ false ]
reference_id:
type: string
required:
- reference_id
ComplexRequest:
allOf:
- $ref: '#/BaseInfo'
- type: object
properties:
should_create:
type: boolean
enum: [ true ]
create_data:
$ref: '#/Reference'
required:
- create_data
BaseInfo:
type: object
properties:
customer_id:
type: …Run Code Online (Sandbox Code Playgroud) 我正在构建一个 REST API,它使用 JWT 令牌中的数据来执行一些操作。(例如,验证数据的所有权,因此在某些情况下,我可能会发送user_idJWT 令牌或类似的内容)。
是否可以使用 OpenAPI 描述 JWT 令牌的预期内容?
我是 OpenApi 新手,想使用 api.yaml (OpenApi 版本 3.0.1)定义我的 api。我的问题是生成的枚举仅包含名称而不包含值。
这是我的代码中的枚举:
TEST1(1, "Test 1", "T1"),
TEST2(2, "Test 2", "T2"),
TEST3(3, "Test 3", "T2");
Run Code Online (Sandbox Code Playgroud)
这是使用 OpenApi 生成后的枚举:
TEST1("TEST1"),
TEST2("TEST2"),
TEST3("TEST3");
Run Code Online (Sandbox Code Playgroud)
枚举自动定义如下:
testenum:
type: string
description: desciption of the enum
enum:
- TEST1
- TEST2
- TEST3
Run Code Online (Sandbox Code Playgroud)
如何在 api.yaml 中定义枚举以使其看起来像第一个示例?
java enums openapi openapi-generator openapi-generator-maven-plugin
有没有办法从 gin 项目生成 OpenAPI 规范文件?这个问题真的很难搜索,到目前为止我所能找到的都是反向操作。
我将 OpenAPI 3 规范中的参数描述为
review_requests:
get:
tags:
- dashboard
operationId: reviewRequests
parameters:
- name: page
in: query
default: 0
description: Page number
schema:
type: integer
responses:
200:
description: OK
Run Code Online (Sandbox Code Playgroud)
编译后,我发现 Java 代码中缺少默认值,并且参数实际上描述如下:
@Valid @RequestParam(value = "page", required = false) Integer page
Run Code Online (Sandbox Code Playgroud)
如果 GET 请求中未提供参数,则0我不会收到。null据我了解应该是
@Valid @RequestParam(value = "page", required = false, defaultValue = "0") Integer page
Run Code Online (Sandbox Code Playgroud)
这是一个错误还是我做错了什么?
我面临一个问题,我的 DTO 类型被命名为一件事,但我希望它们在 OpenAPI 文档页面中以不同的名称出现。例如,我有一个在控制器中使用的 UserDto 类,但希望它在模式部分(以及这适用的其他任何地方)中仅显示为“User”。那可能吗?有我可以使用的装饰器吗?我知道我可以简单地修改类名,但在其他地方已经使用了不同的用户类。我到处寻找都没有结果。
顺便说一句,我正在使用 typescript 和 Nestjs。每一个帮助将不胜感激,谢谢!
openapi ×10
swagger ×7
go ×2
schema ×2
dto ×1
enums ×1
go-gin ×1
java ×1
jsonschema ×1
jwt ×1
nestjs ×1
openapi-generator-maven-plugin ×1
polymorphism ×1
swagger-ui ×1