在 swagger (3.0) 定义 YAML 中,如果我有一个带有字符串属性的架构并添加自定义示例值,则特殊字符(如<、 和)在浏览时会显示“错误”,例如变为。>&<<
我尝试使用\x3c而不是<, 或使用!!str前缀,但没有帮助。
在本例中,响应是“application/xml”,因此这可能是一个问题,但是在属性名称中,小于号完美地显示(见下文)。
一些特殊字符可以正常工作,例如&.
info:
title: poc
servers:
- url: /poc/api
variables: {}
paths:
/ex2:
get:
tags:
- example
summary: debugging schema with example value contains < or >
description:
operationId: example
responses:
200:
description:
content:
application/xml;charset=UTF-8:
schema:
$ref: '#/components/schemas/Wrapper'
components:
schemas:
Entry:
type: object
properties:
name:
type: string
value:
type: number
Wrapper:
type: object
properties:
entry:
type: object …Run Code Online (Sandbox Code Playgroud) Swagger: Reusing an enumDefinition as queryparameter中提出了类似的问题。我的问题是我是否可以使用枚举(可重复使用或不可重复使用)。每当我尝试这样做时,我都会收到错误,但是使用字符串不会给出任何错误
\n/path/{protocol}:\n patch:\n summary:\n operationId:\n tags:\n parameters:\n - name: protocol\n in: path\n description: # some description\n required: true\n schema:\n $ref: "#/components/schemas/ProtocolType"\n\n ProtocolType:\n type: string\n default: abcd\n enum:\n - abcd\n - aaa\n - bbb\nRun Code Online (Sandbox Code Playgroud)\n我的问题是上面的例子是否有效或者我应该尝试哪些可能的改变。我正在使用 OpenAPI 3.0.0 。
\n错误:
\nCompilation errors in XX.client.cpp\nXX.client.cpp: In static member function \xe2\x80\x98static void \nXX::SendSetProtocolReqRequest(std::string, const \nXX::model::SetProtocolReq_Request*, \nHTTPRequestEventContext::Ptr, uint64_t, HTTPClient*, FSM*, Statistics*, \nstd::string, bool)\xe2\x80\x99:\nXX_Management.client.cpp:1822:33: error: no matching function for call to \n\xe2\x80\x98Json::ToValue(XX::model::XXEnumProtocolType*, \nframework::json::Value*)\xe2\x80\x99\n Json::ToValue(¶m, &value); \n …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) 我的目标是建立一个简单的 API,用于通过 Google Endpoints 上传文件。
这是我的简化 OpenAPI 规范,根据 Swagger 验证它是有效的:
swagger: "2.0"
info:
title: "JSON Ingester"
description: "Receive JSON files, transform and load them."
version: "1.0.0"
host: "project-id.appspot.com"
schemes:
- "https"
paths:
/uploadFile:
post:
operationId: uploadFile
consumes:
- multipart/form-data
parameters:
-
in: formData
name: upfile
type: file
description: file
responses:
200:
description: "File uploaded."
400:
description: "Error during file upload."
Run Code Online (Sandbox Code Playgroud)
我总是得到这个晦涩的错误消息:
user@cloudshell:~/google-cloud-json-ingester (project-id)$ gcloud endpoints services deploy ./openapi.yaml
ERROR: (gcloud.endpoints.services.deploy) INVALID_ARGUMENT: Cannot convert to service config.
'location: "openapi.yaml: Operation \'post\' …Run Code Online (Sandbox Code Playgroud) 我正在编写一些 PHP 中间件来将 Clockify 连接到 Xero。
这两个平台都提供精细的 REST API,因此我应该能够相对轻松地在两个平台之间移动数据。
Xero 为 PHP 提供了一个 API 客户端,所以我想看看 Clockify 是否也提供了,但没有找到任何东西。
然而,他们的文档看起来像是通过 Swagger / open api 生成的,这可以很容易地用于为各种语言创建客户端库。
我在网上找不到 Swagger JSON,因此联系了他们的支持团队并得到了以下答复:
我绝对明白为什么将 Clockify 与 Xero 连接起来会有用。不幸的是,这超出了我们作为支持代表的技术专业知识。
虽然我们无法向您提供 swagger 文件,您可以在 Stack Overflow 上发帖(带有标签 Clockify)以及您需要的任何相关详细信息,开发团队的人员可以尽快为您提供帮助。
所以我的问题是,您能否提供用于生成API 文档的Swagger 文件(或等效文件) ,以便可以自动化为任何语言编写客户端库?
我需要指定我的端点有一个必填字段、一个可选字段并对任意数量的字段开放(可以在不验证的情况下发送)。
对于例如端点/user
user_id: str, mandatory
timestamp_utc: timestamp, optional
..*accept_any_extra_fields**..
Run Code Online (Sandbox Code Playgroud)
因此,如果有人将以下 json 发送到我的端点,该端点应该接受它
{ "user_id": 1,
"name": "Sam",
"location": "USA"
}
Run Code Online (Sandbox Code Playgroud)
但如果发送以下 json 则失败,因为它不包含user_id.
{ "name": "Sam",
"location": "USA"
}
Run Code Online (Sandbox Code Playgroud)
它应该失败。
我是 OpenAPI/Swagger 的新手。我知道我可以发送额外的数据。但是我如何将其描述为 OpenAPI 上的文档,以便人(或程序)知道他们可以发送任何字段(例如名称、位置)以及user_id
我有 2 个应用程序,其中应用程序 A 公开 API 供应用程序 B 使用。
应用程序 A 正在为应用程序 B 生成 swagger.json,应用程序 B 正在使用 swagger-codegen 生成模型代码。
在我的应用程序 A 中,它使用 Jackson 和 WRAPPER_OBJECT 进行多态处理
@JsonTypeInfo (use = JsonTypeInfo.Id.NAME, include =
JsonTypeInfo.As.WRAPPER_OBJECT, property = "type")
@JsonSubTypes({@JsonSubTypes.Type(value = Dog.class, name = "doggy"),
@JsonSubTypes.Type(value = Cat.class, name = "kitty")})
@ApiModel(subTypes = {Dog.class, Cat.class}, discriminator = "type")
public abstract class Animal {
}
@ApiModel(value = "kitty", parent = Animal.class)
public class Cat extends Animal {
public int lives = 9;
}
@ApiModel(value …Run Code Online (Sandbox Code Playgroud) 是否可以在 openapi3.0/swagger 中将内联图像渲染为描述文本等的一部分?在查看规范时,我能找到的只是链接到请求示例中的图像的能力。我想要的是能够在我的 API 的介绍性文本中包含图表等,类似于 markdown 等。示例:
openapi: 3.0.2
info:
version: "1.0.0"
title: "My API"
description: "This API bla bla bla [block diagram] bla bla [another inline image]"
Run Code Online (Sandbox Code Playgroud)
这样的事有可能吗?
我有一个 Maven 项目,其中的 API 定义使用 OpenaAPI v3 规范。
我使用 openapi-generator-maven-plugin 生成代码,一切正常。我还可以访问 swagger-ui 并查看和测试我的 API。
问题是我不想两次维护版本号。因此,我想在 api 规范中引用我的 maven pom 中的版本号,而不是冒着过时风险进行复制。
我尝试过maven资源过滤,这似乎有效。由于当我将版本字段放入规范中时,目标文件夹中的 yaml 文件会被很好地替换${project.version},但是当我打开 swagger-ui 时,它会按字面意思打印“${project.version}”而不是实际版本。
这是我的 pom 中的插件配置:
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>${openapi-generator-maven-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.build.resources[0].directory}/spec.yml</inputSpec>
<ignoreFileOverride>${project.build.resources[0].directory}/.openapi-codegen-ignore</ignoreFileOverride>
<language>spring</language>
<library>spring-boot</library>
<configOptions>
<!-- Use the newer java.time package instead of outdated java.util-->
<dateLibrary>java8</dateLibrary>
</configOptions>
<apiPackage>${default.package}.api</apiPackage>
<modelPackage>${default.package}.model</modelPackage>
<invokerPackage>${default.package}.invoker</invokerPackage>
<generateApiTests>false</generateApiTests>
</configuration>
</execution>
</executions>
</plugin>
...
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
这是我的spec.yml:
openapi: 3.0.0
info: …Run Code Online (Sandbox Code Playgroud) 在 OpenAPI 3 中,是否可以在全局级别定义 SecurityScheme,然后在某些端点覆盖它以不使用安全性(对于公共可访问端点)?
例如(取自https://swagger.io/docs/specification/authentication/bearer-authentication/)
openapi: 3.0.0
...
# 1) Define the security scheme type (HTTP bearer)
components:
securitySchemes:
bearerAuth: # arbitrary name for the security scheme
type: http
scheme: bearer
bearerFormat: JWT # optional, arbitrary value for documentation purposes
# 2) Apply the security globally to all operations
security:
- bearerAuth: [] # use the same name as above
Run Code Online (Sandbox Code Playgroud)
然后使给定端点可公开访问(不受保护)
paths:
/unprotected/path:
get:
security: []
Run Code Online (Sandbox Code Playgroud)
或者应该以另一种方式完成?
更新这个问题被标记为重复,但另一个问题处理有关 Swagger 2.x 的问题,并且由于语法不同,我认为这个问题和答案应该保留。