我想知道 Swagger 中是否有一个选项可以授权对包含外部文档的 url 的请求。
我有以下配置,我感兴趣的是urls[1]部分
springdoc.swagger-ui.urls[0].url=/v3/api-docs
springdoc.swagger-ui.urls[0].name=default
springdoc.swagger-ui.urls[1].url=https://asdasd.blob.core.windows.net/my-api/docs.spec
springdoc.swagger-ui.urls[1].name=additional
Run Code Online (Sandbox Code Playgroud)
我可以从服务器(直接从机器上curl)访问文档,但是从Swagger(因此浏览器)我不能。我想知道是否有一个选项可以添加例如。Authorization Bearer xxxx对此请求或实际上使服务器发出请求,而不是客户端。
为了澄清 -我想从远程服务器获取带有 OpenAPI 定义的第二个文件,所以我正在谈论这个:

我实施的解决方案:
海伦指出的可行 - 拦截请求并添加标头 - 但不幸的是,在我的情况下,还存在与存储的防火墙设置有关的问题。只有来自服务器的流量,而不是客户端(浏览器)通过,所以我:
springdoc.swagger-ui.urls[1].url=v3/api-docs/additionalmydomain.swagger-ui.additionalDocsUrl=...@Hidden
@RestController
@RequestMapping("/v3/api-docs/additional")
@RequiredArgsConstructor
public class AdditionalOpenApiController {
@Value("${mydomain.swagger-ui.additionalDocsUrl}")
private String additionalDocsUrl;
@Cacheable(value = "ADDITIONAL_API_DOCS", unless = "#result != null")
@GetMapping(produces = "application/json")
public String getAdditionalDocs() {
// in my case remote produces application/octet-stream …Run Code Online (Sandbox Code Playgroud) 我想在编译时使用 Maven 插件从现有的 Spring(注意:不是引导)应用程序源生成 OpenApi 3.0 定义。
我在控制器类中设置io.swagger.v3.oas.annotations如下:
package com.acme.rest;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
@Tag(name = "Dummy Controller", description = "Dummy controller.")
@RestController
@RequestMapping("/api/v1/dummy")
public class DummyController {
@Operation(summary = "dummy(). Does litrally nothing.")
@RequestMapping(value = "/", method = RequestMethod.GET)
public String doStuff() {
return "dummy";
}
}
Run Code Online (Sandbox Code Playgroud)
<plugin>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-maven-plugin</artifactId>
<version>2.2.0</version>
<configuration>
<outputPath>${project.build.directory}/swagger-def</outputPath>
<resourcePackages>com.acme</resourcePackages>
<prettyPrint>true</prettyPrint>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>resolve</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
但是除了openapi版本之外我什么也没得到。
mvn clean compile,产生:
{
"openapi" : …Run Code Online (Sandbox Code Playgroud) 我尝试以异步方式从串行端口读取数据,请记住操作所花费的时间不得超过指定的时间段。我使用的代码:
private async Task<int> Read(byte[] buffer, int offset, int length)
{
Console.WriteLine("Reading response to buffer of size {0}, offset {1}, max to cnt {2}", buffer.Length, offset, length);
int totalBytesRead = 0;
Console.WriteLine("Begin reading...");
while (true)
{
Console.WriteLine("Re-entering read");
int bytesRead = 0;
using (CancellationTokenSource cts = new CancellationTokenSource(new TimeSpan(0, 0, 0, 0, 333))) // 333 ms
{
Console.WriteLine("Waiting for read to complete...");
int tmpOffset = offset + totalBytesRead;
int tmpLength = length - totalBytesRead;
Console.WriteLine("tmpOffset: {0}, tmpLength: {1}", tmpOffset, tmpLength); …Run Code Online (Sandbox Code Playgroud) swagger ×2
c# ×1
java ×1
maven ×1
openapi ×1
serial-port ×1
spring ×1
spring-boot ×1
springdoc ×1