Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,22 @@ Define a naming strategy to be used globally for all schema properties. Set to o
** A fully-qualified class name of an implementation of a JSON-B property naming strategy (`jakarta.json.bind.config.PropertyNamingStrategy` or `javax.json.bind.config.PropertyNamingStrategy`)
** A fully-qualified class name of an implementation of a Jackson property naming strategy base class (`com.fasterxml.jackson.databind.PropertyNamingStrategies.NamingBase`). Only the `translate` method is utilized.

* Removal of unused schemas
* Remove unused components
+
[source%nowrap]
----
mp.openapi.extensions.smallrye.remove-unused-components
----
Set to a comma-separated list of components types to enable automatic removal of unused components from `/components` in the OpenAPI model. Unused components will be removed following annotation scanning and after running all other `OASFilter` instances that may be configured. Disabled by default. Allowed values are the same as the keys for the https://spec.openapis.org/oas/v3.1.0.html#components-object[components object]. Specify `*` to enable removal of all unused components.

* Removal of unused schemas (DEPRECATED)
+
[source%nowrap]
----
mp.openapi.extensions.smallrye.remove-unused-schemas.enable
----
Deprecated - use `mp.openapi.extensions.smallrye.remove-unused-components=schemas` instead.

Set to `true` enable automatic removal of unused schemas from `components/schemas` in the OpenAPI model. Unused schemas will be removed following annotation scanning but prior to running any `OASFilter` that may be configured. Default value is `false`.

* Automatic Schema Inheritance
Expand Down
16 changes: 16 additions & 0 deletions core/src/main/java/io/smallrye/openapi/api/OpenApiConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.openapi.OASConfig;

import io.smallrye.openapi.api.constants.JsonbConstants;
import io.smallrye.openapi.model.ReferenceType;

/**
* Accessor to OpenAPI configuration options.
Expand Down Expand Up @@ -336,6 +338,20 @@ default boolean removeUnusedSchemas() {
return getConfigValue(SmallRyeOASConfig.SMALLRYE_REMOVE_UNUSED_SCHEMAS, Boolean.class, () -> Boolean.FALSE);
}

default Set<ReferenceType> removeUnusedComponents() {
return getConfigValues(SmallRyeOASConfig.SMALLRYE_REMOVE_UNUSED_COMPONENTS, String.class, this::toSet,
Collections::emptySet)
.stream()
.flatMap(entry -> {
if ("*".equals(entry)) {
return Arrays.stream(ReferenceType.values());
} else {
return Stream.of(ReferenceType.fromComponentPath(entry));
}
})
.collect(Collectors.toSet());
}

default boolean mergeSchemaExamples() {
return getConfigValue(SmallRyeOASConfig.SMALLRYE_MERGE_SCHEMA_EXAMPLES, Boolean.class, () -> Boolean.TRUE);
}
Expand Down
13 changes: 13 additions & 0 deletions core/src/main/java/io/smallrye/openapi/api/OpenApiDocument.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

import org.eclipse.microprofile.openapi.OASFactory;
import org.eclipse.microprofile.openapi.OASFilter;
Expand All @@ -10,7 +11,9 @@
import io.smallrye.openapi.api.util.ConfigUtil;
import io.smallrye.openapi.api.util.FilterUtil;
import io.smallrye.openapi.api.util.MergeUtil;
import io.smallrye.openapi.api.util.UnusedComponentFilter;
import io.smallrye.openapi.api.util.UnusedSchemaFilter;
import io.smallrye.openapi.model.ReferenceType;

/**
* Holds the final OpenAPI document produced during the startup of the app.
Expand Down Expand Up @@ -175,16 +178,26 @@ public synchronized void initialize() {
*
* @param model
*/
@SuppressWarnings("removal")
private OpenAPI filterModel(OpenAPI model) {
if (model == null) {
return model;
}

if (config.removeUnusedSchemas()) {
model = FilterUtil.applyFilter(new UnusedSchemaFilter(), model);
}

for (OASFilter filter : filters.values()) {
model = FilterUtil.applyFilter(filter, model);
}

Set<ReferenceType> removeUnusedComponents = config.removeUnusedComponents();

if (!removeUnusedComponents.isEmpty()) {
model = FilterUtil.applyFilter(new UnusedComponentFilter(removeUnusedComponents), model);
}

return model;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ private SmallRyeOASConfig() {
private static final String SUFFIX_PRIVATE_PROPERTIES_ENABLE = "private-properties.enable";
private static final String SUFFIX_PROPERTY_NAMING_STRATEGY = "property-naming-strategy";
private static final String SUFFIX_SORTED_PROPERTIES_ENABLE = "sorted-properties.enable";
private static final String SUFFIX_REMOVE_UNUSED_COMPONENTS = "remove-unused-components";
private static final String SUFFIX_REMOVE_UNUSED_SCHEMAS_ENABLE = "remove-unused-schemas.enable";
private static final String SUFFIX_MERGE_SCHEMA_EXAMPLES = "merge-schema-examples";
private static final String SUFFIX_SORTED_PARAMETERS_ENABLE = "sorted-parameters.enable";
Expand Down Expand Up @@ -53,6 +54,8 @@ private SmallRyeOASConfig() {

public static final String SMALLRYE_REMOVE_UNUSED_SCHEMAS = SMALLRYE_PREFIX + SUFFIX_REMOVE_UNUSED_SCHEMAS_ENABLE;

public static final String SMALLRYE_REMOVE_UNUSED_COMPONENTS = SMALLRYE_PREFIX + SUFFIX_REMOVE_UNUSED_COMPONENTS;

public static final String SMALLRYE_MERGE_SCHEMA_EXAMPLES = SMALLRYE_PREFIX + SUFFIX_MERGE_SCHEMA_EXAMPLES;

public static final String SMALLRYE_SORTED_PARAMETERS_ENABLE = SMALLRYE_PREFIX + SUFFIX_SORTED_PARAMETERS_ENABLE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*
* @author eric.wittmann@gmail.com
*/
@SuppressWarnings("removal")
@Deprecated(since = "4.0", forRemoval = true)
public abstract class ExtensibleImpl<T extends Extensible<T>> implements Extensible<T>, ModelImpl { // NOSONAR
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ private FilterUtil() {
* OpenAPI model
* @return Filtered OpenAPI model
*/
@Deprecated
public static final OpenAPI applyFilter(OASFilter filter, OpenAPI model) {
((BaseModel<?>) model).filter(filter, new IdentityHashMap<>());
return model;
Expand Down
Loading