How to describe tested type ( schema )


#1

I’m stuck on describing structure in RAML type ( schema ) and can’t figure out by my own how to resolve it.
There’is my RAML:

#%RAML 1.0
title: Encoder API
version: v2
baseUri: https://app.zencoder.com/api/{version}
mediaType: application/vnd.api+json
/jobs: # its fully-resolved URI is https://app.zencoder.com/api/{version}/jobs
  displayName: Jobs
  description: A collection of jobs
  get:
    responses:
      200:
        body:
          application/json:
            type: object
            properties:
              data.id: # wrong :/
                description: Unique ID
                type: number
            example: |
              {
                "data" : [{
                  "id" : 204,
                  "calling_code" : [ 211 ],
                  "country" : "South Sudan",
                  "type": "countries"
                }]
              }

As you can see in example JSON is nested and i can’t figure out how to describe it in schema ( type since RAML 1.0 ).
Following format: data.id seems doesn’t work.


#2

What about

application/json:
  type: object
  properties:
    data:
      type: array
      items:
        type: object
        properties:
          id:
            description: Unique ID
            type: number

#3

Awesome, thanks @christian_vogel! Saved my day. :slightly_smiling:


#4

Perfect! Always good to hear to save someones day :smiley:


#5

RAML 1.0 supporting data-type reminds me of YAML & Swagger, describing the data elements with data types :slight_smile:
http://swagger.io/specification/
http://docs.ansible.com/ansible/YAMLSyntax.html

Great to use these as an alternate of JSON examples :slight_smile:


#6

Taking the opportunity to bump this thread with a related question… :slight_smile:

I am trying to create examples using the RAML schema instead of JSON, but my type has a nested structure. How do I provide an instance of a nested structure within an example facet? Much like @christian_vogel points out, but not an inline declaration of a type but instead an instantiation. Using JSON, this is not a problem off course, but I cannot find any examples of this using RAML schema.


#7

Can you post your RAML type? I will try to help you :slight_smile:


#8

Actually, I just found the answer myself:
http://sap1ens.com/blog/2016/12/26/intro-to-raml-1-dot-0/

Under “RAML vs Swagger” a nested example is shown. Problem solved!


#9

That was easy :stuck_out_tongue: Love that!