From 6ac3b66db4651dda8f0b571d4068b6aff91aea6e Mon Sep 17 00:00:00 2001 From: Michael Edgar Date: Thu, 26 Sep 2024 20:05:23 -0400 Subject: [PATCH 1/2] Split builder API's build method to allow overrides Signed-off-by: Michael Edgar --- .../smallrye/openapi/api/SmallRyeOpenAPI.java | 243 +++++++++++++----- .../smallrye/openapi/runtime/io/ModelIO.java | 4 + 2 files changed, 188 insertions(+), 59 deletions(-) diff --git a/core/src/main/java/io/smallrye/openapi/api/SmallRyeOpenAPI.java b/core/src/main/java/io/smallrye/openapi/api/SmallRyeOpenAPI.java index d7d92174d..4f169c8e0 100644 --- a/core/src/main/java/io/smallrye/openapi/api/SmallRyeOpenAPI.java +++ b/core/src/main/java/io/smallrye/openapi/api/SmallRyeOpenAPI.java @@ -53,7 +53,7 @@ public class SmallRyeOpenAPI { private final BiFunction toString; @SuppressWarnings("unchecked") - private SmallRyeOpenAPI(OpenAPI model, Object jsonModel, BiFunction toString) { + protected SmallRyeOpenAPI(OpenAPI model, Object jsonModel, BiFunction toString) { this.model = model; this.jsonModel = jsonModel; this.toString = (BiFunction) toString; @@ -92,6 +92,9 @@ public static SmallRyeOpenAPI.Builder builder() { public static class Builder { private static final IndexView EMPTY_INDEX = new Indexer().complete(); + + private transient BuildContext buildContext; + private Config config; private ClassLoader applicationClassLoader; private OpenAPI initialModel; @@ -118,7 +121,19 @@ public static class Builder { private boolean enableStandardFilter = true; private Map filters = new LinkedHashMap<>(); - private Builder() { + protected Builder() { + } + + protected void removeContext() { + this.buildContext = null; + } + + @SuppressWarnings("unchecked") + protected BuildContext getContext() { + if (buildContext == null) { + buildContext = new BuildContext<>(this); + } + return (BuildContext) buildContext; } /** @@ -133,6 +148,7 @@ private Builder() { * @return this builder */ public Builder withConfig(Config config) { + removeContext(); this.config = Objects.requireNonNull(config); return this; } @@ -146,6 +162,7 @@ public Builder withConfig(Config config) { * @return this builder */ public Builder withApplicationClassLoader(ClassLoader classLoader) { + removeContext(); this.applicationClassLoader = Objects.requireNonNull(classLoader); return this; } @@ -160,6 +177,7 @@ public Builder withApplicationClassLoader(ClassLoader classLoader) { * @return this builder */ public Builder withInitialModel(OpenAPI initialModel) { + removeContext(); this.initialModel = initialModel; return this; } @@ -174,6 +192,7 @@ public Builder withInitialModel(OpenAPI initialModel) { * @return this builder */ public Builder enableModelReader(boolean enableModelReader) { + removeContext(); this.enableModelReader = enableModelReader; return this; } @@ -189,6 +208,7 @@ public Builder enableModelReader(boolean enableModelReader) { * @return this builder */ public Builder enableStandardStaticFiles(boolean enableStandardStaticFiles) { + removeContext(); this.enableStandardStaticFiles = enableStandardStaticFiles; return this; } @@ -203,6 +223,7 @@ public Builder enableStandardStaticFiles(boolean enableStandardStaticFiles) { * @return this builder */ public Builder enableStandardFilter(boolean enableStandardFilter) { + removeContext(); this.enableStandardFilter = enableStandardFilter; return this; } @@ -225,6 +246,7 @@ public Builder enableStandardFilter(boolean enableStandardFilter) { * @return this builder */ public Builder defaultRequiredProperties(boolean defaultRequiredProperties) { + removeContext(); this.defaultRequiredProperties = defaultRequiredProperties; return this; } @@ -240,6 +262,7 @@ public Builder defaultRequiredProperties(boolean defaultRequiredProperties) { * @return this builder */ public Builder withResourceLocator(Function resourceLocator) { + removeContext(); this.resourceLocator = resourceLocator; return this; } @@ -254,6 +277,7 @@ public Builder withResourceLocator(Function resourceLocator) { * @return this builder */ public Builder withCustomStaticFile(Supplier customStaticFile) { + removeContext(); this.customStaticFile = Objects.requireNonNull(customStaticFile); return this; } @@ -265,6 +289,7 @@ public Builder withCustomStaticFile(Supplier customStaticFile) { * @return this builder */ public Builder withIndex(IndexView index) { + removeContext(); this.index = Objects.requireNonNull(index); return this; } @@ -281,6 +306,7 @@ public Builder withIndex(IndexView index) { * @return this builder */ public Builder withContextRootResolver(Function, String> contextRootResolver) { + removeContext(); this.contextRootResolver = Objects.requireNonNull(contextRootResolver); return this; } @@ -295,6 +321,7 @@ public Builder withContextRootResolver(Function, String> c * @return this builder */ public Builder withTypeConverter(UnaryOperator typeConverter) { + removeContext(); this.typeConverter = Objects.requireNonNull(typeConverter); return this; } @@ -310,6 +337,7 @@ public Builder withTypeConverter(UnaryOperator typeConverter) { * @return this builder */ public Builder withJsonParser(Function jsonParser) { + removeContext(); this.jsonParser = jsonParser; return this; } @@ -324,6 +352,7 @@ public Builder withJsonParser(Function jsonParser) { * @return this builder */ public Builder withSchemaParser(Function schemaParser) { + removeContext(); this.schemaParser = schemaParser; return this; } @@ -336,6 +365,7 @@ public Builder withSchemaParser(Function schemaParser) { * @return this builder */ public Builder enableAnnotationScan(boolean enableAnnotationScan) { + removeContext(); this.enableAnnotationScan = enableAnnotationScan; return this; } @@ -350,6 +380,7 @@ public Builder enableAnnotationScan(boolean enableAnnotationScan) { * @return this builder */ public Builder enableUnannotatedPathParameters(boolean enableUnannotatedPathParameters) { + removeContext(); this.enableUnannotatedPathParameters = enableUnannotatedPathParameters; return this; } @@ -369,6 +400,7 @@ public Builder enableUnannotatedPathParameters(boolean enableUnannotatedPathPara * @return this builder */ public Builder withScannerClassLoader(ClassLoader scannerClassLoader) { + removeContext(); this.scannerClassLoader = scannerClassLoader; return this; } @@ -381,6 +413,7 @@ public Builder withScannerClassLoader(ClassLoader scannerClassLoader) { * @return this builder */ public Builder withScannerFilter(Predicate scannerFilter) { + removeContext(); this.scannerFilter = Objects.requireNonNull(scannerFilter); return this; } @@ -393,9 +426,10 @@ public Builder withScannerFilter(Predicate scannerFilter) { * @return this builder */ public Builder withFilters(Collection filters) { + removeContext(); Objects.requireNonNull(filters); this.filters.clear(); - filters.forEach(filter -> this.filters.put(filter.getClass().getName(), filter)); + filters.forEach(this::addFilter); return this; } @@ -413,9 +447,31 @@ public Builder withFilters(Collection filters) { * @return this builder */ public Builder withFilterNames(Collection filterNames) { + removeContext(); + Objects.requireNonNull(filterNames); + this.filters.clear(); + filterNames.forEach(this::addFilterName); + return this; + } + + /** + * AProvide a collection of OASFilter implementation class names to apply to the final OpenAPI model. New + * instances of the named classes will be instantiated immediately using the + * {@linkplain ClassLoader} provided. If the given index is null, the filters will be + * created with a non-null, empty index. + * + * The filters will be executed in the same order as given in the collection. + * + * @param filterNames collection of OASFilter implementation class names + * @param classLoader CLassLoader use to load the filter + * @param index IndexView passed to the filter, possibly null + * @return this builder + */ + public Builder withFilterNames(Collection filterNames, ClassLoader classLoader, IndexView index) { + removeContext(); Objects.requireNonNull(filterNames); - filters.clear(); - filterNames.forEach(filter -> this.filters.put(filter, null)); + this.filters.clear(); + filterNames.forEach(name -> this.addFilter(name, classLoader, index)); return this; } @@ -427,6 +483,7 @@ public Builder withFilterNames(Collection filterNames) { * @return this builder */ public Builder addFilter(OASFilter filter) { + removeContext(); Objects.requireNonNull(filter); filters.put(filter.getClass().getName(), filter); return this; @@ -446,51 +503,52 @@ public Builder addFilter(OASFilter filter) { * @return this builder */ public Builder addFilterName(String filterName) { + removeContext(); Objects.requireNonNull(filterName); filters.put(filterName, null); return this; } /** - * Build a new {@linkplain SmallRyeOpenAPI} instance based on the current state of this builder. + * Add an OASFilter implementation class name to apply to the final OpenAPI model. A new + * instance of the named class will be instantiated immediately using the + * {@linkplain ClassLoader} provided. If the given index is null, the filter will be + * created with a non-null, empty index. * - * @param JSON value type - * @param JSON array type - * @param JSON object type - * @param JSON array builder type - * @param JSON object builder type - * @return a new {@linkplain SmallRyeOpenAPI} instance + * Filters will be executed in the order they are added. + * + * @param filterName OASFilter implementation class name + * @param classLoader CLassLoader use to load the filter + * @param index IndexView passed to the filter, possibly null + * @return this builder */ - public SmallRyeOpenAPI build() { - ClassLoader appClassLoader = applicationClassLoader != null ? applicationClassLoader - : Thread.currentThread().getContextClassLoader(); - - OpenApiConfig buildConfig = OpenApiConfig.fromConfig(Optional.ofNullable(this.config) - .orElseGet(() -> ConfigProvider.getConfig(appClassLoader))); - IOContext io = IOContext.forJson(JsonIO.newInstance(buildConfig)); - OpenAPIDefinitionIO modelIO = new OpenAPIDefinitionIO<>(io); - FilteredIndexView filteredIndex = new FilteredIndexView(index, buildConfig); - - OpenAPI readerModel = null; - OpenAPI staticModel = null; - OpenAPI annotationModel = null; - OASFilter standardFilter = null; + public Builder addFilter(String filterName, ClassLoader classLoader, IndexView index) { + removeContext(); + Objects.requireNonNull(filterName); + Objects.requireNonNull(classLoader); + OASFilter filter = OpenApiProcessor.getFilter(filterName, classLoader, index != null ? index : EMPTY_INDEX); + filters.put(filterName, filter); + return this; + } + protected void buildReaderModel(BuildContext ctx) { if (enableModelReader) { - readerModel = OpenApiProcessor.modelFromReader(buildConfig, appClassLoader, filteredIndex); - debugModel("reader", readerModel); + ctx.readerModel = OpenApiProcessor.modelFromReader(ctx.buildConfig, ctx.appClassLoader, index); + debugModel("reader", ctx.readerModel); } + } + protected void buildStaticModel(BuildContext ctx) { if (enableStandardStaticFiles) { Function loadFn = Optional.ofNullable(resourceLocator) - .orElse(appClassLoader::getResource); + .orElse(ctx.appClassLoader::getResource); - staticModel = OpenApiProcessor.loadOpenApiStaticFiles(loadFn) + ctx.staticModel = OpenApiProcessor.loadOpenApiStaticFiles(loadFn) .stream() .map(file -> { try (Reader reader = new InputStreamReader(file.getContent())) { - V dom = io.jsonIO().fromReader(reader, file.getFormat()); - OpenAPI fileModel = modelIO.readValue(dom); + V dom = ctx.modelIO.jsonIO().fromReader(reader, file.getFormat()); + OpenAPI fileModel = ctx.modelIO.readValue(dom); debugModel("static file", fileModel); return fileModel; } catch (IOException e) { @@ -506,56 +564,123 @@ public SmallRyeOpenAPI build() { if (customFile != null) { try (Reader reader = new InputStreamReader(customFile)) { - V dom = io.jsonIO().fromReader(reader); - OpenAPI customStaticModel = modelIO.readValue(dom); + V dom = ctx.modelIO.jsonIO().fromReader(reader); + OpenAPI customStaticModel = ctx.modelIO.readValue(dom); debugModel("static file", customStaticModel); - staticModel = MergeUtil.merge(customStaticModel, staticModel); + ctx.staticModel = MergeUtil.merge(customStaticModel, ctx.staticModel); } catch (IOException e) { throw new OpenApiRuntimeException("IOException reading custom static file", e); } } + } - if (enableAnnotationScan && !buildConfig.scanDisable()) { - buildConfig.setAllowNakedPathParameter(enableUnannotatedPathParameters); - AnnotationScannerExtension ext = newExtension(modelIO); - AnnotationScannerContext scannerContext = new AnnotationScannerContext(filteredIndex, appClassLoader, - Collections.singletonList(ext), false, buildConfig, modelIO, new OpenAPIImpl()); - io.scannerContext(scannerContext); + protected void buildAnnotationModel(BuildContext ctx) { + if (enableAnnotationScan && !ctx.buildConfig.scanDisable()) { + ctx.buildConfig.setAllowNakedPathParameter(enableUnannotatedPathParameters); + AnnotationScannerExtension ext = newExtension(ctx.modelIO); + AnnotationScannerContext scannerContext = new AnnotationScannerContext(ctx.filteredIndex, ctx.appClassLoader, + Collections.singletonList(ext), false, ctx.buildConfig, ctx.modelIO, new OpenAPIImpl()); + ctx.modelIO.ioContext().scannerContext(scannerContext); Supplier> supplier = Optional.ofNullable(scannerClassLoader) .map(AnnotationScannerFactory::new) - .orElseGet(() -> new AnnotationScannerFactory(appClassLoader)); + .orElseGet(() -> new AnnotationScannerFactory(ctx.appClassLoader)); OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(scannerContext, supplier); - annotationModel = scanner.scan(scannerFilter); - debugModel("annotation", annotationModel); + ctx.annotationModel = scanner.scan(scannerFilter); + debugModel("annotation", ctx.annotationModel); } + } + protected void buildStandardFilter(BuildContext ctx) { if (enableStandardFilter) { - standardFilter = OpenApiProcessor.getFilter(buildConfig, appClassLoader, filteredIndex); + ctx.standardFilter = OpenApiProcessor.getFilter( + ctx.buildConfig, + ctx.appClassLoader, + ctx.filteredIndex); } + } - OpenApiDocument doc = OpenApiDocument.newInstance(); - doc.config(buildConfig); - doc.defaultRequiredProperties(defaultRequiredProperties); - doc.modelFromReader(MergeUtil.merge(initialModel, readerModel)); - doc.modelFromStaticFile(staticModel); - doc.modelFromAnnotations(annotationModel); + protected void buildPrepare(BuildContext ctx) { + ctx.doc.set(null); + } + + protected SmallRyeOpenAPI buildFinalize(BuildContext ctx) { + ctx.doc.config(ctx.buildConfig); + ctx.doc.defaultRequiredProperties(ctx.defaultRequiredProperties); + ctx.doc.modelFromReader(MergeUtil.merge(ctx.initialModel, ctx.readerModel)); + ctx.doc.modelFromStaticFile(ctx.staticModel); + ctx.doc.modelFromAnnotations(ctx.annotationModel); filters.entrySet() .stream() .map(e -> Optional.ofNullable(e.getValue()) // Create an instance from the key (class name) when the value is null - .orElseGet(() -> OpenApiProcessor.getFilter(e.getKey(), appClassLoader, filteredIndex))) - .forEach(doc::filter); + .orElseGet(() -> OpenApiProcessor.getFilter( + e.getKey(), + ctx.appClassLoader, + ctx.filteredIndex))) + .forEach(ctx.doc::filter); + + if (ctx.standardFilter != null && !filters.containsKey(ctx.standardFilter.getClass().getName())) { + ctx.doc.filter(ctx.standardFilter); + } - if (standardFilter != null && !filters.containsKey(standardFilter.getClass().getName())) { - doc.filter(standardFilter); + ctx.doc.initialize(); + OpenAPI model = ctx.doc.get(); + BiFunction toString = ctx.modelIO.jsonIO()::toString; + return new SmallRyeOpenAPI(model, ctx.modelIO.write(model).orElse(null), toString); + } + + protected static class BuildContext { + ClassLoader appClassLoader; + OpenApiConfig buildConfig; + OpenAPIDefinitionIO modelIO; + FilteredIndexView filteredIndex; + OpenAPI initialModel; + OpenAPI readerModel; + OpenAPI staticModel; + OpenAPI annotationModel; + OASFilter standardFilter; + boolean defaultRequiredProperties; + + OpenApiDocument doc; + + BuildContext(Builder builder) { + this.appClassLoader = builder.applicationClassLoader != null + ? builder.applicationClassLoader + : Thread.currentThread().getContextClassLoader(); + + this.buildConfig = OpenApiConfig.fromConfig(Optional.ofNullable(builder.config) + .orElseGet(() -> ConfigProvider.getConfig(this.appClassLoader))); + IOContext io = IOContext.forJson(JsonIO.newInstance(this.buildConfig)); + this.modelIO = new OpenAPIDefinitionIO<>(io); + this.filteredIndex = new FilteredIndexView(builder.index, this.buildConfig); + this.initialModel = builder.initialModel; + this.defaultRequiredProperties = builder.defaultRequiredProperties; + + this.doc = OpenApiDocument.newInstance(); } + } + + /** + * Build a new {@linkplain SmallRyeOpenAPI} instance based on the current state of this builder. + * + * @param JSON value type + * @param JSON array type + * @param JSON object type + * @param JSON array builder type + * @param JSON object builder type + * @return a new {@linkplain SmallRyeOpenAPI} instance + */ + public SmallRyeOpenAPI build() { + BuildContext ctx = getContext(); - doc.initialize(); + buildPrepare(ctx); + buildReaderModel(ctx); + buildStaticModel(ctx); + buildAnnotationModel(ctx); + buildStandardFilter(ctx); - OpenAPI model = doc.get(); - BiFunction toString = io.jsonIO()::toString; - return new SmallRyeOpenAPI(model, modelIO.write(model).orElse(null), toString); + return buildFinalize(ctx); } private AnnotationScannerExtension newExtension( diff --git a/core/src/main/java/io/smallrye/openapi/runtime/io/ModelIO.java b/core/src/main/java/io/smallrye/openapi/runtime/io/ModelIO.java index ac49bfc7c..ae72d1f87 100644 --- a/core/src/main/java/io/smallrye/openapi/runtime/io/ModelIO.java +++ b/core/src/main/java/io/smallrye/openapi/runtime/io/ModelIO.java @@ -30,6 +30,10 @@ protected ModelIO(IOContext context, DotName annotationName, Do this.modelName = modelName; } + public IOContext ioContext() { + return context; + } + public JsonIO jsonIO() { return context.jsonIO(); } From 47e451c3ef86b097781a920fa0179ccfe5fcbc84 Mon Sep 17 00:00:00 2001 From: Michael Edgar Date: Fri, 27 Sep 2024 08:57:24 -0400 Subject: [PATCH 2/2] Reduce number of initializer lambdas throughout model classes Signed-off-by: Michael Edgar --- .../openapi/api/models/ComponentsImpl.java | 40 +++++++++---------- .../openapi/api/models/ExtensibleImpl.java | 5 +-- .../openapi/api/models/OpenAPIImpl.java | 10 ++--- .../openapi/api/models/OperationImpl.java | 24 +++++------ .../openapi/api/models/PathItemImpl.java | 11 +++-- .../openapi/api/models/PathsImpl.java | 5 +-- .../api/models/callbacks/CallbackImpl.java | 5 +-- .../api/models/headers/HeaderImpl.java | 5 +-- .../openapi/api/models/links/LinkImpl.java | 5 +-- .../openapi/api/models/media/ContentImpl.java | 5 +-- .../api/models/media/DiscriminatorImpl.java | 5 +-- .../api/models/media/EncodingImpl.java | 5 +-- .../api/models/media/MediaTypeImpl.java | 9 ++--- .../openapi/api/models/media/SchemaImpl.java | 2 +- .../api/models/parameters/ParameterImpl.java | 5 +-- .../api/models/responses/APIResponseImpl.java | 9 ++--- .../models/responses/APIResponsesImpl.java | 5 +-- .../api/models/security/OAuthFlowImpl.java | 5 +-- .../api/models/servers/ServerImpl.java | 5 +-- .../models/servers/ServerVariableImpl.java | 7 ++-- .../openapi/runtime/util/ModelUtil.java | 18 ++++++++- 21 files changed, 93 insertions(+), 97 deletions(-) diff --git a/core/src/main/java/io/smallrye/openapi/api/models/ComponentsImpl.java b/core/src/main/java/io/smallrye/openapi/api/models/ComponentsImpl.java index cceb4e47c..da7dbbfce 100644 --- a/core/src/main/java/io/smallrye/openapi/api/models/ComponentsImpl.java +++ b/core/src/main/java/io/smallrye/openapi/api/models/ComponentsImpl.java @@ -1,6 +1,5 @@ package io.smallrye.openapi.api.models; -import java.util.LinkedHashMap; import java.util.Map; import org.eclipse.microprofile.openapi.models.Components; @@ -44,7 +43,7 @@ public Map getSchemas() { */ @Override public void setSchemas(Map schemas) { - this.schemas = ModelUtil.replace(schemas, LinkedHashMap::new); + this.schemas = ModelUtil.replace(schemas); } /** @@ -53,7 +52,7 @@ public void setSchemas(Map schemas) { */ @Override public Components addSchema(String key, Schema schema) { - this.schemas = ModelUtil.add(key, schema, this.schemas, LinkedHashMap::new); + this.schemas = ModelUtil.add(key, schema, this.schemas); return this; } @@ -78,7 +77,7 @@ public Map getResponses() { */ @Override public void setResponses(Map responses) { - this.responses = ModelUtil.replace(responses, LinkedHashMap::new); + this.responses = ModelUtil.replace(responses); } /** @@ -87,7 +86,7 @@ public void setResponses(Map responses) { */ @Override public Components addResponse(String key, APIResponse response) { - this.responses = ModelUtil.add(key, response, this.responses, LinkedHashMap::new); + this.responses = ModelUtil.add(key, response, this.responses); return this; } @@ -112,7 +111,7 @@ public Map getParameters() { */ @Override public void setParameters(Map parameters) { - this.parameters = ModelUtil.replace(parameters, LinkedHashMap::new); + this.parameters = ModelUtil.replace(parameters); } /** @@ -121,7 +120,7 @@ public void setParameters(Map parameters) { */ @Override public Components addParameter(String key, Parameter parameter) { - this.parameters = ModelUtil.add(key, parameter, this.parameters, LinkedHashMap::new); + this.parameters = ModelUtil.add(key, parameter, this.parameters); return this; } @@ -146,7 +145,7 @@ public Map getExamples() { */ @Override public void setExamples(Map examples) { - this.examples = ModelUtil.replace(examples, LinkedHashMap::new); + this.examples = ModelUtil.replace(examples); } /** @@ -155,7 +154,7 @@ public void setExamples(Map examples) { */ @Override public Components addExample(String key, Example example) { - this.examples = ModelUtil.add(key, example, this.examples, LinkedHashMap::new); + this.examples = ModelUtil.add(key, example, this.examples); return this; } @@ -180,7 +179,7 @@ public Map getRequestBodies() { */ @Override public void setRequestBodies(Map requestBodies) { - this.requestBodies = ModelUtil.replace(requestBodies, LinkedHashMap::new); + this.requestBodies = ModelUtil.replace(requestBodies); } /** @@ -189,7 +188,7 @@ public void setRequestBodies(Map requestBodies) { */ @Override public Components addRequestBody(String key, RequestBody requestBody) { - this.requestBodies = ModelUtil.add(key, requestBody, this.requestBodies, LinkedHashMap::new); + this.requestBodies = ModelUtil.add(key, requestBody, this.requestBodies); return this; } @@ -214,7 +213,7 @@ public Map getHeaders() { */ @Override public void setHeaders(Map headers) { - this.headers = ModelUtil.replace(headers, LinkedHashMap::new); + this.headers = ModelUtil.replace(headers); } /** @@ -223,7 +222,7 @@ public void setHeaders(Map headers) { */ @Override public Components addHeader(String key, Header header) { - this.headers = ModelUtil.add(key, header, this.headers, LinkedHashMap::new); + this.headers = ModelUtil.add(key, header, this.headers); return this; } @@ -248,7 +247,7 @@ public Map getSecuritySchemes() { */ @Override public void setSecuritySchemes(Map securitySchemes) { - this.securitySchemes = ModelUtil.replace(securitySchemes, LinkedHashMap::new); + this.securitySchemes = ModelUtil.replace(securitySchemes); } /** @@ -257,8 +256,7 @@ public void setSecuritySchemes(Map securitySchemes) { */ @Override public Components addSecurityScheme(String key, SecurityScheme securityScheme) { - this.securitySchemes = ModelUtil.add(key, securityScheme, this.securitySchemes, - LinkedHashMap::new); + this.securitySchemes = ModelUtil.add(key, securityScheme, this.securitySchemes); return this; } @@ -283,7 +281,7 @@ public Map getLinks() { */ @Override public void setLinks(Map links) { - this.links = ModelUtil.replace(links, LinkedHashMap::new); + this.links = ModelUtil.replace(links); } /** @@ -292,7 +290,7 @@ public void setLinks(Map links) { */ @Override public Components addLink(String key, Link link) { - this.links = ModelUtil.add(key, link, this.links, LinkedHashMap::new); + this.links = ModelUtil.add(key, link, this.links); return this; } @@ -317,7 +315,7 @@ public Map getCallbacks() { */ @Override public void setCallbacks(Map callbacks) { - this.callbacks = ModelUtil.replace(callbacks, LinkedHashMap::new); + this.callbacks = ModelUtil.replace(callbacks); } /** @@ -326,7 +324,7 @@ public void setCallbacks(Map callbacks) { */ @Override public Components addCallback(String key, Callback callback) { - this.callbacks = ModelUtil.add(key, callback, this.callbacks, LinkedHashMap::new); + this.callbacks = ModelUtil.add(key, callback, this.callbacks); return this; } @@ -338,4 +336,4 @@ public void removeCallback(String key) { ModelUtil.remove(this.callbacks, key); } -} \ No newline at end of file +} diff --git a/core/src/main/java/io/smallrye/openapi/api/models/ExtensibleImpl.java b/core/src/main/java/io/smallrye/openapi/api/models/ExtensibleImpl.java index f7649ea93..7042f52db 100644 --- a/core/src/main/java/io/smallrye/openapi/api/models/ExtensibleImpl.java +++ b/core/src/main/java/io/smallrye/openapi/api/models/ExtensibleImpl.java @@ -1,6 +1,5 @@ package io.smallrye.openapi.api.models; -import java.util.LinkedHashMap; import java.util.Map; import org.eclipse.microprofile.openapi.models.Extensible; @@ -31,7 +30,7 @@ public Map getExtensions() { @SuppressWarnings("unchecked") @Override public T addExtension(String name, Object value) { - this.extensions = ModelUtil.add(name, value, this.extensions, LinkedHashMap::new); + this.extensions = ModelUtil.add(name, value, this.extensions); return (T) this; } @@ -48,7 +47,7 @@ public void removeExtension(String name) { */ @Override public void setExtensions(Map extensions) { - this.extensions = ModelUtil.replace(extensions, LinkedHashMap::new); + this.extensions = ModelUtil.replace(extensions); } } diff --git a/core/src/main/java/io/smallrye/openapi/api/models/OpenAPIImpl.java b/core/src/main/java/io/smallrye/openapi/api/models/OpenAPIImpl.java index 93afcd468..94db301af 100644 --- a/core/src/main/java/io/smallrye/openapi/api/models/OpenAPIImpl.java +++ b/core/src/main/java/io/smallrye/openapi/api/models/OpenAPIImpl.java @@ -89,7 +89,7 @@ public List getServers() { */ @Override public void setServers(List servers) { - this.servers = ModelUtil.replace(servers, ArrayList::new); + this.servers = ModelUtil.replace(servers); } /** @@ -97,7 +97,7 @@ public void setServers(List servers) { */ @Override public OpenAPI addServer(Server server) { - this.servers = ModelUtil.add(server, this.servers, ArrayList::new); + this.servers = ModelUtil.add(server, this.servers); return this; } @@ -122,7 +122,7 @@ public List getSecurity() { */ @Override public void setSecurity(List security) { - this.security = ModelUtil.replace(security, ArrayList::new); + this.security = ModelUtil.replace(security); } /** @@ -130,7 +130,7 @@ public void setSecurity(List security) { */ @Override public OpenAPI addSecurityRequirement(SecurityRequirement securityRequirement) { - this.security = ModelUtil.add(securityRequirement, this.security, ArrayList::new); + this.security = ModelUtil.add(securityRequirement, this.security); return this; } @@ -155,7 +155,7 @@ public List getTags() { */ @Override public void setTags(List tags) { - this.tags = ModelUtil.replace(tags, ArrayList::new); + this.tags = ModelUtil.replace(tags); } /** diff --git a/core/src/main/java/io/smallrye/openapi/api/models/OperationImpl.java b/core/src/main/java/io/smallrye/openapi/api/models/OperationImpl.java index ac47bcc29..082d08356 100644 --- a/core/src/main/java/io/smallrye/openapi/api/models/OperationImpl.java +++ b/core/src/main/java/io/smallrye/openapi/api/models/OperationImpl.java @@ -1,7 +1,5 @@ package io.smallrye.openapi.api.models; -import java.util.ArrayList; -import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -57,7 +55,7 @@ public List getTags() { */ @Override public void setTags(List tags) { - this.tags = ModelUtil.replace(tags, ArrayList::new); + this.tags = ModelUtil.replace(tags); } /** @@ -65,7 +63,7 @@ public void setTags(List tags) { */ @Override public Operation addTag(String tag) { - this.tags = ModelUtil.add(tag, this.tags, ArrayList::new); + this.tags = ModelUtil.add(tag, this.tags); return this; } @@ -154,7 +152,7 @@ public List getParameters() { */ @Override public void setParameters(List parameters) { - this.parameters = ModelUtil.replace(parameters, ArrayList::new); + this.parameters = ModelUtil.replace(parameters); } /** @@ -162,7 +160,7 @@ public void setParameters(List parameters) { */ @Override public Operation addParameter(Parameter parameter) { - this.parameters = ModelUtil.add(parameter, this.parameters, ArrayList::new); + this.parameters = ModelUtil.add(parameter, this.parameters); return this; } @@ -219,7 +217,7 @@ public Map getCallbacks() { */ @Override public void setCallbacks(Map callbacks) { - this.callbacks = ModelUtil.replace(callbacks, LinkedHashMap::new); + this.callbacks = ModelUtil.replace(callbacks); } /** @@ -228,7 +226,7 @@ public void setCallbacks(Map callbacks) { */ @Override public Operation addCallback(String key, Callback callback) { - this.callbacks = ModelUtil.add(key, callback, this.callbacks, LinkedHashMap::new); + this.callbacks = ModelUtil.add(key, callback, this.callbacks); return this; } @@ -269,7 +267,7 @@ public List getSecurity() { */ @Override public void setSecurity(List security) { - this.security = ModelUtil.replace(security, ArrayList::new); + this.security = ModelUtil.replace(security); } /** @@ -277,7 +275,7 @@ public void setSecurity(List security) { */ @Override public Operation addSecurityRequirement(SecurityRequirement securityRequirement) { - this.security = ModelUtil.add(securityRequirement, this.security, ArrayList::new); + this.security = ModelUtil.add(securityRequirement, this.security); return this; } @@ -302,7 +300,7 @@ public List getServers() { */ @Override public void setServers(List servers) { - this.servers = ModelUtil.replace(servers, ArrayList::new); + this.servers = ModelUtil.replace(servers); } /** @@ -310,7 +308,7 @@ public void setServers(List servers) { */ @Override public Operation addServer(Server server) { - this.servers = ModelUtil.add(server, this.servers, ArrayList::new); + this.servers = ModelUtil.add(server, this.servers); return this; } @@ -335,7 +333,7 @@ public void setMethodRef(String methodRef) { this.methodRef = methodRef; } - static public String getMethodRef(Operation operation) { + public static String getMethodRef(Operation operation) { return (operation instanceof OperationImpl) ? ((OperationImpl) operation).getMethodRef() : null; } } diff --git a/core/src/main/java/io/smallrye/openapi/api/models/PathItemImpl.java b/core/src/main/java/io/smallrye/openapi/api/models/PathItemImpl.java index 851318635..a6aae9ae1 100644 --- a/core/src/main/java/io/smallrye/openapi/api/models/PathItemImpl.java +++ b/core/src/main/java/io/smallrye/openapi/api/models/PathItemImpl.java @@ -1,6 +1,5 @@ package io.smallrye.openapi.api.models; -import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -286,7 +285,7 @@ public List getServers() { */ @Override public void setServers(List servers) { - this.servers = ModelUtil.replace(servers, ArrayList::new); + this.servers = ModelUtil.replace(servers); } /** @@ -294,7 +293,7 @@ public void setServers(List servers) { */ @Override public PathItem addServer(Server server) { - this.servers = ModelUtil.add(server, this.servers, ArrayList::new); + this.servers = ModelUtil.add(server, this.servers); return this; } @@ -319,7 +318,7 @@ public List getParameters() { */ @Override public void setParameters(List parameters) { - this.parameters = ModelUtil.replace(parameters, ArrayList::new); + this.parameters = ModelUtil.replace(parameters); } /** @@ -327,7 +326,7 @@ public void setParameters(List parameters) { */ @Override public PathItem addParameter(Parameter parameter) { - this.parameters = ModelUtil.add(parameter, this.parameters, ArrayList::new); + this.parameters = ModelUtil.add(parameter, this.parameters); return this; } @@ -352,4 +351,4 @@ private void addOperationToMap(HttpMethod method, Operation operation, Map implements Paths, ModelImpl */ @Override public Paths addPathItem(String name, PathItem item) { - this.pathItems = ModelUtil.add(name, item, this.pathItems, LinkedHashMap::new); + this.pathItems = ModelUtil.add(name, item, this.pathItems); return this; } @@ -46,7 +45,7 @@ public Map getPathItems() { */ @Override public void setPathItems(Map items) { - this.pathItems = ModelUtil.replace(items, LinkedHashMap::new); + this.pathItems = ModelUtil.replace(items); } // Begin Methods to support implementation of Map for MicroProfile OpenAPI 1.1 diff --git a/core/src/main/java/io/smallrye/openapi/api/models/callbacks/CallbackImpl.java b/core/src/main/java/io/smallrye/openapi/api/models/callbacks/CallbackImpl.java index c9214ad52..074f9794f 100644 --- a/core/src/main/java/io/smallrye/openapi/api/models/callbacks/CallbackImpl.java +++ b/core/src/main/java/io/smallrye/openapi/api/models/callbacks/CallbackImpl.java @@ -1,6 +1,5 @@ package io.smallrye.openapi.api.models.callbacks; -import java.util.LinkedHashMap; import java.util.Map; import org.eclipse.microprofile.openapi.models.PathItem; @@ -54,7 +53,7 @@ public Callback ref(String ref) { */ @Override public Callback addPathItem(String name, PathItem item) { - this.pathItems = ModelUtil.add(name, item, this.pathItems, LinkedHashMap::new); + this.pathItems = ModelUtil.add(name, item, this.pathItems); return this; } @@ -79,7 +78,7 @@ public Map getPathItems() { */ @Override public void setPathItems(Map items) { - this.pathItems = ModelUtil.replace(items, LinkedHashMap::new); + this.pathItems = ModelUtil.replace(items); } // Begin Methods to support implementation of Map for MicroProfile OpenAPI 1.1 diff --git a/core/src/main/java/io/smallrye/openapi/api/models/headers/HeaderImpl.java b/core/src/main/java/io/smallrye/openapi/api/models/headers/HeaderImpl.java index 040062266..385004d8d 100644 --- a/core/src/main/java/io/smallrye/openapi/api/models/headers/HeaderImpl.java +++ b/core/src/main/java/io/smallrye/openapi/api/models/headers/HeaderImpl.java @@ -1,6 +1,5 @@ package io.smallrye.openapi.api.models.headers; -import java.util.LinkedHashMap; import java.util.Map; import org.eclipse.microprofile.openapi.models.examples.Example; @@ -174,7 +173,7 @@ public Map getExamples() { */ @Override public void setExamples(Map examples) { - this.examples = ModelUtil.replace(examples, LinkedHashMap::new); + this.examples = ModelUtil.replace(examples); } /** @@ -183,7 +182,7 @@ public void setExamples(Map examples) { */ @Override public Header addExample(String key, Example example) { - this.examples = ModelUtil.add(key, example, this.examples, LinkedHashMap::new); + this.examples = ModelUtil.add(key, example, this.examples); return this; } diff --git a/core/src/main/java/io/smallrye/openapi/api/models/links/LinkImpl.java b/core/src/main/java/io/smallrye/openapi/api/models/links/LinkImpl.java index 286eda6d8..0fd43af5a 100644 --- a/core/src/main/java/io/smallrye/openapi/api/models/links/LinkImpl.java +++ b/core/src/main/java/io/smallrye/openapi/api/models/links/LinkImpl.java @@ -1,6 +1,5 @@ package io.smallrye.openapi.api.models.links; -import java.util.LinkedHashMap; import java.util.Map; import org.eclipse.microprofile.openapi.models.links.Link; @@ -120,7 +119,7 @@ public Map getParameters() { */ @Override public void setParameters(Map parameters) { - this.parameters = ModelUtil.replace(parameters, LinkedHashMap::new); + this.parameters = ModelUtil.replace(parameters); } /** @@ -128,7 +127,7 @@ public void setParameters(Map parameters) { */ @Override public Link addParameter(String name, Object parameter) { - this.parameters = ModelUtil.add(name, parameter, this.parameters, LinkedHashMap::new); + this.parameters = ModelUtil.add(name, parameter, this.parameters); return this; } diff --git a/core/src/main/java/io/smallrye/openapi/api/models/media/ContentImpl.java b/core/src/main/java/io/smallrye/openapi/api/models/media/ContentImpl.java index cd322a4ec..b874fa972 100644 --- a/core/src/main/java/io/smallrye/openapi/api/models/media/ContentImpl.java +++ b/core/src/main/java/io/smallrye/openapi/api/models/media/ContentImpl.java @@ -1,6 +1,5 @@ package io.smallrye.openapi.api.models.media; -import java.util.LinkedHashMap; import java.util.Map; import org.eclipse.microprofile.openapi.models.media.Content; @@ -23,7 +22,7 @@ public class ContentImpl implements Content, ModelImpl, MapModel { */ @Override public Content addMediaType(String name, MediaType mediaType) { - this.mediaTypes = ModelUtil.add(name, mediaType, this.mediaTypes, LinkedHashMap::new); + this.mediaTypes = ModelUtil.add(name, mediaType, this.mediaTypes); return this; } @@ -48,7 +47,7 @@ public Map getMediaTypes() { */ @Override public void setMediaTypes(Map mediaTypes) { - this.mediaTypes = ModelUtil.replace(mediaTypes, LinkedHashMap::new); + this.mediaTypes = ModelUtil.replace(mediaTypes); } // Begin Methods to support implementation of Map for MicroProfile OpenAPI 1.1 diff --git a/core/src/main/java/io/smallrye/openapi/api/models/media/DiscriminatorImpl.java b/core/src/main/java/io/smallrye/openapi/api/models/media/DiscriminatorImpl.java index d52515ed0..683267d78 100644 --- a/core/src/main/java/io/smallrye/openapi/api/models/media/DiscriminatorImpl.java +++ b/core/src/main/java/io/smallrye/openapi/api/models/media/DiscriminatorImpl.java @@ -1,6 +1,5 @@ package io.smallrye.openapi.api.models.media; -import java.util.LinkedHashMap; import java.util.Map; import org.eclipse.microprofile.openapi.models.media.Discriminator; @@ -37,7 +36,7 @@ public void setPropertyName(String propertyName) { */ @Override public Discriminator addMapping(String name, String value) { - this.mapping = ModelUtil.add(name, value, this.mapping, LinkedHashMap::new); + this.mapping = ModelUtil.add(name, value, this.mapping); return this; } @@ -62,7 +61,7 @@ public Map getMapping() { */ @Override public void setMapping(Map mapping) { - this.mapping = ModelUtil.replace(mapping, LinkedHashMap::new); + this.mapping = ModelUtil.replace(mapping); } } diff --git a/core/src/main/java/io/smallrye/openapi/api/models/media/EncodingImpl.java b/core/src/main/java/io/smallrye/openapi/api/models/media/EncodingImpl.java index f26ec5dd2..611167e7f 100644 --- a/core/src/main/java/io/smallrye/openapi/api/models/media/EncodingImpl.java +++ b/core/src/main/java/io/smallrye/openapi/api/models/media/EncodingImpl.java @@ -1,6 +1,5 @@ package io.smallrye.openapi.api.models.media; -import java.util.LinkedHashMap; import java.util.Map; import org.eclipse.microprofile.openapi.models.headers.Header; @@ -43,7 +42,7 @@ public void setContentType(String contentType) { */ @Override public Encoding addHeader(String key, Header header) { - this.headers = ModelUtil.add(key, header, this.headers, LinkedHashMap::new); + this.headers = ModelUtil.add(key, header, this.headers); return this; } @@ -68,7 +67,7 @@ public Map getHeaders() { */ @Override public void setHeaders(Map headers) { - this.headers = ModelUtil.replace(headers, LinkedHashMap::new); + this.headers = ModelUtil.replace(headers); } /** diff --git a/core/src/main/java/io/smallrye/openapi/api/models/media/MediaTypeImpl.java b/core/src/main/java/io/smallrye/openapi/api/models/media/MediaTypeImpl.java index d513a7123..6ae443641 100644 --- a/core/src/main/java/io/smallrye/openapi/api/models/media/MediaTypeImpl.java +++ b/core/src/main/java/io/smallrye/openapi/api/models/media/MediaTypeImpl.java @@ -1,6 +1,5 @@ package io.smallrye.openapi.api.models.media; -import java.util.LinkedHashMap; import java.util.Map; import org.eclipse.microprofile.openapi.models.examples.Example; @@ -51,7 +50,7 @@ public Map getExamples() { */ @Override public void setExamples(Map examples) { - this.examples = ModelUtil.replace(examples, LinkedHashMap::new); + this.examples = ModelUtil.replace(examples); } /** @@ -60,7 +59,7 @@ public void setExamples(Map examples) { */ @Override public MediaType addExample(String key, Example example) { - this.examples = ModelUtil.add(key, example, this.examples, LinkedHashMap::new); + this.examples = ModelUtil.add(key, example, this.examples); return this; } @@ -101,7 +100,7 @@ public Map getEncoding() { */ @Override public void setEncoding(Map encoding) { - this.encoding = ModelUtil.replace(encoding, LinkedHashMap::new); + this.encoding = ModelUtil.replace(encoding); } /** @@ -110,7 +109,7 @@ public void setEncoding(Map encoding) { */ @Override public MediaType addEncoding(String key, Encoding encodingItem) { - this.encoding = ModelUtil.add(key, encodingItem, this.encoding, LinkedHashMap::new); + this.encoding = ModelUtil.add(key, encodingItem, this.encoding); return this; } diff --git a/core/src/main/java/io/smallrye/openapi/api/models/media/SchemaImpl.java b/core/src/main/java/io/smallrye/openapi/api/models/media/SchemaImpl.java index 65d139c18..ed478c5a8 100644 --- a/core/src/main/java/io/smallrye/openapi/api/models/media/SchemaImpl.java +++ b/core/src/main/java/io/smallrye/openapi/api/models/media/SchemaImpl.java @@ -79,7 +79,7 @@ public static int getModCount(Schema schema) { public static void addTypeObserver(Schema observable, Schema observer) { if (observable instanceof SchemaImpl) { SchemaImpl obs = (SchemaImpl) observable; - obs.typeObservers = ModelUtil.add(observer, obs.typeObservers, ArrayList::new); + obs.typeObservers = ModelUtil.add(observer, obs.typeObservers); } observer.setType(observable.getType()); diff --git a/core/src/main/java/io/smallrye/openapi/api/models/parameters/ParameterImpl.java b/core/src/main/java/io/smallrye/openapi/api/models/parameters/ParameterImpl.java index 6b517233a..3b5fe9357 100644 --- a/core/src/main/java/io/smallrye/openapi/api/models/parameters/ParameterImpl.java +++ b/core/src/main/java/io/smallrye/openapi/api/models/parameters/ParameterImpl.java @@ -1,6 +1,5 @@ package io.smallrye.openapi.api.models.parameters; -import java.util.LinkedHashMap; import java.util.Map; import org.eclipse.microprofile.openapi.models.examples.Example; @@ -211,7 +210,7 @@ public Map getExamples() { */ @Override public void setExamples(Map examples) { - this.examples = ModelUtil.replace(examples, LinkedHashMap::new); + this.examples = ModelUtil.replace(examples); } /** @@ -220,7 +219,7 @@ public void setExamples(Map examples) { */ @Override public Parameter addExample(String key, Example example) { - this.examples = ModelUtil.add(key, example, this.examples, LinkedHashMap::new); + this.examples = ModelUtil.add(key, example, this.examples); return this; } diff --git a/core/src/main/java/io/smallrye/openapi/api/models/responses/APIResponseImpl.java b/core/src/main/java/io/smallrye/openapi/api/models/responses/APIResponseImpl.java index cd0a75043..4e652a612 100644 --- a/core/src/main/java/io/smallrye/openapi/api/models/responses/APIResponseImpl.java +++ b/core/src/main/java/io/smallrye/openapi/api/models/responses/APIResponseImpl.java @@ -1,6 +1,5 @@ package io.smallrye.openapi.api.models.responses; -import java.util.LinkedHashMap; import java.util.Map; import org.eclipse.microprofile.openapi.models.headers.Header; @@ -73,7 +72,7 @@ public Map getHeaders() { */ @Override public void setHeaders(Map headers) { - this.headers = ModelUtil.replace(headers, LinkedHashMap::new); + this.headers = ModelUtil.replace(headers); } /** @@ -82,7 +81,7 @@ public void setHeaders(Map headers) { */ @Override public APIResponse addHeader(String name, Header header) { - this.headers = ModelUtil.add(name, header, this.headers, LinkedHashMap::new); + this.headers = ModelUtil.add(name, header, this.headers); return this; } @@ -123,7 +122,7 @@ public Map getLinks() { */ @Override public void setLinks(Map links) { - this.links = ModelUtil.replace(links, LinkedHashMap::new); + this.links = ModelUtil.replace(links); } /** @@ -132,7 +131,7 @@ public void setLinks(Map links) { */ @Override public APIResponse addLink(String name, Link link) { - this.links = ModelUtil.add(name, link, this.links, LinkedHashMap::new); + this.links = ModelUtil.add(name, link, this.links); return this; } diff --git a/core/src/main/java/io/smallrye/openapi/api/models/responses/APIResponsesImpl.java b/core/src/main/java/io/smallrye/openapi/api/models/responses/APIResponsesImpl.java index b90d30f53..f08b5c3ec 100644 --- a/core/src/main/java/io/smallrye/openapi/api/models/responses/APIResponsesImpl.java +++ b/core/src/main/java/io/smallrye/openapi/api/models/responses/APIResponsesImpl.java @@ -1,6 +1,5 @@ package io.smallrye.openapi.api.models.responses; -import java.util.LinkedHashMap; import java.util.Map; import org.eclipse.microprofile.openapi.models.responses.APIResponse; @@ -24,7 +23,7 @@ public class APIResponsesImpl extends ExtensibleImpl implements AP */ @Override public APIResponses addAPIResponse(String name, APIResponse apiResponse) { - this.apiResponses = ModelUtil.add(name, apiResponse, this.apiResponses, LinkedHashMap::new); + this.apiResponses = ModelUtil.add(name, apiResponse, this.apiResponses); return this; } @@ -43,7 +42,7 @@ public Map getAPIResponses() { @Override public void setAPIResponses(Map items) { - this.apiResponses = ModelUtil.replace(items, LinkedHashMap::new); + this.apiResponses = ModelUtil.replace(items); } /** diff --git a/core/src/main/java/io/smallrye/openapi/api/models/security/OAuthFlowImpl.java b/core/src/main/java/io/smallrye/openapi/api/models/security/OAuthFlowImpl.java index 7ed5a1b9e..7e8917cb9 100644 --- a/core/src/main/java/io/smallrye/openapi/api/models/security/OAuthFlowImpl.java +++ b/core/src/main/java/io/smallrye/openapi/api/models/security/OAuthFlowImpl.java @@ -1,6 +1,5 @@ package io.smallrye.openapi.api.models.security; -import java.util.LinkedHashMap; import java.util.Map; import org.eclipse.microprofile.openapi.models.security.OAuthFlow; @@ -80,7 +79,7 @@ public Map getScopes() { */ @Override public void setScopes(Map scopes) { - this.scopes = ModelUtil.replace(scopes, LinkedHashMap::new); + this.scopes = ModelUtil.replace(scopes); } /* @@ -88,7 +87,7 @@ public void setScopes(Map scopes) { */ @Override public OAuthFlow addScope(String scope, String description) { - this.scopes = ModelUtil.add(scope, description, this.scopes, LinkedHashMap::new); + this.scopes = ModelUtil.add(scope, description, this.scopes); return this; } diff --git a/core/src/main/java/io/smallrye/openapi/api/models/servers/ServerImpl.java b/core/src/main/java/io/smallrye/openapi/api/models/servers/ServerImpl.java index 584941fc0..589804724 100644 --- a/core/src/main/java/io/smallrye/openapi/api/models/servers/ServerImpl.java +++ b/core/src/main/java/io/smallrye/openapi/api/models/servers/ServerImpl.java @@ -1,6 +1,5 @@ package io.smallrye.openapi.api.models.servers; -import java.util.LinkedHashMap; import java.util.Map; import org.eclipse.microprofile.openapi.models.servers.Server; @@ -64,7 +63,7 @@ public Map getVariables() { */ @Override public void setVariables(Map variables) { - this.variables = ModelUtil.replace(variables, LinkedHashMap::new); + this.variables = ModelUtil.replace(variables); } /* @@ -72,7 +71,7 @@ public void setVariables(Map variables) { */ @Override public Server addVariable(String variableName, ServerVariable variable) { - this.variables = ModelUtil.add(variableName, variable, this.variables, LinkedHashMap::new); + this.variables = ModelUtil.add(variableName, variable, this.variables); return this; } diff --git a/core/src/main/java/io/smallrye/openapi/api/models/servers/ServerVariableImpl.java b/core/src/main/java/io/smallrye/openapi/api/models/servers/ServerVariableImpl.java index f30fe11fb..dc8d79d85 100644 --- a/core/src/main/java/io/smallrye/openapi/api/models/servers/ServerVariableImpl.java +++ b/core/src/main/java/io/smallrye/openapi/api/models/servers/ServerVariableImpl.java @@ -1,6 +1,5 @@ package io.smallrye.openapi.api.models.servers; -import java.util.ArrayList; import java.util.List; import org.eclipse.microprofile.openapi.models.servers.ServerVariable; @@ -31,7 +30,7 @@ public List getEnumeration() { */ @Override public void setEnumeration(List enumeration) { - this.enumeration = ModelUtil.replace(enumeration, ArrayList::new); + this.enumeration = ModelUtil.replace(enumeration); } /** @@ -39,7 +38,7 @@ public void setEnumeration(List enumeration) { */ @Override public ServerVariable addEnumeration(String enumeration) { - this.enumeration = ModelUtil.add(enumeration, this.enumeration, ArrayList::new); + this.enumeration = ModelUtil.add(enumeration, this.enumeration); return this; } @@ -83,4 +82,4 @@ public void setDescription(String description) { this.description = description; } -} \ No newline at end of file +} diff --git a/core/src/main/java/io/smallrye/openapi/runtime/util/ModelUtil.java b/core/src/main/java/io/smallrye/openapi/runtime/util/ModelUtil.java index 7c76b16a3..0a3bcbe57 100644 --- a/core/src/main/java/io/smallrye/openapi/runtime/util/ModelUtil.java +++ b/core/src/main/java/io/smallrye/openapi/runtime/util/ModelUtil.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.function.Supplier; @@ -360,8 +361,11 @@ public static Map unmodifiableMap(Map map) { return map != null ? Collections.unmodifiableMap(map) : null; } - public static Map replace(Map modified, UnaryOperator> factory) { + public static Map replace(Map modified) { + return replace(modified, LinkedHashMap::new); + } + public static Map replace(Map modified, UnaryOperator> factory) { final Map replacement; if (modified == null) { @@ -373,6 +377,10 @@ public static Map replace(Map modified, UnaryOperator< return replacement; } + public static Map add(String key, V value, Map map) { + return add(key, value, map, LinkedHashMap::new); + } + public static Map add(String key, V value, Map map, Supplier> factory) { if (value != null) { if (map == null) { @@ -393,6 +401,10 @@ public static List unmodifiableList(List list) { return list != null ? Collections.unmodifiableList(list) : null; } + public static List replace(List modified) { + return replace(modified, ArrayList::new); + } + public static List replace(List modified, UnaryOperator> factory) { final List replacement; @@ -405,6 +417,10 @@ public static List replace(List modified, UnaryOperator> facto return replacement; } + public static List add(V value, List list) { + return add(value, list, ArrayList::new); + } + public static List add(V value, List list, Supplier> factory) { if (value != null) { if (list == null) {