-
Notifications
You must be signed in to change notification settings - Fork 5
Generating Java Code From RADL
Rémon (Ray) Sinnema edited this page Jun 17, 2015
·
2 revisions
The code generation process consists of the following steps:
- Inspect the RADL file
- Determine what code should be there to implement the RADL file
- Compare that with what code currently is there
- Make the necessary changes to arrive at the desired state
Currently, only Spring code can be generated.
The intent is to allow two-way changes: both the RADL file and the code can be changed at any time. To support that, the code is divided into two parts:
- Generated code is under control of the code generation process
This code will be created if it doesn't exist, or completely replaced if it does. Any manual changes will be lost.
Generated code consists of controllers and constants for URIs, media types, etc. - Skeleton code is under control of the developer
This code will be created if it doesn't exists, but left alone when it does. The developer is free to make changes.
Generated code consists of services. The controllers are @Autowired
to the services. Where the controllers define the REST "contract" using Spring's @RequestMapping
annotation, the services actually implement the functionality.
The code generation process is implemented in the radl.java.generation.spring.RadlToSpringServer
class. This class supports the following arguments:
- The RADL file to process
- The base directory for the project. This defaults to the current directory
- The package prefix for the generated code. This defaults to
radl.sample
- The directory for the generated code, relative to the base directory. This defaults to
build/src/java
- The directory for the skeleton code, relative to the base directory. This defaults to
src/main/java
- The source code management (SCM) system to use. This defaults to
default
. The SCM is used to prepare files for update and/or delete, which is necessary when the SCM makes files read-only, like Perforce does. To use the Perforce SCM, supplyp4
. Thedefault
SCM does nothing - The header to use for generated files. This defaults to
Generated by RADL.