Skip to content

Commit ace9aee

Browse files
AXIS2-6100 Add REST support for OpenAPI (formerly known as Swagger)
1 parent e5348da commit ace9aee

File tree

34 files changed

+5351
-33
lines changed

34 files changed

+5351
-33
lines changed

modules/distribution/pom.xml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@
537537
<version>${castor.version}</version>
538538
</artifactItem>
539539
</artifactItems>
540-
<outputDirectory>${project.build.directory}/axis2-${project.version}/samples/databinding/lib</outputDirectory>
540+
<outputDirectory>${project.build.directory}/axis2-${project.version}/modules/samples/databinding/lib</outputDirectory>
541541
<overWriteReleases>false</overWriteReleases>
542542
</configuration>
543543
</execution>
@@ -561,18 +561,18 @@
561561
<ant dir="${project.build.directory}/axis2-${project.version}/webapp" useNativeBasedir="true" />
562562

563563
<!-- Test of the databinding sample -->
564-
<ant dir="${project.build.directory}/axis2-${project.version}/samples/databinding" />
565-
564+
<ant dir="${project.build.directory}/axis2-${project.version}/modules/samples/databinding" />
565+
566566
<!-- Test of the mtom sample -->
567-
<ant dir="${project.build.directory}/axis2-${project.version}/samples/mtom" target="generate.service" />
568-
<ant dir="${project.build.directory}/axis2-${project.version}/samples/mtom" target="generate.client" />
569-
567+
<ant dir="${project.build.directory}/axis2-${project.version}/modules/samples/mtom" target="generate.service" />
568+
<ant dir="${project.build.directory}/axis2-${project.version}/modules/samples/mtom" target="generate.client" />
569+
570570
<!-- Test of the faulthandling sample -->
571-
<ant dir="${project.build.directory}/axis2-${project.version}/samples/faulthandling" target="generate.service" />
572-
571+
<ant dir="${project.build.directory}/axis2-${project.version}/modules/samples/faulthandling" target="generate.service" />
572+
573573
<!-- Test of the json sample -->
574-
<ant dir="${project.build.directory}/axis2-${project.version}/samples/json" target="generate.service" />
575-
<ant dir="${project.build.directory}/axis2-${project.version}/samples/json" target="client.jar" />
574+
<ant dir="${project.build.directory}/axis2-${project.version}/modules/samples/json" target="generate.service" />
575+
<ant dir="${project.build.directory}/axis2-${project.version}/modules/samples/json" target="client.jar" />
576576
</target>
577577
</configuration>
578578
</execution>

modules/distribution/src/main/assembly/bin-assembly.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
<!-- copy samples -->
122122
<fileSet>
123123
<directory>../../modules/samples</directory>
124-
<outputDirectory>samples</outputDirectory>
124+
<outputDirectory>modules/samples</outputDirectory>
125125
<includes>
126126
<include>pom.xml</include>
127127
<include>databinding/**/*</include>
@@ -150,7 +150,8 @@
150150
<include>version/**/*</include>
151151
<include>wsdl/**/*</include>
152152
<include>yahoojsonsearch/**/*</include>
153-
<include>yahoorestsearch/**/*</include>
153+
<include>yahoorestsearch/**/*</include>
154+
<include>swagger-server/**/*</include>
154155
</includes>
155156
<excludes>
156157
<!-- The release process builds the binary distribution from a clean checkout,

modules/openapi/pom.xml

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one
4+
~ or more contributor license agreements. See the NOTICE file
5+
~ distributed with this work for additional information
6+
~ regarding copyright ownership. The ASF licenses this file
7+
~ to you under the Apache License, Version 2.0 (the
8+
~ "License"); you may not use this file except in compliance
9+
~ with the License. You may obtain a copy of the License at
10+
~
11+
~ http://www.apache.org/licenses/LICENSE-2.0
12+
~
13+
~ Unless required by applicable law or agreed to in writing,
14+
~ software distributed under the License is distributed on an
15+
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
~ KIND, either express or implied. See the License for the
17+
~ specific language governing permissions and limitations
18+
~ under the License.
19+
-->
20+
21+
<project xmlns="http://maven.apache.org/POM/4.0.0"
22+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
23+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
24+
http://maven.apache.org/xsd/maven-4.0.0.xsd">
25+
<modelVersion>4.0.0</modelVersion>
26+
27+
<parent>
28+
<groupId>org.apache.axis2</groupId>
29+
<artifactId>axis2</artifactId>
30+
<version>2.0.1-SNAPSHOT</version>
31+
<relativePath>../../pom.xml</relativePath>
32+
</parent>
33+
34+
<artifactId>axis2-openapi</artifactId>
35+
<name>Apache Axis2 - OpenAPI Integration Module</name>
36+
<packaging>jar</packaging>
37+
<description>
38+
OpenAPI/Swagger integration module for Apache Axis2, providing automatic API documentation
39+
generation and Swagger UI support for REST services.
40+
</description>
41+
42+
<dependencies>
43+
<!-- Axis2 Core Dependencies -->
44+
<dependency>
45+
<groupId>org.apache.axis2</groupId>
46+
<artifactId>axis2-kernel</artifactId>
47+
<version>${project.version}</version>
48+
</dependency>
49+
<dependency>
50+
<groupId>org.apache.axis2</groupId>
51+
<artifactId>axis2-transport-http</artifactId>
52+
<version>${project.version}</version>
53+
</dependency>
54+
55+
<!-- OpenAPI/Swagger Support -->
56+
<dependency>
57+
<groupId>io.swagger.core.v3</groupId>
58+
<artifactId>swagger-core</artifactId>
59+
<version>2.2.26</version>
60+
</dependency>
61+
<dependency>
62+
<groupId>io.swagger.core.v3</groupId>
63+
<artifactId>swagger-models</artifactId>
64+
<version>2.2.26</version>
65+
</dependency>
66+
<dependency>
67+
<groupId>io.swagger.core.v3</groupId>
68+
<artifactId>swagger-annotations</artifactId>
69+
<version>2.2.26</version>
70+
</dependency>
71+
72+
<!-- JSON Processing -->
73+
<dependency>
74+
<groupId>com.squareup.moshi</groupId>
75+
<artifactId>moshi</artifactId>
76+
<version>1.15.0</version>
77+
</dependency>
78+
79+
<!-- Jackson for OpenAPI model serialization (required by swagger-core) -->
80+
<dependency>
81+
<groupId>com.fasterxml.jackson.core</groupId>
82+
<artifactId>jackson-databind</artifactId>
83+
<version>2.15.2</version>
84+
</dependency>
85+
86+
<!-- Jakarta Servlet API -->
87+
<dependency>
88+
<groupId>jakarta.servlet</groupId>
89+
<artifactId>jakarta.servlet-api</artifactId>
90+
<scope>provided</scope>
91+
</dependency>
92+
93+
<!-- Logging (inherited from parent) -->
94+
<dependency>
95+
<groupId>commons-logging</groupId>
96+
<artifactId>commons-logging</artifactId>
97+
</dependency>
98+
99+
<!-- Testing -->
100+
<dependency>
101+
<groupId>junit</groupId>
102+
<artifactId>junit</artifactId>
103+
<scope>test</scope>
104+
</dependency>
105+
</dependencies>
106+
</project>
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.axis2.openapi;
21+
22+
import org.apache.axis2.AxisFault;
23+
import org.apache.axis2.context.ConfigurationContext;
24+
import org.apache.axis2.description.AxisDescription;
25+
import org.apache.axis2.description.AxisModule;
26+
import org.apache.axis2.modules.Module;
27+
import org.apache.commons.logging.Log;
28+
import org.apache.commons.logging.LogFactory;
29+
import org.apache.neethi.Assertion;
30+
import org.apache.neethi.Policy;
31+
32+
/**
33+
* Apache Axis2 OpenAPI/Swagger integration module.
34+
*
35+
* This module provides automatic OpenAPI specification generation and Swagger UI support
36+
* for Axis2 REST services. It integrates with the Axis2 transport layer to serve
37+
* OpenAPI documentation at standard endpoints.
38+
*
39+
* Key features:
40+
* - Automatic OpenAPI 3.0.1 specification generation from service metadata
41+
* - Swagger UI integration for interactive API documentation
42+
* - Support for REST service introspection and annotation processing
43+
* - Integration with Axis2's existing metadata query mechanisms
44+
*/
45+
public class OpenApiModule implements Module {
46+
47+
private static final Log log = LogFactory.getLog(OpenApiModule.class);
48+
49+
/**
50+
* Initialize the OpenAPI module.
51+
*
52+
* This method is called when the module is loaded and initializes the OpenAPI
53+
* integration components including specification generation and UI serving.
54+
*/
55+
@Override
56+
public void init(ConfigurationContext configContext, AxisModule module) throws AxisFault {
57+
log.info("Initializing Apache Axis2 OpenAPI module");
58+
59+
try {
60+
// Register OpenAPI specification generator
61+
OpenApiSpecGenerator specGenerator = new OpenApiSpecGenerator(configContext);
62+
configContext.setProperty("axis2.openapi.generator", specGenerator);
63+
64+
// Register Swagger UI handler
65+
SwaggerUIHandler uiHandler = new SwaggerUIHandler(configContext);
66+
configContext.setProperty("axis2.openapi.ui", uiHandler);
67+
68+
// Initialize OpenAPI service introspector
69+
ServiceIntrospector introspector = new ServiceIntrospector(configContext);
70+
configContext.setProperty("axis2.openapi.introspector", introspector);
71+
72+
log.info("OpenAPI module initialization completed successfully");
73+
74+
} catch (Exception e) {
75+
log.error("Failed to initialize OpenAPI module", e);
76+
throw new AxisFault("OpenAPI module initialization failed: " + e.getMessage(), e);
77+
}
78+
}
79+
80+
/**
81+
* Called when this module is engaged to a service or operation.
82+
*
83+
* This allows the module to customize behavior per service and validate
84+
* that the service is compatible with OpenAPI documentation generation.
85+
*/
86+
@Override
87+
public void engageNotify(AxisDescription axisDescription) throws AxisFault {
88+
String serviceName = axisDescription.getClass().getSimpleName();
89+
if (axisDescription instanceof org.apache.axis2.description.AxisService) {
90+
serviceName = ((org.apache.axis2.description.AxisService) axisDescription).getName();
91+
}
92+
93+
log.debug("OpenAPI module engaged to: " + serviceName);
94+
95+
// Validate that the service supports REST operations for OpenAPI generation
96+
if (axisDescription.getParameter("enableREST") == null) {
97+
log.warn("Service " + serviceName +
98+
" does not have REST enabled - OpenAPI documentation may be limited");
99+
}
100+
}
101+
102+
/**
103+
* Shutdown the OpenAPI module and clean up resources.
104+
*/
105+
@Override
106+
public void shutdown(ConfigurationContext configurationContext) throws AxisFault {
107+
log.info("Shutting down Apache Axis2 OpenAPI module");
108+
109+
try {
110+
// Clean up registered components
111+
configurationContext.removeProperty("axis2.openapi.generator");
112+
configurationContext.removeProperty("axis2.openapi.ui");
113+
configurationContext.removeProperty("axis2.openapi.introspector");
114+
115+
} catch (Exception e) {
116+
log.warn("Error during OpenAPI module shutdown", e);
117+
}
118+
}
119+
120+
/**
121+
* Policy assertion support - currently not implemented for OpenAPI.
122+
*/
123+
@Override
124+
public boolean canSupportAssertion(Assertion assertion) {
125+
return false;
126+
}
127+
128+
/**
129+
* Policy processing - currently not implemented for OpenAPI.
130+
*/
131+
@Override
132+
public void applyPolicy(Policy policy, AxisDescription axisDescription) throws AxisFault {
133+
// OpenAPI module does not currently support WS-Policy integration
134+
}
135+
}

0 commit comments

Comments
 (0)