Skip to content

Commit

Permalink
Initial commit for v3 programmatic interface
Browse files Browse the repository at this point in the history
  • Loading branch information
navidsh authored and frantuma committed Aug 2, 2017
1 parent 44997dc commit a3ceab8
Show file tree
Hide file tree
Showing 5 changed files with 204 additions and 0 deletions.
70 changes: 70 additions & 0 deletions modules/swagger-web/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.swagger</groupId>
<artifactId>swagger-project</artifactId>
<version>2.0.0-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>
<groupId>io.swagger</groupId>
<artifactId>swagger-web</artifactId>
<version>2.0.0-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>swagger-web</name>
<dependencies>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
<version>${models.version}</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>${felix-version}</version>
<extensions>true</extensions>
<executions>
<execution>
<id>set_failok</id>
<goals>
<goal>manifest</goal>
</goals>
<configuration>
<instructions>
<_failok>true</_failok>
</instructions>
</configuration>
</execution>
</executions>
<configuration>
<manifestLocation>src/main/resources/META-INF</manifestLocation>
<rebuildBundle>true</rebuildBundle>
<instructions>
<Export-Package>io.swagger.oas.web</Export-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<models.version>2.0.0-SNAPSHOT</models.version>
</properties>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package io.swagger.oas.web;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import io.swagger.oas.models.OpenAPI;

public final class OpenAPIConfig {
private Set<Class<?>> classesToBeScanned;
private Map<String, Object> environment;
private Class<?> filterClass;
private Collection<String> ignoredRoutes;
private OpenAPI openAPI;
private boolean prettyPrint;
private boolean scanAllResources;

public OpenAPIConfig() {
classesToBeScanned = Collections.<Class<?>>emptySet();
environment = Collections.<String, Object>emptyMap();
ignoredRoutes = Collections.<String>emptySet();
}

public Set<Class<?>> getClasses() {
return classesToBeScanned;
}

public OpenAPIConfig setClasses(Set<Class<?>> classesToBeScanned) {
this.classesToBeScanned = classesToBeScanned == null || classesToBeScanned.isEmpty()
? Collections.<Class<?>>emptySet() : Collections.unmodifiableSet(classesToBeScanned);
return this;
}

public Class<?> getFilterClass() {
return filterClass;
}

public OpenAPIConfig setFilterClass(Class<?> filterClass) {
this.filterClass = filterClass;
return this;
}

public Collection<String> getIgnoredRoutes() {
return ignoredRoutes;
}

public OpenAPIConfig setIgnoredRoutes(Collection<String> ignoredRoutes) {
this.ignoredRoutes = ignoredRoutes == null || ignoredRoutes.isEmpty() ? Collections.<String>emptySet()
: Collections.unmodifiableCollection(new HashSet<String>(ignoredRoutes));
return this;
}

public OpenAPI getOpenAPI() {
return openAPI;
}

public OpenAPIConfig setOpenAPI(OpenAPI openAPI) {
this.openAPI = openAPI;
return this;
}

public Map<String, Object> getUserDefinedOptions() {
return environment;
}

public OpenAPIConfig setUserDefinedOptions(Map<String, Object> environment) {
this.environment = environment == null || environment.isEmpty() ? Collections.<String, Object>emptyMap()
: Collections.unmodifiableMap(new HashMap<>(environment));
return this;
}

public boolean isPrettyPrint() {
return prettyPrint;
}

public OpenAPIConfig setPrettyPrint(boolean prettyPrint) {
this.prettyPrint = prettyPrint;
return this;
}

public boolean isScanAllResources() {
return scanAllResources;
}

public void setScanAllResources(boolean scanAllResources) {
this.scanAllResources = scanAllResources;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.swagger.oas.web;

import java.util.Map;

public interface OpenAPIController {
OpenAPIConfig bootstrap(Map<String, Object> environment);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.swagger.oas.web;

import java.util.List;
import java.util.Map;

import io.swagger.oas.models.Operation;
import io.swagger.oas.models.media.Schema;
import io.swagger.oas.models.parameters.Parameter;

public interface OpenAPIFilter {
boolean isOperationAllowed(
Operation operation,
String path,
String method,
Map<String, List<String>> params,
Map<String, String> cookies,
Map<String, List<String>> headers);

boolean isParamAllowed(
Parameter parameter,
Operation operation,
String path,
String method,
Map<String, List<String>> params,
Map<String, String> cookies,
Map<String, List<String>> headers);

boolean isPropertyAllowed(
Schema<?> schema,
Schema<?> property,
String propertyName,
Map<String, List<String>> params,
Map<String, String> cookies,
Map<String, List<String>> headers);
}
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@
<module>modules/swagger-models</module>
<module>modules/swagger-jaxrs2</module>
<module>modules/swagger-core</module>
<module>modules/swagger-web</module>
<!-- <module>modules/swagger-hibernate-validations</module> -->
<!-- <module>modules/swagger-servlet</module> -->
</modules>
Expand Down

0 comments on commit a3ceab8

Please sign in to comment.