mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-05-12 20:50:55 +00:00
Move online gen from jersey to spring boot (#44)
This commit is contained in:
parent
803821e210
commit
8dd46a3fb9
23
modules/openapi-generator-online/.openapi-generator-ignore
Normal file
23
modules/openapi-generator-online/.openapi-generator-ignore
Normal file
@ -0,0 +1,23 @@
|
||||
# OpenAPI Generator Ignore
|
||||
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
|
||||
|
||||
# Use this file to prevent files from being overwritten by the generator.
|
||||
# The patterns follow closely to .gitignore or .dockerignore.
|
||||
|
||||
# As an example, the C# client generator defines ApiClient.cs.
|
||||
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
|
||||
#ApiClient.cs
|
||||
|
||||
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
|
||||
#foo/*/qux
|
||||
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
|
||||
|
||||
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
|
||||
#foo/**/qux
|
||||
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
|
||||
|
||||
# You can also negate patterns with an exclamation (!).
|
||||
# For example, you can ignore all files in a docs folder with the file extension .md:
|
||||
#docs/*.md
|
||||
# Then explicitly reverse the ignore rule for a single file:
|
||||
#!docs/README.md
|
@ -0,0 +1 @@
|
||||
3.0.0-SNAPSHOT
|
@ -1,13 +0,0 @@
|
||||
FROM openjdk:8-jre-alpine
|
||||
|
||||
WORKDIR /generator
|
||||
|
||||
COPY target/lib/jetty-runner* /generator/jetty-runner.jar
|
||||
COPY target/*.war /generator/swagger-generator.war
|
||||
|
||||
ENV GENERATOR_HOST=https://generator.swaggerhub.com/api/swagger.json
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
CMD ["java", "-jar", "/generator/jetty-runner.jar", "/generator/swagger-generator.war"]
|
||||
|
15
modules/openapi-generator-online/README.md
Normal file
15
modules/openapi-generator-online/README.md
Normal file
@ -0,0 +1,15 @@
|
||||
# OpenAPI generated server
|
||||
|
||||
Spring Boot Server
|
||||
|
||||
|
||||
## Overview
|
||||
This server was generated by the [OpenAPI Generator](https://openapi-generator.tech) project.
|
||||
By using the [OpenAPI-Spec](https://openapis.org), you can easily generate a server stub.
|
||||
This is an example of building a OpenAPI-enabled server in Java using the SpringBoot framework.
|
||||
|
||||
The underlying library integrating OpenAPI to SpringBoot is [springfox](https://github.com/springfox/springfox)
|
||||
|
||||
Start your server as an simple java application
|
||||
|
||||
Change default port value in application.properties
|
@ -1,5 +1,4 @@
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.openapitools</groupId>
|
||||
@ -8,229 +7,82 @@
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<artifactId>openapi-generator-online</artifactId>
|
||||
<packaging>war</packaging>
|
||||
<packaging>jar</packaging>
|
||||
<name>openapi-generator-online</name>
|
||||
<version>1.0.0</version>
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<springfox-version>2.8.0</springfox-version>
|
||||
</properties>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-dependencies</artifactId>
|
||||
<version>2.0.2.RELEASE</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
<includes>
|
||||
<include>**/version.prop</include>
|
||||
<include>logback.xml</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}/lib</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<configuration>
|
||||
<webResources>
|
||||
<resource>
|
||||
<!-- this is relative to the pom.xml directory -->
|
||||
<directory>${project.build.directory}/swagger-ui-master/dist</directory>
|
||||
<excludes>
|
||||
<exclude>index.html</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
</webResources>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<version>2.6</version>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>integration-test</goal>
|
||||
<goal>verify</goal>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-maven-plugin</artifactId>
|
||||
<version>${jetty-version}</version>
|
||||
<configuration>
|
||||
<webApp>
|
||||
<contextPath>/</contextPath>
|
||||
</webApp>
|
||||
<webAppSourceDirectory>target/${project.artifactId}-${project.version}</webAppSourceDirectory>
|
||||
<stopPort>8079</stopPort>
|
||||
<stopKey>stopit</stopKey>
|
||||
<httpConnector>
|
||||
<idleTimeout>60000</idleTimeout>
|
||||
</httpConnector>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>start-jetty</id>
|
||||
<phase>pre-integration-test</phase>
|
||||
<goals>
|
||||
<goal>start</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<scanIntervalSeconds>0</scanIntervalSeconds>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>stop-jetty</id>
|
||||
<phase>post-integration-test</phase>
|
||||
<goals>
|
||||
<goal>stop</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.googlecode.maven-download-plugin</groupId>
|
||||
<artifactId>download-maven-plugin</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>swagger-ui</id>
|
||||
<goals>
|
||||
<goal>wget</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<url>https://github.com/swagger-api/swagger-ui/archive/master.tar.gz</url>
|
||||
<unpack>true</unpack>
|
||||
<!--<skipCache>true</skipCache>-->
|
||||
<outputDirectory>${project.build.directory}</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>net.revelc.code</groupId>
|
||||
<artifactId>formatter-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<!-- Point at the eclipse-formatter.xml in the openapi-generator parent project directory -->
|
||||
<configFile>${project.basedir}${file.separator}${project.parent.relativePath}${file.separator}eclipse-formatter.xml</configFile>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-jersey2-jaxrs</artifactId>
|
||||
<version>1.5.18</version>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<!--SpringFox dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<type>test-jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>${logback-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-core</artifactId>
|
||||
<version>${logback-version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
<version>${servlet-api-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.containers</groupId>
|
||||
<artifactId>jersey-container-servlet-core</artifactId>
|
||||
<version>${jersey2-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-multipart</artifactId>
|
||||
<version>${jersey2-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.lingala.zip4j</groupId>
|
||||
<artifactId>zip4j</artifactId>
|
||||
<version>${zip-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-server</artifactId>
|
||||
<version>${jetty-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-start</artifactId>
|
||||
<version>${jetty-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-xml</artifactId>
|
||||
<version>${jetty-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-webapp</artifactId>
|
||||
<version>${jetty-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-deploy</artifactId>
|
||||
<version>${jetty-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-runner</artifactId>
|
||||
<version>${jetty-version}</version>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>${springfox-version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.glassfish</groupId>
|
||||
<artifactId>javax.el</artifactId>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-models</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
<artifactId>testng</artifactId>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${springfox-version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
</dependency>
|
||||
<!-- Bean Validation API support -->
|
||||
<dependency>
|
||||
<groupId>javax.validation</groupId>
|
||||
<artifactId>validation-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.jaxrs</groupId>
|
||||
<artifactId>jackson-jaxrs-json-provider</artifactId>
|
||||
<version>${jackson-version}</version>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<servlet-api-version>2.5</servlet-api-version>
|
||||
<logback-version>1.0.1</logback-version>
|
||||
<maven-plugin-version>1.0.0</maven-plugin-version>
|
||||
<servlet-api-version>2.5</servlet-api-version>
|
||||
<zip-version>1.3.2</zip-version>
|
||||
<jetty-version>9.2.9.v20150224</jetty-version>
|
||||
<jersey2-version>2.6</jersey2-version>
|
||||
</properties>
|
||||
</project>
|
||||
|
@ -1,57 +0,0 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
* Copyright 2018 SmartBear Software
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.online;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class Bootstrap extends HttpServlet {
|
||||
private static final long serialVersionUID = 1400930071893332856L;
|
||||
|
||||
@Override
|
||||
public void init(ServletConfig config) throws ServletException {
|
||||
DynamicConfig bc = new DynamicConfig();
|
||||
bc.setBasePath("/api");
|
||||
bc.setTitle("OpenAPI Generator");
|
||||
bc.setDescription("This is an online OpenAPI generator. You can find out more "
|
||||
+ "at https://github.com/openapi-tools/openapi-generator");
|
||||
bc.setTermsOfServiceUrl("https://www.apache.org/licenses/LICENSE-2.0");
|
||||
bc.setContact("openapi-generator@gmail.com");
|
||||
bc.setLicense("Apache 2.0");
|
||||
InputStream stream = getClass().getResourceAsStream("/version.prop");
|
||||
if (stream == null) {
|
||||
bc.setVersion("0.0.0");
|
||||
} else {
|
||||
try {
|
||||
bc.setVersion(IOUtils.toString(stream, "UTF-8"));
|
||||
stream.close();
|
||||
} catch (IOException e) {
|
||||
bc.setVersion("0.0.0");
|
||||
}
|
||||
}
|
||||
|
||||
bc.setLicenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html");
|
||||
bc.setResourcePackage("org.openapitools.codegen.online.resource");
|
||||
bc.setScan(true);
|
||||
}
|
||||
}
|
@ -1,95 +0,0 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
* Copyright 2018 SmartBear Software
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.online;
|
||||
|
||||
import org.openapitools.codegen.CodegenConfig;
|
||||
import org.openapitools.codegen.CodegenConfigLoader;
|
||||
import org.openapitools.codegen.CodegenType;
|
||||
import io.swagger.jaxrs.config.BeanConfig;
|
||||
import io.swagger.models.Operation;
|
||||
import io.swagger.models.Path;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.swagger.models.parameters.Parameter;
|
||||
import io.swagger.models.parameters.PathParameter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class DynamicConfig extends BeanConfig {
|
||||
static List<String> clients = new ArrayList<String>();
|
||||
static List<String> servers = new ArrayList<String>();
|
||||
|
||||
static {
|
||||
List<CodegenConfig> extensions = CodegenConfigLoader.getAll();
|
||||
for (CodegenConfig config : extensions) {
|
||||
if (config.getTag().equals(CodegenType.CLIENT)
|
||||
|| config.getTag().equals(CodegenType.DOCUMENTATION)) {
|
||||
clients.add(config.getName());
|
||||
} else if (config.getTag().equals(CodegenType.SERVER)) {
|
||||
servers.add(config.getName());
|
||||
}
|
||||
}
|
||||
Collections.sort(clients, String.CASE_INSENSITIVE_ORDER);
|
||||
Collections.sort(servers, String.CASE_INSENSITIVE_ORDER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Swagger configure(Swagger swagger) {
|
||||
Path clientPath = swagger.getPaths().get("/gen/clients/{language}");
|
||||
// update the path description based on what clients are available via SPI
|
||||
if (clientPath != null) {
|
||||
Operation post = clientPath.getPost();
|
||||
Parameter framework = post.getParameters().get(0);
|
||||
if (framework instanceof PathParameter) {
|
||||
PathParameter param = (PathParameter) framework;
|
||||
param.setEnum(clients);
|
||||
}
|
||||
|
||||
Operation get = clientPath.getGet();
|
||||
if (get != null) {
|
||||
framework = get.getParameters().get(0);
|
||||
if (framework instanceof PathParameter) {
|
||||
PathParameter param = (PathParameter) framework;
|
||||
param.setEnum(clients);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Path serverPath = swagger.getPaths().get("/gen/servers/{framework}");
|
||||
if (serverPath != null) {
|
||||
Operation post = serverPath.getPost();
|
||||
Parameter framework = post.getParameters().get(0);
|
||||
if (framework instanceof PathParameter) {
|
||||
PathParameter param = (PathParameter) framework;
|
||||
param.setEnum(servers);
|
||||
}
|
||||
|
||||
Operation get = serverPath.getGet();
|
||||
if (get != null) {
|
||||
framework = get.getParameters().get(0);
|
||||
if (framework instanceof PathParameter) {
|
||||
PathParameter param = (PathParameter) framework;
|
||||
param.setEnum(servers);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return swagger.info(getInfo()).host(getHost()).basePath("/api");
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package org.openapitools.codegen.online;
|
||||
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.ExitCodeGenerator;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
@SpringBootApplication
|
||||
@ComponentScan(basePackages = { "org.openapitools.codegen.online", "org.openapitools.codegen.online.api", "org.openapitools.codegen.online.configuration"})
|
||||
public class OpenAPI2SpringBoot implements CommandLineRunner {
|
||||
|
||||
@Override
|
||||
public void run(String... arg0) throws Exception {
|
||||
if (arg0.length > 0 && arg0[0].equals("exitcode")) {
|
||||
throw new ExitException();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
new SpringApplication(OpenAPI2SpringBoot.class).run(args);
|
||||
}
|
||||
|
||||
class ExitException extends RuntimeException implements ExitCodeGenerator {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public int getExitCode() {
|
||||
return 10;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package org.openapitools.codegen.online;
|
||||
|
||||
import com.fasterxml.jackson.databind.util.ISO8601DateFormat;
|
||||
import com.fasterxml.jackson.databind.util.ISO8601Utils;
|
||||
|
||||
import java.text.FieldPosition;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
public class RFC3339DateFormat extends ISO8601DateFormat {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
// Same as ISO8601DateFormat but serializing milliseconds.
|
||||
@Override
|
||||
public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) {
|
||||
String value = ISO8601Utils.format(date, true);
|
||||
toAppendTo.append(value);
|
||||
return toAppendTo;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package org.openapitools.codegen.online.api;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
|
||||
public class ApiOriginFilter implements javax.servlet.Filter {
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response,
|
||||
FilterChain chain) throws IOException, ServletException {
|
||||
HttpServletResponse res = (HttpServletResponse) response;
|
||||
res.addHeader("Access-Control-Allow-Origin", "*");
|
||||
res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
|
||||
res.addHeader("Access-Control-Allow-Headers", "Content-Type");
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package org.openapitools.codegen.online.api;
|
||||
|
||||
import org.springframework.web.context.request.NativeWebRequest;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
public class ApiUtil {
|
||||
public static void setExampleResponse(NativeWebRequest req, String contentType, String example) {
|
||||
try {
|
||||
req.getNativeResponse(HttpServletResponse.class).addHeader("Content-Type", contentType);
|
||||
req.getNativeResponse(HttpServletResponse.class).getOutputStream().print(example);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
/**
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (3.0.0-SNAPSHOT).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.codegen.online.api;
|
||||
|
||||
import io.swagger.annotations.*;
|
||||
import org.openapitools.codegen.CliOption;
|
||||
import org.openapitools.codegen.online.model.GeneratorInput;
|
||||
import org.openapitools.codegen.online.model.ResponseCode;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Api(value = "gen", description = "the gen API")
|
||||
public interface GenApi {
|
||||
GenApiDelegate getDelegate();
|
||||
|
||||
@ApiOperation(value = "Gets languages supported by the client generator", nickname = "clientOptions", notes = "", response = String.class, responseContainer = "List", tags={ "clients", })
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "successful operation", response = String.class, responseContainer = "List") })
|
||||
@RequestMapping(value = "/gen/clients",
|
||||
method = RequestMethod.GET)
|
||||
default ResponseEntity<List<String>> clientOptions() {
|
||||
return getDelegate().clientOptions();
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "Downloads a pre-generated file", nickname = "downloadFile", notes = "A valid `fileId` is generated by the `/clients/{language}` or `/servers/{language}` POST operations. The fileId code can be used just once, after which a new `fileId` will need to be requested.", response = String.class, tags={ "clients","servers", })
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "successful operation", response = String.class) })
|
||||
@RequestMapping(value = "/gen/download/{fileId}",
|
||||
produces = { "application/octet-stream" },
|
||||
method = RequestMethod.GET)
|
||||
default ResponseEntity<Resource> downloadFile(@ApiParam(value = "",required=true) @PathVariable("fileId") String fileId) {
|
||||
return getDelegate().downloadFile(fileId);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "Generates a client library", nickname = "generateClient", notes = "Accepts a `GeneratorInput` options map for spec location and generation options", response = ResponseCode.class, tags={ "clients", })
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "successful operation", response = ResponseCode.class) })
|
||||
@RequestMapping(value = "/gen/clients/{language}",
|
||||
method = RequestMethod.POST)
|
||||
default ResponseEntity<ResponseCode> generateClient(@ApiParam(value = "The target language for the client library",required=true, allowableValues = "ada, akka-scala, android, apex, bash, clojure, cpprest, csharp, csharp-dotnet2, cwiki, dart, dynamic-html, eiffel, elixir, elm, erlang-client, flash, go, groovy, haskell-http-client, html, html2, java, javascript, javascript-closure-angular, jaxrs-cxf-client, jmeter, kotlin, lua, objc, perl, php, powershell, python, qt5cpp, r, ruby, rust, scala, scalaz, swagger, swagger-yaml, swift, swift3, swift4, tizen, typescript-angular, typescript-angularjs, typescript-aurelia, typescript-fetch, typescript-jquery, typescript-node") @PathVariable("language") String language,@ApiParam(value = "Configuration for building the client library" ,required=true ) @Valid @RequestBody GeneratorInput generatorInput) {
|
||||
return getDelegate().generateClient(language, generatorInput);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "Generates a server library", nickname = "generateServerForLanguage", notes = "Accepts a `GeneratorInput` options map for spec location and generation options.", response = ResponseCode.class, tags={ "servers", })
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "successful operation", response = ResponseCode.class) })
|
||||
@RequestMapping(value = "/gen/servers/{framework}",
|
||||
method = RequestMethod.POST)
|
||||
default ResponseEntity<ResponseCode> generateServerForLanguage(@ApiParam(value = "framework",required=true, allowableValues = "ada-server, aspnetcore, erlang-server, finch, go-server, haskell, inflector, java-pkmst, java-play-framework, java-vertx, jaxrs, jaxrs-cxf, jaxrs-cxf-cdi, jaxrs-resteasy, jaxrs-resteasy-eap, jaxrs-spec, lumen, msf4j, nancyfx, nodejs-server, php-silex, php-symfony, pistache-server, python-flask, rails5, restbed, rust-server, scala-lagom-server, scalatra, sinatra, slim, spring, undertow, ze-ph") @PathVariable("framework") String framework,@ApiParam(value = "parameters" ,required=true ) @Valid @RequestBody GeneratorInput generatorInput) {
|
||||
return getDelegate().generateServerForLanguage(framework, generatorInput);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "Returns options for a client library", nickname = "getClientOptions", notes = "", response = CliOption.class, responseContainer = "Map", tags={ "clients", })
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "successful operation", response = CliOption.class, responseContainer = "Map") })
|
||||
@RequestMapping(value = "/gen/clients/{language}",
|
||||
produces = { "application/json" },
|
||||
method = RequestMethod.GET)
|
||||
default ResponseEntity<Map<String, CliOption>> getClientOptions(@ApiParam(value = "The target language for the client library",required=true, allowableValues = "ada, akka-scala, android, apex, bash, clojure, cpprest, csharp, csharp-dotnet2, cwiki, dart, dynamic-html, eiffel, elixir, elm, erlang-client, flash, go, groovy, haskell-http-client, html, html2, java, javascript, javascript-closure-angular, jaxrs-cxf-client, jmeter, kotlin, lua, objc, perl, php, powershell, python, qt5cpp, r, ruby, rust, scala, scalaz, swagger, swagger-yaml, swift, swift3, swift4, tizen, typescript-angular, typescript-angularjs, typescript-aurelia, typescript-fetch, typescript-jquery, typescript-node") @PathVariable("language") String language) {
|
||||
return getDelegate().getClientOptions(language);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "Returns options for a server framework", nickname = "getServerOptions", notes = "", response = CliOption.class, responseContainer = "Map", tags={ "servers", })
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "successful operation", response = CliOption.class, responseContainer = "Map") })
|
||||
@RequestMapping(value = "/gen/servers/{framework}",
|
||||
produces = { "application/json" },
|
||||
method = RequestMethod.GET)
|
||||
default ResponseEntity<Map<String, CliOption>> getServerOptions(@ApiParam(value = "The target language for the server framework",required=true, allowableValues = "ada-server, aspnetcore, erlang-server, finch, go-server, haskell, inflector, java-pkmst, java-play-framework, java-vertx, jaxrs, jaxrs-cxf, jaxrs-cxf-cdi, jaxrs-resteasy, jaxrs-resteasy-eap, jaxrs-spec, lumen, msf4j, nancyfx, nodejs-server, php-silex, php-symfony, pistache-server, python-flask, rails5, restbed, rust-server, scala-lagom-server, scalatra, sinatra, slim, spring, undertow, ze-ph") @PathVariable("framework") String framework) {
|
||||
return getDelegate().getServerOptions(framework);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "Gets languages supported by the server generator", nickname = "serverOptions", notes = "", response = String.class, responseContainer = "List", tags={ "servers", })
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "successful operation", response = String.class, responseContainer = "List") })
|
||||
@RequestMapping(value = "/gen/servers",
|
||||
method = RequestMethod.GET)
|
||||
default ResponseEntity<List<String>> serverOptions() {
|
||||
return getDelegate().serverOptions();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package org.openapitools.codegen.online.api;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
@Controller
|
||||
public class GenApiController implements GenApi {
|
||||
|
||||
private final GenApiDelegate delegate;
|
||||
|
||||
@Autowired
|
||||
public GenApiController(GenApiDelegate delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenApiDelegate getDelegate() {
|
||||
return delegate;
|
||||
}
|
||||
}
|
@ -0,0 +1,117 @@
|
||||
package org.openapitools.codegen.online.api;
|
||||
|
||||
import org.openapitools.codegen.CliOption;
|
||||
import org.openapitools.codegen.online.model.GeneratorInput;
|
||||
import org.openapitools.codegen.online.model.ResponseCode;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.context.request.NativeWebRequest;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* A delegate to be called by the {@link GenApiController}}.
|
||||
* Implement this interface with a {@link org.springframework.stereotype.Service} annotated class.
|
||||
*/
|
||||
|
||||
public interface GenApiDelegate {
|
||||
|
||||
default Optional<NativeWebRequest> getRequest() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see GenApi#clientOptions
|
||||
*/
|
||||
default ResponseEntity<List<String>> clientOptions() {
|
||||
getRequest().ifPresent(request -> {
|
||||
for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) {
|
||||
if (mediaType.isCompatibleWith(MediaType.valueOf("*/*"))) {
|
||||
ApiUtil.setExampleResponse(request, "*/*", "\"\"");
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @see GenApi#downloadFile
|
||||
*/
|
||||
default ResponseEntity<Resource> downloadFile(String fileId) {
|
||||
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @see GenApi#generateClient
|
||||
*/
|
||||
default ResponseEntity<ResponseCode> generateClient( String language,
|
||||
GeneratorInput generatorInput) {
|
||||
getRequest().ifPresent(request -> {
|
||||
for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) {
|
||||
if (mediaType.isCompatibleWith(MediaType.valueOf("*/*"))) {
|
||||
ApiUtil.setExampleResponse(request, "*/*", "{ \"code\" : \"d40029be-eda6-4d62-b1ef-d05e2e91a72a\", \"link\" : \"http://generator.swagger.io:80/api/gen/download/d40029be-eda6-4d62-b1ef-d05e2e91a72a\"}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @see GenApi#generateServerForLanguage
|
||||
*/
|
||||
default ResponseEntity<ResponseCode> generateServerForLanguage( String framework,
|
||||
GeneratorInput generatorInput) {
|
||||
getRequest().ifPresent(request -> {
|
||||
for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) {
|
||||
if (mediaType.isCompatibleWith(MediaType.valueOf("*/*"))) {
|
||||
ApiUtil.setExampleResponse(request, "*/*", "{ \"code\" : \"d40029be-eda6-4d62-b1ef-d05e2e91a72a\", \"link\" : \"http://generator.swagger.io:80/api/gen/download/d40029be-eda6-4d62-b1ef-d05e2e91a72a\"}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @see GenApi#getClientOptions
|
||||
*/
|
||||
default ResponseEntity<Map<String, CliOption>> getClientOptions(String language) {
|
||||
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @see GenApi#getServerOptions
|
||||
*/
|
||||
default ResponseEntity<Map<String, CliOption>> getServerOptions( String framework) {
|
||||
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @see GenApi#serverOptions
|
||||
*/
|
||||
default ResponseEntity<List<String>> serverOptions() {
|
||||
getRequest().ifPresent(request -> {
|
||||
for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) {
|
||||
if (mediaType.isCompatibleWith(MediaType.valueOf("*/*"))) {
|
||||
ApiUtil.setExampleResponse(request, "*/*", "\"\"");
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package org.openapitools.codegen.online.configuration;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
/**
|
||||
* Home redirection to swagger api documentation
|
||||
*/
|
||||
@Controller
|
||||
public class HomeController {
|
||||
@RequestMapping(value = "/")
|
||||
public String index() {
|
||||
System.out.println("swagger-ui.html");
|
||||
return "redirect:swagger-ui.html";
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package org.openapitools.codegen.online.configuration;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.service.ApiInfo;
|
||||
import springfox.documentation.service.Contact;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
public class OpenAPIDocumentationConfig {
|
||||
|
||||
ApiInfo apiInfo() {
|
||||
return new ApiInfoBuilder()
|
||||
.title("Swagger Generator")
|
||||
.description("This is an online swagger codegen server. You can find out more at https://github.com/swagger-api/swagger-codegen or on [irc.freenode.net, #swagger](http://swagger.io/irc/).")
|
||||
.license("Apache 2.0")
|
||||
.licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html")
|
||||
.termsOfServiceUrl("")
|
||||
.version("2.3.1")
|
||||
.contact(new Contact("","", ""))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Docket customImplementation(){
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage("org.openapitools.codegen.online.api"))
|
||||
.build()
|
||||
.directModelSubstitute(java.time.LocalDate.class, java.sql.Date.class)
|
||||
.directModelSubstitute(java.time.OffsetDateTime.class, java.util.Date.class)
|
||||
.apiInfo(apiInfo());
|
||||
}
|
||||
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
* Copyright 2018 SmartBear Software
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.online.exception;
|
||||
|
||||
public class ApiException extends Exception {
|
||||
private static final long serialVersionUID = -5085112752305370687L;
|
||||
private int code;
|
||||
|
||||
public ApiException(int code, String msg) {
|
||||
super(msg);
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
* Copyright 2018 SmartBear Software
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.online.exception;
|
||||
|
||||
import org.apache.http.HttpStatus;
|
||||
|
||||
public class BadRequestException extends ApiException {
|
||||
private static final long serialVersionUID = -5540416398447252055L;
|
||||
|
||||
public BadRequestException(String msg) {
|
||||
super(HttpStatus.SC_BAD_REQUEST, msg);
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
* Copyright 2018 SmartBear Software
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.online.exception;
|
||||
|
||||
import org.apache.http.HttpStatus;
|
||||
|
||||
public class NotFoundException extends ApiException {
|
||||
private static final long serialVersionUID = -1223255119112336573L;
|
||||
|
||||
public NotFoundException(String msg) {
|
||||
super(HttpStatus.SC_NOT_FOUND, msg);
|
||||
}
|
||||
}
|
@ -1,18 +1,15 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
* Copyright 2018 SmartBear Software
|
||||
*
|
||||
* 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.
|
||||
/**
|
||||
* Copyright 2016 SmartBear Software
|
||||
* <p>
|
||||
* 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
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* 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.openapitools.codegen.online.model;
|
||||
|
@ -1,18 +1,15 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
* Copyright 2018 SmartBear Software
|
||||
*
|
||||
* 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.
|
||||
/**
|
||||
* Copyright 2016 SmartBear Software
|
||||
* <p>
|
||||
* 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
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* 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.openapitools.codegen.online.model;
|
||||
|
@ -1,33 +1,16 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
* Copyright 2018 SmartBear Software
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.online.model;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import io.swagger.models.auth.AuthorizationValue;
|
||||
import io.swagger.models.auth.SecuritySchemeDefinition;
|
||||
import io.swagger.v3.parser.core.models.AuthorizationValue;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class GeneratorInput {
|
||||
private JsonNode spec;
|
||||
private Map<String, String> options;
|
||||
private String swaggerUrl;
|
||||
private String openAPIUrl;
|
||||
private SecuritySchemeDefinition auth;
|
||||
private AuthorizationValue authorizationValue;
|
||||
|
||||
@ -57,12 +40,12 @@ public class GeneratorInput {
|
||||
}
|
||||
|
||||
@ApiModelProperty(example = "http://petstore.swagger.io/v2/swagger.json")
|
||||
public String getSwaggerUrl() {
|
||||
return swaggerUrl;
|
||||
public String getOpenAPIUrl() {
|
||||
return openAPIUrl;
|
||||
}
|
||||
|
||||
public void setSwaggerUrl(String url) {
|
||||
this.swaggerUrl = url;
|
||||
public void setOpenAPIUrl(String url) {
|
||||
this.openAPIUrl = url;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
|
@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
* Copyright 2018 SmartBear Software
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.online.model;
|
||||
|
||||
public class InputOption {
|
||||
private String name;
|
||||
private String description;
|
||||
private Boolean required;
|
||||
private String defaultValue;
|
||||
|
||||
public InputOption() {}
|
||||
|
||||
public InputOption(String name, String description, String defaultValue, Boolean required) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.defaultValue = defaultValue;
|
||||
this.required = required;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public Boolean getRequired() {
|
||||
return required;
|
||||
}
|
||||
|
||||
public void setRequired(Boolean required) {
|
||||
this.required = required;
|
||||
}
|
||||
|
||||
public String getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public void setDefaultValue(String defaultValue) {
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
}
|
@ -1,20 +1,3 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
* Copyright 2018 SmartBear Software
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.online.model;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
@ -1,228 +0,0 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
* Copyright 2018 SmartBear Software
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.online.resource;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import org.openapitools.codegen.CliOption;
|
||||
import org.openapitools.codegen.CodegenConfig;
|
||||
import org.openapitools.codegen.CodegenConfigLoader;
|
||||
import org.openapitools.codegen.CodegenType;
|
||||
import org.openapitools.codegen.online.exception.BadRequestException;
|
||||
import org.openapitools.codegen.online.model.Generated;
|
||||
import org.openapitools.codegen.online.model.GeneratorInput;
|
||||
import org.openapitools.codegen.online.model.ResponseCode;
|
||||
import org.openapitools.codegen.online.http.Generator;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
@Path("/gen")
|
||||
@Api(value = "/gen", description = "Resource for generating swagger components")
|
||||
public class CodegenResource {
|
||||
static List<String> clients = new ArrayList<String>();
|
||||
static List<String> servers = new ArrayList<String>();
|
||||
private static Map<String, Generated> fileMap = new HashMap<String, Generated>();
|
||||
|
||||
static {
|
||||
List<CodegenConfig> extensions = CodegenConfigLoader.getAll();
|
||||
for (CodegenConfig config : extensions) {
|
||||
if (config.getTag().equals(CodegenType.CLIENT)
|
||||
|| config.getTag().equals(CodegenType.DOCUMENTATION)) {
|
||||
clients.add(config.getName());
|
||||
} else if (config.getTag().equals(CodegenType.SERVER)) {
|
||||
servers.add(config.getName());
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(clients, String.CASE_INSENSITIVE_ORDER);
|
||||
Collections.sort(servers, String.CASE_INSENSITIVE_ORDER);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/download/{fileId}")
|
||||
@Produces({MediaType.APPLICATION_OCTET_STREAM})
|
||||
@ApiOperation(
|
||||
value = "Downloads a pre-generated file",
|
||||
notes = "A valid `fileId` is generated by the `/clients/{language}` or `/servers/{language}` POST "
|
||||
+ "operations. The fileId code can be used just once, after which a new `fileId` will need to "
|
||||
+ "be requested.", response = String.class, tags = {"clients", "servers"})
|
||||
public Response downloadFile(@PathParam("fileId") String fileId) throws Exception {
|
||||
Generated g = fileMap.get(fileId);
|
||||
System.out.println("looking for fileId " + fileId);
|
||||
System.out.println("got filename " + g.getFilename());
|
||||
if (g.getFilename() != null) {
|
||||
File file = new java.io.File(g.getFilename());
|
||||
byte[] bytes = org.apache.commons.io.FileUtils.readFileToByteArray(file);
|
||||
|
||||
try {
|
||||
FileUtils.deleteDirectory(file.getParentFile());
|
||||
} catch (Exception e) {
|
||||
System.out.println("failed to delete file " + file.getAbsolutePath());
|
||||
}
|
||||
|
||||
return Response
|
||||
.ok(bytes, "application/zip")
|
||||
.header("Content-Disposition",
|
||||
"attachment; filename=\"" + g.getFriendlyName() + "-generated.zip\"")
|
||||
.header("Accept-Range", "bytes").header("Content-Length", bytes.length).build();
|
||||
} else {
|
||||
return Response.status(404).build();
|
||||
}
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/clients/{language}")
|
||||
@ApiOperation(
|
||||
value = "Generates a client library",
|
||||
notes = "Accepts a `GeneratorInput` options map for spec location and generation options",
|
||||
response = ResponseCode.class, tags = "clients")
|
||||
public Response generateClient(
|
||||
@Context HttpServletRequest request,
|
||||
@ApiParam(value = "The target language for the client library", required = true) @PathParam("language") String language,
|
||||
@ApiParam(value = "Configuration for building the client library", required = true) GeneratorInput opts)
|
||||
throws Exception {
|
||||
|
||||
String filename = Generator.generateClient(language, opts);
|
||||
String host = System.getenv("GENERATOR_HOST");
|
||||
|
||||
if (StringUtils.isBlank(host)) {
|
||||
String scheme = request.getHeader("X-SSL");
|
||||
String port = "";
|
||||
if ("1".equals(scheme)) {
|
||||
scheme = "https";
|
||||
} else {
|
||||
scheme = request.getScheme();
|
||||
port = ":" + request.getServerPort();
|
||||
}
|
||||
host = scheme + "://" + request.getServerName() + port;
|
||||
}
|
||||
|
||||
if (filename != null) {
|
||||
String code = String.valueOf(UUID.randomUUID().toString());
|
||||
Generated g = new Generated();
|
||||
g.setFilename(filename);
|
||||
g.setFriendlyName(language + "-client");
|
||||
fileMap.put(code, g);
|
||||
System.out.println(code + ", " + filename);
|
||||
String link = host + "/api/gen/download/" + code;
|
||||
return Response.ok().entity(new ResponseCode(code, link)).build();
|
||||
} else {
|
||||
return Response.status(500).build();
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/clients/{language}")
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
@ApiOperation(value = "Returns options for a client library", response = CliOption.class,
|
||||
responseContainer = "map", tags = "clients")
|
||||
public Response getClientOptions(
|
||||
@SuppressWarnings("unused") @Context HttpServletRequest request,
|
||||
@ApiParam(value = "The target language for the client library", required = true) @PathParam("language") String language)
|
||||
throws Exception {
|
||||
|
||||
Map<String, CliOption> opts = Generator.getOptions(language);
|
||||
|
||||
if (opts != null) {
|
||||
return Response.ok().entity(opts).build();
|
||||
} else {
|
||||
return Response.status(404).build();
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/servers/{framework}")
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
@ApiOperation(value = "Returns options for a server framework", response = CliOption.class,
|
||||
responseContainer = "map", tags = "servers")
|
||||
public Response getServerOptions(
|
||||
@SuppressWarnings("unused") @Context HttpServletRequest request,
|
||||
@ApiParam(value = "The target language for the server framework", required = true) @PathParam("framework") String framework)
|
||||
throws Exception {
|
||||
|
||||
Map<String, CliOption> opts = Generator.getOptions(framework);
|
||||
|
||||
if (opts != null) {
|
||||
return Response.ok().entity(opts).build();
|
||||
} else {
|
||||
return Response.status(404).build();
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/clients")
|
||||
@ApiOperation(value = "Gets languages supported by the client generator",
|
||||
response = String.class, responseContainer = "List", tags = "clients")
|
||||
public Response clientOptions() {
|
||||
String[] languages = new String[clients.size()];
|
||||
languages = clients.toArray(languages);
|
||||
return Response.ok().entity(languages).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/servers")
|
||||
@ApiOperation(value = "Gets languages supported by the server generator",
|
||||
response = String.class, responseContainer = "List", tags = "servers")
|
||||
public Response serverOptions() {
|
||||
String[] languages = new String[servers.size()];
|
||||
languages = servers.toArray(languages);
|
||||
return Response.ok().entity(languages).build();
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/servers/{framework}")
|
||||
@ApiOperation(
|
||||
value = "Generates a server library",
|
||||
notes = "Accepts a `GeneratorInput` options map for spec location and generation options.",
|
||||
response = ResponseCode.class, tags = "servers")
|
||||
public Response generateServerForLanguage(@Context HttpServletRequest request, @ApiParam(
|
||||
value = "framework", required = true) @PathParam("framework") String framework,
|
||||
@ApiParam(value = "parameters", required = true) GeneratorInput opts) throws Exception {
|
||||
if (framework == null) {
|
||||
throw new BadRequestException("Framework is required");
|
||||
}
|
||||
String filename = Generator.generateServer(framework, opts);
|
||||
System.out.println("generated name: " + filename);
|
||||
|
||||
String host =
|
||||
request.getScheme() + "://" + request.getServerName() + ":"
|
||||
+ request.getServerPort();
|
||||
|
||||
if (filename != null) {
|
||||
String code = String.valueOf(UUID.randomUUID().toString());
|
||||
Generated g = new Generated();
|
||||
g.setFilename(filename);
|
||||
g.setFriendlyName(framework + "-server");
|
||||
fileMap.put(code, g);
|
||||
System.out.println(code + ", " + filename);
|
||||
String link = host + "/api/gen/download/" + code;
|
||||
return Response.ok().entity(new ResponseCode(code, link)).build();
|
||||
} else {
|
||||
return Response.status(500).build();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
* Copyright 2018 SmartBear Software
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.online.resource;
|
||||
|
||||
import org.openapitools.codegen.online.exception.ApiException;
|
||||
import org.openapitools.codegen.online.exception.BadRequestException;
|
||||
import org.openapitools.codegen.online.exception.NotFoundException;
|
||||
import org.openapitools.codegen.online.model.ApiResponse;
|
||||
import org.openapitools.codegen.online.util.ValidationException;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
import javax.ws.rs.ext.ExceptionMapper;
|
||||
import javax.ws.rs.ext.Provider;
|
||||
|
||||
@Provider
|
||||
public class ExceptionWriter implements ExceptionMapper<Exception> {
|
||||
@Override
|
||||
public Response toResponse(Exception exception) {
|
||||
if (exception instanceof javax.ws.rs.WebApplicationException) {
|
||||
javax.ws.rs.WebApplicationException e = (javax.ws.rs.WebApplicationException) exception;
|
||||
return Response.status(e.getResponse().getStatus())
|
||||
.entity(new ApiResponse(e.getResponse().getStatus(), exception.getMessage()))
|
||||
.build();
|
||||
} else if (exception instanceof com.fasterxml.jackson.core.JsonParseException) {
|
||||
return Response.status(400).entity(new ApiResponse(400, "bad input")).build();
|
||||
} else if (exception instanceof ValidationException) {
|
||||
ValidationException e = (ValidationException) exception;
|
||||
return Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build();
|
||||
} else if (exception instanceof NotFoundException) {
|
||||
return Response.status(Status.NOT_FOUND)
|
||||
.entity(new ApiResponse(ApiResponse.ERROR, exception.getMessage())).build();
|
||||
} else if (exception instanceof BadRequestException) {
|
||||
return Response.status(Status.BAD_REQUEST)
|
||||
.entity(new ApiResponse(ApiResponse.ERROR, exception.getMessage())).build();
|
||||
} else if (exception instanceof ApiException) {
|
||||
return Response.status(Status.BAD_REQUEST)
|
||||
.entity(new ApiResponse(ApiResponse.ERROR, exception.getMessage())).build();
|
||||
} else {
|
||||
return Response.status(500).entity(new ApiResponse(500, "something bad happened"))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,189 @@
|
||||
package org.openapitools.codegen.online.service;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.online.api.GenApiDelegate;
|
||||
import org.openapitools.codegen.CliOption;
|
||||
import org.openapitools.codegen.CodegenConfig;
|
||||
import org.openapitools.codegen.CodegenConfigLoader;
|
||||
import org.openapitools.codegen.CodegenType;
|
||||
import org.openapitools.codegen.online.model.Generated;
|
||||
import org.openapitools.codegen.online.model.GeneratorInput;
|
||||
import org.openapitools.codegen.online.model.ResponseCode;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.context.request.NativeWebRequest;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
public class GenApiService implements GenApiDelegate {
|
||||
|
||||
private static List<String> clients = new ArrayList<>();
|
||||
private static List<String> servers = new ArrayList<>();
|
||||
private static Map<String, Generated> fileMap = new HashMap<>();
|
||||
|
||||
static {
|
||||
List<CodegenConfig> extensions = CodegenConfigLoader.getAll();
|
||||
for (CodegenConfig config : extensions) {
|
||||
if (config.getTag().equals(CodegenType.CLIENT)
|
||||
|| config.getTag().equals(CodegenType.DOCUMENTATION)) {
|
||||
clients.add(config.getName());
|
||||
} else if (config.getTag().equals(CodegenType.SERVER)) {
|
||||
servers.add(config.getName());
|
||||
}
|
||||
}
|
||||
|
||||
clients.sort(String.CASE_INSENSITIVE_ORDER);
|
||||
servers.sort(String.CASE_INSENSITIVE_ORDER);
|
||||
}
|
||||
|
||||
private final NativeWebRequest request;
|
||||
|
||||
@Autowired
|
||||
public GenApiService(NativeWebRequest request) {
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<NativeWebRequest> getRequest() {
|
||||
return Optional.ofNullable(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Resource> downloadFile(String fileId) {
|
||||
Generated g = fileMap.get(fileId);
|
||||
System.out.println("looking for fileId " + fileId);
|
||||
System.out.println("got filename " + g.getFilename());
|
||||
|
||||
File file = new File(g.getFilename());
|
||||
Path path = Paths.get(file.getAbsolutePath());
|
||||
ByteArrayResource resource;
|
||||
try {
|
||||
resource = new ByteArrayResource(Files.readAllBytes(path));
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "File not found", e);
|
||||
} catch (IOException e) {
|
||||
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "I/O error while reading file", e);
|
||||
}
|
||||
try {
|
||||
FileUtils.deleteDirectory(file.getParentFile());
|
||||
} catch (IOException e) {
|
||||
System.out.println("failed to delete file " + file.getAbsolutePath());
|
||||
}
|
||||
return ResponseEntity
|
||||
.ok()
|
||||
.contentType(MediaType.valueOf("application/zip"))
|
||||
.header("Content-Disposition",
|
||||
"attachment; filename=\"" + g.getFriendlyName() + "-generated.zip\"")
|
||||
.header("Accept-Range", "bytes")
|
||||
//.header("Content-Length", bytes.length)
|
||||
.body(resource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<ResponseCode> generateClient(String language, GeneratorInput generatorInput) {
|
||||
String filename = Generator.generateClient(language, generatorInput);
|
||||
String host = System.getenv("GENERATOR_HOST");
|
||||
HttpServletRequest servletRequest = request.getNativeRequest(HttpServletRequest.class);
|
||||
|
||||
if (StringUtils.isBlank(host)) {
|
||||
String scheme = servletRequest.getHeader("X-SSL");
|
||||
String port = "";
|
||||
if ("1".equals(scheme)) {
|
||||
scheme = "https";
|
||||
} else {
|
||||
scheme = servletRequest.getScheme();
|
||||
port = ":" + servletRequest.getServerPort();
|
||||
}
|
||||
host = scheme + "://" + servletRequest.getServerName() + port;
|
||||
}
|
||||
|
||||
if (filename != null) {
|
||||
String code = String.valueOf(UUID.randomUUID().toString());
|
||||
Generated g = new Generated();
|
||||
g.setFilename(filename);
|
||||
g.setFriendlyName(language + "-client");
|
||||
fileMap.put(code, g);
|
||||
System.out.println(code + ", " + filename);
|
||||
String link = host + "/api/gen/download/" + code;
|
||||
return ResponseEntity.ok().body(new ResponseCode(code, link));
|
||||
} else {
|
||||
return ResponseEntity.status(500).build();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Map<String, CliOption>> getClientOptions(String language) {
|
||||
Map<String, CliOption> opts = Generator.getOptions(language);
|
||||
|
||||
if (opts != null) {
|
||||
return ResponseEntity.ok().body(opts);
|
||||
} else {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Map<String, CliOption>> getServerOptions(String framework) {
|
||||
Map<String, CliOption> opts = Generator.getOptions(framework);
|
||||
|
||||
if (opts != null) {
|
||||
return ResponseEntity.ok().body(opts);
|
||||
} else {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<List<String>> clientOptions() {
|
||||
return ResponseEntity.ok().body(clients);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<List<String>> serverOptions() {
|
||||
return ResponseEntity.ok().body(servers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<ResponseCode> generateServerForLanguage(String framework, GeneratorInput generatorInput) {
|
||||
if (framework == null) {
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Framework is required");
|
||||
}
|
||||
String filename = Generator.generateServer(framework, generatorInput);
|
||||
System.out.println("generated name: " + filename);
|
||||
|
||||
HttpServletRequest servletRequest = request.getNativeRequest(HttpServletRequest.class);
|
||||
|
||||
String host =
|
||||
servletRequest.getScheme() + "://" + servletRequest.getServerName() + ":"
|
||||
+ servletRequest.getServerPort();
|
||||
|
||||
if (filename != null) {
|
||||
String code = String.valueOf(UUID.randomUUID().toString());
|
||||
Generated g = new Generated();
|
||||
g.setFilename(filename);
|
||||
g.setFriendlyName(framework + "-server");
|
||||
fileMap.put(code, g);
|
||||
System.out.println(code + ", " + filename);
|
||||
String link = host + "/api/gen/download/" + code;
|
||||
return ResponseEntity.ok().body(new ResponseCode(code, link));
|
||||
} else {
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,35 +1,17 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
* Copyright 2018 SmartBear Software
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.online.http;
|
||||
package org.openapitools.codegen.online.service;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import io.swagger.parser.OpenAPIParser;
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.parser.core.models.ParseOptions;
|
||||
import org.openapitools.codegen.*;
|
||||
import org.openapitools.codegen.online.exception.ApiException;
|
||||
import org.openapitools.codegen.online.exception.BadRequestException;
|
||||
import org.openapitools.codegen.online.model.GeneratorInput;
|
||||
import org.openapitools.codegen.online.model.InputOption;
|
||||
import org.openapitools.codegen.online.util.ZipUtil;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.swagger.models.auth.AuthorizationValue;
|
||||
import io.swagger.parser.SwaggerParser;
|
||||
import io.swagger.v3.parser.core.models.AuthorizationValue;
|
||||
import io.swagger.util.Json;
|
||||
import org.openapitools.codegen.online.model.GeneratorInput;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
@ -38,14 +20,14 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Generator {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Generator.class);
|
||||
static Logger LOGGER = LoggerFactory.getLogger(Generator.class);
|
||||
|
||||
public static Map<String, CliOption> getOptions(String language) throws ApiException {
|
||||
public static Map<String, CliOption> getOptions(String language) {
|
||||
CodegenConfig config = null;
|
||||
try {
|
||||
config = CodegenConfigLoader.forName(language);
|
||||
} catch (Exception e) {
|
||||
throw new BadRequestException(String.format("Unsupported target %s supplied. %s",
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, String.format("Unsupported target %s supplied. %s",
|
||||
language, e));
|
||||
}
|
||||
Map<String, CliOption> map = new LinkedHashMap<String, CliOption>();
|
||||
@ -69,51 +51,49 @@ public class Generator {
|
||||
}
|
||||
}
|
||||
|
||||
public static String generateClient(String language, GeneratorInput opts) throws ApiException {
|
||||
public static String generateClient(String language, GeneratorInput opts) {
|
||||
return generate(language, opts, Type.CLIENT);
|
||||
}
|
||||
|
||||
public static String generateServer(String language, GeneratorInput opts) throws ApiException {
|
||||
public static String generateServer(String language, GeneratorInput opts) {
|
||||
return generate(language, opts, Type.SERVER);
|
||||
}
|
||||
|
||||
private static String generate(String language, GeneratorInput opts, Type type)
|
||||
throws ApiException {
|
||||
private static String generate(String language, GeneratorInput opts, Type type) {
|
||||
LOGGER.debug(String.format("generate %s for %s", type.getTypeName(), language));
|
||||
if (opts == null) {
|
||||
throw new BadRequestException("No options were supplied");
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "No options were supplied");
|
||||
}
|
||||
JsonNode node = opts.getSpec();
|
||||
if (node != null && "{}".equals(node.toString())) {
|
||||
LOGGER.debug("ignoring empty spec");
|
||||
node = null;
|
||||
}
|
||||
Swagger swagger;
|
||||
OpenAPI openapi;
|
||||
ParseOptions parseOptions = new ParseOptions();
|
||||
parseOptions.setResolve(true);
|
||||
if (node == null) {
|
||||
if (opts.getSwaggerUrl() != null) {
|
||||
if (opts.getOpenAPIUrl() != null) {
|
||||
if (opts.getAuthorizationValue() != null) {
|
||||
List<AuthorizationValue> authorizationValues =
|
||||
new ArrayList<AuthorizationValue>();
|
||||
List<AuthorizationValue> authorizationValues = new ArrayList<>();
|
||||
authorizationValues.add(opts.getAuthorizationValue());
|
||||
|
||||
swagger =
|
||||
new SwaggerParser().read(opts.getSwaggerUrl(), authorizationValues,
|
||||
true);
|
||||
openapi = new OpenAPIParser().readLocation(opts.getOpenAPIUrl(), authorizationValues, parseOptions).getOpenAPI();
|
||||
} else {
|
||||
swagger = new SwaggerParser().read(opts.getSwaggerUrl());
|
||||
openapi = new OpenAPIParser().readLocation(opts.getOpenAPIUrl(), null, parseOptions).getOpenAPI();
|
||||
}
|
||||
} else {
|
||||
throw new BadRequestException("No OpenAPI specification was supplied");
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "No OpenAPI specification was supplied");
|
||||
}
|
||||
} else if (opts.getAuthorizationValue() != null) {
|
||||
List<AuthorizationValue> authorizationValues = new ArrayList<AuthorizationValue>();
|
||||
authorizationValues.add(opts.getAuthorizationValue());
|
||||
swagger = new SwaggerParser().read(node, authorizationValues, true);
|
||||
openapi = new OpenAPIParser().readContents(node.toString(), authorizationValues, parseOptions).getOpenAPI();
|
||||
|
||||
} else {
|
||||
swagger = new SwaggerParser().read(node, true);
|
||||
openapi = new OpenAPIParser().readContents(node.toString(), null, parseOptions).getOpenAPI();
|
||||
}
|
||||
if (swagger == null) {
|
||||
throw new BadRequestException("The OpenAPI specification supplied was not valid");
|
||||
if (openapi == null) {
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "The OpenAPI specification supplied was not valid");
|
||||
}
|
||||
|
||||
String destPath = null;
|
||||
@ -130,19 +110,18 @@ public class Generator {
|
||||
String outputFolder = getTmpFolder().getAbsolutePath() + File.separator + destPath;
|
||||
String outputFilename = outputFolder + "-bundle.zip";
|
||||
|
||||
// TODO revise below
|
||||
//clientOptInput.opts(clientOpts).swagger(swagger);
|
||||
clientOptInput.opts(clientOpts).openAPI(openapi);
|
||||
|
||||
CodegenConfig codegenConfig = null;
|
||||
try {
|
||||
codegenConfig = CodegenConfigLoader.forName(language);
|
||||
} catch (RuntimeException e) {
|
||||
throw new BadRequestException("Unsupported target " + language + " supplied");
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Unsupported target " + language + " supplied");
|
||||
}
|
||||
|
||||
if (opts.getOptions() != null) {
|
||||
codegenConfig.additionalProperties().putAll(opts.getOptions());
|
||||
codegenConfig.additionalProperties().put("swagger", swagger);
|
||||
codegenConfig.additionalProperties().put("openAPI", openapi);
|
||||
}
|
||||
|
||||
codegenConfig.setOutputDir(outputFolder);
|
||||
@ -160,35 +139,27 @@ public class Generator {
|
||||
ZipUtil zip = new ZipUtil();
|
||||
zip.compressFiles(filesToAdd, outputFilename);
|
||||
} else {
|
||||
throw new BadRequestException(
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST,
|
||||
"A target generation was attempted, but no files were created!");
|
||||
}
|
||||
for (File file : files) {
|
||||
try {
|
||||
file.delete();
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("unable to delete file " + file.getAbsolutePath());
|
||||
LOGGER.error("unable to delete file " + file.getAbsolutePath(), e);
|
||||
}
|
||||
}
|
||||
try {
|
||||
new File(outputFolder).delete();
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("unable to delete output folder " + outputFolder);
|
||||
LOGGER.error("unable to delete output folder " + outputFolder, e);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new BadRequestException("Unable to build target: " + e.getMessage());
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Unable to build target: " + e.getMessage(), e);
|
||||
}
|
||||
return outputFilename;
|
||||
}
|
||||
|
||||
public static InputOption clientOptions(@SuppressWarnings("unused") String language) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static InputOption serverOptions(@SuppressWarnings("unused") String language) {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected static File getTmpFolder() {
|
||||
try {
|
||||
File outputFolder = File.createTempFile("codegen-", "-tmp");
|
@ -1,21 +1,18 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
* Copyright 2018 SmartBear Software
|
||||
*
|
||||
* 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.
|
||||
/**
|
||||
* Copyright 2016 SmartBear Software
|
||||
* <p>
|
||||
* 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
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* 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.openapitools.codegen.online.util;
|
||||
package org.openapitools.codegen.online.service;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
* Copyright 2018 SmartBear Software
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.online.util;
|
||||
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.FilterConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
public class ApiOriginFilter implements javax.servlet.Filter {
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
|
||||
throws IOException, ServletException {
|
||||
HttpServletResponse res = (HttpServletResponse) response;
|
||||
res.addHeader("Access-Control-Allow-Origin", "*");
|
||||
res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
|
||||
res.addHeader("Access-Control-Allow-Headers", "Content-Type");
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {}
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException {}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
* Copyright 2018 SmartBear Software
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.online.util;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
|
||||
import io.swagger.util.Json;
|
||||
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.ext.Provider;
|
||||
|
||||
@Provider
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public class JacksonJsonProvider extends JacksonJaxbJsonProvider {
|
||||
private static ObjectMapper commonMapper = Json.mapper();
|
||||
|
||||
public JacksonJsonProvider() {
|
||||
super.setMapper(commonMapper);
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
* Copyright 2018 SmartBear Software
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.online.util;
|
||||
|
||||
public class ValidationException extends Exception {
|
||||
private static final long serialVersionUID = 6861195361018260380L;
|
||||
private int code;
|
||||
private String msg;
|
||||
|
||||
public ValidationException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMessage(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
* Copyright 2018 SmartBear Software
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.online.util;
|
||||
|
||||
public class ValidationMessage {
|
||||
private String path, message, severity;
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public void setPath(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public String getSeverity() {
|
||||
return severity;
|
||||
}
|
||||
|
||||
public void setSeverity(String severity) {
|
||||
this.severity = severity;
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
springfox.documentation.swagger.v2.path=/api-docs
|
||||
server.servlet.context-path=/api
|
||||
server.port=8080
|
||||
spring.jackson.date-format=org.openapitools.codegen.online.RFC3339DateFormat
|
||||
spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=false
|
@ -1,11 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<layout class="ch.qos.logback.classic.PatternLayout">
|
||||
<Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern>
|
||||
</layout>
|
||||
</appender>
|
||||
<root level="error">
|
||||
<appender-ref ref="STDOUT"/>
|
||||
</root>
|
||||
</configuration>
|
@ -1 +0,0 @@
|
||||
${project.version}
|
@ -1,59 +0,0 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.0"
|
||||
xmlns="http://java.sun.com/xml/ns/javaee"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
|
||||
|
||||
<servlet>
|
||||
<servlet-name>jersey</servlet-name>
|
||||
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
|
||||
<init-param>
|
||||
<param-name>jersey.config.server.provider.packages</param-name>
|
||||
<param-value>
|
||||
io.swagger.jaxrs.json,
|
||||
org.openapitools.codegen.online.resource
|
||||
</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>jersey.config.server.provider.classnames</param-name>
|
||||
<param-value>
|
||||
io.swagger.online.ExceptionWriter,
|
||||
org.openapitools.codegen.online.util.JacksonJsonProvider,
|
||||
io.swagger.jaxrs.listing.ApiListingResource,
|
||||
io.swagger.jersey.listing.JerseyApiDeclarationProvider,
|
||||
io.swagger.jersey.listing.JerseyResourceListingProvider
|
||||
</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>jersey.config.server.wadl.disableWadl</param-name>
|
||||
<param-value>true</param-value>
|
||||
</init-param>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>jersey</servlet-name>
|
||||
<url-pattern>/api/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<filter>
|
||||
<filter-name>ApiOriginFilter</filter-name>
|
||||
<filter-class>org.openapitools.codegen.online.util.ApiOriginFilter</filter-class>
|
||||
</filter>
|
||||
<servlet>
|
||||
<servlet-name>Bootstrap</servlet-name>
|
||||
<servlet-class>org.openapitools.codegen.online.Bootstrap</servlet-class>
|
||||
<init-param>
|
||||
<param-name>generator.host</param-name>
|
||||
<param-value>localhost:8080</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>generator.protocol</param-name>
|
||||
<param-value>http</param-value>
|
||||
</init-param>
|
||||
<load-on-startup>2</load-on-startup>
|
||||
</servlet>
|
||||
<filter-mapping>
|
||||
<filter-name>ApiOriginFilter</filter-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</filter-mapping>
|
||||
</web-app>
|
@ -1,93 +0,0 @@
|
||||
<!-- HTML for static distribution bundle build -->
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Swagger UI</title>
|
||||
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700|Source+Code+Pro:300,600|Titillium+Web:400,600,700" rel="stylesheet">
|
||||
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" >
|
||||
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
|
||||
<link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
|
||||
<style>
|
||||
html
|
||||
{
|
||||
box-sizing: border-box;
|
||||
overflow: -moz-scrollbars-vertical;
|
||||
overflow-y: scroll;
|
||||
}
|
||||
*,
|
||||
*:before,
|
||||
*:after
|
||||
{
|
||||
box-sizing: inherit;
|
||||
}
|
||||
|
||||
body {
|
||||
margin:0;
|
||||
background: #fafafa;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="position:absolute;width:0;height:0">
|
||||
<defs>
|
||||
<symbol viewBox="0 0 20 20" id="unlocked">
|
||||
<path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V6h2v-.801C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8z"></path>
|
||||
</symbol>
|
||||
|
||||
<symbol viewBox="0 0 20 20" id="locked">
|
||||
<path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8zM12 8H8V5.199C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8z"/>
|
||||
</symbol>
|
||||
|
||||
<symbol viewBox="0 0 20 20" id="close">
|
||||
<path d="M14.348 14.849c-.469.469-1.229.469-1.697 0L10 11.819l-2.651 3.029c-.469.469-1.229.469-1.697 0-.469-.469-.469-1.229 0-1.697l2.758-3.15-2.759-3.152c-.469-.469-.469-1.228 0-1.697.469-.469 1.228-.469 1.697 0L10 8.183l2.651-3.031c.469-.469 1.228-.469 1.697 0 .469.469.469 1.229 0 1.697l-2.758 3.152 2.758 3.15c.469.469.469 1.229 0 1.698z"/>
|
||||
</symbol>
|
||||
|
||||
<symbol viewBox="0 0 20 20" id="large-arrow">
|
||||
<path d="M13.25 10L6.109 2.58c-.268-.27-.268-.707 0-.979.268-.27.701-.27.969 0l7.83 7.908c.268.271.268.709 0 .979l-7.83 7.908c-.268.271-.701.27-.969 0-.268-.269-.268-.707 0-.979L13.25 10z"/>
|
||||
</symbol>
|
||||
|
||||
<symbol viewBox="0 0 20 20" id="large-arrow-down">
|
||||
<path d="M17.418 6.109c.272-.268.709-.268.979 0s.271.701 0 .969l-7.908 7.83c-.27.268-.707.268-.979 0l-7.908-7.83c-.27-.268-.27-.701 0-.969.271-.268.709-.268.979 0L10 13.25l7.418-7.141z"/>
|
||||
</symbol>
|
||||
|
||||
|
||||
<symbol viewBox="0 0 24 24" id="jump-to">
|
||||
<path d="M19 7v4H5.83l3.58-3.59L8 6l-6 6 6 6 1.41-1.41L5.83 13H21V7z"/>
|
||||
</symbol>
|
||||
|
||||
<symbol viewBox="0 0 24 24" id="expand">
|
||||
<path d="M10 18h4v-2h-4v2zM3 6v2h18V6H3zm3 7h12v-2H6v2z"/>
|
||||
</symbol>
|
||||
|
||||
</defs>
|
||||
</svg>
|
||||
|
||||
<div id="swagger-ui"></div>
|
||||
|
||||
<script src="./swagger-ui-bundle.js"> </script>
|
||||
<script src="./swagger-ui-standalone-preset.js"> </script>
|
||||
<script>
|
||||
window.onload = function() {
|
||||
// Build a system
|
||||
const ui = SwaggerUIBundle({
|
||||
url: "/api/swagger.json",
|
||||
dom_id: '#swagger-ui',
|
||||
presets: [
|
||||
SwaggerUIBundle.presets.apis,
|
||||
SwaggerUIStandalonePreset
|
||||
],
|
||||
plugins: [
|
||||
SwaggerUIBundle.plugins.DownloadUrl
|
||||
],
|
||||
layout: "StandaloneLayout"
|
||||
})
|
||||
|
||||
window.ui = ui
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user