Repository: camel Updated Branches: refs/heads/master ba7b652fc -> 06f6e1d64
CAMEL-7999: apt plugin should support @Metadata required for endpoint/component parameters Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/2a5dda60 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2a5dda60 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2a5dda60 Branch: refs/heads/master Commit: 2a5dda60bc0940bace3118d248a170c47ed573b7 Parents: ba7b652 Author: Claus Ibsen <davscl...@apache.org> Authored: Mon Feb 9 10:24:04 2015 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Mon Feb 9 10:24:04 2015 +0100 ---------------------------------------------------------------------- .../camel/component/rest/RestEndpoint.java | 42 +++++++++++++++- .../tools/apt/EndpointAnnotationProcessor.java | 53 ++++++++++++++++---- 2 files changed, 83 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/2a5dda60/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java b/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java index 18811dc..e6c1f9b 100644 --- a/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java +++ b/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java @@ -25,6 +25,7 @@ import org.apache.camel.NoSuchBeanException; import org.apache.camel.Processor; import org.apache.camel.Producer; import org.apache.camel.impl.DefaultEndpoint; +import org.apache.camel.spi.Metadata; import org.apache.camel.spi.RestConfiguration; import org.apache.camel.spi.RestConsumerFactory; import org.apache.camel.spi.UriEndpoint; @@ -36,9 +37,9 @@ import org.apache.camel.util.ObjectHelper; @UriEndpoint(scheme = "rest", label = "core,http,rest") public class RestEndpoint extends DefaultEndpoint { - @UriPath + @UriPath(enums = "get,post,put,delete,patch,head,trace,connect,options") @Metadata(required = "true") private String method; - @UriPath + @UriPath @Metadata(required = "true") private String path; @UriPath private String uriTemplate; @@ -72,6 +73,9 @@ public class RestEndpoint extends DefaultEndpoint { return method; } + /** + * HTTP method to use. + */ public void setMethod(String method) { this.method = method; } @@ -80,6 +84,9 @@ public class RestEndpoint extends DefaultEndpoint { return path; } + /** + * The base path + */ public void setPath(String path) { this.path = path; } @@ -88,6 +95,9 @@ public class RestEndpoint extends DefaultEndpoint { return uriTemplate; } + /** + * The uri template + */ public void setUriTemplate(String uriTemplate) { this.uriTemplate = uriTemplate; } @@ -96,6 +106,10 @@ public class RestEndpoint extends DefaultEndpoint { return consumes; } + /** + * Media type such as: 'text/xml', or 'application/json' this REST service accepts. + * By default we accept all kinds of types. + */ public void setConsumes(String consumes) { this.consumes = consumes; } @@ -104,6 +118,9 @@ public class RestEndpoint extends DefaultEndpoint { return produces; } + /** + * Media type such as: 'text/xml', or 'application/json' this REST service returns. + */ public void setProduces(String produces) { this.produces = produces; } @@ -112,6 +129,12 @@ public class RestEndpoint extends DefaultEndpoint { return componentName; } + /** + * The Camel Rest component to use for the REST transport, such as restlet, spark-rest. + * If no component has been explicit configured, then Camel will lookup if there is a Camel component + * that integrates with the Rest DSL, or if a org.apache.camel.spi.RestConsumerFactory is registered in the registry. + * If either one is found, then that is being used. + */ public void setComponentName(String componentName) { this.componentName = componentName; } @@ -120,6 +143,9 @@ public class RestEndpoint extends DefaultEndpoint { return inType; } + /** + * To declare the incoming POJO binding type as a FQN class name + */ public void setInType(String inType) { this.inType = inType; } @@ -128,6 +154,9 @@ public class RestEndpoint extends DefaultEndpoint { return outType; } + /** + * To declare the outgoing POJO binding type as a FQN class name + */ public void setOutType(String outType) { this.outType = outType; } @@ -136,6 +165,9 @@ public class RestEndpoint extends DefaultEndpoint { return routeId; } + /** + * Name of the route this REST services creates + */ public void setRouteId(String routeId) { this.routeId = routeId; } @@ -144,6 +176,9 @@ public class RestEndpoint extends DefaultEndpoint { return description; } + /** + * Human description to document this REST service + */ public void setDescription(String description) { this.description = description; } @@ -152,6 +187,9 @@ public class RestEndpoint extends DefaultEndpoint { return parameters; } + /** + * Additional parameters to configure the consumer of the REST transport for this REST service + */ public void setParameters(Map<String, Object> parameters) { this.parameters = parameters; } http://git-wip-us.apache.org/repos/asf/camel/blob/2a5dda60/tooling/apt/src/main/java/org/apache/camel/tools/apt/EndpointAnnotationProcessor.java ---------------------------------------------------------------------- diff --git a/tooling/apt/src/main/java/org/apache/camel/tools/apt/EndpointAnnotationProcessor.java b/tooling/apt/src/main/java/org/apache/camel/tools/apt/EndpointAnnotationProcessor.java index d580929..22d7f34 100644 --- a/tooling/apt/src/main/java/org/apache/camel/tools/apt/EndpointAnnotationProcessor.java +++ b/tooling/apt/src/main/java/org/apache/camel/tools/apt/EndpointAnnotationProcessor.java @@ -46,6 +46,7 @@ import static org.apache.camel.tools.apt.JsonSchemaHelper.sanitizeDescription; import static org.apache.camel.tools.apt.Strings.canonicalClassName; import static org.apache.camel.tools.apt.Strings.getOrElse; import static org.apache.camel.tools.apt.Strings.isNullOrEmpty; +import static org.apache.camel.tools.apt.Strings.safeNull; /** * Processes all Camel {@link UriEndpoint}s and generate json schema and html documentation for the endpoint/component. @@ -200,7 +201,8 @@ public class EndpointAnnotationProcessor extends AbstractAnnotationProcessor { // as its json we need to sanitize the docs String doc = entry.getDocumentationWithNotes(); doc = sanitizeDescription(doc, false); - buffer.append(JsonSchemaHelper.toJson(entry.getName(), "property", null, entry.getType(), entry.getDefaultValue(), doc, entry.isDeprecated(), + Boolean required = entry.getRequired() != null ? Boolean.valueOf(entry.getRequired()) : null; + buffer.append(JsonSchemaHelper.toJson(entry.getName(), "property", required, entry.getType(), entry.getDefaultValue(), doc, entry.isDeprecated(), entry.isEnumType(), entry.getEnums(), false, null)); } buffer.append("\n },"); @@ -215,7 +217,10 @@ public class EndpointAnnotationProcessor extends AbstractAnnotationProcessor { buffer.append(","); } buffer.append("\n "); - buffer.append(JsonSchemaHelper.toJson(path.getName(), "path", null, path.getType(), "", path.getDocumentation(), path.isDeprecated(), + String doc = path.getDocumentation(); + doc = sanitizeDescription(doc, false); + Boolean required = path.getRequired() != null ? Boolean.valueOf(path.getRequired()) : null; + buffer.append(JsonSchemaHelper.toJson(path.getName(), "path", required, path.getType(), null, doc, path.isDeprecated(), path.isEnumType(), path.getEnums(), false, null)); } @@ -230,7 +235,8 @@ public class EndpointAnnotationProcessor extends AbstractAnnotationProcessor { // as its json we need to sanitize the docs String doc = entry.getDocumentationWithNotes(); doc = sanitizeDescription(doc, false); - buffer.append(JsonSchemaHelper.toJson(entry.getName(), "parameter", null, entry.getType(), entry.getDefaultValue(), doc, entry.isDeprecated(), + Boolean required = entry.getRequired() != null ? Boolean.valueOf(entry.getRequired()) : null; + buffer.append(JsonSchemaHelper.toJson(entry.getName(), "parameter", required, entry.getType(), entry.getDefaultValue(), doc, entry.isDeprecated(), entry.isEnumType(), entry.getEnums(), false, null)); } buffer.append("\n }"); @@ -258,6 +264,7 @@ public class EndpointAnnotationProcessor extends AbstractAnnotationProcessor { writer.println(" <th>Name</th>"); writer.println(" <th>Kind</th>"); writer.println(" <th>Type</th>"); + writer.println(" <th>Required</th>"); writer.println(" <th>Deprecated</th>"); writer.println(" <th>Default Value</th>"); writer.println(" <th>Enum Values</th>"); @@ -269,6 +276,7 @@ public class EndpointAnnotationProcessor extends AbstractAnnotationProcessor { writer.println(" <td>" + path.getName() + "</td>"); writer.println(" <td>" + "path" + "</td>"); writer.println(" <td>" + path.getType() + "</td>"); + writer.println(" <td>" + safeNull(path.getRequired()) + "</td>"); writer.println(" <td>" + path.isDeprecated() + "</td>"); writer.println(" <td>" + path.getEnumValuesAsHtml() + "</td>"); writer.println(" <td>" + path.getDocumentation() + "</td>"); @@ -280,6 +288,7 @@ public class EndpointAnnotationProcessor extends AbstractAnnotationProcessor { writer.println(" <td>" + option.getName() + "</td>"); writer.println(" <td>" + "parameter" + "</td>"); writer.println(" <td>" + option.getType() + "</td>"); + writer.println(" <td>" + safeNull(option.getRequired()) + "</td>"); writer.println(" <td>" + option.isDeprecated() + "</td>"); writer.println(" <td>" + option.getDefaultValue() + "</td>"); writer.println(" <td>" + option.getEnumValuesAsHtml() + "</td>"); @@ -372,7 +381,6 @@ public class EndpointAnnotationProcessor extends AbstractAnnotationProcessor { String fieldTypeName = fieldType.toString(); TypeElement fieldTypeElement = findTypeElement(roundEnv, fieldTypeName); - // we do not yet have default values / notes / as no annotation support yet // String defaultValueNote = param.defaultValueNote(); String defaultValue = metadata != null ? metadata.defaultValue() : null; @@ -383,6 +391,8 @@ public class EndpointAnnotationProcessor extends AbstractAnnotationProcessor { docComment = ""; } + String required = metadata != null ? metadata.required() : null; + // gather enums Set<String> enums = new LinkedHashSet<String>(); boolean isEnum = fieldTypeElement != null && fieldTypeElement.getKind() == ElementKind.ENUM; @@ -398,7 +408,7 @@ public class EndpointAnnotationProcessor extends AbstractAnnotationProcessor { } } - ComponentOption option = new ComponentOption(name, fieldTypeName, defaultValue, defaultValueNote, + ComponentOption option = new ComponentOption(name, fieldTypeName, required, defaultValue, defaultValueNote, docComment.trim(), deprecated, isEnum, enums); componentOptions.add(option); } @@ -425,6 +435,7 @@ public class EndpointAnnotationProcessor extends AbstractAnnotationProcessor { List<VariableElement> fieldElements = ElementFilter.fieldsIn(classElement.getEnclosedElements()); for (VariableElement fieldElement : fieldElements) { + Metadata metadata = fieldElement.getAnnotation(Metadata.class); boolean deprecated = fieldElement.getAnnotation(Deprecated.class) != null; UriPath path = fieldElement.getAnnotation(UriPath.class); @@ -444,6 +455,8 @@ public class EndpointAnnotationProcessor extends AbstractAnnotationProcessor { docComment = path.description(); } + String required = metadata != null ? metadata.required() : null; + // gather enums Set<String> enums = new LinkedHashSet<String>(); @@ -469,7 +482,7 @@ public class EndpointAnnotationProcessor extends AbstractAnnotationProcessor { } } - EndpointPath ep = new EndpointPath(name, fieldTypeName, docComment, deprecated, isEnum, enums); + EndpointPath ep = new EndpointPath(name, fieldTypeName, required, docComment, deprecated, isEnum, enums); endpointPaths.add(ep); } @@ -506,6 +519,8 @@ public class EndpointAnnotationProcessor extends AbstractAnnotationProcessor { docComment = param.description(); } + String required = metadata != null ? metadata.required() : null; + // gather enums Set<String> enums = new LinkedHashSet<String>(); @@ -531,7 +546,7 @@ public class EndpointAnnotationProcessor extends AbstractAnnotationProcessor { } } - EndpointOption option = new EndpointOption(name, fieldTypeName, defaultValue, defaultValueNote, + EndpointOption option = new EndpointOption(name, fieldTypeName, required, defaultValue, defaultValueNote, docComment.trim(), deprecated, isEnum, enums); endpointOptions.add(option); } @@ -638,6 +653,7 @@ public class EndpointAnnotationProcessor extends AbstractAnnotationProcessor { private String name; private String type; + private String required; private String defaultValue; private String defaultValueNote; private String documentation; @@ -645,10 +661,11 @@ public class EndpointAnnotationProcessor extends AbstractAnnotationProcessor { private boolean enumType; private Set<String> enums; - private ComponentOption(String name, String type, String defaultValue, String defaultValueNote, + private ComponentOption(String name, String type, String required, String defaultValue, String defaultValueNote, String documentation, boolean deprecated, boolean enumType, Set<String> enums) { this.name = name; this.type = type; + this.required = required; this.defaultValue = defaultValue; this.defaultValueNote = defaultValueNote; this.documentation = documentation; @@ -665,6 +682,10 @@ public class EndpointAnnotationProcessor extends AbstractAnnotationProcessor { return type; } + public String getRequired() { + return required; + } + public String getDefaultValue() { return defaultValue; } @@ -734,6 +755,7 @@ public class EndpointAnnotationProcessor extends AbstractAnnotationProcessor { private String name; private String type; + private String required; private String defaultValue; private String defaultValueNote; private String documentation; @@ -741,10 +763,11 @@ public class EndpointAnnotationProcessor extends AbstractAnnotationProcessor { private boolean enumType; private Set<String> enums; - private EndpointOption(String name, String type, String defaultValue, String defaultValueNote, + private EndpointOption(String name, String type, String required, String defaultValue, String defaultValueNote, String documentation, boolean deprecated, boolean enumType, Set<String> enums) { this.name = name; this.type = type; + this.required = required; this.defaultValue = defaultValue; this.defaultValueNote = defaultValueNote; this.documentation = documentation; @@ -761,6 +784,10 @@ public class EndpointAnnotationProcessor extends AbstractAnnotationProcessor { return type; } + public String getRequired() { + return required; + } + public String getDefaultValue() { return defaultValue; } @@ -830,15 +857,17 @@ public class EndpointAnnotationProcessor extends AbstractAnnotationProcessor { private String name; private String type; + private String required; private String documentation; private boolean deprecated; private boolean enumType; private Set<String> enums; - private EndpointPath(String name, String type, String documentation, boolean deprecated, + private EndpointPath(String name, String type, String required, String documentation, boolean deprecated, boolean enumType, Set<String> enums) { this.name = name; this.type = type; + this.required = required; this.documentation = documentation; this.deprecated = deprecated; this.enumType = enumType; @@ -853,6 +882,10 @@ public class EndpointAnnotationProcessor extends AbstractAnnotationProcessor { return type; } + public String getRequired() { + return required; + } + public String getDocumentation() { return documentation; }