Clone Tools
  • last updated 27 mins ago
Constraints
Constraints: committers
 
Constraints: files
Constraints: dates
CAMEL-11006 Auto generate REST DSL for Camel fr...

...om Swagger2.0/OAI specification

Refactored `directRouteGenerator` to `destinationGenerator` in remaining

places. Refactored `Function<Operation, String>` to

`DestinationGenerator` makes for nicer interface.

CAMEL-11006 Auto generate REST DSL for Camel fr...

...om Swagger2.0/OAI specification

Refactored `directRouteGenerator` to `destinationGenerator` and made

`RestDslDefinitionGenerator` public -- otherwise it could not be used.

  1. … 1 more file in changeset.
CAMEL-11006 Auto generate REST DSL for Camel fr...

...om Swagger2.0/OAI specification

This is initial work on REST DSL code|object generation from Swagger

specification.

Entry point to the implementation is RestDslGenerator::to...(...)

methods. Several options are provided for generating source files:

- for code generation in Maven plugin ones accepting Path or Appendable

should be suitable

- for generation in Annotation Processing ones accepting Filer are more

appropriate

- and for generation of the object graph in runtime the one accepting

CamelContext is provided

Both the source code and object graph implementation depend on a

CodeEmitter implementation: one relying on reflection

(RestDefinitionEmitter) is used to generate the object graph, and the

one generating the source code for the RouteBuilder::configure method

body using the javapoet library (MethodBodySourceCodeEmitter).

CodeEmitter is driven by two visitor pattern implementations one

for processing path elements of the specification (RestDslPathGenerator)

and one for processing operation elements of he specification

(RestDslOperationGenerator). Both can be further adapted to support more

of the Swagger specification. I believe they map the currently used /

relevant parts of the Swagger specification covered by REST DSL.

Example of usage:

RestDslGenerator.toPath(swagger)

.withClassName("MyRestRoute")

.withPackageName("com.example")

.withIndent("\t")

.generate(Paths.get("src", "generated"));

    • -0
    • +25
    ./java/org/apache/camel/generator/swagger/CodeEmitter.java
    • -0
    • +40
    ./java/org/apache/camel/generator/swagger/FilerGenerator.java
    • -0
    • +122
    ./java/org/apache/camel/generator/swagger/OperationVisitor.java
    • -0
    • +39
    ./java/org/apache/camel/generator/swagger/PathGenerator.java
    • -0
    • +43
    ./java/org/apache/camel/generator/swagger/PathVisitor.java
    • -0
    • +86
    ./java/org/apache/camel/generator/swagger/RestDslGenerator.java
  1. … 9 more files in changeset.