由于在本地生成swagger json大约需要3秒(由于在dotnet中的反射(,我尝试实现以下内容:
- swagger ui中使用的swagger.json应该位于CDN服务器上,这样它就不会在运行时生成。它是在构建时通过cli生成的
- 当我使用swagger ui进行调用时,基本url当然不应该是这个cdn位置,而是一个相对位置
这是不起作用的:
var cdnPath = https://linktomycdn.com/staticswaggerstore
app.UseSwagger(c => c.SerializeAsV2 = true);
string swaggerUrl = $"{cdnPath}/swagger-{Version}.json";
app.UseSwaggerUI(options =>
{
options.SwaggerEndpoint(swaggerUrl, $"My API v{Version}");
options.OAuthClientId($"{config.ClientAuthConfig.JwtClientId}");
options.OAuthAppName($"{config.ClientAuthConfig.JwtClientApp}");
});
发生的情况是,服务器正确地加载了json文件(我使用swaggercli工具创建了该文件(,但当我尝试使用swagger-ui进行调用时,它使用cdnpath作为基础以便不进行任何调用。
我可以";拆分";swagger.json的位置和实际终点?
我通过生成带有特定--host标志的json文件来实现它
例如
dotnet swagger tofile --serializeasv2 --host mycoolapi.com --output .swagger-1.0.0.json /app/MyDll.dll v1.0.0
所以现在我的API正在使用https://mycoolapi.com作为主机,但json位于我的CDN上https://linktomycdn.com/staticswaggerstore.这在C#代码中配置为SwaggerEndpoint
请确保不要在--host参数中提供架构(https(