Assistance with array types not generating model objects


#1

I’m using https://github.com/mulesoft-labs/raml-for-jax-rs/blob/master/raml-to-jaxrs/raml-to-jaxrs-gradle-plugin/README.md to generate JAXB objects for my RAML API and while Atomic objects are generated nicely, I am running into issues with array collections. My array types are not generating JAXB models, instead they are referenced as List in the Atomic JAXB models that are created.

Below is the User.raml that creats User.java/UserImpl.java

#%RAML 1.0 DataType
displayName: User
description: User Details
type: object
properties: 
  emails:
    description: User Email List
    type: !include Emails.raml 
example: !include ../examples/User.raml

examples/User.raml

#%RAML 1.0 NamedExample
  
  createdDate: 2002-10-02T10:00:00-05:00
  sourceIdentifierValue: User
  emails:
    -
      emailType: Primary Email
      email: user.name@foobar.org
    -
      emailType: Secondary Email
      email: user.name@foobar.org

Emails.raml:

#%RAML 1.0 DataType
displayName: Emails
description: User Email List
type: array
items: 
  type: object
  properties:
    emailType:
      type: string
      description : User Email Type
    email:
      type: string
      description: User Email

My generated UserImpl.java contains the following:

  @XmlElement(
      name = "emails",
      namespace = "##default"
  )
  private List<Object> emails;

Thoughts on what is needed to generate an Email JAXB object and instead use that in UserImpl.java? Thanks in advance.


#2

What does your .gradle file look like? Is generateTypesWith = ['jaxb'] set?


#3

Basically. I had to write my own DSL/Plugin that invokes CodeGenerator because the ramltojaxrs bytecode wasn’t in any repository that I could find. Below is my plugin

def task = proj.task(taskName, type: CodeGeneratorTask, description: taskDesc, group: taskGroup)
task.sourceDirectory = proj.file(schemaDirectory)
task.generateTypesWith = 'jaxb'
task.supportPackageName = schema.javaPackageName + '.support'
task.resourcePackageName = schema.javaPackageName + '.resource'
task.modelPackageName = schema.javaPackageName + '.model'

#4

Have you tried defining email as an object type containing name and address, and emails as an email[] something like:

#%RAML 1.0 Library
usage: contains email types
types: 
  email:
    description: single email
    properties: 
      name: string
      address: string
  
  emails:
    type: email[]