From 2c13f4ab02e970b776134f920a2a2734f254164d Mon Sep 17 00:00:00 2001 From: Andreas Grub Date: Sun, 6 Dec 2020 18:04:07 +0100 Subject: [PATCH] [#10] Add setterTarget to referenced entries, add ReferencedItemBuildContext --- .../AbstractReferencedItemStorage.java | 41 +++++++++++++------ .../ReferencedItemSupportFactory.java | 7 +++- .../ReferencedCallbacksHandlerImpl.java | 6 ++- .../ReferencedExamplesHandlerImpl.java | 6 ++- .../header/ReferencedHeadersHandlerImpl.java | 6 ++- .../link/ReferencedLinksHandlerImpl.java | 6 ++- .../ReferencedParametersHandlerImpl.java | 5 ++- .../ReferencedRequestBodyHandlerImpl.java | 6 ++- .../ReferencedApiResponsesHandlerImpl.java | 6 ++- .../schema/ReferencedSchemaHandlerImpl.java | 6 ++- .../ReferencedSecuritySchemesHandlerImpl.java | 4 +- ...ctDependentReferencedComponentHandler.java | 2 + .../AbstractReferencedComponentHandler.java | 10 +++-- .../handler/ReferencedItemBuildContext.java | 24 +++++++++++ .../handler/ReferencedItemHandler.java | 2 +- .../tag/ReferencedTagsHandlerImpl.java | 4 +- 16 files changed, 105 insertions(+), 36 deletions(-) create mode 100644 openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/handler/ReferencedItemBuildContext.java diff --git a/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/AbstractReferencedItemStorage.java b/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/AbstractReferencedItemStorage.java index f054276d..4fcd90e7 100644 --- a/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/AbstractReferencedItemStorage.java +++ b/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/AbstractReferencedItemStorage.java @@ -23,10 +23,12 @@ import de.qaware.openapigeneratorforspring.common.reference.fortype.ReferenceDeciderForType; import de.qaware.openapigeneratorforspring.common.reference.fortype.ReferenceIdentifierBuilderForType; import de.qaware.openapigeneratorforspring.common.reference.fortype.ReferenceIdentifierConflictResolverForType; +import de.qaware.openapigeneratorforspring.common.reference.handler.ReferencedItemBuildContext; import de.qaware.openapigeneratorforspring.common.util.OpenApiProxyUtils; import de.qaware.openapigeneratorforspring.model.trait.HasReference; import lombok.AccessLevel; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; @@ -34,6 +36,7 @@ import org.apache.commons.lang3.tuple.Pair; import javax.annotation.Nullable; +import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; @@ -63,6 +66,10 @@ public abstract class AbstractReferencedItemStorage> { private final List> entries = new ArrayList<>(); + public static ReferencedItemBuildContext createContext() { + return null; + } + @Builder @Getter(AccessLevel.PRIVATE) protected static class AddEntryParameters { @@ -93,7 +100,23 @@ protected void addEntry(T item, Consumer setter, AddEntryParameters options) ReferenceSetter.of(setter, options.isReferenceRequired()), options.getSuggestedIdentifier() ); - entries.add(Entry.of(item, referenceSetterWithIdentifier, options.getOwner())); + entries.add(Entry.of(item, referenceSetterWithIdentifier, options.getOwner(), findSetterTarget(setter))); + } + + @Nullable + private Object findSetterTarget(Consumer setter) { + Field[] declaredFields = setter.getClass().getDeclaredFields(); + if (declaredFields.length == 1) { + Field declaredField = declaredFields[0]; + declaredField.setAccessible(true); + try { + return declaredField.get(setter); + } catch (IllegalAccessException e) { + // this should not happen, as we've made it accessible... + return null; + } + } + return null; } protected void removeEntriesOwnedBy(Object owner) { @@ -104,7 +127,7 @@ public Pair> getBuildDependencies() { return Pair.of(referenceType, buildDependencies); } - public void buildReferencedItems(Consumer> referencedItemsConsumer) { + public void buildReferencedItems(Consumer> referencedItemsConsumer, @Nullable ReferencedItemBuildContext context) { Map referencedItems = new LinkedHashMap<>(); ReferenceActions referenceActions = new ReferenceActions(); buildGroupedEntries() @@ -257,21 +280,15 @@ private GroupedEntry createNewGroupedEntry(Entry entry) { @RequiredArgsConstructor(staticName = "of") @Getter + @EqualsAndHashCode(onlyExplicitlyIncluded = true) private static class Entry { + @EqualsAndHashCode.Include private final T item; private final ReferenceSetterWithIdentifier referenceSetterWithIdentifier; @Nullable private final Object owner; - - @Override - public boolean equals(Object obj) { - return obj instanceof Entry && item.equals(((Entry) obj).item); - } - - @Override - public int hashCode() { - return item.hashCode(); - } + @Nullable + private final Object setterTarget; } @RequiredArgsConstructor(staticName = "of") diff --git a/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/ReferencedItemSupportFactory.java b/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/ReferencedItemSupportFactory.java index 55501539..1a180a8d 100644 --- a/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/ReferencedItemSupportFactory.java +++ b/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/ReferencedItemSupportFactory.java @@ -21,6 +21,7 @@ package de.qaware.openapigeneratorforspring.common.reference; import de.qaware.openapigeneratorforspring.common.reference.handler.AbstractDependentReferencedComponentHandler; +import de.qaware.openapigeneratorforspring.common.reference.handler.ReferencedItemBuildContext; import de.qaware.openapigeneratorforspring.common.reference.handler.ReferencedItemHandler; import de.qaware.openapigeneratorforspring.common.reference.handler.ReferencedItemHandlerFactory; import de.qaware.openapigeneratorforspring.model.Components; @@ -69,7 +70,7 @@ public void applyToOpenApi(OpenApi openApi) { return (AbstractDependentReferencedComponentHandler) itemHandler; } // non-dependent handler can already be handled here - itemHandler.applyToOpenApi(openApi); + itemHandler.applyToOpenApi(openApi, null); return null; }) .filter(Objects::nonNull) @@ -103,11 +104,13 @@ public DependentReferencedComponentHandlersSupport(OpenApi openApi, List> transitiveDependencies = handlersMap.keySet().stream() .collect(Collectors.toMap(r -> r, r -> buildTransitiveDependencies(r).collect(Collectors.toSet()))); + + ReferencedItemBuildContext buildContext = AbstractReferencedItemStorage.createContext(); handlersMap.values().stream() .sorted(buildDependencyComparator(transitiveDependencies)) // makes less-dependent handlers go first! .forEach(handler -> { LOGGER.debug("Building components for {}", handler.getType()); - handler.getHandler().applyToOpenApi(openApi); + handler.getHandler().applyToOpenApi(openApi, buildContext); }); } diff --git a/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/component/callback/ReferencedCallbacksHandlerImpl.java b/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/component/callback/ReferencedCallbacksHandlerImpl.java index 3bbd3404..64057793 100644 --- a/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/component/callback/ReferencedCallbacksHandlerImpl.java +++ b/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/component/callback/ReferencedCallbacksHandlerImpl.java @@ -22,11 +22,13 @@ import de.qaware.openapigeneratorforspring.common.reference.ReferenceType; import de.qaware.openapigeneratorforspring.common.reference.handler.AbstractDependentReferencedComponentHandler; +import de.qaware.openapigeneratorforspring.common.reference.handler.ReferencedItemBuildContext; import de.qaware.openapigeneratorforspring.model.Components; import de.qaware.openapigeneratorforspring.model.operation.Callback; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.tuple.Pair; +import javax.annotation.Nullable; import java.util.List; import java.util.Map; import java.util.function.Consumer; @@ -48,7 +50,7 @@ public Pair> getBuildDependencies() { } @Override - public void applyToComponents(Components components) { - storage.buildReferencedItems(components::setCallbacks); + public void applyToComponents(Components components, @Nullable ReferencedItemBuildContext context) { + storage.buildReferencedItems(components::setCallbacks, context); } } diff --git a/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/component/example/ReferencedExamplesHandlerImpl.java b/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/component/example/ReferencedExamplesHandlerImpl.java index a166754e..3a7f0cf9 100644 --- a/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/component/example/ReferencedExamplesHandlerImpl.java +++ b/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/component/example/ReferencedExamplesHandlerImpl.java @@ -22,11 +22,13 @@ import de.qaware.openapigeneratorforspring.common.reference.ReferenceType; import de.qaware.openapigeneratorforspring.common.reference.handler.AbstractDependentReferencedComponentHandler; +import de.qaware.openapigeneratorforspring.common.reference.handler.ReferencedItemBuildContext; import de.qaware.openapigeneratorforspring.model.Components; import de.qaware.openapigeneratorforspring.model.example.Example; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.tuple.Pair; +import javax.annotation.Nullable; import java.util.List; import java.util.Map; import java.util.function.Consumer; @@ -48,8 +50,8 @@ public Pair> getBuildDependencies() { } @Override - public void applyToComponents(Components components) { - storage.buildReferencedItems(components::setExamples); + public void applyToComponents(Components components, @Nullable ReferencedItemBuildContext context) { + storage.buildReferencedItems(components::setExamples, context); } } diff --git a/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/component/header/ReferencedHeadersHandlerImpl.java b/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/component/header/ReferencedHeadersHandlerImpl.java index 2924f536..974adb1c 100644 --- a/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/component/header/ReferencedHeadersHandlerImpl.java +++ b/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/component/header/ReferencedHeadersHandlerImpl.java @@ -22,11 +22,13 @@ import de.qaware.openapigeneratorforspring.common.reference.ReferenceType; import de.qaware.openapigeneratorforspring.common.reference.handler.AbstractDependentReferencedComponentHandler; +import de.qaware.openapigeneratorforspring.common.reference.handler.ReferencedItemBuildContext; import de.qaware.openapigeneratorforspring.model.Components; import de.qaware.openapigeneratorforspring.model.header.Header; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.tuple.Pair; +import javax.annotation.Nullable; import java.util.List; import java.util.Map; import java.util.function.Consumer; @@ -48,7 +50,7 @@ public Pair> getBuildDependencies() { } @Override - public void applyToComponents(Components components) { - storage.buildReferencedItems(components::setHeaders); + public void applyToComponents(Components components, @Nullable ReferencedItemBuildContext context) { + storage.buildReferencedItems(components::setHeaders, context); } } diff --git a/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/component/link/ReferencedLinksHandlerImpl.java b/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/component/link/ReferencedLinksHandlerImpl.java index f56dc334..7e04e536 100644 --- a/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/component/link/ReferencedLinksHandlerImpl.java +++ b/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/component/link/ReferencedLinksHandlerImpl.java @@ -22,11 +22,13 @@ import de.qaware.openapigeneratorforspring.common.reference.ReferenceType; import de.qaware.openapigeneratorforspring.common.reference.handler.AbstractDependentReferencedComponentHandler; +import de.qaware.openapigeneratorforspring.common.reference.handler.ReferencedItemBuildContext; import de.qaware.openapigeneratorforspring.model.Components; import de.qaware.openapigeneratorforspring.model.link.Link; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.tuple.Pair; +import javax.annotation.Nullable; import java.util.List; import java.util.Map; import java.util.function.Consumer; @@ -48,7 +50,7 @@ public Pair> getBuildDependencies() { } @Override - public void applyToComponents(Components components) { - storage.buildReferencedItems(components::setLinks); + public void applyToComponents(Components components, @Nullable ReferencedItemBuildContext context) { + storage.buildReferencedItems(components::setLinks, context); } } diff --git a/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/component/parameter/ReferencedParametersHandlerImpl.java b/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/component/parameter/ReferencedParametersHandlerImpl.java index a8a3c960..3794053e 100644 --- a/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/component/parameter/ReferencedParametersHandlerImpl.java +++ b/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/component/parameter/ReferencedParametersHandlerImpl.java @@ -22,6 +22,7 @@ import de.qaware.openapigeneratorforspring.common.reference.ReferenceType; import de.qaware.openapigeneratorforspring.common.reference.handler.AbstractDependentReferencedComponentHandler; +import de.qaware.openapigeneratorforspring.common.reference.handler.ReferencedItemBuildContext; import de.qaware.openapigeneratorforspring.model.Components; import de.qaware.openapigeneratorforspring.model.parameter.Parameter; import lombok.RequiredArgsConstructor; @@ -52,7 +53,7 @@ public Pair> getBuildDependencies() { } @Override - public void applyToComponents(Components components) { - storage.buildReferencedItems(components::setParameters); + public void applyToComponents(Components components, @Nullable ReferencedItemBuildContext context) { + storage.buildReferencedItems(components::setParameters, context); } } diff --git a/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/component/requestbody/ReferencedRequestBodyHandlerImpl.java b/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/component/requestbody/ReferencedRequestBodyHandlerImpl.java index 45cbdc68..75dde034 100644 --- a/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/component/requestbody/ReferencedRequestBodyHandlerImpl.java +++ b/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/component/requestbody/ReferencedRequestBodyHandlerImpl.java @@ -22,11 +22,13 @@ import de.qaware.openapigeneratorforspring.common.reference.ReferenceType; import de.qaware.openapigeneratorforspring.common.reference.handler.AbstractDependentReferencedComponentHandler; +import de.qaware.openapigeneratorforspring.common.reference.handler.ReferencedItemBuildContext; import de.qaware.openapigeneratorforspring.model.Components; import de.qaware.openapigeneratorforspring.model.requestbody.RequestBody; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.tuple.Pair; +import javax.annotation.Nullable; import java.util.List; import java.util.function.Consumer; @@ -47,7 +49,7 @@ public Pair> getBuildDependencies() { } @Override - public void applyToComponents(Components components) { - storage.buildReferencedItems(components::setRequestBodies); + public void applyToComponents(Components components, @Nullable ReferencedItemBuildContext context) { + storage.buildReferencedItems(components::setRequestBodies, context); } } diff --git a/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/component/response/ReferencedApiResponsesHandlerImpl.java b/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/component/response/ReferencedApiResponsesHandlerImpl.java index 236eb309..1dc59308 100644 --- a/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/component/response/ReferencedApiResponsesHandlerImpl.java +++ b/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/component/response/ReferencedApiResponsesHandlerImpl.java @@ -22,11 +22,13 @@ import de.qaware.openapigeneratorforspring.common.reference.ReferenceType; import de.qaware.openapigeneratorforspring.common.reference.handler.AbstractDependentReferencedComponentHandler; +import de.qaware.openapigeneratorforspring.common.reference.handler.ReferencedItemBuildContext; import de.qaware.openapigeneratorforspring.model.Components; import de.qaware.openapigeneratorforspring.model.response.ApiResponses; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.tuple.Pair; +import javax.annotation.Nullable; import java.util.List; import java.util.function.Consumer; @@ -47,7 +49,7 @@ public Pair> getBuildDependencies() { } @Override - public void applyToComponents(Components components) { - storage.buildReferencedItems(components::setResponses); + public void applyToComponents(Components components, @Nullable ReferencedItemBuildContext context) { + storage.buildReferencedItems(components::setResponses, context); } } diff --git a/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/component/schema/ReferencedSchemaHandlerImpl.java b/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/component/schema/ReferencedSchemaHandlerImpl.java index 77723ff9..b2b6d3fa 100644 --- a/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/component/schema/ReferencedSchemaHandlerImpl.java +++ b/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/component/schema/ReferencedSchemaHandlerImpl.java @@ -22,11 +22,13 @@ import de.qaware.openapigeneratorforspring.common.reference.ReferenceType; import de.qaware.openapigeneratorforspring.common.reference.handler.AbstractDependentReferencedComponentHandler; +import de.qaware.openapigeneratorforspring.common.reference.handler.ReferencedItemBuildContext; import de.qaware.openapigeneratorforspring.model.Components; import de.qaware.openapigeneratorforspring.model.media.Schema; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.tuple.Pair; +import javax.annotation.Nullable; import java.util.List; import java.util.function.Consumer; @@ -54,7 +56,7 @@ public Pair> getBuildDependencies() { } @Override - public void applyToComponents(Components components) { - storage.buildReferencedItems(components::setSchemas); + public void applyToComponents(Components components, @Nullable ReferencedItemBuildContext context) { + storage.buildReferencedItems(components::setSchemas, context); } } diff --git a/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/component/securityscheme/ReferencedSecuritySchemesHandlerImpl.java b/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/component/securityscheme/ReferencedSecuritySchemesHandlerImpl.java index e23f1337..34f878cb 100644 --- a/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/component/securityscheme/ReferencedSecuritySchemesHandlerImpl.java +++ b/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/component/securityscheme/ReferencedSecuritySchemesHandlerImpl.java @@ -22,12 +22,14 @@ import de.qaware.openapigeneratorforspring.common.mapper.SecuritySchemeAnnotationMapper; import de.qaware.openapigeneratorforspring.common.reference.handler.AbstractReferencedComponentHandler; +import de.qaware.openapigeneratorforspring.common.reference.handler.ReferencedItemBuildContext; import de.qaware.openapigeneratorforspring.common.security.OpenApiSecuritySchemesSupplier; import de.qaware.openapigeneratorforspring.common.supplier.OpenApiSpringBootApplicationAnnotationsSupplier; import de.qaware.openapigeneratorforspring.model.Components; import de.qaware.openapigeneratorforspring.model.security.SecurityScheme; import lombok.extern.slf4j.Slf4j; +import javax.annotation.Nullable; import java.util.Collection; import java.util.LinkedHashMap; import java.util.List; @@ -80,7 +82,7 @@ public void accept(Map map) { } @Override - public void applyToComponents(Components components) { + public void applyToComponents(Components components, @Nullable ReferencedItemBuildContext context) { setMapIfNotEmpty(securitySchemes, components::setSecuritySchemes); } } diff --git a/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/handler/AbstractDependentReferencedComponentHandler.java b/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/handler/AbstractDependentReferencedComponentHandler.java index e0e66a9d..ed78750d 100644 --- a/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/handler/AbstractDependentReferencedComponentHandler.java +++ b/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/handler/AbstractDependentReferencedComponentHandler.java @@ -25,6 +25,8 @@ import java.util.List; +// TODO do not derive from AbstractReferencedComponentHandler public abstract class AbstractDependentReferencedComponentHandler extends AbstractReferencedComponentHandler { + public abstract Pair> getBuildDependencies(); } diff --git a/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/handler/AbstractReferencedComponentHandler.java b/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/handler/AbstractReferencedComponentHandler.java index 5de30a23..659587b7 100644 --- a/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/handler/AbstractReferencedComponentHandler.java +++ b/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/handler/AbstractReferencedComponentHandler.java @@ -23,15 +23,19 @@ import de.qaware.openapigeneratorforspring.model.Components; import de.qaware.openapigeneratorforspring.model.OpenApi; +import javax.annotation.Nullable; import java.util.Objects; public abstract class AbstractReferencedComponentHandler implements ReferencedItemHandler { @Override - public final void applyToOpenApi(OpenApi openApi) { + public final void applyToOpenApi(OpenApi openApi, @Nullable ReferencedItemBuildContext context) { // ReferencedItemSupportFactory ensures that openApi.getComponents() is not null - applyToComponents(Objects.requireNonNull(openApi.getComponents(), "components of openApi must not be null")); + applyToComponents( + Objects.requireNonNull(openApi.getComponents(), "components of openApi must not be null"), + context + ); } - protected abstract void applyToComponents(Components components); + protected abstract void applyToComponents(Components components, @Nullable ReferencedItemBuildContext context); } diff --git a/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/handler/ReferencedItemBuildContext.java b/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/handler/ReferencedItemBuildContext.java new file mode 100644 index 00000000..a646834f --- /dev/null +++ b/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/handler/ReferencedItemBuildContext.java @@ -0,0 +1,24 @@ +/*- + * #%L + * OpenAPI Generator for Spring Boot :: Common + * %% + * Copyright (C) 2020 QAware GmbH + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +package de.qaware.openapigeneratorforspring.common.reference.handler; + +public interface ReferencedItemBuildContext { +} diff --git a/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/handler/ReferencedItemHandler.java b/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/handler/ReferencedItemHandler.java index 2d69f6aa..77de261c 100644 --- a/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/handler/ReferencedItemHandler.java +++ b/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/handler/ReferencedItemHandler.java @@ -26,7 +26,7 @@ import javax.annotation.Nullable; public interface ReferencedItemHandler { - void applyToOpenApi(OpenApi openApi); + void applyToOpenApi(OpenApi openApi, @Nullable ReferencedItemBuildContext context); default ReferencedItemHandler withOwner(@Nullable Object object) { return this; diff --git a/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/tag/ReferencedTagsHandlerImpl.java b/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/tag/ReferencedTagsHandlerImpl.java index 4c1fff2c..05fdea22 100644 --- a/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/tag/ReferencedTagsHandlerImpl.java +++ b/openapi-generator-for-spring-common/src/main/java/de/qaware/openapigeneratorforspring/common/reference/tag/ReferencedTagsHandlerImpl.java @@ -21,6 +21,7 @@ package de.qaware.openapigeneratorforspring.common.reference.tag; import de.qaware.openapigeneratorforspring.common.mapper.TagAnnotationMapper; +import de.qaware.openapigeneratorforspring.common.reference.handler.ReferencedItemBuildContext; import de.qaware.openapigeneratorforspring.common.reference.handler.ReferencedItemHandler; import de.qaware.openapigeneratorforspring.common.supplier.OpenAPIDefinitionAnnotationSupplier; import de.qaware.openapigeneratorforspring.model.OpenApi; @@ -28,6 +29,7 @@ import io.swagger.v3.oas.annotations.OpenAPIDefinition; import org.apache.commons.lang3.StringUtils; +import javax.annotation.Nullable; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; @@ -52,7 +54,7 @@ public void accept(List tags) { @Override - public void applyToOpenApi(OpenApi openApi) { + public void applyToOpenApi(OpenApi openApi, @Nullable ReferencedItemBuildContext context) { setCollectionIfNotEmpty(new ArrayList<>(tagsByName.values()), openApi::setTags); }