
io.muserver.openapi.OpenAPIObject Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mu-server Show documentation
Show all versions of mu-server Show documentation
A simple but powerful web server framework
The 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 {
private final String openapi = "3.0.1";
private final InfoObject info;
private final List servers;
private final PathsObject paths;
private final ComponentsObject components;
private final List security;
private final List tags;
private 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('}');
}
/**
* @return The OpenAPI spec version this document conforms to
*/
public String openApi() {
return openapi;
}
/**
* @return the value described in {@link OpenAPIObjectBuilder#withInfo}
*/
public InfoObject info() {
return info;
}
/**
@return the value described in {@link OpenAPIObjectBuilder#withServers}
*/
public List servers() {
return servers;
}
/**
@return the value described in {@link OpenAPIObjectBuilder#withPaths}
*/
public PathsObject paths() {
return paths;
}
/**
@return the value described in {@link OpenAPIObjectBuilder#withComponents}
*/
public ComponentsObject components() {
return components;
}
/**
@return the value described in {@link OpenAPIObjectBuilder#withSecurity}
*/
public List security() {
return security;
}
/**
@return the value described in {@link OpenAPIObjectBuilder#withTags}
*/
public List tags() {
return tags;
}
/**
@return the value described in {@link OpenAPIObjectBuilder#withExternalDocs}
*/
public ExternalDocumentationObject externalDocs() {
return externalDocs;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy