Search in sources :

Example 31 with RefProperty

use of io.swagger.models.properties.RefProperty in project syndesis by syndesisio.

the class UnifiedXmlDataShapeGenerator method defineArrayElement.

static void defineArrayElement(final Property property, final String propertyName, final Element parent, final Swagger swagger, final Map<String, SchemaPrefixAndElement> moreSchemas) {
    final ArrayProperty array = (ArrayProperty) property;
    final Element sequence;
    final Xml arrayXml = array.getXml();
    if (arrayXml != null && Boolean.TRUE.equals(arrayXml.getWrapped())) {
        final String arrayElementName = determineArrayElementName(propertyName, array);
        final Element arrayElement = addElement(parent, "element");
        arrayElement.addAttribute("name", requireNonNull(arrayElementName, "missing array property name"));
        final Element arrayComplex = addElement(arrayElement, "complexType");
        sequence = addElement(arrayComplex, "sequence");
    } else {
        sequence = parent;
    }
    final Property items = array.getItems();
    final Element itemsElement;
    final String arrayItemsType = items.getType();
    if ("ref".equals(arrayItemsType)) {
        itemsElement = defineComplexElement((RefProperty) items, sequence, swagger, moreSchemas);
    } else {
        itemsElement = addElement(sequence, "element");
        itemsElement.addAttribute("name", determineArrayItemName(propertyName, array));
        itemsElement.addAttribute("type", toXsdType(arrayItemsType));
    }
    if (array.getMaxItems() == null) {
        itemsElement.addAttribute("maxOccurs", "unbounded");
    } else {
        itemsElement.addAttribute("maxOccurs", String.valueOf(array.getMaxItems()));
    }
    if (array.getMinItems() == null) {
        itemsElement.addAttribute("minOccurs", "0");
    } else {
        itemsElement.addAttribute("minOccurs", String.valueOf(array.getMinItems()));
    }
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) Xml(io.swagger.models.Xml) XmlSchemaHelper.isElement(io.syndesis.server.connector.generator.swagger.util.XmlSchemaHelper.isElement) XmlSchemaHelper.addElement(io.syndesis.server.connector.generator.swagger.util.XmlSchemaHelper.addElement) Element(org.dom4j.Element) ArrayProperty(io.swagger.models.properties.ArrayProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) RefProperty(io.swagger.models.properties.RefProperty)

Example 32 with RefProperty

use of io.swagger.models.properties.RefProperty in project carbon-apimgt by wso2.

the class WSDL11SOAPOperationExtractor method createPropertyFromNode.

/**
 * Creates a swagger property from given wsdl node.
 *
 * @param node wsdl node
 * @return generated swagger property
 */
private Property createPropertyFromNode(Node node, boolean prevNodeExist) {
    Property property = null;
    if (node.hasAttributes()) {
        if (node.getAttributes().getNamedItem(SOAPToRESTConstants.TYPE_ATTRIBUTE) != null) {
            if (node.getAttributes().getNamedItem(NAME_ATTRIBUTE) != null) {
                String dataType = node.getAttributes().getNamedItem(SOAPToRESTConstants.TYPE_ATTRIBUTE).getNodeValue().contains(":") ? node.getAttributes().getNamedItem(SOAPToRESTConstants.TYPE_ATTRIBUTE).getNodeValue().split(":")[1] : node.getAttributes().getNamedItem(SOAPToRESTConstants.TYPE_ATTRIBUTE).getNodeValue();
                property = getPropertyFromDataType(dataType);
                if (property instanceof RefProperty) {
                    ((RefProperty) property).set$ref(SOAPToRESTConstants.Swagger.DEFINITIONS_ROOT + dataType);
                }
                property.setName(node.getAttributes().getNamedItem(NAME_ATTRIBUTE).getNodeValue());
            }
        } else if (node.getAttributes().getNamedItem(SOAPToRESTConstants.REF_ATTRIBUTE) != null) {
            property = new RefProperty();
            String dataType = node.getAttributes().getNamedItem(SOAPToRESTConstants.REF_ATTRIBUTE).getNodeValue().contains(":") ? node.getAttributes().getNamedItem(SOAPToRESTConstants.REF_ATTRIBUTE).getNodeValue().split(":")[1] : node.getAttributes().getNamedItem(SOAPToRESTConstants.REF_ATTRIBUTE).getNodeValue();
            ((RefProperty) property).set$ref(SOAPToRESTConstants.Swagger.DEFINITIONS_ROOT + dataType);
            property.setName(dataType);
        } else if (node.getAttributes().getNamedItem("base") != null) {
            String dataType = node.getAttributes().getNamedItem("base").getNodeValue().contains(":") ? node.getAttributes().getNamedItem("base").getNodeValue().split(":")[1] : node.getAttributes().getNamedItem("base").getNodeValue();
            property = getPropertyFromDataType(dataType);
            if (property instanceof RefProperty) {
                ((RefProperty) property).set$ref(SOAPToRESTConstants.Swagger.DEFINITIONS_ROOT + dataType);
            }
            property.setName(dataType);
        } else if (node.getAttributes().getNamedItem(NAME_ATTRIBUTE) != null && prevNodeExist) {
            property = new ObjectProperty();
            property.setName(getNodeName(node));
            if (node.hasChildNodes()) {
                NodeList childNodes = node.getChildNodes();
                for (int i = 0; i < childNodes.getLength(); i++) {
                    Node childNode = childNodes.item(i);
                    if (SOAPToRESTConstants.COMPLEX_TYPE_NODE_NAME.equals(childNode.getLocalName())) {
                        isComplexTypeContainsArray(childNode);
                    }
                }
            }
        }
        if (isArrayType(node) || isArrayType) {
            isArrayType = false;
            Property arrayProperty = new ArrayProperty();
            ((ArrayProperty) arrayProperty).setItems(property);
            return arrayProperty;
        }
    }
    return property;
}
Also used : ObjectProperty(io.swagger.models.properties.ObjectProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) LongProperty(io.swagger.models.properties.LongProperty) DecimalProperty(io.swagger.models.properties.DecimalProperty) Property(io.swagger.models.properties.Property) DoubleProperty(io.swagger.models.properties.DoubleProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) RefProperty(io.swagger.models.properties.RefProperty) FloatProperty(io.swagger.models.properties.FloatProperty) DateProperty(io.swagger.models.properties.DateProperty) ObjectProperty(io.swagger.models.properties.ObjectProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) BooleanProperty(io.swagger.models.properties.BooleanProperty) RefProperty(io.swagger.models.properties.RefProperty)

Example 33 with RefProperty

use of io.swagger.models.properties.RefProperty in project carbon-apimgt by wso2.

the class WSDL11SOAPOperationExtractor method addModelDefinition.

/**
 * Adds swagger type definitions to swagger model
 *
 * @param current current wsdl node
 * @param model   swagger model element
 * @param type    wsdl node type{i.e: complexType, simpleType}
 */
private void addModelDefinition(Node current, ModelImpl model, String type, boolean prevNodeExist, Node prevNode) {
    if (current.getParentNode() != null) {
        String xPath = getXpathFromNode(current);
        if (log.isDebugEnabled()) {
            log.debug("Processing current document node: " + getNodeName(current) + " with the xPath:" + xPath);
        }
        String[] elements = xPath.split(XPATH_REPLACEMENT);
        if (getNodeName(current).equals(elements[elements.length - 1]) || getNodeName(current).equals(elements[elements.length - 1].substring(elements[elements.length - 1].indexOf(":") + 1)) || type.equals(SOAPToRESTConstants.RESTRICTION_ATTR)) {
            if (StringUtils.isBlank(model.getName())) {
                model.setName(getNodeName(current));
                if (!SOAPToRESTConstants.SIMPLE_TYPE_NODE_NAME.equals(type)) {
                    if (!prevNodeExist) {
                        Property prop = createPropertyFromNode(current, false);
                        Map<String, Property> propertyMap = new HashMap<>();
                        propertyMap.put(getNodeName(current), prop);
                        model.setProperties(propertyMap);
                    }
                    if (isArrayType(current)) {
                        model.setType(ArrayProperty.TYPE);
                    } else {
                        model.setType(ObjectProperty.TYPE);
                    }
                    String elementFormDefault = null;
                    if (current.getParentNode().getAttributes() != null && current.getParentNode().getAttributes().getNamedItem(SOAPToRESTConstants.ELEMENT_FORM_DEFAULT) != null) {
                        elementFormDefault = current.getParentNode().getAttributes().getNamedItem(SOAPToRESTConstants.ELEMENT_FORM_DEFAULT).getNodeValue();
                    }
                    if (StringUtils.isNotEmpty(elementFormDefault) && SOAPToRESTConstants.QUALIFIED.equals(elementFormDefault)) {
                        model.setVendorExtension(SOAPToRESTConstants.X_NAMESPACE_QUALIFIED, true);
                    } else {
                        model.setVendorExtension(SOAPToRESTConstants.X_NAMESPACE_QUALIFIED, false);
                    }
                }
            } else if (model.getProperties() == null) {
                if (SOAPToRESTConstants.RESTRICTION_ATTR.equals(type)) {
                    Property restrictionProp = createPropertyFromNode(current, true);
                    if (!(restrictionProp instanceof RefProperty || restrictionProp instanceof ObjectProperty || restrictionProp instanceof ArrayProperty)) {
                        model.setType(restrictionProp.getType());
                    } else {
                        model.setType(StringProperty.TYPE);
                    }
                } else {
                    Map<String, Property> propertyMap = new HashMap<>();
                    Property prop = createPropertyFromNode(current, true);
                    propertyMap.put(getNodeName(current), prop);
                    model.setProperties(propertyMap);
                }
            } else {
                Property parentProp = null;
                int pos = 0;
                for (String element : elements) {
                    if (model.getName().equals(element)) {
                    // do nothing
                    } else if (model.getProperties().containsKey(element)) {
                        parentProp = model.getProperties().get(element);
                        if (pos == elements.length - 1) {
                            if (SOAPToRESTConstants.RESTRICTION_ATTR.equals(type)) {
                                model.getProperties().remove(element);
                                parentProp = createPropertyFromNode(current, true);
                                parentProp.setName(element);
                                model.addProperty(element, parentProp);
                            } else {
                                if (isChildNode(current, prevNode)) {
                                    int index = Arrays.asList(elements).indexOf(element);
                                    Property parentProperty = null;
                                    String parentName = "";
                                    for (int i = 1; i < index; i++) {
                                        parentProperty = model.getProperties().get(elements[index - i]);
                                        if (parentProperty != null) {
                                            model.getProperties().remove(element);
                                            parentName = elements[index - i];
                                            break;
                                        }
                                    }
                                    if (parentProperty instanceof ArrayProperty) {
                                        if (((ArrayProperty) parentProperty).getItems() != null) {
                                            if (parentName.equals(((ArrayProperty) parentProperty).getItems().getName())) {
                                                ObjectProperty objectProperty = new ObjectProperty();
                                                Map propertiesMap = new HashMap();
                                                if (((ObjectProperty) (((ArrayProperty) parentProperty).getItems())).getProperties() != null) {
                                                    propertiesMap = ((ObjectProperty) (((ArrayProperty) parentProperty).getItems())).getProperties();
                                                }
                                                propertiesMap.put(element, createPropertyFromNode(current, true));
                                                objectProperty.setProperties(propertiesMap);
                                                objectProperty.setName(parentName);
                                                ((ArrayProperty) parentProperty).setItems(objectProperty);
                                                parentProp = parentProperty;
                                            }
                                        } else {
                                            ((ArrayProperty) parentProperty).setItems(createPropertyFromNode(current, true));
                                        }
                                    } else if (parentProperty instanceof ObjectProperty) {
                                        if (((ObjectProperty) parentProperty).getProperties() != null) {
                                            if ((((ObjectProperty) parentProperty).getProperties()).get(parentName) != null) {
                                                Property objectProperty = new ObjectProperty();
                                                Map propertiesMap = new HashMap();
                                                propertiesMap.put(element, createPropertyFromNode(current, true));
                                                ((ObjectProperty) objectProperty).setProperties(propertiesMap);
                                                ((ObjectProperty) parentProperty).setProperties(propertiesMap);
                                            }
                                        }
                                    }
                                } else {
                                    model.addProperty(getNodeName(current), createPropertyFromNode(current, true));
                                }
                            }
                        }
                    } else {
                        if (parentProp instanceof ArrayProperty) {
                            if (((ArrayProperty) parentProp).getItems().getName() == null) {
                                Property currentProp = createPropertyFromNode(current, true);
                                if (currentProp instanceof ObjectProperty) {
                                    ((ArrayProperty) parentProp).setItems(currentProp);
                                } else if (currentProp instanceof ArrayProperty) {
                                    Map<String, Property> arrayPropMap = new HashMap();
                                    arrayPropMap.put(getNodeName(current), currentProp);
                                    ObjectProperty arrayObjProp = new ObjectProperty();
                                    arrayObjProp.setProperties(arrayPropMap);
                                    ((ArrayProperty) parentProp).setItems(arrayObjProp);
                                } else {
                                    if (((ArrayProperty) parentProp).getItems() instanceof ObjectProperty) {
                                        Property objectProperty = ((ArrayProperty) parentProp).getItems();
                                        Map parentProperties = null;
                                        if (((ObjectProperty) objectProperty).getProperties() != null) {
                                            parentProperties = ((ObjectProperty) objectProperty).getProperties();
                                        }
                                        Map propertiesMap = new HashMap();
                                        propertiesMap.put(currentProp.getName(), currentProp);
                                        if (parentProperties != null) {
                                            Property obj = new ObjectProperty();
                                            obj.setName(element);
                                            if (parentProperties.get(element) instanceof ArrayProperty) {
                                                ((ObjectProperty) obj).setProperties(propertiesMap);
                                                parentProperties.remove(element);
                                                parentProperties.put(element, obj);
                                            } else if (parentProperties.get(element) instanceof ObjectProperty) {
                                                Map parentPropertyMap = ((ObjectProperty) parentProperties.get(element)).getProperties();
                                                parentPropertyMap.put(currentProp.getName(), currentProp);
                                                ((ObjectProperty) obj).setProperties(parentProperties);
                                            }
                                            ((ObjectProperty) objectProperty).setProperties(parentProperties);
                                        } else {
                                            ((ObjectProperty) objectProperty).setProperties(propertiesMap);
                                        }
                                        ((ArrayProperty) parentProp).setItems(objectProperty);
                                    } else {
                                        ((ArrayProperty) parentProp).setItems(currentProp);
                                    }
                                }
                            } else {
                                ((ArrayProperty) parentProp).setItems(createPropertyFromNode(current, true));
                            }
                            parentProp = ((ArrayProperty) parentProp).getItems();
                        } else if (parentProp instanceof ObjectProperty) {
                            if (SOAPToRESTConstants.RESTRICTION_ATTR.equals(type) && pos == elements.length - 1) {
                                parentProp = createPropertyFromNode(current, true);
                                parentProp.setName(element);
                            } else {
                                if (((ObjectProperty) parentProp).getProperties() == null) {
                                    Map<String, Property> propertyMap = new HashMap<>();
                                    ((ObjectProperty) parentProp).setProperties(propertyMap);
                                }
                                Property childProp = createPropertyFromNode(current, true);
                                if (((ObjectProperty) parentProp).getProperties().get(element) == null) {
                                    ((ObjectProperty) parentProp).getProperties().put(getNodeName(current), childProp);
                                }
                                if (childProp instanceof ObjectProperty) {
                                    parentProp = ((ObjectProperty) parentProp).getProperties().get(element);
                                } else if (childProp instanceof ArrayProperty) {
                                    parentProp = childProp;
                                }
                            }
                        } else if (parentProp == null) {
                            if (StringUtils.isNotBlank(getNodeName(current))) {
                                model.addProperty(getNodeName(current), createPropertyFromNode(current, true));
                            } else if (StringUtils.isNotBlank(getRefNodeName(current))) {
                                model.addProperty(getRefNodeName(current), createPropertyFromNode(current, true));
                            }
                        }
                    }
                    pos++;
                }
            }
        }
    }
}
Also used : ObjectProperty(io.swagger.models.properties.ObjectProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) HashMap(java.util.HashMap) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) LongProperty(io.swagger.models.properties.LongProperty) DecimalProperty(io.swagger.models.properties.DecimalProperty) Property(io.swagger.models.properties.Property) DoubleProperty(io.swagger.models.properties.DoubleProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) RefProperty(io.swagger.models.properties.RefProperty) FloatProperty(io.swagger.models.properties.FloatProperty) DateProperty(io.swagger.models.properties.DateProperty) ObjectProperty(io.swagger.models.properties.ObjectProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) BooleanProperty(io.swagger.models.properties.BooleanProperty) Map(java.util.Map) HashMap(java.util.HashMap) NamedNodeMap(org.w3c.dom.NamedNodeMap) RefProperty(io.swagger.models.properties.RefProperty)

Example 34 with RefProperty

use of io.swagger.models.properties.RefProperty in project carbon-apimgt by wso2.

the class WSDL11SOAPOperationExtractor method getSoapOutputParameterModel.

/**
 * Gets swagger output parameter model for a given soap operation
 *
 * @param bindingOperation soap operation
 * @return list of swagger models for the parameters
 * @throws APIMgtWSDLException
 */
private List<ModelImpl> getSoapOutputParameterModel(BindingOperation bindingOperation) throws APIMgtWSDLException {
    List<ModelImpl> outputParameterModelList = new ArrayList<>();
    Operation operation = bindingOperation.getOperation();
    if (operation != null) {
        Output output = operation.getOutput();
        if (output != null) {
            Message message = output.getMessage();
            if (message != null) {
                Map map = message.getParts();
                for (Object obj : map.entrySet()) {
                    Map.Entry entry = (Map.Entry) obj;
                    Part part = (Part) entry.getValue();
                    if (part != null) {
                        if (part.getElementName() != null) {
                            outputParameterModelList.add(parameterModelMap.get(part.getElementName().getLocalPart()));
                        } else {
                            if (part.getTypeName() != null && parameterModelMap.containsKey(part.getTypeName().getLocalPart())) {
                                outputParameterModelList.add(parameterModelMap.get(part.getTypeName().getLocalPart()));
                            } else {
                                ModelImpl model = new ModelImpl();
                                model.setType(ObjectProperty.TYPE);
                                model.setName(message.getQName().getLocalPart());
                                if (getPropertyFromDataType(part.getTypeName().getLocalPart()) instanceof RefProperty) {
                                    RefProperty property = (RefProperty) getPropertyFromDataType(part.getTypeName().getLocalPart());
                                    property.set$ref(SOAPToRESTConstants.Swagger.DEFINITIONS_ROOT + part.getTypeName().getLocalPart());
                                    model.addProperty(part.getName(), property);
                                } else {
                                    model.addProperty(part.getName(), getPropertyFromDataType(part.getTypeName().getLocalPart()));
                                }
                                parameterModelMap.put(model.getName(), model);
                                outputParameterModelList.add(model);
                            }
                        }
                    }
                }
            }
        }
    }
    return outputParameterModelList;
}
Also used : Message(javax.wsdl.Message) Part(javax.wsdl.Part) Output(javax.wsdl.Output) ArrayList(java.util.ArrayList) Operation(javax.wsdl.Operation) SOAP12Operation(javax.wsdl.extensions.soap12.SOAP12Operation) WSDLSOAPOperation(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLSOAPOperation) BindingOperation(javax.wsdl.BindingOperation) SOAPOperation(javax.wsdl.extensions.soap.SOAPOperation) WSDLOperation(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLOperation) ModelImpl(io.swagger.models.ModelImpl) Map(java.util.Map) HashMap(java.util.HashMap) NamedNodeMap(org.w3c.dom.NamedNodeMap) RefProperty(io.swagger.models.properties.RefProperty)

Example 35 with RefProperty

use of io.swagger.models.properties.RefProperty in project camel by apache.

the class RestSwaggerReader method modelTypeAsProperty.

private Property modelTypeAsProperty(String typeName, Swagger swagger) {
    boolean array = typeName.endsWith("[]");
    if (array) {
        typeName = typeName.substring(0, typeName.length() - 2);
    }
    String ref = modelTypeAsRef(typeName, swagger);
    Property prop = ref != null ? new RefProperty(ref) : new StringProperty(typeName);
    if (array) {
        return new ArrayProperty(prop);
    } else {
        return prop;
    }
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) StringProperty(io.swagger.models.properties.StringProperty) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) LongProperty(io.swagger.models.properties.LongProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) DoubleProperty(io.swagger.models.properties.DoubleProperty) FloatProperty(io.swagger.models.properties.FloatProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) BooleanProperty(io.swagger.models.properties.BooleanProperty) RefProperty(io.swagger.models.properties.RefProperty)

Aggregations

RefProperty (io.swagger.models.properties.RefProperty)74 Property (io.swagger.models.properties.Property)50 ArrayProperty (io.swagger.models.properties.ArrayProperty)46 StringProperty (io.swagger.models.properties.StringProperty)35 Test (org.testng.annotations.Test)35 Model (io.swagger.models.Model)23 MapProperty (io.swagger.models.properties.MapProperty)20 ModelImpl (io.swagger.models.ModelImpl)18 Response (io.swagger.models.Response)18 IntegerProperty (io.swagger.models.properties.IntegerProperty)18 Operation (io.swagger.models.Operation)17 RefModel (io.swagger.models.RefModel)17 LongProperty (io.swagger.models.properties.LongProperty)14 Path (io.swagger.models.Path)12 Swagger (io.swagger.models.Swagger)12 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)12 ArrayModel (io.swagger.models.ArrayModel)11 BodyParameter (io.swagger.models.parameters.BodyParameter)11 Map (java.util.Map)11