Search in sources :

Example 1 with TypeDefinition

use of com.reprezen.swagedit.core.schema.TypeDefinition in project KaiZen-OpenAPI-Editor by RepreZen.

the class OutlineStyledLabelProvider method getStyledString.

public StyledString getStyledString(AbstractNode element) {
    StyledString styledString = new StyledString(element.getText(), getTextStyler());
    if (element.getParent() != null && (element.isObject() || element.isArray())) {
        TypeDefinition definition = element.getType();
        String label = null;
        if (definition != null && definition.asJson() != null) {
            if (definition.asJson().has("title")) {
                label = definition.asJson().get("title").asText();
            } else if (definition.getContainingProperty() != null) {
                label = definition.getContainingProperty();
            }
        }
        if (label != null) {
            styledString.append(" ");
            styledString.append(label, getTagStyler());
        }
    } else if (element.getParent() == null) {
        if (element.getModel().getPath() != null) {
            styledString.append(" ");
            styledString.append(element.getModel().getPath().toString(), getTagStyler());
        }
    }
    return styledString;
}
Also used : StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) TypeDefinition(com.reprezen.swagedit.core.schema.TypeDefinition)

Example 2 with TypeDefinition

use of com.reprezen.swagedit.core.schema.TypeDefinition in project KaiZen-OpenAPI-Editor by RepreZen.

the class JsonProposalProvider method createObjectProposals.

protected Collection<Proposal> createObjectProposals(ObjectTypeDefinition type, AbstractNode element, String prefix) {
    final Collection<Proposal> proposals = new LinkedHashSet<>();
    for (String property : type.getProperties().keySet()) {
        Proposal proposal = createPropertyProposal(property, type.getProperties().get(property));
        if (proposal != null) {
            if (Strings.emptyToNull(prefix) != null && property.startsWith(prefix)) {
                proposals.add(proposal);
            } else if (element.get(property) == null) {
                proposals.add(proposal);
            }
        }
    }
    for (String property : type.getPatternProperties().keySet()) {
        TypeDefinition typeDef = type.getPatternProperties().get(property);
        if (property.startsWith("^")) {
            property = property.substring(1);
        }
        Proposal proposal = createPropertyProposal(property, typeDef);
        if (proposal != null) {
            proposals.add(proposal);
        }
    }
    if (proposals.isEmpty()) {
        proposals.add(new Proposal("_key_" + ":", "_key_", null, null));
    }
    return proposals;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ObjectTypeDefinition(com.reprezen.swagedit.core.schema.ObjectTypeDefinition) ArrayTypeDefinition(com.reprezen.swagedit.core.schema.ArrayTypeDefinition) MultipleTypeDefinition(com.reprezen.swagedit.core.schema.MultipleTypeDefinition) ComplexTypeDefinition(com.reprezen.swagedit.core.schema.ComplexTypeDefinition) ReferenceTypeDefinition(com.reprezen.swagedit.core.schema.ReferenceTypeDefinition) TypeDefinition(com.reprezen.swagedit.core.schema.TypeDefinition)

Aggregations

TypeDefinition (com.reprezen.swagedit.core.schema.TypeDefinition)2 ArrayTypeDefinition (com.reprezen.swagedit.core.schema.ArrayTypeDefinition)1 ComplexTypeDefinition (com.reprezen.swagedit.core.schema.ComplexTypeDefinition)1 MultipleTypeDefinition (com.reprezen.swagedit.core.schema.MultipleTypeDefinition)1 ObjectTypeDefinition (com.reprezen.swagedit.core.schema.ObjectTypeDefinition)1 ReferenceTypeDefinition (com.reprezen.swagedit.core.schema.ReferenceTypeDefinition)1 LinkedHashSet (java.util.LinkedHashSet)1 StyledString (org.eclipse.jface.viewers.StyledString)1