@Override public Map<String, List<RamlFormParameter>> getFormParameters() { if (formParameters == null) { this.formParameters = ((ObjectTypeDeclaration) mimeType).properties().stream() .collect(Collectors.toMap(this::getName, this::getList)); } return this.formParameters; }
@Override public String discriminator() { return ((ObjectTypeDeclaration) typeDeclaration).discriminator(); }
@Override public String getDiscriminatorValue() { if (this.dataType instanceof ObjectTypeDeclaration) { return ((ObjectTypeDeclaration) this.dataType).discriminatorValue(); } return null; } }
if (objectType.name().endsWith("." + objectType.type())) { name = StringUtils.capitalize(objectType.type()); } else { name = StringUtils.capitalize(objectType.name()); String typeName = objectType.type(); if (RamlTypeHelper.isBaseObject(objectType.name()) && !RamlTypeHelper.isBaseObject(typeName)) { if (!RamlTypeHelper.isBaseObject(objectType.name()) && !RamlTypeHelper.isBaseObject(typeName) && property) { name = typeName; if (types.get(name) == null) { if (!StringUtils.isEmpty(objectType.discriminator())) { for (RamlDataType ramlDataType : document.getTypes().values()) { if (name.equals(ramlDataType.getType().type())) { } else if (objectType.parentTypes() != null && objectType.parentTypes().size() > 0) { TypeDeclaration tempParent = objectType.parentTypes().get(0); // java for (TypeDeclaration objectProperty : objectType.properties()) { builder.withJsonDiscriminator(childTypes, objectType.discriminator());
.addModifiers(Modifier.PUBLIC); Optional<String> discriminator = Optional.fromNullable(objectTypeDeclaration.discriminator()); for (TypeDeclaration propertyDeclaration : objectTypeDeclaration.properties()) { if ( propertyDeclaration.name().equals(discriminator.orNull())) { String discriminatorValue = Optional.fromNullable(objectTypeDeclaration.discriminatorValue()).or(objectTypeDeclaration.name()); field.addModifiers(Modifier.PRIVATE, Modifier.FINAL) .initializer(CodeBlock.builder().add("$S", discriminatorValue).build());
.addMember("value", "$T.$L", JsonInclude.Include.class, "NON_NULL").build()); if (obj.discriminatorValue() != null) { .addMember("value", "$S", obj.discriminatorValue()).build()); for (TypeDeclaration declaration : obj.properties()) {
if (otr.discriminator() != null && objectPluginContext.childClasses(otr.name()).size() > 0) { .addMember("property", "$S", otr.discriminator()).build()); for (CreationResult result : objectPluginContext.childClasses(ramlType.name())) { if (otr.discriminatorValue() != null) { .addMember("value", "$S", otr.discriminatorValue()).build());
Optional<String> discriminator = Optional.fromNullable(objectTypeDeclaration.discriminator()); for (TypeDeclaration typeDeclaration : objectTypeDeclaration.parentTypes()) { for (TypeDeclaration propertyDeclaration : objectTypeDeclaration.properties()) {
if (otr.discriminator() != null && type.childClasses(type.name()).size() > 0) { .addMember("property", "$S", otr.discriminator()).build()); if (otr.discriminatorValue() != null) { .addMember("value", "$S", otr.discriminatorValue()).build());
@Override public TypeSpec.Builder classCreated(ObjectPluginContext objectPluginContext, ObjectTypeDeclaration type, TypeSpec.Builder builder, EventType eventType) { String namespace = type.xml() != null && type.xml().namespace() != null ? type.xml().namespace() : "##default"; String name = type.xml() != null && type.xml().name() != null ? type.xml().name() : type.name(); if (eventType == EventType.IMPLEMENTATION) { builder.addAnnotation(AnnotationSpec.builder(XmlAccessorType.class) .addMember("value", "$T.$L", XmlAccessType.class, "FIELD").build()); AnnotationSpec.Builder annotation = AnnotationSpec.builder(XmlRootElement.class) .addMember("namespace", "$S", namespace) .addMember("name", "$S", name); builder.addAnnotation(annotation.build()); } else { builder.addAnnotation(AnnotationSpec.builder(XmlRootElement.class) .addMember("namespace", "$S", namespace) .addMember("name", "$S", name).build()); } return builder; }
@Override public TypeSpec.Builder classCreated(ObjectPluginContext objectPluginContext, ObjectTypeDeclaration ramlType, final TypeSpec.Builder incoming, EventType eventType) { if (ramlType.description() != null) { incoming.addJavadoc("$L\n", ramlType.description().value()); } javadocExamples(new JavadocAdder() { @Override public void addJavadoc(String format, Object... args) { incoming.addJavadoc(format, args); } }, ramlType); return incoming; }
@Override public TypeSpec.Builder classCreated(ObjectPluginContext objectPluginContext, ObjectTypeDeclaration obj, TypeSpec.Builder typeSpec, EventType eventType) { if (!obj.additionalProperties()) {
@Override public TypeSpec.Builder classCreated(ObjectPluginContext objectPluginContext, ObjectTypeDeclaration obj, TypeSpec.Builder typeSpec, EventType eventType) { if (eventType != EventType.IMPLEMENTATION) { return typeSpec; } typeSpec.addAnnotation(AnnotationSpec.builder(JsonInclude.class) .addMember("value", "$T.$L", JsonInclude.Include.class, "NON_NULL").build()); if (obj.discriminatorValue() != null) { typeSpec.addAnnotation(AnnotationSpec.builder(JsonTypeName.class) .addMember("value", "$S", obj.discriminatorValue()).build()); } AnnotationSpec.Builder builder = AnnotationSpec.builder(JsonPropertyOrder.class); for (TypeDeclaration declaration : obj.properties()) { if (EcmaPattern.isSlashedPattern(declaration.name())) { continue; } builder.addMember("value", "$S", declaration.name()); } typeSpec.addAnnotation(builder.build()); return typeSpec; }
if (otr.discriminator() != null && objectPluginContext.childClasses(otr.name()).size() > 0) { .addMember("property", "$S", otr.discriminator()).build()); for (CreationResult result : objectPluginContext.childClasses(ramlType.name())) { if (otr.discriminatorValue() != null) { .addMember("value", "$S", otr.discriminatorValue()).build());
private static Set<String> pullNames(ObjectTypeDeclaration extending) { return FluentIterable.from(extending.properties()).transform(new Function<TypeDeclaration, String>() { @Nullable @Override public String apply(@Nullable TypeDeclaration input) { return input.name(); } }).toSet(); }
@Override public TypeSpec.Builder classCreated(ObjectPluginContext objectPluginContext, ObjectTypeDeclaration obj, TypeSpec.Builder typeSpec, EventType eventType) { if (eventType != EventType.IMPLEMENTATION) { return typeSpec; } typeSpec.addAnnotation(AnnotationSpec.builder(JsonInclude.class) .addMember("value", "$T.$L", JsonInclude.Include.class, "NON_NULL").build()); if (obj.discriminatorValue() != null) { typeSpec.addAnnotation(AnnotationSpec.builder(JsonTypeName.class) .addMember("value", "$S", obj.discriminatorValue()).build()); } AnnotationSpec.Builder builder = AnnotationSpec.builder(JsonPropertyOrder.class); for (TypeDeclaration declaration : obj.properties()) { if (EcmaPattern.isSlashedPattern(declaration.name())) { continue; } builder.addMember("value", "$S", declaration.name()); } typeSpec.addAnnotation(builder.build()); return typeSpec; }
@Override public String discriminatorValue() { return ((ObjectTypeDeclaration) typeDeclaration).discriminatorValue(); }
private static List<V10GProperty> getProperties(final TypeDeclaration input, final V10TypeRegistry registry) { if (input instanceof ObjectTypeDeclaration) { ObjectTypeDeclaration otd = (ObjectTypeDeclaration) input; return Lists.transform(otd.properties(), new Function<TypeDeclaration, V10GProperty>() { @Nullable @Override public V10GProperty apply(@Nullable TypeDeclaration declaration) { return new V10GProperty(declaration, registry.fetchType(declaration.type(), declaration)); } }); } else { return Collections.emptyList(); } }
private void buildLooksLike(TypeSpec.Builder builder, TypeDeclaration typeDeclaration) { String name = Names.methodName("looksLike", typeDeclaration.name()); MethodSpec.Builder spec = MethodSpec.methodBuilder(name).addParameter(ParameterizedTypeName.get(ClassName.get(Map.class), ClassName.get(String.class), ClassName.get(Object.class)), "map"); if (typeDeclaration instanceof ObjectTypeDeclaration) { ObjectTypeDeclaration otd = (ObjectTypeDeclaration) typeDeclaration; List<String> names = Lists.transform(otd.properties(), new Function<TypeDeclaration, String>() { @Nullable @Override public String apply(@Nullable TypeDeclaration input) { return "\"" + input.name() + "\""; } }); spec.addStatement("return map.keySet().containsAll($T.asList($L))", Arrays.class, Joiner.on(",").join(names)); } spec.addModifiers(Modifier.PRIVATE).returns(TypeName.BOOLEAN); builder.addMethod(spec.build()); }
private void buildLooksLike(TypeSpec.Builder builder, TypeDeclaration typeDeclaration) { String name = Names.methodName("looksLike", typeDeclaration.name()); MethodSpec.Builder spec = MethodSpec.methodBuilder(name).addParameter(ParameterizedTypeName.get(ClassName.get(Map.class), ClassName.get(String.class), ClassName.get(Object.class)), "map"); if (typeDeclaration instanceof ObjectTypeDeclaration) { ObjectTypeDeclaration otd = (ObjectTypeDeclaration) typeDeclaration; List<String> names = Lists.transform(otd.properties(), new Function<TypeDeclaration, String>() { @Nullable @Override public String apply(@Nullable TypeDeclaration input) { return "\"" + input.name() + "\""; } }); spec.addStatement("return map.keySet().containsAll($T.asList($L))", Arrays.class, Joiner.on(",").join(names)); } spec.addModifiers(Modifier.PRIVATE).returns(TypeName.BOOLEAN); builder.addMethod(spec.build()); }