Java Code Examples for io.swagger.models.properties.ArrayProperty#getItems()

The following examples show how to use io.swagger.models.properties.ArrayProperty#getItems() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PlantUMLCodegen.java    From swagger2puml with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param modelObject
 * @param models
 * @param variablName
 * @param classMemberObject
 * @param propObject
 */
private ClassMembers getClassMember(ArrayProperty property, Model modelObject, Map<String, Model> models,
		String variablName) {
	LOGGER.entering(LOGGER.getName(), "getClassMember-ArrayProperty");

	ClassMembers classMemberObject = new ClassMembers();
	Property propObject = property.getItems();

	if (propObject instanceof RefProperty) {
		classMemberObject = getClassMember((RefProperty) propObject, models, modelObject, variablName);
	} else if (propObject instanceof StringProperty) {
		classMemberObject = getClassMember((StringProperty) propObject, variablName);
	}

	LOGGER.exiting(LOGGER.getName(), "getClassMember-ArrayProperty");
	return classMemberObject;
}
 
Example 2
Source File: AbstractOktaJavaClientCodegen.java    From okta-sdk-java with Apache License 2.0 6 votes vote down vote up
@Override
public String getTypeDeclaration(Property p) {

    if ("password".equals(p.getFormat())) {
        return "char[]";
    }

    if (p instanceof ArrayProperty) {
        ArrayProperty ap = (ArrayProperty) p;
        Property inner = ap.getItems();
        if (inner == null) {
            // mimic super behavior
            log.warn("{} (array property) does not have a proper inner type defined", ap.getName());
            return null;
        }

        String type = super.getTypeDeclaration(inner);
        if (!languageSpecificPrimitives.contains(type) && topLevelResources.contains(type)) {
            return type + "List";
        }
    }
    return super.getTypeDeclaration(p);
}
 
Example 3
Source File: SwaggerInventory.java    From swagger-parser with Apache License 2.0 6 votes vote down vote up
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);
            }
        }
    }

}
 
Example 4
Source File: AbstractKotlinCodegen.java    From TypeScript-Microservices with MIT License 5 votes vote down vote up
/**
 * Provides a strongly typed declaration for simple arrays of some type and arrays of arrays of some type.
 *
 * @param arr
 * @return
 */
private String getArrayTypeDeclaration(ArrayProperty arr) {
    // TODO: collection type here should be fully qualified namespace to avoid model conflicts
    // This supports arrays of arrays.
    String arrayType = typeMapping.get("array");
    StringBuilder instantiationType = new StringBuilder(arrayType);
    Property items = arr.getItems();
    String nestedType = getTypeDeclaration(items);
    // TODO: We may want to differentiate here between generics and primitive arrays.
    instantiationType.append("<").append(nestedType).append(">");
    return instantiationType.toString();
}
 
Example 5
Source File: PropertyAdapter.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
/**
 * Generate example for an ArrayProperty
 *
 * @param property ArrayProperty to generate example for
 * @param markupDocBuilder MarkupDocBuilder containing all associated settings
 * @return String example
 */
private static Object generateArrayExample(ArrayProperty property, MarkupDocBuilder markupDocBuilder) {
    Property itemProperty = property.getItems();
    List<Object> exampleArray = new ArrayList<>();

    exampleArray.add(generateExample(itemProperty, markupDocBuilder));
    return exampleArray;
}
 
Example 6
Source File: XmlExampleGenerator.java    From TypeScript-Microservices with MIT License 4 votes vote down vote up
protected String toXml(String name, Property property, int indent, Collection<String> path) {
    if (property == null) {
        return "";
    }
    StringBuilder sb = new StringBuilder();

    if (property instanceof ArrayProperty) {
        ArrayProperty p = (ArrayProperty) property;
        Property inner = p.getItems();
        boolean wrapped = false;
        if (property.getXml() != null && property.getXml().getWrapped() != null && property.getXml().getWrapped()) {
            wrapped = true;
        }
        if (wrapped) {
            String prefix = EMPTY;
            if (name != null) {
                sb.append(indent(indent));
                sb.append(openTag(name));
                prefix = NEWLINE;
            }
            final String asXml = toXml(name, inner, indent + 1, path);
            if (StringUtils.isNotEmpty(asXml)) {
                sb.append(prefix).append(asXml);
            }
            if (name != null) {
                sb.append(NEWLINE);
                sb.append(indent(indent));
                sb.append(closeTag(name));
            }
        } else {
            sb.append(toXml(name, inner, indent, path));
        }
    } else if (property instanceof RefProperty) {
        RefProperty ref = (RefProperty) property;
        Model actualModel = examples.get(ref.getSimpleRef());
        sb.append(toXml(actualModel, indent, path));
    } else {
        if (name != null) {
            sb.append(indent(indent));
            sb.append(openTag(name));
        }
        sb.append(getExample(property));
        if (name != null) {
            sb.append(closeTag(name));
        }
    }
    return sb.toString();
}
 
Example 7
Source File: AbstractOktaJavaClientCodegen.java    From okta-sdk-java with Apache License 2.0 4 votes vote down vote up
private Map<String, Model> processListsFromProperties(Collection<Property> properties, Model baseModel, Swagger swagger) {

        Map<String, Model> result = new LinkedHashMap<>();

        for (Property p : properties) {
            if (p != null && "array".equals(p.getType())) {

                ArrayProperty arrayProperty = (ArrayProperty) p;
                if ( arrayProperty.getItems() instanceof RefProperty) {
                    RefProperty ref = (RefProperty) arrayProperty.getItems();

                    String baseName = ref.getSimpleRef();

                    // Do not generate List wrappers for primitives (or strings)
                    if (!languageSpecificPrimitives.contains(baseName) && topLevelResources.contains(baseName)) {

                        String modelName = baseName + "List";

                        ModelImpl model = new ModelImpl();
                        model.setName(modelName);
                        model.setAllowEmptyValue(false);
                        model.setDescription("Collection List for " + baseName);

                        if (baseModel == null) {
                            baseModel = swagger.getDefinitions().get(baseName);
                        }

                        // only add the tags from the base model
                        if (baseModel.getVendorExtensions().containsKey("x-okta-tags")) {
                            model.setVendorExtension("x-okta-tags", baseModel.getVendorExtensions().get("x-okta-tags"));
                        }

                        model.setVendorExtension("x-isResourceList", true);
                        model.setVendorExtension("x-baseType", baseName);
                        model.setType(modelName);

                        result.put(modelName, model);
                    }
                }
            }
        }

        return result;
    }