Java Code Examples for io.swagger.v3.oas.models.media.Schema#setName()

The following examples show how to use io.swagger.v3.oas.models.media.Schema#setName() . 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: OpenApiObjectGenerator.java    From flow with Apache License 2.0 6 votes vote down vote up
private Schema createSingleSchema(String fullQualifiedName,
        TypeDeclaration<?> typeDeclaration) {
    Optional<String> description = typeDeclaration.getJavadoc()
            .map(javadoc -> javadoc.getDescription().toText());
    Schema schema = new ObjectSchema();
    schema.setName(fullQualifiedName);
    description.ifPresent(schema::setDescription);
    Map<String, Schema> properties = getPropertiesFromClassDeclaration(
            typeDeclaration);
    schema.properties(properties);
    List<String> requiredList = properties.entrySet().stream()
            .filter(stringSchemaEntry -> GeneratorUtils
                    .isNotTrue(stringSchemaEntry.getValue().getNullable()))
            .map(Map.Entry::getKey).collect(Collectors.toList());
    // Nullable is represented in requiredList instead.
    properties.values()
            .forEach(propertySchema -> propertySchema.nullable(null));
    schema.setRequired(requiredList);
    return schema;
}
 
Example 2
Source File: SwaggerAnnotationUtils.java    From servicecomb-toolkit with Apache License 2.0 6 votes vote down vote up
public static Schema getSchemaFromAnnotation(io.swagger.v3.oas.annotations.media.Schema schema) {
  if (schema == null) {
    return null;
  }
  Schema schemaObj = new Schema();
  schemaObj.setName(schema.name());
  schemaObj.setDescription(schema.description());
  schemaObj.setType(schema.type());
  schemaObj.setTitle(schema.title());
  schemaObj.setNullable(schema.nullable());
  schemaObj.setDefault(schema.defaultValue());
  schemaObj.setFormat(schema.format());
  schemaObj.setDeprecated(schema.deprecated());
  Map<String, Object> extensionsFromAnnotation = getExtensionsFromAnnotation(schema.extensions());
  schemaObj.extensions(extensionsFromAnnotation);
  return schemaObj;
}
 
Example 3
Source File: InlineModelResolverTest.java    From swagger-parser with Apache License 2.0 5 votes vote down vote up
@Test
public void resolveInlineModelTestWithoutTitle() throws Exception {
    OpenAPI openAPI = new OpenAPI();
    openAPI.setComponents(new Components());


    Schema objectSchema = new ObjectSchema();
    objectSchema.setDefault("default");
    objectSchema.setReadOnly(false);
    objectSchema.setDescription("description");
    objectSchema.setName("name");
    objectSchema.addProperties("street", new StringSchema());
    objectSchema.addProperties("city", new StringSchema());

    Schema schema =  new Schema();
    schema.setName("user");
    schema.setDescription("a common user");
    List<String> required = new ArrayList<>();
    required.add("address");
    schema.setRequired(required);
    schema.addProperties("name", new StringSchema());
    schema.addProperties("address", objectSchema);


    openAPI.getComponents().addSchemas("User", schema);

    new InlineModelResolver().flatten(openAPI);

    Schema user = openAPI.getComponents().getSchemas().get("User");

    assertNotNull(user);
    Schema address = (Schema)user.getProperties().get("address");
    assertTrue((address.get$ref()!= null));
    Schema userAddress = openAPI.getComponents().getSchemas().get("User_address");
    assertNotNull(userAddress);
    assertNotNull(userAddress.getProperties().get("city"));
    assertNotNull(userAddress.getProperties().get("street"));
}
 
Example 4
Source File: InlineModelResolverTest.java    From swagger-parser with Apache License 2.0 5 votes vote down vote up
@Test
public void testArbitraryObjectModelWithArrayInlineWithTitle() {
    OpenAPI openAPI = new OpenAPI();
    openAPI.setComponents(new Components());

    Schema items = new ObjectSchema();
    items.setTitle("InnerUserTitle");
    items.setDefault("default");
    items.setReadOnly(false);
    items.setDescription("description");
    items.setName("name");
    items.addProperties("arbitrary", new ObjectSchema());

    openAPI.getComponents().addSchemas("User", new ArraySchema().items(items).addRequiredItem("name"));

    new InlineModelResolver().flatten(openAPI);

    Schema model = openAPI.getComponents().getSchemas().get("User");
    assertTrue(model instanceof ArraySchema);
    ArraySchema am = (ArraySchema) model;
    Schema inner = am.getItems();
    assertTrue(inner.get$ref() != null);

    Schema userInner = openAPI.getComponents().getSchemas().get("InnerUserTitle");
    assertNotNull(userInner);
    Schema inlineProp = (Schema) userInner.getProperties().get("arbitrary");
    assertTrue(inlineProp instanceof ObjectSchema);
    ObjectSchema op = (ObjectSchema) inlineProp;
    assertNull(op.getProperties());
}
 
Example 5
Source File: InlineModelResolverTest.java    From swagger-parser with Apache License 2.0 5 votes vote down vote up
@Test
public void testArbitraryObjectModelWithArrayInlineWithoutTitle() {
    OpenAPI openAPI = new OpenAPI();
    openAPI.setComponents(new Components());

    Schema items = new ObjectSchema();
    items.setDefault("default");
    items.setReadOnly(false);
    items.setDescription("description");
    items.setName("name");
    items.addProperties("arbitrary", new ObjectSchema());

    openAPI.getComponents().addSchemas("User", new ArraySchema().items(items).addRequiredItem("name"));

    new InlineModelResolver().flatten(openAPI);

    Schema model = openAPI.getComponents().getSchemas().get("User");
    assertTrue(model instanceof ArraySchema);
    ArraySchema am = (ArraySchema) model;
    Schema inner = am.getItems();
    assertTrue(inner.get$ref() != null);

    Schema userInner = openAPI.getComponents().getSchemas().get("User_inner");
    assertNotNull(userInner);
    Schema inlineProp = (Schema)userInner.getProperties().get("arbitrary");
    assertTrue(inlineProp instanceof ObjectSchema);
    ObjectSchema op = (ObjectSchema) inlineProp;
    assertNull(op.getProperties());
}
 
Example 6
Source File: InlineModelResolverTest.java    From swagger-parser with Apache License 2.0 5 votes vote down vote up
@Test
public void testArbitraryObjectModelInline() {
    OpenAPI openAPI = new OpenAPI();
    openAPI.setComponents(new Components());

    Schema userSchema = new Schema();
    userSchema.setName("user");
    userSchema.setDescription("a common user");
    userSchema.addProperties("name", new StringSchema());

    ObjectSchema objectSchema = new ObjectSchema();
    objectSchema.setTitle("title");
    objectSchema.setDefault("default");
    objectSchema.setReadOnly(false);
    objectSchema.setDescription("description");
    objectSchema.setName("name");

    userSchema.addProperties("arbitrary", objectSchema);
    List required = new ArrayList();
    required.add("arbitrary");
    userSchema.setRequired(required);


    openAPI.getComponents().addSchemas("User", userSchema);

    new InlineModelResolver().flatten(openAPI);

    Schema user = openAPI.getComponents().getSchemas().get("User");
    assertNotNull(user);
    Schema inlineProp = (Schema) user.getProperties().get("arbitrary");
    assertTrue(inlineProp instanceof ObjectSchema);
    assertNull(inlineProp.getProperties());
}
 
Example 7
Source File: InlineModelResolverTest.java    From swagger-parser with Apache License 2.0 5 votes vote down vote up
@Test
public void resolveInlineArrayModelWithoutTitle() throws Exception {
    OpenAPI openAPI = new OpenAPI();
    openAPI.setComponents(new Components());

    Schema objectSchema = new ObjectSchema();
    objectSchema.setDefault("default");
    objectSchema.setReadOnly(false);
    objectSchema.setDescription("description");
    objectSchema.setName("name");
    objectSchema.addProperties("street", new StringSchema());
    objectSchema.addProperties("city", new StringSchema());

    ArraySchema arraySchema =  new ArraySchema();
    List<String> required = new LinkedList<>();
    required.add("name");
    arraySchema.setRequired(required);
    arraySchema.setItems(objectSchema);

    openAPI.getComponents().addSchemas("User", arraySchema);


    new InlineModelResolver().flatten(openAPI);

    Schema model = openAPI.getComponents().getSchemas().get("User");
    assertTrue(model instanceof ArraySchema);

    Schema user = openAPI.getComponents().getSchemas().get("User_inner");
    assertNotNull(user);
    assertEquals("description", user.getDescription());
}
 
Example 8
Source File: InlineModelResolverTest.java    From swagger-parser with Apache License 2.0 5 votes vote down vote up
@Test
public void resolveInlineArrayModelWithTitle() throws Exception {
    OpenAPI openAPI = new OpenAPI();
    openAPI.setComponents(new Components());

    Schema objectSchema = new ObjectSchema();
    objectSchema.setTitle("InnerUserTitle");
    objectSchema.setDefault("default");
    objectSchema.setReadOnly(false);
    objectSchema.setDescription("description");
    objectSchema.setName("name");
    objectSchema.addProperties("street", new StringSchema());
    objectSchema.addProperties("city", new StringSchema());

    ArraySchema arraySchema =  new ArraySchema();
    List<String> required = new LinkedList<>();
    required.add("name");
    arraySchema.setRequired(required);
    arraySchema.setItems(objectSchema);


    openAPI.getComponents().addSchemas("User", arraySchema);


    new InlineModelResolver().flatten(openAPI);

    Schema model = openAPI.getComponents().getSchemas().get("User");
    assertTrue(model instanceof ArraySchema);

    Schema user = openAPI.getComponents().getSchemas().get("InnerUserTitle");
    assertNotNull(user);
    assertEquals("description", user.getDescription());
}
 
Example 9
Source File: InlineModelResolverTest.java    From swagger-parser with Apache License 2.0 5 votes vote down vote up
@Test
public void resolveInlineModelTestWithTitle() throws Exception {
    OpenAPI openAPI = new OpenAPI();
    openAPI.setComponents(new Components());


    Schema objectSchema = new ObjectSchema();
    objectSchema.setTitle("UserAddressTitle");
    objectSchema.setDefault("default");
    objectSchema.setReadOnly(false);
    objectSchema.setDescription("description");
    objectSchema.setName("name");
    objectSchema.addProperties("street", new StringSchema());
    objectSchema.addProperties("city", new StringSchema());

    Schema schema =  new Schema();
    schema.setName("user");
    schema.setDescription("a common user");
    List<String> required = new ArrayList<>();
    required.add("address");
    schema.setRequired(required);
    schema.addProperties("name", new StringSchema());
    schema.addProperties("address", objectSchema);


    openAPI.getComponents().addSchemas("User", schema);

    new InlineModelResolver().flatten(openAPI);

    Schema user = openAPI.getComponents().getSchemas().get("User");

    assertNotNull(user);
    Schema address = (Schema)user.getProperties().get("address");
    assertTrue( address.get$ref() != null);

    Schema userAddressTitle = openAPI.getComponents().getSchemas().get("UserAddressTitle");
    assertNotNull(userAddressTitle);
    assertNotNull(userAddressTitle.getProperties().get("city"));
    assertNotNull(userAddressTitle.getProperties().get("street"));
}
 
Example 10
Source File: ExampleBuilderTest.java    From swagger-inflector with Apache License 2.0 5 votes vote down vote up
@Test
public void testComplexArray() throws Exception {
    Map<String, Schema> definitions = new HashMap<>();

    Schema address = new Schema()
            .xml(new XML().name("address"));

    Schema propertyDefinition1 = new StringSchema();
    propertyDefinition1.setName("street");
    propertyDefinition1.setExample("12345 El Monte Blvd");

    Schema propertyDefinition2 = new StringSchema();
    propertyDefinition2.setName("city");
    propertyDefinition2.setExample("Los Altos Hills");

    Schema propertyDefinition3 = new StringSchema();
    propertyDefinition3.setName("state");
    propertyDefinition3.setExample("CA");
    propertyDefinition3.setMinLength(2);
    propertyDefinition3.setMaxLength(2);

    Schema propertyDefinition4 = new StringSchema();
    propertyDefinition4.setName("zip");
    propertyDefinition4.setExample("94022");

    address.addProperties("street",propertyDefinition1);
    address.addProperties("city",propertyDefinition2);
    address.addProperties("state",propertyDefinition3);
    address.addProperties("zip",propertyDefinition4);

    definitions.put("Address", address);

    Example rep = (Example) ExampleBuilder.fromSchema(new ArraySchema().$ref("Address"), definitions);

    String json = Json.pretty(rep);

    assertEqualsIgnoreLineEnding(json,"{\n  \"street\" : \"12345 El Monte Blvd\",\n  \"city\" : \"Los Altos Hills\",\n  \"state\" : \"CA\",\n  \"zip\" : \"94022\"\n}");
}
 
Example 11
Source File: ModelConverter.java    From servicecomb-toolkit with Apache License 2.0 5 votes vote down vote up
private static void ensureSchemaNameExist(Schema schema) {
  if (schema.getName() != null) {
    return;
  }

  if (schema.get$ref() != null) {
    schema.setName((String) RefUtils.extractSimpleName(schema.get$ref()).getKey());
    return;
  }
}
 
Example 12
Source File: ExternalRefProcessorTest.java    From swagger-parser with Apache License 2.0 4 votes vote down vote up
@Test
  public void testNestedExternalRefs(@Injectable final Schema mockedModel){
  	final RefFormat refFormat = RefFormat.URL;

  	//Swagger test instance
  	OpenAPI testedOpenAPI = new OpenAPI();

  	//Start with customer, add address property to it
  	final String customerURL = "http://my.company.com/path/to/customer.json#/definitions/Customer";

  	final Schema customerModel = new Schema();
  	Map<String,Schema> custProps = new HashMap<>();
  	Schema address = new Schema();
  	final String addressURL = "http://my.company.com/path/to/address.json#/definitions/Address";
  	address.set$ref(addressURL);
  	custProps.put("Address", address);

  	//Create a 'local' reference to something in #/definitions, this should be ignored a no longer result in a null pointer exception
  	final String loyaltyURL = "#/definitions/LoyaltyScheme";

  	Schema loyaltyProp = new Schema();
  	loyaltyProp.set$ref(loyaltyURL);
  	loyaltyProp.setName("LoyaltyCardNumber");
  	List<String> required = new ArrayList<>();
  	required.add("LoyaltyCardNumber");
  	loyaltyProp.setRequired(required);

  	custProps.put("Loyalty", loyaltyProp);
  	customerModel.setProperties(custProps);

  	//create address model, add Contact Ref Property to it
  	final Schema addressModel = new Schema();
  	Map<String, Schema> addressProps = new HashMap<>();
  	Schema contact = new Schema();
  	final String contactURL = "http://my.company.com/path/to/Contact.json#/definitions/Contact";
  	contact.set$ref(contactURL);
  	addressProps.put("Contact", contact);
  	addressModel.setProperties(addressProps);


  	//Create contact model, with basic type property
  	final Schema contactModel = new Schema();
  	Schema contactProp = new StringSchema();
  	contactProp.setName("PhoneNumber");
List<String> requiredList = new ArrayList<>();
requiredList.add("PhoneNumber");
  	contactProp.setRequired(requiredList);
  	Map<String, Schema> contactProps = new HashMap<>();
  	contactProps.put("PhoneNumber", contactProp);
  	contactModel.setProperties(contactProps);

  	new Expectations(){{
  		cache.loadRef(customerURL, refFormat, Schema.class);
  		result = customerModel;
  		times = 1;

  		cache.loadRef(addressURL, refFormat, Schema.class);
  		result = addressModel;
  		times = 1;

  		cache.loadRef(contactURL, refFormat, Schema.class);
  		result = contactModel;
  		times = 1;
	}};

new ExternalRefProcessor(cache, testedOpenAPI).processRefToExternalSchema(customerURL, refFormat);

assertThat(testedOpenAPI.getComponents().getSchemas().get("Customer"), notNullValue());
assertThat(testedOpenAPI.getComponents().getSchemas().get("Contact"), notNullValue());
assertThat(testedOpenAPI.getComponents().getSchemas().get("Address"), notNullValue());
  }
 
Example 13
Source File: InlineModelResolverTest.java    From swagger-parser with Apache License 2.0 4 votes vote down vote up
@Test
public void resolveInlineModel2EqualInnerModels() throws Exception {
    OpenAPI openAPI = new OpenAPI();
    openAPI.setComponents(new Components());


    Schema objectSchema = new ObjectSchema();
    objectSchema.setTitle("UserAddressTitle");
    objectSchema.setDefault("default");
    objectSchema.setReadOnly(false);
    objectSchema.setDescription("description");
    objectSchema.setName("name");
    objectSchema.addProperties("street", new StringSchema());
    objectSchema.addProperties("city", new StringSchema());

    Schema schema =  new Schema();
    schema.setName("user");
    schema.setDescription("a common user");
    List<String> required = new ArrayList<>();
    required.add("address");
    schema.setRequired(required);
    schema.addProperties("name", new StringSchema());
    schema.addProperties("address", objectSchema);


    openAPI.getComponents().addSchemas("User", schema);

    Schema addressSchema = new ObjectSchema();
    addressSchema.setTitle("UserAddressTitle");
    addressSchema.setDefault("default");
    addressSchema.setReadOnly(false);
    addressSchema.setDescription("description");
    addressSchema.setName("name");
    addressSchema.addProperties("street", new StringSchema());
    addressSchema.addProperties("city", new StringSchema());

    Schema anotherSchema =  new Schema();
    anotherSchema.setName("user");
    anotherSchema.setDescription("a common user");
    List<String> requiredFields = new ArrayList<>();
    requiredFields.add("address");
    anotherSchema.setRequired(requiredFields);
    anotherSchema.addProperties("name", new StringSchema());
    anotherSchema.addProperties("lastName", new StringSchema());
    anotherSchema.addProperties("address", addressSchema);

    openAPI.getComponents().addSchemas("AnotherUser", anotherSchema);

    new InlineModelResolver().flatten(openAPI);

    Schema user = openAPI.getComponents().getSchemas().get("User");

    assertNotNull(user);
    Schema addressSchema1 = (Schema) user.getProperties().get("address");
    assertTrue(addressSchema1.get$ref() != null);

    Schema address = openAPI.getComponents().getSchemas().get("UserAddressTitle");
    assertNotNull(address);
    assertNotNull(address.getProperties().get("city"));
    assertNotNull(address.getProperties().get("street"));
    Schema duplicateAddress = openAPI.getComponents().getSchemas().get("UserAddressTitle_0");
    assertNull(duplicateAddress);
}
 
Example 14
Source File: InlineModelResolverTest.java    From swagger-parser with Apache License 2.0 4 votes vote down vote up
@Test
public void resolveInlineModel2DifferentInnerModelsWIthSameTitle() throws Exception {
    OpenAPI openAPI = new OpenAPI();
    openAPI.setComponents(new Components());

    Schema objectSchema = new ObjectSchema();
    objectSchema.setTitle("UserAddressTitle");
    objectSchema.setDefault("default");
    objectSchema.setReadOnly(false);
    objectSchema.setDescription("description");
    objectSchema.setName("name");
    objectSchema.addProperties("street", new StringSchema());
    objectSchema.addProperties("city", new StringSchema());

    Schema schema =  new Schema();
    schema.setName("user");
    schema.setDescription("a common user");
    List<String> required = new ArrayList<>();
    required.add("address");
    schema.setRequired(required);
    schema.addProperties("name", new StringSchema());
    schema.addProperties("address", objectSchema);


    openAPI.getComponents().addSchemas("User", schema);

    Schema addressSchema = new ObjectSchema();
    addressSchema.setTitle("UserAddressTitle");
    addressSchema.setDefault("default");
    addressSchema.setReadOnly(false);
    addressSchema.setDescription("description");
    addressSchema.setName("name");
    addressSchema.addProperties("street", new StringSchema());
    addressSchema.addProperties("city", new StringSchema());
    addressSchema.addProperties("apartment", new StringSchema());


    Schema anotherSchema =  new Schema();
    anotherSchema.setName("AnotherUser");
    anotherSchema.setDescription("a common user");
    List<String> requiredFields = new ArrayList<>();
    requiredFields.add("address");
    anotherSchema.setRequired(requiredFields);
    anotherSchema.addProperties("name", new StringSchema());
    anotherSchema.addProperties("lastName", new StringSchema());
    anotherSchema.addProperties("address", addressSchema);


    openAPI.getComponents().addSchemas("AnotherUser", anotherSchema);

    new InlineModelResolver().flatten(openAPI);

    Schema user = openAPI.getComponents().getSchemas().get("User");

    assertNotNull(user);
    Schema userAddress = (Schema) user.getProperties().get("address");
    assertTrue( userAddress.get$ref()!= null);

    Schema address = openAPI.getComponents().getSchemas().get("UserAddressTitle");
    assertNotNull(address);
    assertNotNull(address.getProperties().get("city"));
    assertNotNull(address.getProperties().get("street"));
    Schema duplicateAddress = openAPI.getComponents().getSchemas().get("UserAddressTitle_1");
    assertNotNull(duplicateAddress);
    assertNotNull(duplicateAddress.getProperties().get("city"));
    assertNotNull(duplicateAddress.getProperties().get("street"));
    assertNotNull(duplicateAddress.getProperties().get("apartment"));
}
 
Example 15
Source File: InlineModelResolver.java    From swagger-parser with Apache License 2.0 4 votes vote down vote up
public Schema createModelFromProperty(Schema schema, String path) {
    String description = schema.getDescription();
    String example = null;
    List<String> requiredList = schema.getRequired();


    Object obj = schema.getExample();
    if (obj != null) {
        example = obj.toString();
    }
    String name = schema.getName();
    XML xml = schema.getXml();
    Map<String, Schema> properties = schema.getProperties();


    if (schema instanceof ComposedSchema && this.flattenComposedSchemas){
        ComposedSchema composedModel = (ComposedSchema) schema;

        composedModel.setDescription(description);
        composedModel.setExample(example);
        composedModel.setName(name);
        composedModel.setXml(xml);
        composedModel.setType(schema.getType());
        composedModel.setRequired(requiredList);

        return composedModel;


    } else {
        Schema model = new Schema();//TODO Verify this!
        model.setDescription(description);
        model.setExample(example);
        model.setName(name);
        model.setXml(xml);
        model.setType(schema.getType());
        model.setRequired(requiredList);

        if (properties != null) {
            flattenProperties(properties, path);
            model.setProperties(properties);
        }

        return model;
    }
}
 
Example 16
Source File: ExampleBuilderTest.java    From swagger-inflector with Apache License 2.0 4 votes vote down vote up
@Test
public void testComplexArrayWithExample() throws Exception {
    Map<String, Schema> definitions = new HashMap<>();

    Schema address = new Schema()
      .example("{\"foo\":\"bar\"}")
      .xml(new XML()
        .name("address"));

    Schema propertyDefinition1 = new StringSchema();
    propertyDefinition1.setName("street");
    propertyDefinition1.setExample("12345 El Monte Blvd");

    Schema propertyDefinition2 = new StringSchema();
    propertyDefinition2.setName("city");
    propertyDefinition2.setExample("Los Altos Hills");

    Schema propertyDefinition3 = new StringSchema();
    propertyDefinition3.setName("state");
    propertyDefinition3.setExample("CA");
    propertyDefinition3.setMinLength(2);
    propertyDefinition3.setMaxLength(2);

    Schema propertyDefinition4 = new StringSchema();
    propertyDefinition4.setName("zip");
    propertyDefinition4.setExample("94022");

    address.addProperties("street",propertyDefinition1);
    address.addProperties("city",propertyDefinition2);
    address.addProperties("state",propertyDefinition3);
    address.addProperties("zip",propertyDefinition4);


    definitions.put("Address", address);

    // register the JSON serializer
    SimpleModule simpleModule = new SimpleModule();
    simpleModule.addSerializer(new JsonNodeExampleSerializer());
    simpleModule.addDeserializer(Example.class, new JsonExampleDeserializer());
    Json.mapper().registerModule(simpleModule);

    Example rep = (Example) ExampleBuilder.fromSchema(new StringSchema().addEnumItem("hello").example("fun"), definitions);
    assertEqualsIgnoreLineEnding(Json.pretty(rep), "\"fun\"");
}
 
Example 17
Source File: ExampleBuilderTest.java    From swagger-inflector with Apache License 2.0 4 votes vote down vote up
@Test
public void testXmlJackson() throws Exception {
    Schema model = new Schema()
            .xml(new XML()
                    .name("user"));

    Schema property1 = new StringSchema();
    property1.setName("username");
    property1.setExample("fehguy");
    property1.setXml(new XML()
            .name("userName"));

    ArraySchema property2 = new ArraySchema();
    property2.setName("addresses");
    property2.setXml(new XML().wrapped(true));
    property2.setItems(new Schema().$ref("Address"));
    Schema property3 = new Schema();
    property3.setName("managers");
    property3.setAdditionalProperties(new StringSchema().example("SVP Engineering"));
    ArraySchema property4 = new ArraySchema();
    property4.setName("kidsAges");
    property4.setItems(new IntegerSchema().example(9));

    model.addProperties("username",property1);
    model.addProperties("addresses",property2);
    model.addProperties("managers",property3);
    model.addProperties("kidsAges",property4);

    Map<String, Schema> definitions = new HashMap<>();
    definitions.put("User", model);

    Schema address = new Schema()
            .xml(new XML().name("address"));

    Schema propertyDefinition1 = new StringSchema();
    propertyDefinition1.setName("street");
    propertyDefinition1.setExample("12345 El Monte Blvd");

    Schema propertyDefinition2 = new StringSchema();
    propertyDefinition2.setName("city");
    propertyDefinition2.setExample("Los Altos Hills");

    Schema propertyDefinition3 = new StringSchema();
    propertyDefinition3.setName("state");
    propertyDefinition3.setExample("CA");
    propertyDefinition3.setMinLength(2);
    propertyDefinition3.setMaxLength(2);

    Schema propertyDefinition4 = new StringSchema();
    propertyDefinition4.setName("zip");
    propertyDefinition4.setExample("94022");

    address.addProperties("street",propertyDefinition1);
    address.addProperties("city",propertyDefinition2);
    address.addProperties("state",propertyDefinition3);
    address.addProperties("zip",propertyDefinition4);

    definitions.put("Address", address);

    Example rep = ExampleBuilder.fromSchema(new Schema().$ref("User"), definitions);

    String xmlString = new XmlExampleSerializer().serialize(rep);
    assertEqualsIgnoreLineEnding(xmlString, "<?xml version='1.1' encoding='UTF-8'?><user><userName>fehguy</userName><addressess><address><street>12345 El Monte Blvd</street><city>Los Altos Hills</city><state>CA</state><zip>94022</zip></address></addressess><managers><additionalProp1>SVP Engineering</additionalProp1><additionalProp2>SVP Engineering</additionalProp2><additionalProp3>SVP Engineering</additionalProp3></managers><kidsAges>9</kidsAges></user>");
    assertEqualsIgnoreLineEnding(Yaml.pretty().writeValueAsString(rep),"username: fehguy\naddresses:\n- street: 12345 El Monte Blvd\n  city: Los Altos Hills\n  state: CA\n  zip: \"94022\"\nmanagers:\n  additionalProp1: SVP Engineering\n  additionalProp2: SVP Engineering\n  additionalProp3: SVP Engineering\nkidsAges:\n- 9\n");
}