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

io.muserver.openapi.OpenAPIObject 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.List;
import java.util.stream.Collectors;

import static io.muserver.Mutils.notNull;
import static io.muserver.openapi.Jsonizer.append;

/**
 * @see OpenAPIObjectBuilder
 */
public class OpenAPIObject implements JsonWriter {
    public final String openapi = "3.0.1";
    public final InfoObject info;
    public final List servers;
    public final PathsObject paths;
    public final ComponentsObject components;
    public final List security;
    public final List tags;
    public final ExternalDocumentationObject externalDocs;

    OpenAPIObject(InfoObject info, List servers, PathsObject paths, ComponentsObject components, List security, List tags, ExternalDocumentationObject externalDocs) {
        notNull("info", info);
        notNull("paths", paths);
        if (tags != null && tags.size() != tags.stream().map(t -> t.name).collect(Collectors.toSet()).size()) {
            throw new IllegalArgumentException("Tags must have unique names");
        }
        this.info = info;
        this.servers = servers;
        this.paths = paths;
        this.components = components;
        this.security = security;
        this.tags = tags;
        this.externalDocs = externalDocs;
    }

    @Override
    public void writeJson(Writer writer) throws IOException {
        writer.write('{');
        boolean isFirst = true;
        isFirst = append(writer, "openapi", openapi, isFirst);
        isFirst = append(writer, "info", info, isFirst);
        isFirst = append(writer, "servers", servers, isFirst);
        isFirst = append(writer, "paths", paths, isFirst);
        isFirst = append(writer, "components", components, isFirst);
        isFirst = append(writer, "security", security, isFirst);
        isFirst = append(writer, "tags", tags, isFirst);
        isFirst = append(writer, "externalDocs", externalDocs, isFirst);
        writer.write('}');
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy