use of io.apicurio.datamodels.openapi.v3.models.Oas30Server in project apicurio-data-models by Apicurio.
the class DeleteAllServersCommand method undo.
/**
* @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
*/
@Override
public void undo(Document document) {
LoggerCompat.info("[DeleteAllServersCommand] Reverting.");
if (this._oldServers.size() == 0) {
return;
}
IServerParent parent = (IServerParent) this._parentPath.resolve(document);
if (this.isNullOrUndefined(parent)) {
return;
}
List<Server> servers = parent.getServers();
if (this.isNullOrUndefined(servers)) {
servers = new ArrayList<>();
NodeCompat.setProperty(parent, Constants.PROP_SERVERS, servers);
}
for (Object oldServer : this._oldServers) {
Oas30Server server = (Oas30Server) parent.createServer();
Library.readNode(oldServer, server);
servers.add(server);
}
}
use of io.apicurio.datamodels.openapi.v3.models.Oas30Server in project apicurio-data-models by Apicurio.
the class Oas30DataModelReader method readOperation.
/**
* @see io.apicurio.datamodels.openapi.io.OasDataModelReader#readOperation(java.lang.Object, io.apicurio.datamodels.core.models.common.Operation)
*/
@Override
public void readOperation(Object json, Operation node) {
Oas30Operation operation = (Oas30Operation) node;
Object requestBody = JsonCompat.consumeProperty(json, Constants.PROP_REQUEST_BODY);
Object callbacks = JsonCompat.consumeProperty(json, Constants.PROP_CALLBACKS);
List<Object> servers = JsonCompat.consumePropertyArray(json, Constants.PROP_SERVERS);
if (requestBody != null) {
operation.requestBody = operation.createRequestBody();
this.readRequestBody(requestBody, operation.requestBody);
}
if (callbacks != null) {
JsonCompat.keys(callbacks).forEach(name -> {
Object callback = JsonCompat.consumeProperty(callbacks, name);
Oas30Callback callbackModel = operation.createCallback(name);
this.readCallback(callback, callbackModel);
operation.addCallback(name, callbackModel);
});
}
if (servers != null) {
servers.forEach(server -> {
Oas30Server serverModel = (Oas30Server) operation.createServer();
this.readServer(server, serverModel);
operation.addServer(serverModel);
});
}
super.readOperation(json, node);
}
use of io.apicurio.datamodels.openapi.v3.models.Oas30Server in project apicurio-data-models by Apicurio.
the class Oas20to30TransformationVisitor method visitOperation.
/**
* @see io.apicurio.datamodels.core.visitors.IVisitor#visitOperation(io.apicurio.datamodels.core.models.common.Operation)
*/
@Override
public void visitOperation(Operation node) {
Oas20Operation op = (Oas20Operation) node;
Oas30PathItem pathItem30 = (Oas30PathItem) this.lookup(node.parent());
Oas30Operation operation30 = (Oas30Operation) pathItem30.createOperation(node.getType());
pathItem30.setOperation(operation30);
operation30.tags = op.tags;
operation30.summary = op.summary;
operation30.description = op.description;
operation30.operationId = op.operationId;
operation30.deprecated = op.deprecated;
if (!NodeCompat.isNullOrUndefined(op.schemes) && op.schemes.size() > 0 && !NodeCompat.isNullOrUndefined(this.doc30.servers) && this.doc30.servers.size() > 0) {
Oas30Server server30 = (Oas30Server) operation30.createServer();
operation30.servers = new ArrayList<>();
operation30.servers.add(server30);
server30.url = this.doc30.servers.get(0).url;
if (op.schemes.size() == 1) {
server30.url = server30.url.replace("{scheme}", op.schemes.get(0));
server30.removeServerVariable("scheme");
} else {
server30.url = "{scheme}" + server30.url.substring(server30.url.indexOf("://"));
Oas30ServerVariable var30 = (Oas30ServerVariable) server30.createServerVariable("scheme");
server30.addServerVariable("scheme", var30);
var30.description = "The supported protocol schemes.";
var30.default_ = op.schemes.get(0);
var30.enum_ = NodeCompat.copyList(op.schemes);
}
}
// Note: consumes/produces will be handled elsewhere (when Request Body and Response models are created)
this.mapNode(op, operation30);
}
use of io.apicurio.datamodels.openapi.v3.models.Oas30Server in project apicurio-data-models by Apicurio.
the class Oas30DataModelReader method readPathItem.
/**
* @see io.apicurio.datamodels.openapi.io.OasDataModelReader#readPathItem(java.lang.Object, io.apicurio.datamodels.openapi.models.OasPathItem)
*/
@Override
public void readPathItem(Object json, OasPathItem node) {
Oas30PathItem pi = (Oas30PathItem) node;
String summary = JsonCompat.consumePropertyString(json, Constants.PROP_SUMMARY);
String description = JsonCompat.consumePropertyString(json, Constants.PROP_DESCRIPTION);
Object trace = JsonCompat.consumeProperty(json, Constants.PROP_TRACE);
List<Object> servers = JsonCompat.consumePropertyArray(json, Constants.PROP_SERVERS);
pi.summary = summary;
pi.description = description;
if (trace != null) {
pi.trace = (Oas30Operation) pi.createOperation(Constants.PROP_TRACE);
this.readOperation(trace, pi.trace);
}
if (servers != null) {
servers.forEach(server -> {
Oas30Server serverModel = (Oas30Server) pi.createServer();
this.readServer(server, serverModel);
pi.addServer(serverModel);
});
}
super.readPathItem(json, node);
}
use of io.apicurio.datamodels.openapi.v3.models.Oas30Server in project apicurio-data-models by Apicurio.
the class OasServerVarNotFoundInTemplateRule method visitServerVariable.
/**
* @see io.apicurio.datamodels.combined.visitors.CombinedAllNodeVisitor#visitServerVariable(io.apicurio.datamodels.core.models.common.ServerVariable)
*/
@Override
public void visitServerVariable(ServerVariable node) {
String varName = node.getName();
Oas30Server server = (Oas30Server) node.parent();
List<String> vars = parseServerTemplate(server.url);
String[] varArray = NodeCompat.asArray(vars);
this.reportIfInvalid(isValidEnumItem(varName, varArray), node, null, map("name", varName));
}
Aggregations