From b58404be410db74e5891030a12c5d2ccb191f5ae Mon Sep 17 00:00:00 2001 From: Petri Tuomola Date: Sun, 3 May 2020 13:42:14 +0300 Subject: [PATCH] FINERACT-910: Serving apiDocs as part of the fineract-provider --- .github/PULL_REQUEST_TEMPLATE.MD | 2 +- fineract-provider/build.gradle | 1 + .../integrationtests/ApiDocsTest.java | 47 +++++++++++++++++++ .../core/boot/WebFrontEndConfiguration.java | 16 ++++--- .../resources/static/api-docs}/apiLive.htm | 0 .../resources/static/api-docs}/apidocs.css | 0 .../static/api-docs}/jquery-1.7.min.js | 0 7 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/ApiDocsTest.java rename {api-docs => fineract-provider/src/main/resources/static/api-docs}/apiLive.htm (100%) rename {api-docs => fineract-provider/src/main/resources/static/api-docs}/apidocs.css (100%) rename {api-docs => fineract-provider/src/main/resources/static/api-docs}/jquery-1.7.min.js (100%) diff --git a/.github/PULL_REQUEST_TEMPLATE.MD b/.github/PULL_REQUEST_TEMPLATE.MD index 7ba444e93..39568c5e8 100644 --- a/.github/PULL_REQUEST_TEMPLATE.MD +++ b/.github/PULL_REQUEST_TEMPLATE.MD @@ -8,7 +8,7 @@ Please make sure these boxes are checked before submitting your pull request - t - [ ] Coding conventions at https://cwiki.apache.org/confluence/display/FINERACT/Coding+Conventions have been followed. -- [ ] API documentation at https://github.com/apache/fineract/blob/develop/api-docs/apiLive.htm has been updated with details of any API changes. +- [ ] API documentation at fineract-provider/src/main/resources/static/api-docs/apiLive.htm has been updated with details of any API changes. - [ ] Integration tests have been created/updated for verifying the changes made. diff --git a/fineract-provider/build.gradle b/fineract-provider/build.gradle index fec5e5e33..6d0d15636 100644 --- a/fineract-provider/build.gradle +++ b/fineract-provider/build.gradle @@ -424,6 +424,7 @@ license { "**/package-info.java", "**/keystore.jks", "**/swagger-ui/**", + "**/api-docs/**", ]) strictCheck true } diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/ApiDocsTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/ApiDocsTest.java new file mode 100644 index 000000000..3faaffd1a --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/ApiDocsTest.java @@ -0,0 +1,47 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.integrationtests; + +import io.restassured.builder.RequestSpecBuilder; +import io.restassured.builder.ResponseSpecBuilder; +import io.restassured.http.ContentType; +import io.restassured.specification.RequestSpecification; +import io.restassured.specification.ResponseSpecification; +import org.apache.fineract.integrationtests.common.Utils; +import org.junit.Before; +import org.junit.Test; + +public class ApiDocsTest { + + private ResponseSpecification responseSpec; + private RequestSpecification requestSpec; + + @Before + public void setup() { + Utils.initializeRESTAssured(); + this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); + } + + @Test + public void testApiDocsAccess() { + Utils.performServerGet(requestSpec, responseSpec, "/fineract-provider/api-docs/apiLive.htm", null); + } + +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/boot/WebFrontEndConfiguration.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/boot/WebFrontEndConfiguration.java index 35663236c..06c6b9741 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/boot/WebFrontEndConfiguration.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/boot/WebFrontEndConfiguration.java @@ -27,11 +27,15 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Configuration public class WebFrontEndConfiguration implements WebMvcConfigurer { - @Override - public void addResourceHandlers(ResourceHandlerRegistry registry) { - registry.addResourceHandler("/apps/**").addResourceLocations("file:" + - System.getProperty("user.dir") + System.getProperty("file.separator") + - "apps" + System.getProperty("file.separator")); - } + private static final String[] CLASSPATH_RESOURCE_LOCATIONS = { + "classpath:/static/", "classpath:/public/" + }; + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + if (!registry.hasMappingForPattern("/**")) { + registry.addResourceHandler("/**").addResourceLocations( + CLASSPATH_RESOURCE_LOCATIONS); + } + } } diff --git a/api-docs/apiLive.htm b/fineract-provider/src/main/resources/static/api-docs/apiLive.htm similarity index 100% rename from api-docs/apiLive.htm rename to fineract-provider/src/main/resources/static/api-docs/apiLive.htm diff --git a/api-docs/apidocs.css b/fineract-provider/src/main/resources/static/api-docs/apidocs.css similarity index 100% rename from api-docs/apidocs.css rename to fineract-provider/src/main/resources/static/api-docs/apidocs.css diff --git a/api-docs/jquery-1.7.min.js b/fineract-provider/src/main/resources/static/api-docs/jquery-1.7.min.js similarity index 100% rename from api-docs/jquery-1.7.min.js rename to fineract-provider/src/main/resources/static/api-docs/jquery-1.7.min.js