All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.muserver.openapi.ComponentsObjectBuilder Maven / Gradle / Ivy

The newest version!
package io.muserver.openapi;

import java.util.Map;

import static io.muserver.openapi.OpenApiUtils.immutable;

/**
 * Holds a set of reusable objects for different aspects of the OAS. All objects defined within the components object
 * will have no effect on the API unless they are explicitly referenced from properties outside the components object.
 */
public class ComponentsObjectBuilder {
    Map schemas;
    private Map responses;
    private Map parameters;
    private Map examples;
    private Map requestBodies;
    private Map headers;
    private Map securitySchemes;
    private Map links;
    private Map callbacks;

    /**
     * @param schemas An object to hold reusable Schema Objects.
     * @return The current builder
     */
    public ComponentsObjectBuilder withSchemas(Map schemas) {
        this.schemas = schemas;
        return this;
    }

    /**
     * @param responses An object to hold reusable Response Objects.
     * @return The current builder
     */
    public ComponentsObjectBuilder withResponses(Map responses) {
        this.responses = responses;
        return this;
    }

    /**
     * @param parameters An object to hold reusable Parameter Objects.
     * @return The current builder
     */
    public ComponentsObjectBuilder withParameters(Map parameters) {
        this.parameters = parameters;
        return this;
    }

    /**
     * @param examples An object to hold reusable Example Objects.
     * @return The current builder
     */
    public ComponentsObjectBuilder withExamples(Map examples) {
        this.examples = examples;
        return this;
    }

    /**
     * @param requestBodies An object to hold reusable Request Body Objects.
     * @return The current builder
     */
    public ComponentsObjectBuilder withRequestBodies(Map requestBodies) {
        this.requestBodies = requestBodies;
        return this;
    }

    /**
     * @param headers An object to hold reusable Header Objects.
     * @return The current builder
     */
    public ComponentsObjectBuilder withHeaders(Map headers) {
        this.headers = headers;
        return this;
    }

    /**
     * @param securitySchemes An object to hold reusable Security Scheme Objects.
     * @return The current builder
     */
    public ComponentsObjectBuilder withSecuritySchemes(Map securitySchemes) {
        this.securitySchemes = securitySchemes;
        return this;
    }

    /**
     * @param links An object to hold reusable Link Objects.
     * @return The current builder
     */
    public ComponentsObjectBuilder withLinks(Map links) {
        this.links = links;
        return this;
    }

    /**
     * @param callbacks An object to hold reusable Callback Objects.
     * @return The current builder
     */
    public ComponentsObjectBuilder withCallbacks(Map callbacks) {
        this.callbacks = callbacks;
        return this;
    }

    /**
     * @return A new object
     */
    public ComponentsObject build() {
        return new ComponentsObject(immutable(schemas), immutable(responses), immutable(parameters), immutable(examples),
            immutable(requestBodies), immutable(headers), immutable(securitySchemes), immutable(links), immutable(callbacks));
    }

    /**
     * Creates a builder for a {@link ComponentsObject}
     *
     * @return A new builder
     */
    public static ComponentsObjectBuilder componentsObject() {
        return new ComponentsObjectBuilder();
    }

    /**
     * Creates a builder for a {@link ComponentsObject} based on an existing components object
     * @param toCopy A component to copy. If null then an empty builder is returned.
     * @return A new builder pre-populated with values from an existing component
     */
    public static ComponentsObjectBuilder componentsObject(ComponentsObject toCopy) {
        ComponentsObjectBuilder builder = componentsObject();
        if (toCopy != null) {
            builder
                .withCallbacks(toCopy.callbacks())
                .withExamples(toCopy.examples())
                .withHeaders(toCopy.headers())
                .withLinks(toCopy.links())
                .withParameters(toCopy.parameters())
                .withRequestBodies(toCopy.requestBodies())
                .withResponses(toCopy.responses())
                .withSecuritySchemes(toCopy.securitySchemes())
                .withSchemas(toCopy.schemas());

        }
        return builder;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy