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

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

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

import java.io.IOException;
import java.io.Writer;
import java.util.Map;

import static io.muserver.openapi.ParameterObject.allowedStyles;

/**
 * @see EncodingObjectBuilder
 */
public class EncodingObject implements JsonWriter {

    public final String contentType;
    public final Map headers;
    public final String style;
    public final boolean explode;
    public final boolean allowReserved;

    EncodingObject(String contentType, Map headers, String style, boolean explode, boolean allowReserved) {
        if (style != null && !allowedStyles.contains(style)) {
            throw new IllegalArgumentException("'style' must be one of " + allowedStyles + " but was " + style);
        }
        this.contentType = contentType;
        this.headers = headers;
        this.style = style;
        this.explode = explode;
        this.allowReserved = allowReserved;
    }

    @Override
    public void writeJson(Writer writer) throws IOException {
        writer.append('{');
        boolean isFirst = true;
        isFirst = Jsonizer.append(writer, "contentType", contentType, isFirst);
        isFirst = Jsonizer.append(writer, "headers", headers, isFirst);
        isFirst = Jsonizer.append(writer, "style", style, isFirst);
        isFirst = Jsonizer.append(writer, "explode", explode, isFirst);
        isFirst = Jsonizer.append(writer, "allowReserved", allowReserved, isFirst);
        writer.append('}');
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy