Skip to content

Commit

Permalink
chore(#1175): minor adjustments on imports and code style
Browse files Browse the repository at this point in the history
  • Loading branch information
bbortt committed Jun 30, 2024
1 parent 8d5bb14 commit 00ea177
Show file tree
Hide file tree
Showing 46 changed files with 299 additions and 374 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@

package org.citrusframework.openapi;

import static java.lang.String.format;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static java.lang.String.format;

/**
* A registry to store objects by OpenApi paths. The registry uses a digital tree data structure
Expand Down Expand Up @@ -187,5 +188,4 @@ class RegistryNode {
String path;
T value = null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@

package org.citrusframework.openapi;

import org.citrusframework.repository.BaseRepository;
import org.citrusframework.spi.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
Expand All @@ -24,10 +29,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import org.citrusframework.repository.BaseRepository;
import org.citrusframework.spi.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* OpenApi repository holding a set of {@link OpenApiSpecification} known in the test scope.
Expand Down Expand Up @@ -140,7 +141,4 @@ static Optional<String> determineResourceAlias(Resource openApiResource) {
public List<OpenApiSpecification> getOpenApiSpecifications() {
return openApiSpecifications;
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,6 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import io.apicurio.datamodels.Library;
import io.apicurio.datamodels.openapi.models.OasDocument;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.util.Objects;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import org.apache.hc.client5.http.ssl.NoopHostnameVerifier;
import org.apache.hc.client5.http.ssl.TrustAllStrategy;
import org.apache.hc.core5.http.HttpHeaders;
Expand All @@ -40,6 +31,16 @@
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;

import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.util.Objects;

/**
* Loads Open API specifications from different locations like file resource or web resource.
* @author Christoph Deppisch
Expand All @@ -48,7 +49,6 @@ public final class OpenApiResourceLoader {

static final RawResolver RAW_RESOLVER = new RawResolver();


static final OasResolver OAS_RESOLVER = new OasResolver();

/**
Expand All @@ -60,17 +60,13 @@ private OpenApiResourceLoader() {

/**
* Loads the specification from a file resource. Either classpath or file system resource path is supported.
* @param resource
* @return
*/
public static OasDocument fromFile(String resource) {
return fromFile(FileUtils.getFileResource(resource), OAS_RESOLVER);
}

/**
* Loads the raw specification from a file resource. Either classpath or file system resource path is supported.
* @param resource
* @return
*/
public static String rawFromFile(String resource) {
return fromFile(FileUtils.getFileResource(resource),
Expand All @@ -79,17 +75,13 @@ public static String rawFromFile(String resource) {

/**
* Loads the specification from a resource.
* @param resource
* @return
*/
public static OasDocument fromFile(Resource resource) {
return fromFile(resource, OAS_RESOLVER);
}

/**
* Loads the raw specification from a resource.
* @param resource
* @return
*/
public static String rawFromFile(Resource resource) {
return fromFile(resource, RAW_RESOLVER);
Expand All @@ -105,17 +97,13 @@ private static <T> T fromFile(Resource resource, Resolver<T> resolver) {

/**
* Loads specification from given web URL location.
* @param url
* @return
*/
public static OasDocument fromWebResource(URL url) {
return fromWebResource(url, OAS_RESOLVER);
}

/**
* Loads raw specification from given web URL location.
* @param url
* @return
*/
public static String rawFromWebResource(URL url) {
return fromWebResource(url, RAW_RESOLVER);
Expand All @@ -130,13 +118,13 @@ private static <T> T fromWebResource(URL url, Resolver<T> resolver) {

int status = con.getResponseCode();
if (status > 299) {
throw new IllegalStateException("Failed to retrieve Open API specification: " + url.toString(),
throw new IllegalStateException("Failed to retrieve Open API specification: " + url,
new IOException(FileUtils.readToString(con.getErrorStream())));
} else {
return resolve(FileUtils.readToString(con.getInputStream()), resolver);
}
} catch (IOException e) {
throw new IllegalStateException("Failed to retrieve Open API specification: " + url.toString(), e);
throw new IllegalStateException("Failed to retrieve Open API specification: " + url, e);
} finally {
if (con != null) {
con.disconnect();
Expand All @@ -146,17 +134,13 @@ private static <T> T fromWebResource(URL url, Resolver<T> resolver) {

/**
* Loads specification from given web URL location using secured Http connection.
* @param url
* @return
*/
public static OasDocument fromSecuredWebResource(URL url) {
return fromSecuredWebResource(url, OAS_RESOLVER);
}

/**
* Loads raw specification from given web URL location using secured Http connection.
* @param url
* @return
*/
public static String rawFromSecuredWebResource(URL url) {
return fromSecuredWebResource(url, RAW_RESOLVER);
Expand All @@ -181,15 +165,15 @@ private static <T> T fromSecuredWebResource(URL url, Resolver<T> resolver) {

int status = con.getResponseCode();
if (status > 299) {
throw new IllegalStateException("Failed to retrieve Open API specification: " + url.toString(),
throw new IllegalStateException("Failed to retrieve Open API specification: " + url,
new IOException(FileUtils.readToString(con.getErrorStream())));
} else {
return resolve(FileUtils.readToString(con.getInputStream()), resolver);
}
} catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) {
throw new IllegalStateException("Failed to create https client for ssl connection", e);
} catch (IOException e) {
throw new IllegalStateException("Failed to retrieve Open API specification: " + url.toString(), e);
throw new IllegalStateException("Failed to retrieve Open API specification: " + url, e);
} finally {
if (con != null) {
con.disconnect();
Expand Down Expand Up @@ -256,5 +240,4 @@ public String resolveFromNode(JsonNode node) {
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,11 @@

package org.citrusframework.openapi;

import static org.citrusframework.openapi.OpenApiSettings.isGenerateOptionalFieldsGlobally;
import static org.citrusframework.openapi.OpenApiSettings.isRequestValidationEnabledlobally;
import static org.citrusframework.openapi.OpenApiSettings.isResponseValidationEnabledGlobally;
import static org.citrusframework.openapi.OpenApiSettings.isValidateOptionalFieldsGlobally;

import com.atlassian.oai.validator.OpenApiInteractionValidator;
import com.atlassian.oai.validator.OpenApiInteractionValidator.Builder;
import io.apicurio.datamodels.core.models.common.Info;
import io.apicurio.datamodels.openapi.models.OasDocument;
import io.apicurio.datamodels.openapi.models.OasOperation;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.http.client.HttpClient;
Expand All @@ -49,6 +34,23 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;

import static org.citrusframework.openapi.OpenApiSettings.isGenerateOptionalFieldsGlobally;
import static org.citrusframework.openapi.OpenApiSettings.isRequestValidationEnabledlobally;
import static org.citrusframework.openapi.OpenApiSettings.isResponseValidationEnabledGlobally;
import static org.citrusframework.openapi.OpenApiSettings.isValidateOptionalFieldsGlobally;

/**
* OpenApi specification resolves URL or local file resources to a specification document.
* <p>
Expand Down Expand Up @@ -209,7 +211,6 @@ public synchronized OasDocument getOpenApiDoc(TestContext context) {
}

if (resolvedSpecUrl.startsWith(HTTP)) {

URL specWebResource = toSpecUrl(resolvedSpecUrl);
if (resolvedSpecUrl.startsWith(HTTPS)) {
initApiDoc(
Expand Down Expand Up @@ -257,10 +258,10 @@ public synchronized OasDocument getOpenApiDoc(TestContext context) {
// provided for testing
URL toSpecUrl(String resolvedSpecUrl) {
try {
return new URL(resolvedSpecUrl);
return URI.create(resolvedSpecUrl).toURL();
} catch (MalformedURLException e) {
throw new IllegalStateException(
"Failed to retrieve Open API specification as web resource: " + specUrl, e);
"Failed to retrieve Open API specification as web resource: " + resolvedSpecUrl, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,6 @@
*
* @param <T> the type to which the specification is adapted.
*/
public class OpenApiSpecificationAdapter<T> {

private final OpenApiSpecification openApiSpecification;
public record OpenApiSpecificationAdapter<T>(OpenApiSpecification openApiSpecification, T entity) {

private final T entity;

public OpenApiSpecificationAdapter(OpenApiSpecification openApiSpecification, T entity) {
this.openApiSpecification = openApiSpecification;
this.entity = entity;
}

public OpenApiSpecification getOpenApiSpecification() {
return openApiSpecification;
}

public T getEntity() {
return entity;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@

package org.citrusframework.openapi;

import java.util.Map;
import org.citrusframework.spi.ResourcePathTypeResolver;
import org.citrusframework.spi.TypeResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

/**
* Interface for processing OpenAPI specifications.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@

package org.citrusframework.openapi;

import java.util.Collection;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationFeature;
Expand All @@ -33,6 +30,9 @@
import org.yaml.snakeyaml.nodes.Tag;
import org.yaml.snakeyaml.representer.Representer;

import java.util.Collection;
import java.util.Map;

public class OpenApiSupport {

private static final ObjectMapper OBJECT_MAPPER;
Expand Down
Loading

0 comments on commit 00ea177

Please sign in to comment.