public Dto build() { return new Dto(newName, newDocumentation, newQualifier, Collections.unmodifiableList(newTypeParameters), newNamespace, newSchemaName, Collections.unmodifiableList(newAttributes), Collections.unmodifiableList(newEnumerations), newSource); } }
@Override public Map<String, ?> resolve(final ArrayDto type) { final ImmutableMap.Builder<String, Object> map = ImmutableMap.builder(); map.put("$schema", JSON_SCHEMA); map.put("type", "array"); final ImmutableList.Builder<Map<String, ?>> attributes = ImmutableList.builder(); final List<Enumeration> enumerations = FluentIterable.from(type.getTypeParameters()).filter(Enumeration.class).toList(); if (enumerations != null && !enumerations.isEmpty()) { final Enumeration singleEnum = enumerations.get(0); attributes.add(ImmutableMap.of("enum", SchemaJSONUtils.processEnumValues(singleEnum))); } final List<Dto> dtos = FluentIterable.from(type.getTypeParameters()).filter(Dto.class).toList(); if (dtos != null && !dtos.isEmpty()) { final Dto singleDto = dtos.get(0); attributes.add(ImmutableMap.of("$ref", singleDto.getSchemaName())); } map.put("items", attributes.build()); return map.build(); }
@Override public Map<String, ?> resolve(final Dto type) { final ImmutableMap.Builder<String, Object> map = ImmutableMap.builder(); map.put("$schema", JSON_SCHEMA); map.put("type", "object"); final List<Attribute> attrs = type.getSimpleAttributes(); if (attrs != null && !attrs.isEmpty()) { final ImmutableMap.Builder<String, Object> attributeWrapper = ImmutableMap.builder(); for (final Attribute attr : type.getSimpleAttributes()) { final Map<String, ?> attrAsSchema = propertyResolver.resolve(attr); attributeWrapper.put(attr.getQualifier(), attrAsSchema); } map.put("properties", attributeWrapper.build()); } return map.build(); } }
return Dto.dtoBuilder() .name("Generated Dto for " + definingClass.name()) .namespace(namespace)
typeModel = Dto.dtoBuilder() .namespace(namespace) .name(TypeUtils.getErasureType(singleField.type()))
@Override public DefaultEntry apply(final Dto dto) { if (dto instanceof ArrayDto) { return new DefaultEntry(dto.getSchemaName(), singleArrayResolver.resolve((ArrayDto) dto)); } else { return new DefaultEntry(dto.getSchemaName(), singleDtoResolver.resolve(dto)); } } });
@Override public Map<String, ?> resolve(final Attribute attribute) { final ImmutableMap.Builder<String, Object> attributeMeta = ImmutableMap.builder(); if (attribute.getType() instanceof Enumeration) { final Enumeration enumValues = (Enumeration) attribute.getType(); attributeMeta.put("enum", SchemaJSONUtils.processEnumValues(enumValues)); } else if (attribute.getType() instanceof Dto) { final Dto attributeType = (Dto) attribute.getType(); attributeMeta.put("$ref", attributeType.getSchemaName()); } else { attributeMeta.put("type", SchemaJSONUtils.resolveJSONPrimitiveType(attribute)); } if (attribute.getDocumentation() != null) { attributeMeta.put("description", attribute.getDocumentation()); } return attributeMeta.build(); } }