use of org.springframework.ide.vscode.commons.yaml.schema.YType in project sts4 by spring-projects.
the class SchemaBasedSnippetGeneratorTest method toplevelSnippet.
@Test
public void toplevelSnippet() throws Exception {
YType v2Schema = typeUtil.inferMoreSpecificType(schema.getTopLevelType(), DynamicSchemaContext.NULL);
assertEquals("name: $1\n" + "releases:\n" + "- name: $2\n" + " version: $3\n" + "stemcells:\n" + "- alias: $4\n" + " version: $5\n" + "update:\n" + " canaries: $6\n" + " max_in_flight: $7\n" + " canary_watch_time: $8\n" + " update_watch_time: $9\n" + "instance_groups:\n" + "- name: $10\n" + " azs:\n" + " - $11\n" + " instances: $12\n" + " jobs:\n" + " - name: $13\n" + " release: $14\n" + " vm_type: $15\n" + " stemcell: $16\n" + " networks:\n" + " - name: $17", generator.getSnippets(v2Schema).iterator().next().getSnippet());
}
use of org.springframework.ide.vscode.commons.yaml.schema.YType in project sts4 by spring-projects.
the class BoshCloudConfigSchema method createNetworkBlockSchema.
private YType createNetworkBlockSchema(BoshModels models) {
AbstractType t_manual_nw = f.ybean("ManualNetwork");
{
YBeanType t_subnet = f.ybean("Subnet[Manual]");
addProp(t_subnet, "range", t_ip_range).isRequired(true);
addProp(t_subnet, "gateway", t_ip_address).isRequired(true);
addProp(t_subnet, "dns", f.yseq(t_ip_address));
addProp(t_subnet, "reserved", f.yseq(t_ip_address_or_range));
addProp(t_subnet, "static", f.yseq(t_ip_address_or_range));
addProp(t_subnet, "az", t_az_ref);
addProp(t_subnet, "azs", f.yseq(t_az_ref));
addProp(t_subnet, "cloud_properties", t_params);
addProp(t_manual_nw, "subnets", f.yseq(t_subnet)).isRequired(true);
}
AbstractType t_vip_nw = f.ybean("VipNetwork");
addProp(t_vip_nw, "cloud_properties", t_params);
AbstractType t_dynamic_nw = f.ybean("DynamicNetwork");
addProp(t_dynamic_nw, "dns", f.yseq(t_ip_address));
addProp(t_dynamic_nw, "cloud_properties", t_params);
{
YBeanType t_subnet = f.ybean("Subnet[Dynamic]");
addProp(t_subnet, "dns", f.yseq(t_ip_address));
addProp(t_subnet, "az", t_az_ref);
addProp(t_subnet, "azs", f.yseq(t_az_ref));
addProp(t_subnet, "cloud_properties", t_params);
addProp(t_dynamic_nw, "subnets", f.yseq(t_subnet));
}
t_dynamic_nw.require(Constraints.mutuallyExclusive("dns", "subnets"));
t_dynamic_nw.require(Constraints.mutuallyExclusive("cloud_properties", "subnets"));
AbstractType t_network = f.contextAware("Network", dc -> {
String type = models.getTypeTag(dc);
if (StringUtil.hasText(type)) {
switch(type) {
case "manual":
return t_manual_nw;
case "dynamic":
return t_dynamic_nw;
case "vip":
return t_vip_nw;
default:
}
}
return null;
}).treatAsBean();
// Add shared properties to the 'super' type.
addProp(t_network, "name", t_network_def).isPrimary(true);
addProp(t_network, "type", f.yenum("NetworkType", "manual", "dynamic", "vip")).isRequired(true);
// Add shared properties to all 'sub' types.
for (AbstractType subtype : ImmutableList.of(t_dynamic_nw, t_manual_nw, t_vip_nw)) {
for (YTypedProperty sharedProp : t_network.getProperties()) {
subtype.addProperty(sharedProp);
}
}
return t_network;
}
use of org.springframework.ide.vscode.commons.yaml.schema.YType in project sts4 by spring-projects.
the class AppendTextBuilder method singleMostImportantProperty.
private void singleMostImportantProperty(YType type, int indent, StringBuilder text) {
if (type != null) {
YTypedProperty singleProp = Streams.getSingle(typeUtil.getProperties(type).stream().filter(p -> p.isPrimary()));
if (singleProp == null) {
singleProp = Streams.getSingle(typeUtil.getProperties(type).stream().filter(p -> p.isRequired()));
}
if (singleProp != null) {
text.append(singleProp.getName());
text.append(':');
build(singleProp.getType(), indent + YamlIndentUtil.INDENT_BY, text);
}
}
}
use of org.springframework.ide.vscode.commons.yaml.schema.YType in project sts4 by spring-projects.
the class SchemaBasedYamlASTReconciler method checkRequiredProperties.
private void checkRequiredProperties(Node parent, MappingNode map, YType type, Map<String, YTypedProperty> beanProperties, DynamicSchemaContext dc) {
Set<String> foundProps = NodeUtil.getScalarKeys(map);
boolean allPropertiesKnown = beanProperties.keySet().containsAll(foundProps);
// Don't check for missing properties if some properties look like they might be spelled incorrectly.
if (allPropertiesKnown) {
// Check for missing required properties:
List<YTypedProperty> missingProps = beanProperties.values().stream().filter(YTypedProperty::isRequired).filter(prop -> !foundProps.contains(prop.getName())).collect(CollectorUtil.toImmutableList());
Set<String> missingPropNames = missingProps.stream().map(YTypedProperty::getName).collect(Collectors.toCollection(TreeSet::new));
if (!missingPropNames.isEmpty()) {
String message;
if (missingPropNames.size() == 1) {
// slightly more specific message when only one missing property
String missing = missingPropNames.stream().findFirst().get();
message = "Property '" + missing + "' is required for '" + type + "'";
} else {
message = "Properties " + missingPropNames + " are required for '" + type + "'";
}
SchemaBasedSnippetGenerator snippetProvider = new SchemaBasedSnippetGenerator(typeUtil, SnippetBuilder::gimped);
Snippet snippet = snippetProvider.getSnippet(missingProps);
problems.accept(YamlSchemaProblems.missingProperties(message, dc, missingPropNames, snippet.getSnippet(), snippet.getPlaceHolder(1).getOffset(), parent, map, quickfixes.MISSING_PROP_FIX));
}
}
}
use of org.springframework.ide.vscode.commons.yaml.schema.YType in project sts4 by spring-projects.
the class TypeBasedYamlSymbolHandler method handle.
@Override
public List<? extends SymbolInformation> handle(DocumentSymbolParams params) {
Builder<SymbolInformation> builder = ImmutableList.builder();
TextDocument doc = documents.getDocument(params.getTextDocument().getUri());
for (Entry<Node, YType> entry : astTypeCache.getNodeTypes(params.getTextDocument().getUri()).getTypes().entrySet()) {
if (definitionTypes.contains(entry.getValue())) {
try {
builder.add(createSymbol(doc, entry.getKey(), entry.getValue()));
} catch (Exception e) {
Log.log(e);
}
}
}
return builder.build();
}
Aggregations