Skip to content

Commit

Permalink
Formatting, fix Maven plugin test
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Edgar <michael@xlate.io>
  • Loading branch information
MikeEdgar committed Mar 15, 2024
1 parent a6b8ef0 commit d3020d9
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.function.UnaryOperator;

import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;
import org.eclipse.microprofile.openapi.OASFilter;
import org.eclipse.microprofile.openapi.models.Components;
import org.eclipse.microprofile.openapi.models.OpenAPI;
Expand Down Expand Up @@ -223,7 +224,8 @@ public <V, A extends V, O extends V, AB, OB> SmallRyeOpenAPI build() {
ClassLoader appClassLoader = applicationClassLoader != null ? applicationClassLoader
: Thread.currentThread().getContextClassLoader();

OpenApiConfig buildConfig = OpenApiConfig.fromConfig(this.config);
OpenApiConfig buildConfig = OpenApiConfig.fromConfig(Optional.ofNullable(this.config)
.orElseGet(ConfigProvider::getConfig));
IOContext<V, A, O, AB, OB> io = IOContext.forJson(JsonIO.newInstance(buildConfig));
OpenAPIDefinitionIO<V, A, O, AB, OB> modelIO = new OpenAPIDefinitionIO<>(io);
FilteredIndexView filteredIndex = new FilteredIndexView(index, buildConfig);
Expand Down Expand Up @@ -252,7 +254,8 @@ public <V, A extends V, O extends V, AB, OB> SmallRyeOpenAPI build() {
debugModel("static file", fileModel);
return fileModel;
} catch (IOException e) {
throw new OpenApiRuntimeException("IOException reading " + file.getFormat() + " static file", e);
throw new OpenApiRuntimeException("IOException reading " + file.getFormat() + " static file",
e);
}
})
.reduce(MergeUtil::merge)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public OpenApiStaticFile(InputStream content, Format format) {
this(null, content, format);
}


/**
* @see java.io.Closeable#close()
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ private static boolean isPathMatrixObject(Parameter parameter) {

public static String schemaToString(String entityName, Schema schema) {
return toJSON(OASFactory.createOpenAPI()
.components(OASFactory.createComponents()
.addSchema(entityName, schema)));
.components(OASFactory.createComponents()
.addSchema(entityName, schema)));
}

public static void assertJsonEquals(String entityName, String expectedResource, Schema actual)
Expand Down Expand Up @@ -204,7 +204,8 @@ public static OpenAPI scan(Config config, Class<?>... classes) {
return scan(config, false, null, classes);
}

public static OpenAPI scan(Config config, boolean defaultRequiredProperties, InputStream customStaticFile, Class<?>... classes) {
public static OpenAPI scan(Config config, boolean defaultRequiredProperties, InputStream customStaticFile,
Class<?>... classes) {
Index index = indexOf(classes);

OpenAPI result = SmallRyeOpenAPI.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,24 @@ class PropertyNamingStrategyTest extends IndexScannerTestBase {
@Test
void testSnakeCase() throws Exception {
OpenAPI result = scan(config(OpenApiConstants.SMALLRYE_PROPERTY_NAMING_STRATEGY,
"com.fasterxml.jackson.databind.PropertyNamingStrategies$SnakeCaseStrategy"),
"com.fasterxml.jackson.databind.PropertyNamingStrategies$SnakeCaseStrategy"),
NameStrategyBean1.class);
assertJsonEquals("components.schemas.name-strategy-snake.json", result);
}

@Test
void testJacksonNamingIgnoresConfig() throws Exception {
OpenAPI result = scan(config(OpenApiConstants.SMALLRYE_PROPERTY_NAMING_STRATEGY,
"com.fasterxml.jackson.databind.PropertyNamingStrategies$SnakeCaseStrategy"),
NameStrategyBean2.class);
"com.fasterxml.jackson.databind.PropertyNamingStrategies$SnakeCaseStrategy"),
NameStrategyBean2.class);
assertJsonEquals("components.schemas.name-strategy-ignored.json", result);
}

@Test
void testJacksonNamingOverridesConfig() throws Exception {
OpenAPI result = scan(config(OpenApiConstants.SMALLRYE_PROPERTY_NAMING_STRATEGY,
"com.fasterxml.jackson.databind.PropertyNamingStrategies$SnakeCaseStrategy"),
NameStrategyKebab.class);
"com.fasterxml.jackson.databind.PropertyNamingStrategies$SnakeCaseStrategy"),
NameStrategyKebab.class);
assertJsonEquals("components.schemas.name-strategy-kebab.json", result);
}

Expand All @@ -58,7 +58,7 @@ void testInvalidNamingStrategyClass() throws Exception {
@Test
void testNoValidTranslationMethods() throws Exception {
Config config = config(OpenApiConstants.SMALLRYE_PROPERTY_NAMING_STRATEGY,
NoValidTranslationMethods.class.getName());
NoValidTranslationMethods.class.getName());
assertThrows(OpenApiRuntimeException.class, () -> scan(config, NameStrategyKebab.class));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ static class AlligatorNoAllOf extends ReptileNoAllOf {
@Test
void testRegisteredSchemaTypePreserved() throws IOException, JSONException {
assertJsonEquals("components.schemas.registered-schema-type-preserved.json",
RegisteredSchemaTypePreservedModel.Animal.class,
RegisteredSchemaTypePreservedModel.AnimalListEnvelope.class,
RegisteredSchemaTypePreservedModel.MessageBase.class,
RegisteredSchemaTypePreservedModel.MessageData.class,
RegisteredSchemaTypePreservedModel.MessageDataItems.class);
RegisteredSchemaTypePreservedModel.Animal.class,
RegisteredSchemaTypePreservedModel.AnimalListEnvelope.class,
RegisteredSchemaTypePreservedModel.MessageBase.class,
RegisteredSchemaTypePreservedModel.MessageData.class,
RegisteredSchemaTypePreservedModel.MessageDataItems.class);
}

static class RegisteredSchemaTypePreservedModel {
Expand Down Expand Up @@ -313,13 +313,13 @@ public int getCurrentItemCount() {
@Test
void testJavaxJaxbElementUnwrapped() throws IOException, JSONException {
assertJsonEquals("components.schemas.jaxbelement-generic-type-unwrapped.json",
test.io.smallrye.openapi.runtime.scanner.javax.JAXBElementDto.class);
test.io.smallrye.openapi.runtime.scanner.javax.JAXBElementDto.class);
}

@Test
void testJakartaJaxbElementUnwrapped() throws IOException, JSONException {
assertJsonEquals("components.schemas.jaxbelement-generic-type-unwrapped.json",
test.io.smallrye.openapi.runtime.scanner.jakarta.JAXBElementDto.class);
test.io.smallrye.openapi.runtime.scanner.jakarta.JAXBElementDto.class);
}

/****************************************************************/
Expand All @@ -330,8 +330,8 @@ void testJakartaJaxbElementUnwrapped() throws IOException, JSONException {
@Test
void testJacksonJsonUnwrapped() throws IOException, JSONException {
assertJsonEquals("components.schemas-jackson-jsonunwrapped.json",
JacksonJsonPerson.class, JacksonJsonPersonWithPrefixedAddress.class,
JacksonJsonPersonWithSuffixedAddress.class, JacksonJsonAddress.class);
JacksonJsonPerson.class, JacksonJsonPersonWithPrefixedAddress.class,
JacksonJsonPersonWithSuffixedAddress.class, JacksonJsonAddress.class);
}

@Schema
Expand Down Expand Up @@ -378,17 +378,17 @@ static class JacksonJsonAddress {
void testNestedCollectionSchemas() throws IOException, JSONException {
// Place the JDK classes in the index to simulate Quarkus
assertJsonEquals("components.schemas.nested-parameterized-collection-types.json", CollectionBean.class,
EntryBean.class,
MultivaluedCollection.class,
MultivaluedMap.class,
// CustomMap.class excluded intentionally
Collection.class,
ArrayList.class,
HashMap.class,
List.class,
Map.class,
Set.class,
UUID.class);
EntryBean.class,
MultivaluedCollection.class,
MultivaluedMap.class,
// CustomMap.class excluded intentionally
Collection.class,
ArrayList.class,
HashMap.class,
List.class,
Map.class,
Set.class,
UUID.class);
}

@Schema
Expand Down Expand Up @@ -447,7 +447,8 @@ static class MultivaluedMap<K, V> extends HashMap<K, List<V>> {
*/
@Test
void testNestedCustomGenericSchemas() throws IOException, JSONException {
assertJsonEquals("components.schemas.nested-custom-generics.json", Foo.class, Generic0.class, Generic1.class, Generic2.class, CustomMap.class);
assertJsonEquals("components.schemas.nested-custom-generics.json", Foo.class, Generic0.class, Generic1.class,
Generic2.class, CustomMap.class);
}

/*
Expand Down Expand Up @@ -497,7 +498,8 @@ class A {
public List<Optional<B>> listOfOptionalB;
}

assertJsonEquals("components.schemas.optional-arraytype.json", B.class, A.class, UUID.class, List.class, Optional.class);
assertJsonEquals("components.schemas.optional-arraytype.json", B.class, A.class, UUID.class, List.class,
Optional.class);
}

@Target(ElementType.TYPE_USE)
Expand Down Expand Up @@ -629,7 +631,8 @@ class Bean {
OtherBean third;
}

assertJsonEquals("components.schemas.field-overrides-type.json", OtherBean.class, /* BeanTwo.class, BeanThree.class, */ Bean.class);
assertJsonEquals("components.schemas.field-overrides-type.json", OtherBean.class,
/* BeanTwo.class, BeanThree.class, */ Bean.class);
}

/*
Expand Down Expand Up @@ -673,7 +676,8 @@ class ZonedDateTimeArrayWrapper {
ZonedDateTime[] now;
}

assertJsonEquals("components.schemas.terminal-array-item-registration.json", ZonedDateTimeArrayWrapper.class, ZonedDateTime.class);
assertJsonEquals("components.schemas.terminal-array-item-registration.json", ZonedDateTimeArrayWrapper.class,
ZonedDateTime.class);
}

/*
Expand Down Expand Up @@ -720,9 +724,9 @@ class Bean {

String nullableStringArySig = Nullable.class.getName() + "<java.lang.String[]>";
OpenAPI result = scan(config(
OASConfig.SCHEMA_PREFIX + nullableStringArySig,
"{ \"name\": \"NullableStringArray\", \"type\": \"array\", \"items\": { \"type\": \"string\" }, \"nullable\": true }"),
Nullable.class, Bean.class);
OASConfig.SCHEMA_PREFIX + nullableStringArySig,
"{ \"name\": \"NullableStringArray\", \"type\": \"array\", \"items\": { \"type\": \"string\" }, \"nullable\": true }"),
Nullable.class, Bean.class);
assertJsonEquals("components.schemas.parameterized-type-schema-config.json", result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,8 @@ public Reference getDefaultBranch() {
}

assertJsonEquals("responses.nonjaxrs-methods-skipped.json", TreeApi.class,
HttpTreeApi.class,
Reference.class,
ReferencesResponse.class);
HttpTreeApi.class,
Reference.class,
ReferencesResponse.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ class VersionTest extends JaxRsDataObjectScannerTestBase {
*/
@Test
void testJavaxSettingViaProvidedSchema() throws IOException, JSONException {
testSettingViaProvidedSchema(test.io.smallrye.openapi.runtime.scanner.resources.javax.GreetingGetResource.class, Greeting.class);
testSettingViaProvidedSchema(test.io.smallrye.openapi.runtime.scanner.resources.javax.GreetingGetResource.class,
Greeting.class);
}

@Test
void testJakartaSettingViaProvidedSchema() throws IOException, JSONException {
testSettingViaProvidedSchema(test.io.smallrye.openapi.runtime.scanner.resources.jakarta.GreetingGetResource.class, Greeting.class);
testSettingViaProvidedSchema(test.io.smallrye.openapi.runtime.scanner.resources.jakarta.GreetingGetResource.class,
Greeting.class);
}

void testSettingViaProvidedSchema(Class<?>... classes) throws IOException, JSONException {
Expand All @@ -42,12 +44,14 @@ void testSettingViaProvidedSchema(Class<?>... classes) throws IOException, JSONE

@Test
void testJavaxSettingViaConfig() throws IOException, JSONException {
testSettingViaConfig(test.io.smallrye.openapi.runtime.scanner.resources.javax.GreetingGetResource.class, Greeting.class);
testSettingViaConfig(test.io.smallrye.openapi.runtime.scanner.resources.javax.GreetingGetResource.class,
Greeting.class);
}

@Test
void testJakartaSettingViaConfig() throws IOException, JSONException {
testSettingViaConfig(test.io.smallrye.openapi.runtime.scanner.resources.jakarta.GreetingGetResource.class, Greeting.class);
testSettingViaConfig(test.io.smallrye.openapi.runtime.scanner.resources.jakarta.GreetingGetResource.class,
Greeting.class);
}

void testSettingViaConfig(Class<?>... classes) throws IOException, JSONException {
Expand All @@ -63,12 +67,14 @@ void testSettingViaConfig(Class<?>... classes) throws IOException, JSONException

@Test
void testJavaxSettingViaConfigWhenStaticPresent() throws IOException, JSONException {
testSettingViaConfigWhenStaticPresent(test.io.smallrye.openapi.runtime.scanner.resources.javax.GreetingGetResource.class, Greeting.class);
testSettingViaConfigWhenStaticPresent(
test.io.smallrye.openapi.runtime.scanner.resources.javax.GreetingGetResource.class, Greeting.class);
}

@Test
void testJakartaSettingViaConfigWhenStaticPresent() throws IOException, JSONException {
testSettingViaConfigWhenStaticPresent(test.io.smallrye.openapi.runtime.scanner.resources.jakarta.GreetingGetResource.class, Greeting.class);
testSettingViaConfigWhenStaticPresent(
test.io.smallrye.openapi.runtime.scanner.resources.jakarta.GreetingGetResource.class, Greeting.class);
}

void testSettingViaConfigWhenStaticPresent(Class<?>... classes) throws IOException, JSONException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import com.soebes.itf.jupiter.maven.MavenExecutionResult;

import io.smallrye.config.SmallRyeConfigBuilder;
import io.smallrye.openapi.api.SmallRyeOpenAPI;

public class SchemaTestBase {
Expand Down Expand Up @@ -44,6 +45,7 @@ private OpenAPI read(MavenExecutionResult result, String path) throws IOExceptio
.resolve(path);

return SmallRyeOpenAPI.builder()
.withConfig(new SmallRyeConfigBuilder().addDefaultSources().build())
.enableAnnotationScan(false)
.enableModelReader(false)
.enableStandardFilter(false)
Expand Down

0 comments on commit d3020d9

Please sign in to comment.