Search in sources :

Example 71 with ArrayProperty

use of io.swagger.models.properties.ArrayProperty in project swagger-parser by swagger-api.

the class SwaggerParserTest method testLoadRecursiveExternalDef.

@Test
public void testLoadRecursiveExternalDef() throws Exception {
    SwaggerParser parser = new SwaggerParser();
    final Swagger swagger = parser.read("src/test/resources/file-reference-to-recursive-defs/b.yaml");
    Map<String, Model> definitions = swagger.getDefinitions();
    assertEquals(((RefProperty) ((ArrayProperty) definitions.get("v").getProperties().get("children")).getItems()).get$ref(), "#/definitions/v");
    assertTrue(definitions.containsKey("y"));
    assertEquals(((RefProperty) ((ArrayProperty) definitions.get("x").getProperties().get("children")).getItems()).get$ref(), "#/definitions/y");
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) ByteArrayProperty(io.swagger.models.properties.ByteArrayProperty) Swagger(io.swagger.models.Swagger) Model(io.swagger.models.Model) RefModel(io.swagger.models.RefModel) ComposedModel(io.swagger.models.ComposedModel) ArrayModel(io.swagger.models.ArrayModel) Test(org.testng.annotations.Test)

Example 72 with ArrayProperty

use of io.swagger.models.properties.ArrayProperty in project swagger-parser by swagger-api.

the class SwaggerCompatConverter method convertParameter.

public Parameter convertParameter(io.swagger.models.apideclaration.Parameter param) {
    Parameter output = null;
    List<String> _enum = param.getEnumValues();
    if (ParamType.PATH.equals(param.getParamType())) {
        PathParameter p = new PathParameter();
        p.setDefaultValue(param.getDefaultValue());
        p.setEnum(_enum);
        output = p;
    } else if (ParamType.QUERY.equals(param.getParamType())) {
        QueryParameter p = new QueryParameter();
        p.setDefaultValue(param.getDefaultValue());
        p.setEnum(_enum);
        output = p;
    } else if (ParamType.HEADER.equals(param.getParamType())) {
        HeaderParameter p = new HeaderParameter();
        p.setDefaultValue(param.getDefaultValue());
        p.setEnum(_enum);
        output = p;
    } else if (ParamType.BODY.equals(param.getParamType())) {
        BodyParameter p = new BodyParameter();
        output = p;
    } else if (ParamType.FORM.equals(param.getParamType())) {
        FormParameter p = new FormParameter();
        p.setDefaultValue(param.getDefaultValue());
        p.setEnum(_enum);
        output = p;
    }
    output.setName(param.getName());
    output.setDescription(param.getDescription());
    if (param.getRequired() != null) {
        output.setRequired(param.getRequired());
    }
    Property property = null;
    String type = param.getType() == null ? null : param.getType().toString();
    String format = param.getFormat() == null ? null : param.getFormat().toString();
    if (null == type) {
        LOGGER.warn("Empty type in Param: " + param);
    }
    if (output instanceof BodyParameter) {
        BodyParameter bp = (BodyParameter) output;
        bp.setSchema(modelFromExtendedTypedObject(param));
    } else if (output instanceof SerializableParameter) {
        SerializableParameter sp = (SerializableParameter) output;
        Property p = null;
        if (param.getAllowMultiple() != null && param.getAllowMultiple() == true) {
            ArrayProperty arrayProperty = new ArrayProperty();
            Property innerType = PropertyBuilder.build(type, format, null);
            arrayProperty.setItems(innerType);
            p = arrayProperty;
        } else {
            p = propertyFromTypedObject(param);
            if (p == null) {
                LOGGER.warn(String.format("WARNING! No property detected for parameter '%s' (%s)! Falling back to string!", param.getName(), param.getParamType()));
                p = new StringProperty();
            }
        }
        if (p instanceof ArrayProperty) {
            ArrayProperty ap = (ArrayProperty) p;
            sp.setType("array");
            sp.setCollectionFormat("csv");
            sp.setItems(ap.getItems());
        } else {
            sp.setType(p.getType());
            sp.setFormat(p.getFormat());
        }
    }
    // all path parameters are required
    if (output instanceof PathParameter) {
        ((PathParameter) output).setRequired(true);
    }
    return output;
}
Also used : SerializableParameter(io.swagger.models.parameters.SerializableParameter) QueryParameter(io.swagger.models.parameters.QueryParameter) ArrayProperty(io.swagger.models.properties.ArrayProperty) SerializableParameter(io.swagger.models.parameters.SerializableParameter) FormParameter(io.swagger.models.parameters.FormParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) StringProperty(io.swagger.models.properties.StringProperty) HeaderParameter(io.swagger.models.parameters.HeaderParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) PathParameter(io.swagger.models.parameters.PathParameter) FormParameter(io.swagger.models.parameters.FormParameter) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property) ModelProperty(io.swagger.models.apideclaration.ModelProperty) RefProperty(io.swagger.models.properties.RefProperty) UntypedProperty(io.swagger.models.properties.UntypedProperty)

Example 73 with ArrayProperty

use of io.swagger.models.properties.ArrayProperty in project cxf by apache.

the class JaxRs2Extension method enforcePrimitive.

private Property enforcePrimitive(final Property in, final int level) {
    if (in instanceof RefProperty) {
        return new StringProperty();
    }
    if (in instanceof ArrayProperty) {
        if (level == 0) {
            final ArrayProperty array = (ArrayProperty) in;
            array.setItems(enforcePrimitive(array.getItems(), level + 1));
        } else {
            return new StringProperty();
        }
    }
    return in;
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) StringProperty(io.swagger.models.properties.StringProperty) RefProperty(io.swagger.models.properties.RefProperty)

Example 74 with ArrayProperty

use of io.swagger.models.properties.ArrayProperty in project swagger-parser by swagger-api.

the class SwaggerInventory method process.

public void process(Property property) {
    this.properties.add(property);
    if (property instanceof ArrayProperty) {
        ArrayProperty p = (ArrayProperty) property;
        Property ap = p.getItems();
        this.process(ap);
    } else if (property instanceof MapProperty) {
        MapProperty p1 = (MapProperty) property;
    } else if (property instanceof ObjectProperty) {
        ObjectProperty p2 = (ObjectProperty) property;
        if (p2.getProperties() != null) {
            Iterator ap1 = p2.getProperties().keySet().iterator();
            while (ap1.hasNext()) {
                String name = (String) ap1.next();
                Property ip = (Property) p2.getProperties().get(name);
                this.process(ip);
            }
        }
    }
}
Also used : ObjectProperty(io.swagger.models.properties.ObjectProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) MapProperty(io.swagger.models.properties.MapProperty) Iterator(java.util.Iterator) MapProperty(io.swagger.models.properties.MapProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) ObjectProperty(io.swagger.models.properties.ObjectProperty) Property(io.swagger.models.properties.Property)

Example 75 with ArrayProperty

use of io.swagger.models.properties.ArrayProperty in project ballerina by ballerina-lang.

the class SwaggerResourceMapper method createHeadersModel.

/**
 * Creates headers definitions for swagger response.
 * @param annotationAttributeValue The annotation attribute value which has the headers.
 * @param response The swagger response.
 */
private void createHeadersModel(AnnotationAttachmentAttributeValueNode annotationAttributeValue, Response response) {
    if (null != annotationAttributeValue) {
        List<? extends AnnotationAttachmentAttributeValueNode> headersValueArray = annotationAttributeValue.getValueArray();
        for (AnnotationAttachmentAttributeValueNode headersValue : headersValueArray) {
            if (headersValue instanceof AnnotationAttachmentNode) {
                AnnotationAttachmentNode headerAnnotationAttachment = (AnnotationAttachmentNode) headersValue;
                Map<String, Property> headers = new HashMap<>();
                Map<String, AnnotationAttachmentAttributeValueNode> headersAttributes = this.listToMap(headerAnnotationAttachment);
                if (headersAttributes.containsKey("name") && headersAttributes.containsKey("headerType")) {
                    String headerName = this.getStringLiteralValue(headersAttributes.get("name"));
                    String type = this.getStringLiteralValue(headersAttributes.get("headerType"));
                    Property property = null;
                    if ("string".equals(type)) {
                        property = new StringProperty();
                    } else if ("number".equals(type) || "integer".equals(type)) {
                        property = new IntegerProperty();
                    } else if ("boolean".equals(type)) {
                        property = new BooleanProperty();
                    } else if ("array".equals(type)) {
                        property = new ArrayProperty();
                    }
                    if (null != property) {
                        if (headersAttributes.containsKey("description")) {
                            property.setDescription(this.getStringLiteralValue(headersAttributes.get("description")));
                        }
                        headers.put(headerName, property);
                    }
                }
                response.setHeaders(headers);
            }
        }
    }
}
Also used : IntegerProperty(io.swagger.models.properties.IntegerProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) HashMap(java.util.HashMap) BooleanProperty(io.swagger.models.properties.BooleanProperty) AnnotationAttachmentAttributeValueNode(org.ballerinalang.model.tree.expressions.AnnotationAttachmentAttributeValueNode) StringProperty(io.swagger.models.properties.StringProperty) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property) IntegerProperty(io.swagger.models.properties.IntegerProperty) BooleanProperty(io.swagger.models.properties.BooleanProperty) AnnotationAttachmentNode(org.ballerinalang.model.tree.AnnotationAttachmentNode)

Aggregations

ArrayProperty (io.swagger.models.properties.ArrayProperty)82 Property (io.swagger.models.properties.Property)62 StringProperty (io.swagger.models.properties.StringProperty)42 RefProperty (io.swagger.models.properties.RefProperty)39 Test (org.testng.annotations.Test)36 MapProperty (io.swagger.models.properties.MapProperty)25 Model (io.swagger.models.Model)23 IntegerProperty (io.swagger.models.properties.IntegerProperty)23 LongProperty (io.swagger.models.properties.LongProperty)14 ModelImpl (io.swagger.models.ModelImpl)13 BooleanProperty (io.swagger.models.properties.BooleanProperty)12 DoubleProperty (io.swagger.models.properties.DoubleProperty)12 RefModel (io.swagger.models.RefModel)10 FloatProperty (io.swagger.models.properties.FloatProperty)10 Operation (io.swagger.models.Operation)9 ByteArrayProperty (io.swagger.models.properties.ByteArrayProperty)9 DecimalProperty (io.swagger.models.properties.DecimalProperty)9 HashMap (java.util.HashMap)9 Response (io.swagger.models.Response)7 Swagger (io.swagger.models.Swagger)7