Skip to content

Commit

Permalink
FINERACT-835: Complete work on automatically generating Swagger docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ptuomola authored and vorburger committed Jul 13, 2020
1 parent a440d56 commit acca72f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 55,433 deletions.
4 changes: 2 additions & 2 deletions fineract-provider/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,8 @@ dependencyManagement {
dependency 'com.github.spotbugs:spotbugs-annotations:4.0.6'
dependency 'javax.cache:cache-api:1.1.1'
dependency 'org.mock-server:mockserver-junit-jupiter:5.10.0'

// If this is upgraded, you need to change path in WebFrontEndConfiguration
dependency 'org.webjars.npm:swagger-ui-dist:3.28.0'
dependency 'org.webjars:webjars-locator-core:0.46'

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

// Configuration for JaCoCo code coverage task
Expand Down
16 changes: 16 additions & 0 deletions fineract-provider/config/swagger/fineract-input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"openapi" : "3.0.3",
"info": {
"version": "1.4.0",
"title": "Apache Fineract",
"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",
"termsOfService": "https://demo.fineract.dev/fineract-provider/api-docs/apiLive.htm",
"contact": {
"email": "[email protected]"
},
"license": {
"name": "Apache 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
}
}
}
3 changes: 2 additions & 1 deletion fineract-provider/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ dependencies {
'javax.cache:cache-api',

'com.github.spotbugs:spotbugs-annotations',
'io.swagger.core.v3:swagger-annotations'
'io.swagger.core.v3:swagger-annotations',
'org.webjars:webjars-locator-core'
)
implementation ('org.apache.activemq:activemq-broker') {
exclude group: 'org.apache.geronimo.specs'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,21 @@
*/
package org.apache.fineract.infrastructure.core.boot;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.webjars.WebJarAssetLocator;

@EnableWebMvc
@Configuration
public class WebFrontEndConfiguration implements WebMvcConfigurer {

private static final Logger LOG = LoggerFactory.getLogger(WebFrontEndConfiguration.class);

private static final String[] CLASSPATH_RESOURCE_LOCATIONS = { "classpath:/static/", "classpath:/public/" };

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

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

String[] SWAGGER_RESOURCE_LOCATIONS = { "classpath:/static/swagger-ui/", "classpath:" + fullPathToSwaggerUi };

registry.addResourceHandler("/swagger-ui/**").addResourceLocations(SWAGGER_RESOURCE_LOCATIONS);
}
Expand Down
Loading

5 comments on commit acca72f

@Grandolf49
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! I am working on a project that aims to build a Fineract Client SDK based on Java and Retrofit as mentioned by @vorburger in this comment.
Here is the link to my project.
I am using Swagger Codegen to generate the client SDK. Here is the script that generates the SDK.

Issue

As you can see, the generator script uses an API Specification JSON file which in my case was fineract-provider/src/main/resources/static/swagger-ui/response.json file.
In this commit, this file was deleted so I am unable to proceed with my project.
For temporary purposes, I used the previous commits and copied the response.json file to my personal Github Gist and will use that for now

Can you please let me know what is the plan for the API Specification response.json file?
Is it going to be permanently removed from the project or was it for a temporary purpose?

Thanks in advance!

@vorburger
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Grandolf49 it sounds like you have effectively started working on FINERACT-838, right? If that is so, could I suggest that you assign that issue to yourself, and we have this discussion over there, instead of here?

BTW I think it's great that you are experimenting with this in https://github.com/Grandolf49/fineract-client, but IMHO ultimately we (you or someone else, we can help!) should make that part of https://github.com/apache/fineract!

The reason that response.json was deleted from Git is FINERACT-835 - does that make sense? It's now generated at build time, as it should (much better). So you now need to git clone [email protected]:apache/fineract.git to grab the latest Fineract sources, build it using ./gradlew build, and you'll find it again in ./build/classes/java/main/static/swagger-ui/fineract.json. Alternatively, you could also just grab the latest live version from (my) https://demo.fineract.dev/fineract-provider/swagger-ui/fineract.json server (but only for your quick local testing; the final "real" solution in FINERACT-838 can't do that, but that would have to be properly fully integrated into the Gradle build - eventually).

@thesmallstar @ptuomola FYI...

@Grandolf49
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @vorburger! Yes, it looks like I am effectively working on FINERACT-838. The task of building the Fineract Client SDK is a part of my GSoC 2020 project. @droidchef is mentoring me on this task. Yes, we can have this discussion on Jira but I am unable to assign this issue to myself on Jira (probably because of permissions). Can you help me with this?

Once the process of SDK generation and creating releases is tested on https://github.com/Grandolf49/fineract-client we can move it to official repositories. The plan is to set up CircleCI on this repo and automate releases from CircleCI using Git Tagging. Here are more details on this: https://circleci.com/blog/publishing-to-github-releases-via-circleci/.

Yes, FINERACT-835 makes sense. Even I was wondering response.json should be created in runtime. Great! Thanks for clearing the process of how to generate the spec file in runtime. I'll update the Client Generator Script accordingly.

@vorburger
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am unable to assign this issue to myself on Jira (probably because of permissions). Can you help me with this?

I have just granted Contributor permission on the ASF JIRA to a Grandolf49, I hope that's you there as well (there are several other Chinmay Kulkarni in the system).

Once the process of SDK generation and creating releases is tested on https://github.com/Grandolf49/fineract-client we can move it to official repositories. The plan is to set up CircleCI on this repo and automate releases from CircleCI using Git Tagging. Here are more details on this: https://circleci.com/blog/publishing-to-github-releases-via-circleci/.

I would much prefer if, ultimately (easy, step by step) you would make a contribution for this to https://github.com/apache/fineract/ itself, and we would figure out together how release it from there; much better than a separate new repo just for this.

@Grandolf49
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I have assigned the issue to myself.

Please sign in to comment.