io.github.swagger2markup.builder.Swagger2MarkupExtensionRegistryBuilder Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2017 Robert Winkler
*
* 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.
*/
package io.github.swagger2markup.builder;
import io.github.swagger2markup.Swagger2MarkupExtensionRegistry;
import io.github.swagger2markup.spi.*;
import java.util.List;
import static java.util.ServiceLoader.load;
import static org.apache.commons.collections4.IteratorUtils.toList;
public class Swagger2MarkupExtensionRegistryBuilder {
private final Context context;
public Swagger2MarkupExtensionRegistryBuilder() {
List swaggerModelExtensions = toList(load(SwaggerModelExtension.class).iterator());
List overviewDocumentExtensions = toList(load(OverviewDocumentExtension.class).iterator());
List definitionsDocumentExtensions = toList(load(DefinitionsDocumentExtension.class).iterator());
List pathsDocumentExtensions = toList(load(PathsDocumentExtension.class).iterator());
List securityDocumentExtensions = toList(load(SecurityDocumentExtension.class).iterator());
context = new Context(
swaggerModelExtensions,
overviewDocumentExtensions,
definitionsDocumentExtensions,
pathsDocumentExtensions,
securityDocumentExtensions);
}
public Swagger2MarkupExtensionRegistry build() {
return new DefaultSwagger2MarkupExtensionRegistry(context);
}
public Swagger2MarkupExtensionRegistryBuilder withSwaggerModelExtension(SwaggerModelExtension extension) {
context.swaggerModelExtensions.add(extension);
return this;
}
public Swagger2MarkupExtensionRegistryBuilder withOverviewDocumentExtension(OverviewDocumentExtension extension) {
context.overviewDocumentExtensions.add(extension);
return this;
}
public Swagger2MarkupExtensionRegistryBuilder withDefinitionsDocumentExtension(DefinitionsDocumentExtension extension) {
context.definitionsDocumentExtensions.add(extension);
return this;
}
public Swagger2MarkupExtensionRegistryBuilder withPathsDocumentExtension(PathsDocumentExtension extension) {
context.pathsDocumentExtensions.add(extension);
return this;
}
public Swagger2MarkupExtensionRegistryBuilder withSecurityDocumentExtension(SecurityDocumentExtension extension) {
context.securityDocumentExtensions.add(extension);
return this;
}
static class DefaultSwagger2MarkupExtensionRegistry implements Swagger2MarkupExtensionRegistry {
private Context context;
DefaultSwagger2MarkupExtensionRegistry(Context context) {
this.context = context;
}
@Override
public List getSwaggerModelExtensions() {
return context.swaggerModelExtensions;
}
@Override
public List getOverviewDocumentExtensions() {
return context.overviewDocumentExtensions;
}
@Override
public List getDefinitionsDocumentExtensions() {
return context.definitionsDocumentExtensions;
}
@Override
public List getSecurityDocumentExtensions() {
return context.securityDocumentExtensions;
}
@Override
public List getPathsDocumentExtensions() {
return context.pathsDocumentExtensions;
}
}
private static class Context {
public final List swaggerModelExtensions;
public final List overviewDocumentExtensions;
public final List definitionsDocumentExtensions;
public final List pathsDocumentExtensions;
public final List securityDocumentExtensions;
public Context(List swaggerModelExtensions,
List overviewDocumentExtensions,
List definitionsDocumentExtensions,
List pathsDocumentExtensions,
List securityDocumentExtensions) {
this.swaggerModelExtensions = swaggerModelExtensions;
this.overviewDocumentExtensions = overviewDocumentExtensions;
this.definitionsDocumentExtensions = definitionsDocumentExtensions;
this.pathsDocumentExtensions = pathsDocumentExtensions;
this.securityDocumentExtensions = securityDocumentExtensions;
}
}
}