Java RAML Parser doesn't seem to parse complete ResourceType objects


#1

Hi,
I’m trying to parse the following RAML with the Java parser.

#%RAML 0.8
title: ExampleAPI
version: v0.1
mediaType: application/json
resourceTypes:
  - base:
      get?: &common
        responses:
          200?:
            description: OK
          201?:
            description: CREATED
          204?:
            description: NO CONTENT
          400:
            description: |
              The request was invalid or cannot be otherwise served. An accompanying 
              error message will explain further.
          401:
            description: Authentication credentials were missing or incorrect.
          403:
            description: |
              The request is understood, but it has been refused or access is not 
              allowed.
          404:
            description: |
              The URI requested is invalid or the resource requested, such as a user, 
              does not exist. Also returned when the requested format is not supported 
              by the requested method.
          500:
            description: |
              Something went wrong on the server.
          503:
            description: |
              CMI is up, but overloaded with requests. Try again later.
      put?: *common
      post?: *common
      delete?: *common
  - collection:
      type: base
      get:
        is: [ paged ]
        responses:
          200:
            body:
              schema: <<get_schema>>
      post:
        body:
            schema: <<post_schema>>
        responses:
          201:
            headers:
              location:
                description: This will be the URL to the newly created member.
            body:
              schema: <<get_schema>>
  - member:
      type: base
      get:
        responses:
          200:
            body:
              schema: <<get_schema>>
              example: <<get_example>>
      put:
        body:
          schema: <<put_schema>>
          example: <<put_example>>
        responses:
          200:
            body:
              schema: <<get_schema>>
      delete:
        responses:
          204:
            description: Member deleted.
traits:
  - paged:
      displayName: paged
      queryParameters:
        start:
          displayName: start
          description: The first page to return
          type: number
        pages:
          displayName: pages
          description: Number of pages to return
          type: number

I am able to parse the file like so:

Raml baseRaml = new RamlDocumentBuilder().build(RamlGenerator.class.getResourceAsStream("/" + config.getBaseRaml()), config.getBaseRaml());

However, when I call the method to get the resourceTypes:

baseRaml.getResourceTypes()

Only the top level types are returned:

resourceTypes: 
    - 
        "base": 
            displayName: "base"
    - 
        "collection": 
            displayName: "collection"
    - 
        "member": 
            displayName: "member"

Is this something I am missing?

Thanks so much,
Jeff


#2

Hi Jeff,

your observation is right, the java parser applies resource types and traits to resources and actions but does not keep their model as separate entities.

Regards,
Santiago


#3

Thanks Santiago! I had an aha moment yesterday and realized I was approaching my problem the wrong way. Appreciate the reply.

Jeff


#4

I’m having the same problem; my trait definitions are lost during the parse. @jeff_lowrey is there a workaround?