Skip to content

Instantly share code, notes, and snippets.

@jensklose
Last active May 29, 2017 18:49
Show Gist options
  • Save jensklose/784c7a6e8c1e987a3b273c9be65ce20f to your computer and use it in GitHub Desktop.
Save jensklose/784c7a6e8c1e987a3b273c9be65ce20f to your computer and use it in GitHub Desktop.
RAML 1.0 HAL type
#%RAML 1.0 Library
types:
# https://tools.ietf.org/html/draft-kelly-json-hal
LinkObject:
displayName: HAL Link Object
type: object
description: An object with link information
properties:
href: string
name?: string
type?: string
profile?: string
title?: string
hreflang?: string
deprecation?: string
templated?:
type: boolean
default: false
LinkArray:
displayName: HAL Link Array
type: LinkObject[]
description: An array of Links of the same link relation
Links:
displayName: HAL Links
properties:
self?: LinkObject
//: LinkArray | LinkObject
Resource:
properties:
_links?: Links
_embedded?:
properties:
//: Resource | ResourceArray
ResourceArray:
type: Resource[]
@jensklose
Copy link
Author

Installation

First copy the Gist in your types directory. Next, include the library in your own definitions.

Example usage

api.raml

#%RAML 1.0
title: My HAL based API
version: 1
baseUri: https://{API_HOST}/api
mediaType: application/json
uses:
  Hal: types/hal.raml

/:
  displayName: Entry
  get:
    description: Initial request endpoint
    responses:
      200:
        body:
          type: Hal.Resource

types/myapi.raml

#%RAML 1.0 Library
uses:
  Hal: hal.raml

types:
  root:
    type: Hal.Resource
    properties:
      _links: Hal.Links

  device:
    type: Hal.Resource
    properties:
      mac: string
      customerId: string

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment