use of io.apicurio.datamodels.core.models.common.ServerVariable in project apicurio-data-models by Apicurio.
the class DataModelReader method readServer.
/**
* Reads a server model.
* @param json
* @param node
*/
public void readServer(Object json, Server node) {
String url = JsonCompat.consumePropertyString(json, Constants.PROP_URL);
String description = JsonCompat.consumePropertyString(json, Constants.PROP_DESCRIPTION);
Object variables = JsonCompat.consumeProperty(json, Constants.PROP_VARIABLES);
node.url = url;
node.description = description;
if (variables != null) {
JsonCompat.keys(variables).forEach(key -> {
Object serverVariable = JsonCompat.consumeProperty(variables, key);
ServerVariable serverVariableModel = node.createServerVariable(key);
this.readServerVariable(serverVariable, serverVariableModel);
node.addServerVariable(key, serverVariableModel);
});
}
this.readExtensions(json, node);
this.readExtraProperties(json, node);
}
use of io.apicurio.datamodels.core.models.common.ServerVariable in project apicurio-data-models by Apicurio.
the class IoTestRunner method cloneNode.
static Node cloneNode(Node node) {
Constructor<? extends Node> constructor;
Node clonedNode = null;
try {
if (node instanceof INamed) {
constructor = node.getClass().getConstructor(String.class);
clonedNode = constructor.newInstance(((INamed) node).getName());
} else if (node instanceof OasPathItem) {
constructor = node.getClass().getConstructor(String.class);
clonedNode = constructor.newInstance(((OasPathItem) node).getPath());
} else if (node instanceof Operation) {
constructor = node.getClass().getConstructor(String.class);
clonedNode = constructor.newInstance(((Operation) node).getType());
} else if (node instanceof Oas20PropertySchema) {
constructor = node.getClass().getConstructor(String.class);
clonedNode = constructor.newInstance(((Oas20PropertySchema) node).getPropertyName());
} else if (node instanceof Oas30PropertySchema) {
constructor = node.getClass().getConstructor(String.class);
clonedNode = constructor.newInstance(((Oas30PropertySchema) node).getPropertyName());
} else if (node instanceof ServerVariable) {
constructor = node.getClass().getConstructor(String.class);
clonedNode = constructor.newInstance(((ServerVariable) node).getName());
} else {
constructor = node.getClass().getConstructor();
clonedNode = constructor.newInstance();
}
} catch (SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
System.err.println("Skipping partial I/O for: " + node.getClass().getSimpleName());
}
if (clonedNode != null) {
clonedNode._parent = node._parent;
clonedNode._ownerDocument = node.ownerDocument();
if (clonedNode instanceof Document) {
clonedNode._ownerDocument = (Document) clonedNode;
}
}
return clonedNode;
}
use of io.apicurio.datamodels.core.models.common.ServerVariable in project syndesis by syndesisio.
the class Oas30PropertyGeneratorsTest method shouldDetermineHostFromSpecification.
@Test
public void shouldDetermineHostFromSpecification() {
Oas30Document openApiDoc = new Oas30Document();
Server server = openApiDoc.addServer("{scheme}://api.example.com", "TestServer");
ServerVariable schemes = server.createServerVariable("scheme");
schemes.default_ = "https";
schemes.enum_ = new ArrayList<>();
schemes.enum_.add("https");
server.addServerVariable("scheme", schemes);
assertThat(GENERATOR.determineHost(new OpenApiModelInfo.Builder().model(openApiDoc).build())).isEqualTo("https://api.example.com");
schemes.enum_.add("http");
assertThat(GENERATOR.determineHost(new OpenApiModelInfo.Builder().model(openApiDoc).build())).isEqualTo("https://api.example.com");
schemes.default_ = "http";
assertThat(GENERATOR.determineHost(new OpenApiModelInfo.Builder().model(openApiDoc).build())).isEqualTo("http://api.example.com");
}
use of io.apicurio.datamodels.core.models.common.ServerVariable in project syndesis by syndesisio.
the class Oas30ModelHelperTest method getOpenApiDocWithUrl.
private static Oas30Document getOpenApiDocWithUrl(String url, ServerVariable... variables) {
Oas30Document openApiDoc = new Oas30Document();
Server server = openApiDoc.addServer(url, "Dummy for testing");
for (ServerVariable variable : variables) {
server.addServerVariable(variable._name, variable);
}
return openApiDoc;
}
use of io.apicurio.datamodels.core.models.common.ServerVariable in project syndesis by syndesisio.
the class Oas30PropertyGeneratorsTest method shouldDetermineHostFromSpecificationUrl.
@Test
public void shouldDetermineHostFromSpecificationUrl() {
final URI specificationUrl = URI.create("https://api.example.com/swagger.json");
Oas30Document openApiDoc = new Oas30Document();
Extension extension = new Extension();
extension.name = OasModelHelper.URL_EXTENSION;
extension.value = specificationUrl;
openApiDoc.addExtension(OasModelHelper.URL_EXTENSION, extension);
assertThat(GENERATOR.determineHost(new OpenApiModelInfo.Builder().model(openApiDoc).build())).isEqualTo("https://api.example.com");
Server server = openApiDoc.addServer("{scheme}://api.example.com", "TestServer");
ServerVariable schemes = server.createServerVariable("scheme");
schemes.default_ = "http";
schemes.enum_ = new ArrayList<>();
schemes.enum_.add("http");
server.addServerVariable("scheme", schemes);
assertThat(GENERATOR.determineHost(new OpenApiModelInfo.Builder().model(openApiDoc).build())).isEqualTo("http://api.example.com");
server.url = "{scheme}://api2.example.com";
assertThat(GENERATOR.determineHost(new OpenApiModelInfo.Builder().model(openApiDoc).build())).isEqualTo("http://api2.example.com");
}
Aggregations