オールド・エンジニア:
私は、私たちのAPIのドキュメントとしてYAMLファイル(OpenAPIの3.0.0形式)を作成しました。私は、アプリケーションが実行されているURLでこの(静的)威張っ-UI YAMLファイルを、表示したいと思います。何かのようにhttp:// localhost:8080 /威張っ-UI。どこが(同じYAMLファイルのグラフィカルな表現が表示され、ここに)。YAMLファイルは、プロジェクト内のルートフォルダに置かれています。
私はMavenのビルドで、Javaの11、springboot 2.1.5上でアプリケーションを実行しています。
私が使用してコードから闊歩のYAMLを生成してみました
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
しかし、この1は(行方不明のデフォルト値、説明...)完璧ではありません
私が試した春の静的リソースをなし成功を収めて。問題は、YAMLファイルはHTMLではないということです。
別の方法は、APIドキュメントを表示する方法、(多分よりよい)ありますか?
オールド・エンジニア:
私たちは、@Configugarionクラスを使用してこのタスクを完了することができました
@Configuration
public class SwaggerConfiguration implements WebMvcConfigurer {
private final String swaggerUILocation = "whatEverLocationYouWant";
private final String swaggerApiDocsLocation = "whatEverLocationYouWant";
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler(swaggerUILocation + "**")
.addResourceLocations("classpath:/swagger-ui/");
registry.addResourceHandler(swaggerApiDocsLocation + "**")
.addResourceLocations("classpath:/swagger/");
}
}
その後、我々は、闊歩-UIのjarファイルを使用したindex.htmlここでは、ファイル内の1行を置換するフォルダやリソースにそれをunziped:
<script>
window.onload = function () {
// Begin Swagger UI call region
const ui = SwaggerUIBundle({
url: "placeHereExactLinkToYourYamlFile",
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
})
// End Swagger UI call region
window.ui = ui
}
</script>
闊歩のHTMLが表示され、次のアプリケーションに取り組んでいます。