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

The following examples show how to use io.swagger.models.ArrayModel#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: MappingConverterImplTest.java    From binder-swagger-java with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testMtoModel() {
    Model model = converter.mToModel(list(mapping(
            field("id", $(intv()).desc("id").$$),
            field("name", $(text(required())).desc("name").$$)
    )));
    assertTrue(model instanceof ArrayModel);
    ArrayModel m = (ArrayModel) model;

    assertTrue(m.getItems() instanceof ObjectProperty);
    ObjectProperty p = (ObjectProperty) m.getItems();

    assertTrue(p.getProperties() != null);
    assertEquals(p.getProperties().size(), 2);
    assertTrue(p.getProperties().get("id") instanceof IntegerProperty);
    assertTrue(p.getProperties().get("name") instanceof StringProperty);

    IntegerProperty p1 = (IntegerProperty) p.getProperties().get("id");
    assertEquals(p1.getRequired(), false);
    assertEquals(p1.getFormat(), "int32");
    assertEquals(p1.getDescription(), "id");

    StringProperty p2 = (StringProperty) p.getProperties().get("name");
    assertEquals(p2.getRequired(), true);
    assertEquals(p2.getDescription(), "name");
}
 
Example 2
Source File: JaxrsReader.java    From swagger-maven-plugin with Apache License 2.0 6 votes vote down vote up
private Parameter replaceArrayModelForOctetStream(Operation operation, Parameter parameter) {
    if (parameter instanceof BodyParameter
            && operation.getConsumes() != null
            && operation.getConsumes().contains("application/octet-stream")) {
        BodyParameter bodyParam = (BodyParameter) parameter;
        Model schema = bodyParam.getSchema();
        if (schema instanceof ArrayModel) {
            ArrayModel arrayModel = (ArrayModel) schema;
            Property items = arrayModel.getItems();
            if (items != null && items.getFormat() == "byte" && items.getType() == "string") {
                ModelImpl model = new ModelImpl();
                model.setFormat("byte");
                model.setType("string");
                bodyParam.setSchema(model);
            }
        }
    }
    return parameter;
}
 
Example 3
Source File: JavascriptClientCodegen.java    From TypeScript-Microservices with MIT License 5 votes vote down vote up
@Override
public CodegenModel fromModel(String name, Model model, Map<String, Model> allDefinitions) {
    CodegenModel codegenModel = super.fromModel(name, model, allDefinitions);

    if (allDefinitions != null && codegenModel != null && codegenModel.parent != null && codegenModel.hasEnums) {
        final Model parentModel = allDefinitions.get(codegenModel.parentSchema);
        final CodegenModel parentCodegenModel = super.fromModel(codegenModel.parent, parentModel, allDefinitions);
        codegenModel = JavascriptClientCodegen.reconcileInlineEnums(codegenModel, parentCodegenModel);
    }
    if (model instanceof ArrayModel) {
        ArrayModel am = (ArrayModel) model;
        if (am.getItems() != null) {
            codegenModel.vendorExtensions.put("x-isArray", true);
            codegenModel.vendorExtensions.put("x-itemType", getSwaggerType(am.getItems()));
        }
    } else if (model instanceof ModelImpl) {
        ModelImpl mm = (ModelImpl)model;
        if (mm.getAdditionalProperties() != null) {
            codegenModel.vendorExtensions.put("x-isMap", true);
            codegenModel.vendorExtensions.put("x-itemType", getSwaggerType(mm.getAdditionalProperties()));
        } else {
            String type = mm.getType();
            if (isPrimitiveType(type)){
                codegenModel.vendorExtensions.put("x-isPrimitive", true);
            }
        }
    }

    return codegenModel;
}
 
Example 4
Source File: ElmClientCodegen.java    From TypeScript-Microservices with MIT License 5 votes vote down vote up
@Override
public CodegenModel fromModel(String name, Model model, Map<String, Model> allDefinitions) {
    CodegenModel m = super.fromModel(name, model, allDefinitions);

    if (model instanceof ArrayModel) {
        ArrayModel am = (ArrayModel) model;
        ArrayProperty arrayProperty = new ArrayProperty(am.getItems());
        CodegenProperty codegenProperty = fromProperty(name, arrayProperty);
        m.vendorExtensions.putAll(codegenProperty.vendorExtensions);
    }

    return m;
}
 
Example 5
Source File: ArrayModelConverter.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Override
public JavaType doConvert(Swagger swagger, Object model) {
  ArrayModel arrayModel = (ArrayModel) model;

  if (arrayModel.getItems() != null) {
    return ArrayPropertyConverter.findJavaType(swagger, arrayModel.getItems(), false);
  }

  // don't know when will this happen.
  throw new IllegalStateException("not support null array model items.");
}
 
Example 6
Source File: PlantUMLCodegen.java    From swagger2puml with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @param model
 * @return
 */
private String getSuperClass(Model model) {
	LOGGER.entering(LOGGER.getName(), "getSuperClass");

	String superClass = null;

	if (model instanceof ArrayModel) {
		ArrayModel arrayModel = (ArrayModel) model;
		Property propertyObject = arrayModel.getItems();

		if (propertyObject instanceof RefProperty) {
			superClass = new StringBuilder().append("ArrayList[")
					.append(((RefProperty) propertyObject).getSimpleRef()).append("]").toString();
		}
	} else if (model instanceof ModelImpl) {
		Property addProperty = ((ModelImpl) model).getAdditionalProperties();

		if (addProperty instanceof RefProperty) {
			superClass = new StringBuilder().append("Map[").append(((RefProperty) addProperty).getSimpleRef())
					.append("]").toString();
		}
	}

	LOGGER.exiting(LOGGER.getName(), "getSuperClass");

	return superClass;
}
 
Example 7
Source File: PlantUMLCodegen.java    From swagger2puml with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @param arrayModel
 * @param modelsMap
 * @return
 */
private List<ClassMembers> getClassMembers(ArrayModel arrayModel, Map<String, Model> modelsMap) {
	LOGGER.entering(LOGGER.getName(), "getClassMembers-ArrayModel");

	List<ClassMembers> classMembers = new ArrayList<ClassMembers>();

	Property propertyObject = arrayModel.getItems();

	if (propertyObject instanceof RefProperty) {
		classMembers.add(getRefClassMembers((RefProperty) propertyObject));
	}

	LOGGER.exiting(LOGGER.getName(), "getClassMembers-ArrayModel");
	return classMembers;
}