Search code examples
restraml

RAML 1.0 ciclical nested includes


I have this issue, I have created two libraries to define two different types, here they are:

Category.raml

#%RAML 1.0 Library
uses:
  - Event: !include Event.raml
  - Tournament: !include Tournament.raml

types:
#############################################################################
    base:
    usage: The base type for a category
    properties:
      min_age:
        description: The minimum age to participate in the category
        required: true
        type: number
      max_age:
        description: The maximum age to participate in the category
        required: true
        type: number
      name:
        description: The name of the category
        required: true
        type: string
      gender:
        description: The gender of the category
        required: true
        enum:
          - male
          - female
          - mix
      tournament:
        description: The tournament of the category
        required: true
        type: Tournament.base
  #############################################################################
  full:
    usage: A category with all of its events
    type: base
    properties:
      events:
        description: The events that the category contains
        required: true
        type: Event.base[]

Tournament.raml

#%RAML 1.0 Library
uses:
  - ClubInscription:  !include Club.raml
  - Category:         !include Category.raml

types:
  #############################################################################
  base:
    usage: The base type for the tournament
    properties:
      name:
        description: The name of the tournament
        required: true
        type: string
      date:
        description: Date of the tournament
        required: true
        type: string
      available_lanes:
        description: Maximum number of lanes in a serie
        required: true
        type: number
      max_swimmer_inscriptions:
        description: Maximum number of events a swimmer may be inscripted
        required: true
        type: number
      award_type:
        description: The type of awarding used in the competition
        required: true
        enum:
          - points
          - medals
          - none
      state:
        description: The current state of the tournament
        required: true
        enum:
          - closed
          - open
          - finished
  #############################################################################
  full:
    usage: A tournament with all its categories and club inscriptions
    type: base
    properties:
      club_inscriptions:
        description: The clubs inscripted in the tournament
        required: true
        type: ClubInscription.base[]
      categories:
        description: The categories the tournament has
        required: true
        type: Category.base[]

Having this, it makes sense having a conflict. I am pretty knew at RAML, so I read somewhere that "uses" should only be used when using something as a parent, but then what should I do to not re-write everything in everywhere in my project (because this happens everywhere in it).

I have thought of defining the base of the types in one file, but it would be just a mix of information that should not be together, I want to know if there is an alternative to "uses" to re-use the types in another file.

Thanks in advance.


Solution

  • The simplest solution is make:

    • TournamentBase.raml
    • TournamentFull.raml
    • CategoryBase.raml
    • CategoryFull.raml

    You will not have circular dependencies.