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

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

There is a newer version: 2.0.3
Show newest version
package io.muserver.openapi;

import java.util.Map;

/**
 * A single encoding definition applied to a single schema property.
 */
public class EncodingObjectBuilder {
    private String contentType;
    private Map headers;
    private String style;
    private Boolean explode;
    private boolean allowReserved;

    /**
     * @param contentType The Content-Type for encoding a specific property. Default value depends on the property type:
     *                    for string with format being binaryapplication/octet-stream;
     *                    for other primitive types – text/plain; for object - application/json;
     *                    for array – the default is defined based on the inner type. The value can be a specific media
     *                    type (e.g. application/json), a wildcard media type (e.g. image/*), or a
     *                    comma-separated list of the two types.
     * @return The current builder
     */
    public EncodingObjectBuilder withContentType(String contentType) {
        this.contentType = contentType;
        return this;
    }

    /**
     * @param headers A map allowing additional information to be provided as headers, for example Content-Disposition.
     *                Content-Type is described separately and SHALL be ignored in this section. This property SHALL
     *                be ignored if the request body media type is not a multipart.
     * @return The current builder
     */
    public EncodingObjectBuilder withHeaders(Map headers) {
        this.headers = headers;
        return this;
    }

    /**
     * @param style Describes how a specific property value will be serialized depending on its type.
     *              See {@link ParameterObjectBuilder#withStyle(String)} for details on the style property.
     *              The behavior follows the same values as query parameters, including default values.
     *              This property SHALL be ignored if the request body media type is not application/x-www-form-urlencoded.
     * @return The current builder
     */
    public EncodingObjectBuilder withStyle(String style) {
        this.style = style;
        return this;
    }

    /**
     * @param explode When this is true, property values of type array or object generate separate
     *                parameters for each value of the array, or key-value-pair of the map.  For other types of properties this
     *                property has no effect. When style is form, the default value is true.
     *                For all other styles, the default value is false. This property SHALL be ignored if the request
     *                body media type is not application/x-www-form-urlencoded.
     * @return The current builder
     */
    public EncodingObjectBuilder withExplode(boolean explode) {
        this.explode = explode;
        return this;
    }

    /**
     * @param allowReserved Determines whether the parameter value SHOULD allow reserved characters, as defined by
     *                      RFC3986 :/?#[]@!$&'()*+,;=
     *                      to be included without percent-encoding. The default value is false. This property
     *                      SHALL be ignored if the request body media type is not application/x-www-form-urlencoded.
     * @return The current builder
     */
    public EncodingObjectBuilder withAllowReserved(boolean allowReserved) {
        this.allowReserved = allowReserved;
        return this;
    }

    public EncodingObject build() {
        boolean explodeVal = this.explode == null ? "form".equals(style) : this.explode;
        return new EncodingObject(contentType, headers, style, explodeVal, allowReserved);
    }

    /**
     * Creates a builder for an {@link EncodingObject}
     *
     * @return A new builder
     */
    public static EncodingObjectBuilder encodingObject() {
        return new EncodingObjectBuilder();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy