Skip to content

Commit

Permalink
More Rollback of #27
Browse files Browse the repository at this point in the history
  • Loading branch information
pilhuhn committed Oct 1, 2020
1 parent 6e9d514 commit 522c105
Show file tree
Hide file tree
Showing 14 changed files with 648 additions and 418 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,5 @@ jobs:
- uses: actions/upload-artifact@v2
name: Upload openapi.json
with:
name: openapi.notifications.json
path: target/classes/openapi.notifications.json
- uses: actions/upload-artifact@v2
name: Upload openapi.json
with:
name: openapi.integrations.json
path: target/classes/openapi.integrations.json
name: openapi.json
path: target/openapi.json
42 changes: 1 addition & 41 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
<quarkus.platform.artifact-id>quarkus-universe-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
<quarkus.platform.version>1.7.1.Final</quarkus.platform.version>
<surefire-plugin.version>2.22.2</surefire-plugin.version>
<surefire-plugin.version>2.22.1</surefire-plugin.version>
<policies.version>2.1.0-20200917.130620-1</policies.version>
<r2dbc.version>0.8.4.RELEASE</r2dbc.version>
<checkstyle-plugin.version>3.1.1</checkstyle-plugin.version>
<mutiny-reactor.version>0.7.0</mutiny-reactor.version>
<testcontainers.version>1.14.3</testcontainers.version>
<mockserver-client-java.version>5.5.4</mockserver-client-java.version> <!-- not the newest, but matches what is in org.testcontainers:mockserver -->
<version.cloud-commons>0.1.1</version.cloud-commons>
<openapi-parser.version>4.0.4</openapi-parser.version>
</properties>
<dependencyManagement>
<dependencies>
Expand Down Expand Up @@ -179,12 +178,6 @@
<version>${mockserver-client-java.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.reprezen.kaizen</groupId>
<artifactId>openapi-parser</artifactId>
<version>${openapi-parser.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down Expand Up @@ -212,21 +205,10 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<configuration>
<excludedGroups>integration</excludedGroups>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<phase>integration-test</phase>
<goals><goal>test</goal></goals>
<configuration>
<excludedGroups>!integration</excludedGroups>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -249,28 +231,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>split-oapi</id>
<phase>prepare-package</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.redhat.cloud.oapi_splitter.OApiSplitter</mainClass>
<workingDirectory>${project.basedir}</workingDirectory>
<arguments>
<argument>target/openapi.json</argument>
<argument>target/classes/</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
Expand Down
91 changes: 91 additions & 0 deletions src/main/java/com/redhat/cloud/notifications/oapi/OASModifier.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package com.redhat.cloud.notifications.oapi;

import org.eclipse.microprofile.openapi.OASFilter;
import org.eclipse.microprofile.openapi.models.Components;
import org.eclipse.microprofile.openapi.models.OpenAPI;
import org.eclipse.microprofile.openapi.models.Operation;
import org.eclipse.microprofile.openapi.models.PathItem;
import org.eclipse.microprofile.openapi.models.Paths;
import org.eclipse.microprofile.openapi.models.media.Schema;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
* Modify the path in the openapi document to not
* have the prefix, which is already in the
* servers part of the document. See POL-358
* This also allows to do more filtering and
* rewriting of the document.
*
* Also provides an operationId for all operations.
*/
public class OASModifier implements OASFilter {

@Override
public void filterOpenAPI(OpenAPI openAPI) {
Paths paths = openAPI.getPaths();
Set<String> keySet = paths.getPathItems().keySet();
Map<String, PathItem> replacementItems = new HashMap<>();
for (String key : keySet) {
PathItem p = paths.getPathItem(key);
String mangledName = mangleName(key);
replacementItems.put(mangledName, p);

Map<PathItem.HttpMethod, Operation> operations = p.getOperations();
for (Map.Entry<PathItem.HttpMethod, Operation> entry : operations.entrySet()) {
Operation op = entry.getValue();

if (op.getOperationId() == null || op.getOperationId().isEmpty()) {

String id = toCamelCase(mangledName);
id = entry.getKey().toString().toLowerCase() + id;
op.setOperationId(id);
}
}
}
paths.setPathItems(replacementItems);

// Settings values should not be shown in openapi export
Components components = openAPI.getComponents();
Map<String, Schema> existingSchemas = components.getSchemas();
Map<String, Schema> modifiedSchemas = new HashMap<>(existingSchemas);
// TODO Add modifications here
components.setSchemas(modifiedSchemas);
}

private String toCamelCase(String mangledName) {
StringBuilder sb = new StringBuilder();
boolean needsUpper = false;
for (char c : mangledName.toCharArray()) {
if (c == '/') {
needsUpper = true;
continue;
}
if (c == '}') {
continue;
}
if (c == '{') {
sb.append("By");
needsUpper = true;
continue;
}
if (needsUpper) {
sb.append(Character.toUpperCase(c));
needsUpper = false;
} else {
sb.append(c);
}
}
return sb.toString();
}

private String mangleName(String key) {
// Base Filler - would report as empty otherwise
if (key.equals("/api/notifications/v1.0")) {
return "/";
}
return key.replace("/api/notifications/v1.0", "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,43 +28,26 @@
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.SecurityContext;
import javax.ws.rs.core.StreamingOutput;
import javax.ws.rs.core.UriInfo;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.UUID;

@Path("/api/integrations/v1.0")
@Path("/endpoints")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
// Email endpoints are not added at this point
// TODO Needs documentation annotations
public class IntegrationsService {
public class EndpointService {

@Inject
EndpointResources resources;

@Inject
NotificationResources notifResources;

@GET
@Path("openapi.json")
public StreamingOutput getOpenAPI() {
return new StreamingOutput() {
@Override
public void write(OutputStream output) throws IOException, WebApplicationException {
InputStream is = getClass().getResourceAsStream("/openapi.integrations.json");
is.transferTo(output);
}
};
}

@GET
@RolesAllowed("read")
@Parameters({
Expand Down

This file was deleted.

0 comments on commit 522c105

Please sign in to comment.