RAML 1.0 representation of Java Map
I have RAML schema which contains "javaType": "java.util.Map<String, java.util.List<Employee>>"
I have separate schema (employee.schema) available which represent class Employee.
But as I have not used employee.schema in RAML so it is not generating class Employee and throws an Error while converting RAML to Java.
{
"$schema": "http://json-schema.org/schema#",
"type": "object",
"description": "Desc",
"properties": {
"employeeGroups": {
"type": "object",
"javaType": "java.util.Map<String, java.util.List<Employee>>"
}
},
"additionalProperties": false
}
Can anybody share comments how to represent "javaType": "java.util.Map<String, java.util.List<Employee>>"
in RAML ?
RAML Version: 1.0
You have 2 options here.
The first one is to just include the external file with the schema in the types
definition of your raml
file.
For instance, assuming that:
- The object represented in your example is called
EmployeeGroupsContainer
, - And the file with the
Employee
schema is calledemployee.schema
and is in the same directory as theraml
file.
The types
section would look like this:
types:
EmployeeGroupsContainer:
schema: |
{
"$schema": "http://json-schema.org/schema#",
"type": "object",
"description": "Desc",
"properties": {
"employeeGroups": {
"type": "object",
"javaType": "java.util.Map<String, java.util.List<Employee>>"
}
},
"additionalProperties": false
}
Employee:
schema:
!include employee.schema
This would be the recomended approach and the one I would use.
A second option would be to previously generate the Employee
object, and once you have it you can generate the rest because the Employee
class would now be in your classpath. The best way to do this is by two separate executions of the tool you use to generate the code (the first one with employee.schema
to generate the Employee
class, and the second one with the rest).
May be you are tempted to generate Employee
once and move it to src/main/java
, but I would recommend against this, as keeping generated code versioned (in git or any other VCS) is always a bad practice. Code generation should always be a part of the overall build process (tipically with a maven plugin, if you use maven).
The only scenario I can think of to choose the second approach instead of the first one is that you don't have access to the main raml
file. But if you do have it, I would definitely go for the first approach.