我正在努力寻找一种解决方案,如何将多个 OpenApi v3 组件定义合并到一个文件中。
让我们想象一个情况:

blueprint.v1.yaml)。通常,我用来swagger-cli合并所有$ref依赖项,但现在不是这样,因为我无法引用整个组件/模式对象列表

swagger-cli bundle。所以,问题是 - 如何在我的blueprint.v1.yaml文件中重用已定义的组件块(名为 Components.v1.yaml 的文件)?
PS 每个components.v1.yaml看起来都是这样的:

例如,location-create-single.v1.yaml路径定义如下图所示。值得一提的是,所有这些都是$ref指components.v1.yaml文件。

对于我记录的旧 API 以便成功进行身份验证,我需要提供以下标头:
X-Access-Token: {token}
Accept: application/json; version=public/v2
Run Code Online (Sandbox Code Playgroud)
对于令牌部分,我需要通过以下方式记录它:
X-Access-Token: {token}
Accept: application/json; version=public/v2
Run Code Online (Sandbox Code Playgroud)
但是我如何记录这一点以进行身份验证,我需要提供Accept: application/json; version=public/v2. 标Accept头必须包含application/json; version=public/v2任何其他返回406 Not Acceptable标头。
Accept另外,具有值的标头application/json; version=public/v2应该在我的请求中。响应标头始终为application/json.
你知道我如何记录这一点吗?
我目前有名为 jwt 的 JWT 依赖项,它确保它在到达端点之前通过 JWT 身份验证阶段,如下所示:
sample_endpoint.py:
from fastapi import APIRouter, Depends, Request
from JWTBearer import JWTBearer
from jwt import jwks
router = APIRouter()
jwt = JWTBearer(jwks)
@router.get("/test_jwt", dependencies=[Depends(jwt)])
async def test_endpoint(request: Request):
return True
Run Code Online (Sandbox Code Playgroud)
以下是使用 JWT 对用户进行身份验证的 JWT 依赖项(来源:https ://medium.com/datadriveninvestor/jwt-authentication-with-fastapi-and-aws-cognito-1333f7f2729e ):
JWTBearer.py
from typing import Dict, Optional, List
from fastapi import HTTPException
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
from jose import jwt, jwk, JWTError
from jose.utils import base64url_decode
from pydantic import BaseModel
from starlette.requests import Request …Run Code Online (Sandbox Code Playgroud) 我有以下架构定义:
swagger: '2.0'
...
definitions:
Service:
type: object
properties:
serviceId:
type: string
description: Device or service identification number
example: 1111111111
location:
type: string
description: Location of the service
example: '400 Street name, City State postcode, Country'
Run Code Online (Sandbox Code Playgroud)
我想对location已弃用的字段进行注释。有没有办法做到这一点?
definitionsSwagger 2.0中的全局部分和部分有什么区别components?
我遇到了一个 Swagger 定义 YAML 文件,该文件标记为swagger: '2.0'. 它有一个名为definitions下面的部分parameters。这类似于
https://swagger.io/docs/specification/2-0/basic-struct/
的“输入和输出模型”部分中描述的内容。
此外,在文件的更下方,它还包含下面的部分components。这与https://swagger.io/docs/specification/components/schemas中描述的类似,
这看起来像 OAS3。
但是,这个特定的 YAML 文件具有两个部分。我不确定是否definitions适用于 Swagger 2.0 和components是否schemas适用于 OAS 3.0。是这样吗?
和 可以definitions在components同一类型的 YAML 文件中使用吗swagger: '2.0'?或者我们应该坚持使用definitionsor 吗components?
# definitions section looks like this
definitions:
User:
properties:
id:
type: integer
name:
type: string
# Both properties are required
required:
- …Run Code Online (Sandbox Code Playgroud) 使用以下内容定义通用 API 信息的文档quarkus-smallrye-openapi非常稀疏,并且没有解释如何使用所有注释来设置 openApi 生成。
对于某些背景,我使用1.0.1.FINAL从 生成的一个干净且大部分为空的项目(quarkus 版本)code.quarkus.io,其单个类定义如下(带有尝试的@OpenAPIDefinition注释):
@OpenAPIDefinition(
info = @Info(
title = "Custom API title",
version = "3.14"
)
)
@Path("/hello")
public class ExampleResource {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
return "hello";
}
}
Run Code Online (Sandbox Code Playgroud)
经过大量挖掘,我最终发现一般 api 信息(联系信息、版本等)是使用注释定义的@OpenAPIDefinition,但是当在我现有的端点定义上使用时,不会对生成的 openapi 规范进行任何更改。我究竟做错了什么?
我希望 OpenAPI 生成器(https://github.com/OpenAPITools/openapi-generator)能够根据 Spring Boot Data 中的实现在 API 中生成 Pageable 参数。我一直在尝试寻找一种合适的开箱即用的解决方案,但找不到。
理想情况下,此 Pageable 参数应仅按以下方式添加到 GET 方法:
default ResponseEntity<User> getUser(@ApiParam(value = "value",required=true) @PathVariable("id") Long id, **Pageable pageable**)
Run Code Online (Sandbox Code Playgroud)
因此,在我的控制器中实现此接口后,我需要重写它并具有上述的 Pageable 参数。我不想有单独的大小或页面参数,这里只有这个可分页。
感谢您的任何提示和帮助!
我有一个 HTTP 302(重定向),我实现了一个新的状态参数,该参数将附加到RedirectURL,因此可以显示类似的消息
如果调用 URL 传递为
GET http://localhost:8080/info/status?redirectUrl=http://localhost:8080/redirect
Run Code Online (Sandbox Code Playgroud)
然后它会重定向为
GET http://localhost:8080/info/status?redirectUrl=http://localhost:8080/redirect
Run Code Online (Sandbox Code Playgroud)
它是对应的
http://localhost:8080/redirect?status=success
Run Code Online (Sandbox Code Playgroud)
但是 OpenAPI 规范中如何描述这一点呢?parameters我似乎无法在响应中使用,并找到了一些使用的代码responseParameters,但我没有运气让它工作......甚至不知道它是否受支持,至少,我没有编译错误与这两个命令
http://localhost:8080/redirect?status=error
Run Code Online (Sandbox Code Playgroud)
出现这种情况的常见方式是什么?
我们应该有 2 个重定向 URL,例如
GET http://localhost:8080/info/status
?redirectUrl=http://localhost:8080/redirect
&errorUrl=http://localhost:8080/redirect_error
Run Code Online (Sandbox Code Playgroud)
我对这个简单的困境有点茫然,也许有人可以帮助
我使用OpenApi Generator为我的 Angular 项目创建服务和模型。
这是我的 Json 的示例:
"uploadDate" : {
"type" : "string",
"description" : "Data caricamento",
"format" : "date-time"
},
Run Code Online (Sandbox Code Playgroud)
当我生成文件时,uploadDate 被转换为字符串而不是日期。
看:
/**
* Data caricamento
*/
uploadDate?: string;
Run Code Online (Sandbox Code Playgroud)
有没有办法添加配置并创建以日期为类型且格式为日期时间的模型?
这是我用来启动生成的脚本:
"generate": "openapi-generator-cli generate -g typescript-angular -i openapi.json -o ./generated-sources/client"
Run Code Online (Sandbox Code Playgroud) 我正在尝试运行 OpenAPI 生成器,但我不断收到一条没有意义的错误消息。
Failed to execute goal org.openapitools:openapi-generator-maven-plugin:5.0.0-SNAPSHOT:generate (default-cli) on project miguelmunoz.challenge: The parameters 'inputSpec' for goal org.openapitools:openapi-generator-maven-plugin:5.0.0-SNAPSHOT:generate are missing or invalid
问题是我的inputSpec值指向有效的 .yaml 文件。该文件位于src/main/resources/yaml/pizzeria.yaml,我使用复制和粘贴来确保该路径中没有拼写错误。您可以在https://github.com/SwingGuy1024/OpenAPI_inputSpec_Bug下载最小可重现测试用例。
这是我的插件规范:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<!-- RELEASE_VERSION -->
<version>5.0.0-SNAPSHOT</version>
<!-- /RELEASE_VERSION -->
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<!-- General Configuration properties taken from -->
<!-- https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator-maven-plugin/README.md -->
<!--Changed to https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator-maven-plugin-->
<!-- Modifications from /sf/ask/4501283461/#64363872 -->
<ignoreFileOverride>${project.basedir}/my-springboot.ignores</ignoreFileOverride> <!--Added-->
<inputSpec>${project.basedir}/src/main/resources/yaml/pizzeria.yaml</inputSpec>
<!--the language tag was replaced by the generatorName tag:-->
<generatorName>spring</generatorName>
<!--<templateDirectory>${project.basedir}/src/gen/templates/</templateDirectory>--> …Run Code Online (Sandbox Code Playgroud) openapi ×10
java ×2
swagger ×2
swagger-2.0 ×2
angular ×1
annotations ×1
fastapi ×1
jpa ×1
jwt ×1
oauth ×1
python ×1
quarkus ×1
redirect ×1
spring ×1
typescript ×1