我在这里阅读以下内容:
Swagger目前不包含从客户端或服务器角度支持多个API版本的建议 - 声明版本信息(规范和底层API实现).
我想知道的是如何配置swagger UI来显示多个服务的API,即驻留在不同服务器上的服务.我尝试在另一台服务器上配置swagger UI,但是我收到以下错误:
无法从服务器读取.它可能没有适当的访问控制原点设置.
我已经阅读了关于在服务器上启用CORS的内容,但是在我的情况下,由于服务在自由配置文件上运行,因此无效.
Swagger UI在WAS的本地运行的自由配置文件上配置,并且服务在不同的WAS实例上运行.
我要移动的方向是拥有多个服务的UI,但我认为这是一个合乎逻辑的起点.
我的问题与以下问题相同;
Jackson POJOPropertyBuilder在POJO中找到多个setter
但是,因为我使用"springfox-swagger2",我不使用SwaggerSpringMvcPlugin.
有没有办法解决这个问题?
Application.java
/* Makes this Application Run as Spring Boot Application */
@SpringBootApplication
/* Enables Swagger2API for documentation */
@EnableSwagger2
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
LogService.info(Application.class.getName(), "CustomerAPI Service Started");
}
@Bean
public Docket customerApi() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("Customer Application")
.apiInfo(apiInfo())
.select()
.paths(myAppPaths())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Customer API")
.description("Some Description to Show")
.termsOfServiceUrl(null)
.contact("Test Test")
.license("Apache License Version 2.0") …Run Code Online (Sandbox Code Playgroud) 我使用Swagger(Swashbuckle)作为Web API项目的文档工具.我可以使用自定义的css文件自定义index.html.一切都很好,除了,我想在索引页面添加我们公司的特定徽标,我无法让它工作.
建议??
我正在尝试使用几个简单的控制器创建一个WebApi项目.如果我使用fiddler调用方法一切都很好,但我更喜欢使用swashbuckle,因为它有点漂亮.
但是,使用默认配置安装swashbuckle时它无法正常工作.
当我导航到 http:// localhost/api/mycontroller/swagger时
它重定向到 http:// localhost/api/mycontroller/swagger/ui/index
但是它只显示以下错误:
<错误>
<消息>
未找到与请求URI" http:// localhost/api/Management/swagger/ui/index " 匹配的HTTP资源.
</ Message>
<MessageDetail>
未找到与名为'swagger'的控制器匹配的类型.</ MessageDetail>
</ Error>
我的路由如下:config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
Run Code Online (Sandbox Code Playgroud) 有没有一种方法可以“聚合”(或至少链接到)多个Swagger API以在单个UI上显示?
假设我有两个服务Foo和Bar,我要做的是制作第三个服务Baz,它提供Foo和Bar的元数据。Foo,Bar和Baz将位于不同的主机上,这就是为什么我不确定是否可能的原因。
一种解决方案是使用服务发现的思想(在这种情况下可能不是正确的术语),并在执行GET时让Baz提供指向Foo和Bar的链接。
GET / HTTP/1.1
Host: baz
Accept: application/json
...
Run Code Online (Sandbox Code Playgroud)
HTTP/1.1 200 OK
Content-Type: application/json
...
{
"services": [
{
"name": "foo",
"link": "http://foo"
},
{
"name": "bar",
"link": "http://bar"
}
]
}
Run Code Online (Sandbox Code Playgroud)
这就是我通常会采用的方式,但是我想知道是否有办法让Baz上的Swagger UI显示Foo和Bar的UI。
spring spring-mvc documentation-generation swagger-ui springfox
我们有一个 Asp.Net Core 2.0 Web 服务,我们将其部署在 Docker 容器中。
对于 Web 服务,我们生成一个 xml 文档文件,并在 Swagger-ui 中使用该文件。这适用于从项目本身生成的 xml 文档,但是当 Web 服务部署在 Docker 容器中时,我无法获得为可见的包含包生成的 xml 注释。
nuget 包(也由我们创建)确实包含一个 xml 文档文件,我们可以让 swagger 在本地机器上运行服务时使用它。通过调用 .IncludeXmlComments 使文档可用于 swagger,并且文档的路径是通过获取程序集的路径然后用 .xml 替换 .dll 扩展名来确定的。
我怀疑该包的xml doc文件未包含在容器中,因此无法找到。在 Dockerfile 我看到命令
COPY publish .
Run Code Online (Sandbox Code Playgroud)
我想要一个还添加/复制包的 xml doc 文件的命令,或者知道如何使 xml doc 文件成为发布资产的一部分。任何其他能够以稳健的方式(不仅仅是在我的机器上)进行这项工作的解决方案也是受欢迎的。
编辑:我们现在在 Docker 容器中有额外的 xml doc 文件,但 Swagger 仍然没有显示该文件中提供的描述(它在本地运行时会显示)。我们使用了类似的东西:
<Target Name="PrepublishScript" BeforeTargets="PrepareForPublish">
<ItemGroup>
<DocFile Include="$(USERPROFILE)\.nuget\packages\{packagename}\**\lib\$(TargetFramework)\{PackageName}.xml" />
</ItemGroup>
<Copy SourceFiles="@(DocFile)" DestinationFolder="$(PublishDir)" SkipUnchangedFiles="false" />
</Target>
Run Code Online (Sandbox Code Playgroud)
其中 {PackageName} 应替换为您的包的实际名称。路径中的通配符使其版本独立(尽管我们现在必须检查这是否会导致问题,因为我们有多个版本)。
我们在Swagger项目中使用Web API 2。我的问题是,当Microsoft.AspNet.WebApi.Versioning应用如下:
该扬鞭UI被忽略的事实是,现在我在的API,它需要提供具有版本。
我看了几个例子,但似乎没有一个能以令人满意的方式解决这个问题。
如何强制 Swagger 让我添加 API 版本或仅将版本号自动添加到 URL?
到目前为止的 Swagger 配置:
GlobalConfiguration.Configuration
.EnableSwagger(c =>
{
c.SingleApiVersion("v1", "MoovShack.ServerApi");
// If your API has multiple versions, use "MultipleApiVersions" instead of "SingleApiVersion".
// In this case, you must provide a lambda that tells Swashbuckle which actions should be
// included in the docs for a given API version. Like "SingleApiVersion", each call to "Version"
// returns an "Info" builder so you can …Run Code Online (Sandbox Code Playgroud) 我正试图让swagger UI与我的服务一起工作.我正在使用spring boot 2.0和Java 9.为swagger添加了以下依赖项
compile('io.springfox:springfox-swagger2:2.8.0')
compile('io.springfox:springfox-swagger-ui:2.8.0')
Run Code Online (Sandbox Code Playgroud)
招摇是按照它应该配置的
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
}
Run Code Online (Sandbox Code Playgroud)
编译得很好,但是当我使用BootRun命令启动应用程序时,它失败了:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xmlModelPlugin': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [springfox.documentation.schema.XmlModelPlugin] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@4f8e5cde]
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlType
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
... 25 common frames omitted
Run Code Online (Sandbox Code Playgroud)
可能是什么问题呢?与Java9不兼容?然后我能以某种方式使它工作吗?
我大胆地从事多种微服务的工作。部署到Azure时,由于安全最佳实践,我们需要一起删除所有选项。使用.net core 2.1查找定义示例。
swagger-ui ×10
swagger ×6
spring ×2
spring-boot ×2
swagger-2.0 ×2
swashbuckle ×2
c# ×1
docker ×1
java ×1
java-8 ×1
java-9 ×1
rest ×1
spring-mvc ×1
springfox ×1