我想schema在 OpenAPI 3.0 API 定义中将以下 JSON 表示为 a :
{
get-question: {
question-id:string
}
}
Run Code Online (Sandbox Code Playgroud)
到目前为止,我已经写了:
{
get-question: {
question-id:string
}
}
Run Code Online (Sandbox Code Playgroud)
但我在 Swagger 编辑器中收到这些错误:
Schema error at components.schemas['GetQuestion']
should have required property '$ref'
missingProperty: $ref
Jump to line 79
Schema error at components.schemas['GetQuestion']
should match exactly one schema in oneOf
Jump to line 79
Schema error at components.schemas['GetQuestion'].properties['get-questions']
should have required property '$ref'
missingProperty: $ref
Jump to line 81
Schema error at components.schemas['GetQuestion'].properties['get-questions']
should match exactly one …Run Code Online (Sandbox Code Playgroud) 我负责维护公司API文档。我们的 API 是用 ASP.NET 编写的。我最近改用 Swashbuckle 5.6.0,它运行得很好。
我遇到的问题是这样的:
我们将数据模型分为 Post 数据和 Get 数据,例如WebAccountGetData.cs和WebAccountPostData.cs。创建(POST)和更新(PUT)时可以使用Post数据。
Post 数据类中的大多数(如果不是全部)字段都可以为 null,当调用 API 方法时,存储过程会返回描述缺少/需要哪些字段的错误消息。API 不处理必填字段。
使用可为 null 的字段意味着 Swashbuckle 不会向文档添加必需标志。但我们想根据使用的 Http 方法(Post/Put)来显示某个字段是否为必填字段。

API 密钥是必需参数,因为它不可为空。
我知道我可以使用[Required]System.ComponentModel.DataAnnotations 命名空间中的属性,但这会将必需标志应用于 POST 和 PUT 方法,这是我们不希望的。
理想情况下,我想使用自定义属性,在其中可以指定 Post 或 Put 方法中是否需要某个字段。
public class ApiRequiredAttribute : Attribute
{
public bool RequiredInPost
{
get;
set;
} = false;
public bool RequiredInPut
{
get;
set;
} = false;
}
Run Code Online (Sandbox Code Playgroud)
然后像这样使用它:
[ApiRequired(RequiredInPost = true)]
public int? ApprovalStatusId
{
get;
set; …Run Code Online (Sandbox Code Playgroud) 假设我的 OpenAPI 定义有两个服务器。两者共享相同的变量。因此我想引用这些变量以防止重复代码。
实际上,我将 OpenAPI 分成文件并将其与swagger-cli bundle. 这就是它创建的:
openapi: 3.0.2
info:
title: My API
description: 'some description'
version: 1.0.0
servers:
- url: 'https://stage-api.domain.com/foo/{v1}/{v2}/{v3}'
description: Staging API server for QA
variables:
v1:
description: 'variable 1'
default: 'something'
enum:
- 'foo1'
- 'foo2'
v2:
description: 'variable 2'
default: 'something'
enum:
- 'foo1'
- 'foo2'
v3:
description: 'variable 3'
default: 'something'
enum:
- 'foo1'
- 'foo2'
- url: 'https://api.domain.com/foo/{v1}/{v2}/{v3}'
description: PRODUCTION API server
variables:
region:
$ref: '#/servers/0/variables/v1'
brand:
$ref: '#/servers/0/variables/v2'
locale: …Run Code Online (Sandbox Code Playgroud) 如何pattern使用 Swagger Node.js 注释正确定义以下正则表达式?
* reviews_ratings_description:\n * type: string\n * minimum: 10\n * maximum: 50\n * pattern: "^[ a-zA-Z0-9](?!,.*?[^\\na-zA-Z0-9!\xe2\x80\x9d$%&~^&#<>.?:"\'\xe2\x80\x99=@()*\\+,\\/;\\[\\\\\\]\\-^_`{|}~]{1}).*?[a-zA-Z0-9!\xe2\x80\x9d$%&~^&#<>.?:"\'\xe2\x80\x99=@()*\\+,\\/;\\\\\\\\]\\-^_`{|}~]$" \nRun Code Online (Sandbox Code Playgroud)\n\n运行上面的代码会产生以下错误:
\n\n{"error":{},"level":"error","message":"uncaughtException: YAMLException: can not read an implicit mapping pair; a colon is missed at line 42, column 159:\\n ... \\"\'\xe2\x80\x99=@()*\\\\+,\\\\/;\\\\[\\\\\\\\\\\\]\\\\-^_`{|}~]$\'\\n\nRun Code Online (Sandbox Code Playgroud)\n\n字符串是否pattern需要以某种方式转义?
如何从 Swagger UI 禁用或隐藏“服务器”下拉列表?

我的 Maven 依赖项是:
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.13</version>
</dependency>
Run Code Online (Sandbox Code Playgroud) 在DirectX 10应用程序中,在全屏模式和窗口模式之间切换会产生任何类型的开销,例如必须重新创建纹理和/或顶点缓冲区吗?
换句话说,我可以构建一个应用程序,它可以在窗口模式和全屏模式之间进行"大量"切换,而不会在交换机出现时遭受性能损失吗?
我尝试使用 WMI 在远程计算机上通过 .appref-ms 快捷方式启动 ClickOnce 应用程序,但无法成功。如果我尝试运行 notepad.exe,下面的代码可以正常工作。
ManagementPath pm = new ManagementPath(@"\\server\root\cimv2:Win32_process");
ManagementClass processClass = new ManagementClass(pm);
//Get an input parameters object for this method
ManagementBaseObject inParams = processClass.GetMethodParameters("Create");
//Fill in input parameter values
inParams["CommandLine"] = @"C:\Documents and Settings\Start Menu\Programs\New\New App.appref-ms";
//Execute the method
ManagementBaseObject outParams = processClass.InvokeMethod("Create", inParams, null);
Run Code Online (Sandbox Code Playgroud) 我想从C#应用程序管理远程计算机上的共享文件夹.有没有办法用C#做到这一点?
我知道WMI可以进行远程管理,但我还没有找到管理文件和文件夹共享的方法.
我使用https://generator.swagger.io/ 上的在线 Swagger Codegen为这个 API生成了一个 Python 客户端库。API 使用 Bearer 身份验证:
openapi: 3.0.0
...
paths:
/sandbox/register:
post:
...
security:
- sso_auth: []
...
components:
securitySchemes:
sso_auth:
type: http
scheme: bearer
Run Code Online (Sandbox Code Playgroud)
但是,Configuration生成的 Python 客户端中的类没有access_token字段。
使用生成的客户端库时如何填写不记名访问令牌?
代码生成端点POST /gen/clients/{language}具有authorizationValue和securityDefinition参数 - 我是否需要以某种方式配置这些参数?
"authorizationValue": {
"value": "string",
"type": "string",
"keyName": "string"
},
"securityDefinition": {
"type": "string",
"description": "string"
}
Run Code Online (Sandbox Code Playgroud) 我意识到关于为什么 Java 或其他语言不支持无符号整数有很多类似的问题,但这些都是关于语言设计背后的基本原理和哲学的问题,旨在表达新事物的创造力。
OpenAPI 应该是描述性的。如果 API 想要公开 64 位无符号字,它应该能够做到。OpenAPI 应该有助于代码生成器构建客户端来使用该 API。
好吧,这个论点可以无限地进行,以允许各种奇异的原始类型。这可以被指出为“他们必须在某处划清界限”。
但无符号 32 位和 64 位字是非常常见的原语。为什么他们不受支持?
额外奖励:哪些 REST API 规范格式支持它们?
openapi ×4
c# ×3
swagger ×3
wmi ×2
.net ×1
bearer-token ×1
clickonce ×1
directx-10 ×1
fullscreen ×1
jsonschema ×1
node.js ×1
python ×1
redoc ×1
rest ×1
springdoc ×1
swagger-ui ×1
swashbuckle ×1
windowed ×1
windows ×1
yaml ×1