Skip to content

Commit acca72f

Browse files
ptuomolavorburger
authored andcommitted
FINERACT-835: Complete work on automatically generating Swagger docs
1 parent a440d56 commit acca72f

File tree

5 files changed

+31
-55433
lines changed

5 files changed

+31
-55433
lines changed

fineract-provider/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,8 @@ dependencyManagement {
124124
dependency 'com.github.spotbugs:spotbugs-annotations:4.0.6'
125125
dependency 'javax.cache:cache-api:1.1.1'
126126
dependency 'org.mock-server:mockserver-junit-jupiter:5.10.0'
127-
128-
// If this is upgraded, you need to change path in WebFrontEndConfiguration
129127
dependency 'org.webjars.npm:swagger-ui-dist:3.28.0'
128+
dependency 'org.webjars:webjars-locator-core:0.46'
130129

131130
dependency ('org.dom4j:dom4j:2.1.3') {
132131
exclude 'relaxngDatatype:relaxngDatatype' // already in com.sun.xml.bind:jaxb-osgi:2.3.0.1
@@ -201,6 +200,7 @@ resolve {
201200
prettyPrint = 'TRUE'
202201
classpath = sourceSets.main.runtimeClasspath
203202
outputDir = file("${buildDir}/classes/java/main/static/swagger-ui")
203+
openApiFile = file("config/swagger/fineract-input.json")
204204
}
205205

206206
// Configuration for JaCoCo code coverage task
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"openapi" : "3.0.3",
3+
"info": {
4+
"version": "1.4.0",
5+
"title": "Apache Fineract",
6+
"description": "Apache Fineract is a secure, multi-tenanted microfinance platform\n\nThe goal of the Apache Fineract API is to empower developers to build apps on top of the Apache Fineract Platform<br>The [reference app](https://cui.fineract.dev) (username: mifos, password: password) works on the same demo tenant as the interactive links in this documentation\n\n- The API is organized around [REST](https://en.wikipedia.org/wiki/Representational_state_transfer)\n- Find out more about Apache Fineract [here](/fineract-provider/api-docs/apiLive.htm#top)\n- You can [Try The API From Your Browser](/fineract-provider/api-docs/apiLive.htm#interact)\n- The Generic Options are available [here](/fineract-provider/api-docs/apiLive.htm#genopts)\n- Find out more about [Updating Dates and Numbers](/fineract-provider/api-docs/apiLive.htm#dates_and_numbers)\n- For the Authentication and the Basic of HTTP and HTTPS refer [here](/fineract-provider/api-docs/apiLive.htm#authentication_overview)\n- Check about ERROR codes [here](/fineract-provider/api-docs/apiLive.htm#errors)\n\nPlease refer to the [old documentation](/fineract-provider/api-docs/apiLive.htm) for any documentation queries",
7+
"termsOfService": "https://demo.fineract.dev/fineract-provider/api-docs/apiLive.htm",
8+
"contact": {
9+
"email": "[email protected]"
10+
},
11+
"license": {
12+
"name": "Apache 2.0",
13+
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
14+
}
15+
}
16+
}

fineract-provider/dependencies.gradle

+2-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ dependencies {
7979
'javax.cache:cache-api',
8080

8181
'com.github.spotbugs:spotbugs-annotations',
82-
'io.swagger.core.v3:swagger-annotations'
82+
'io.swagger.core.v3:swagger-annotations',
83+
'org.webjars:webjars-locator-core'
8384
)
8485
implementation ('org.apache.activemq:activemq-broker') {
8586
exclude group: 'org.apache.geronimo.specs'

fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/boot/WebFrontEndConfiguration.java

+11-3
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,21 @@
1818
*/
1919
package org.apache.fineract.infrastructure.core.boot;
2020

21+
import org.slf4j.Logger;
22+
import org.slf4j.LoggerFactory;
2123
import org.springframework.context.annotation.Configuration;
2224
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
2325
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
2426
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
2527
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
28+
import org.webjars.WebJarAssetLocator;
2629

2730
@EnableWebMvc
2831
@Configuration
2932
public class WebFrontEndConfiguration implements WebMvcConfigurer {
3033

34+
private static final Logger LOG = LoggerFactory.getLogger(WebFrontEndConfiguration.class);
35+
3136
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = { "classpath:/static/", "classpath:/public/" };
3237

3338
@Override
@@ -36,9 +41,12 @@ public void addResourceHandlers(ResourceHandlerRegistry registry) {
3641
registry.addResourceHandler("/**").addResourceLocations(CLASSPATH_RESOURCE_LOCATIONS);
3742
}
3843

39-
// TODO: The below path should be version agnostic
40-
String[] SWAGGER_RESOURCE_LOCATIONS = { "classpath:/static/swagger-ui/",
41-
"classpath:/META-INF/resources/webjars/swagger-ui-dist/3.26.0/" };
44+
WebJarAssetLocator locator = new WebJarAssetLocator();
45+
String fullPathToSwaggerUiJs = locator.getFullPath("swagger-ui.js");
46+
LOG.info("Found Swagger UI at {}", fullPathToSwaggerUiJs);
47+
String fullPathToSwaggerUi = fullPathToSwaggerUiJs.substring(0, fullPathToSwaggerUiJs.lastIndexOf("/") + 1);
48+
49+
String[] SWAGGER_RESOURCE_LOCATIONS = { "classpath:/static/swagger-ui/", "classpath:" + fullPathToSwaggerUi };
4250

4351
registry.addResourceHandler("/swagger-ui/**").addResourceLocations(SWAGGER_RESOURCE_LOCATIONS);
4452
}

0 commit comments

Comments
 (0)