
io.muserver.openapi.PathItemObject 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.Map;
import java.util.Set;
import static io.muserver.openapi.Jsonizer.append;
import static java.util.stream.Collectors.toSet;
/**
* @see PathItemObjectBuilder
*/
public class PathItemObject implements JsonWriter {
private final String summary;
private final String description;
private final Map operations;
private final List servers;
private final List parameters;
PathItemObject(String summary, String description, Map operations,
List servers, List parameters) {
if (parameters != null) {
Set nameIns = parameters.stream().map(p -> p.name() + "\0" + p.in()).collect(toSet());
if (nameIns.size() != parameters.size()) {
throw new IllegalArgumentException("Got duplicate parameter name and locations in " + parameters);
}
}
this.summary = summary;
this.description = description;
this.operations = operations;
this.servers = servers;
this.parameters = parameters;
}
@Override
public void writeJson(Writer writer) throws IOException {
writer.write('{');
boolean isFirst = true;
isFirst = append(writer, "summary", summary, isFirst);
isFirst = append(writer, "description", description, isFirst);
if (operations != null) {
for (String method : new String[]{"get", "put", "post", "delete", "options", "head", "patch", "trace"}) {
isFirst = append(writer, method, operations.get(method), isFirst);
}
}
isFirst = append(writer, "servers", servers, isFirst);
isFirst = append(writer, "parameters", parameters, isFirst);
writer.write('}');
}
/**
* @return the value described by {@link PathItemObjectBuilder#withSummary}
*/
public String summary() {
return summary;
}
/**
@return the value described by {@link PathItemObjectBuilder#withDescription}
*/
public String description() {
return description;
}
/**
@return the value described by {@link PathItemObjectBuilder#withOperations}
*/
public Map operations() {
return operations;
}
/**
@return the value described by {@link PathItemObjectBuilder#withServers}
*/
public List servers() {
return servers;
}
/**
@return the value described by {@link PathItemObjectBuilder#withParameters}
*/
public List parameters() {
return parameters;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy