Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Swagger 2 #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions onebusaway-api-webapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@

<dependencies>

<!-- SWAGGER2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox-version}</version>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox-version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>

<dependency>
<groupId>org.onebusaway</groupId>
<artifactId>onebusaway-agency-metadata</artifactId>
Expand All @@ -31,6 +49,11 @@
<artifactId>onebusaway-transit-data-federation</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.onebusaway</groupId>
<artifactId>onebusaway-transit-data-federation-webapp</artifactId>
<version>2.1.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.onebusaway</groupId>
<artifactId>onebusaway-presentation</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.onebusaway.api.configs;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
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 springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
@EnableWebMvc
public class SpringFoxConfig implements WebMvcConfigurer {
private final String baseUrl = "http://localhost:9090/oba-api";

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
String baseUrl = StringUtils.trimTrailingCharacter(this.baseUrl, '/');
registry.
addResourceHandler(baseUrl + "/swagger-ui/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/")
.resourceChain(false);
}

@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController(baseUrl + "/swagger-ui/")
.setViewName("forward:" + baseUrl + "/swagger-ui/index.html");
}

@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.apiInfo(apiInfo());

}

private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("OBA")
.description("Api Services")
.version("2.1.2")
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright (C) 2011 Brian Ferris <bdferris@onebusaway.org>

Licensed 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.

-->
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">

<context:component-scan base-package="org.onebusaway.api.configs, org.onebusaway.transit_data_federation_webapp.controllers" />

<mvc:resources mapping="/swagger-ui/**" location="classpath:/META-INF/resources/webjars/springfox-swagger-ui/"/>

<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/swagger-ui/**"/>
<mvc:mapping path="/v2/api-docs/**"/>
<bean class="org.onebusaway.api.configs.SpringFoxConfig"/>
</mvc:interceptor>
</mvc:interceptors>

<mvc:annotation-driven/>

</beans>
71 changes: 71 additions & 0 deletions onebusaway-api-webapp/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,75 @@
<welcome-file>index.html</welcome-file>
</welcome-file-list>

<servlet>
<servlet-name>swagger</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:org/onebusaway/api/swagger-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>swagger</servlet-name>
<url-pattern>/swagger-ui.html</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>swagger</servlet-name>
<url-pattern>/swagger-ui.index.html</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>swagger</servlet-name>
<url-pattern>/swagger-ui/springfox.css</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>swagger</servlet-name>
<url-pattern>/swagger-ui/springfox.js</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>swagger</servlet-name>
<url-pattern>/swagger-ui/swagger-ui.css</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>swagger</servlet-name>
<url-pattern>/swagger-ui/swagger-ui.js</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>swagger</servlet-name>
<url-pattern>/swagger-ui/swagger-ui-bundle.js</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>swagger</servlet-name>
<url-pattern>/swagger-ui/swagger-ui-standalone-preset.js</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>swagger</servlet-name>
<url-pattern>/v2/api-docs</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>swagger</servlet-name>
<url-pattern>/swagger-resources</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>swagger</servlet-name>
<url-pattern>/swagger-resources/configuration/ui</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>swagger</servlet-name>
<url-pattern>/swagger-resources/configuration/security</url-pattern>
</servlet-mapping>

</web-app>
2 changes: 1 addition & 1 deletion onebusaway-gtfs-realtime-model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<dependency>
<groupId>org.onebusaway</groupId>
<artifactId>onebusaway-container</artifactId>
<version>2.1.1-SNAPSHOT</version>
<version>2.1.2-SNAPSHOT</version>
</dependency>

<dependency>
Expand Down
13 changes: 13 additions & 0 deletions onebusaway-transit-data-federation-webapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>

<!-- SWAGGER2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox-version}</version>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox-version}</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@

-->
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:sec="http://www.springframework.org/schema/security"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:sec="http://www.springframework.org/schema/security"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<wiki_integration_version>1.0.0</wiki_integration_version>
<slf4j.version>1.7.5</slf4j.version>
<guava-version>16.0.1</guava-version>
<springfox-version>2.9.2</springfox-version>
<!-- These properties are primarily used in configuring joint integration tests -->
<org_onebusaway_test_port>9900</org_onebusaway_test_port>
<org_onebusaway_test_ajp_port>9901</org_onebusaway_test_ajp_port>
Expand Down
Loading