Any identifier in raml to know if schema is embedded or refferenced


#1

Hi,

there are two ways of defining schema as shown below ,how to pragmatically know if schema is embedded or referenced.I am using java raml parser.

responses:
        200:
          body:
            application/json:
              schema: apiContact

responses:
      200:
        body:
          application/json:
            schema: |
              {
                "$schema": "http://json-schema.org/draft-03/schema",
                "javaType": "com.ricston.blog.contactsapp.rest.api.model.ApiContacts",
                "type": "object",
                "description": "A object containing an array of apiContact",
                "properties": {
                  "size": { "type": "integer", "required": true },
                  "contacts": {
                    "type": "array",
                    "items": { "$ref": "apiContact" }
                   }
                 }
              }

#2

I am not really sure if you can as the parser embed the schema right away if I am not wrong, right?


#3

If you can lookup the schema value, attached to the MIME type you’re working with, in the consolidated schemas, then the net result - as far as the processor is concerned - is that it was referenced.

org.raml.model.Raml model;
org.raml.model.MimeType type;

model.getConsolidatedSchemas().containsKey(type.getSchema());

If the intent was to use a reference, yet the value of the reference cannot be found as a key under schemas, then the reference value will be processed as embedded. There is no explicit syntax to distinguish between the two, hence this confusion.

Furthermore, if one tries to understand if the schema is external or not (i.e. via !include), then what @christian_vogel noted is correct. The way we’ve dealt with it, was to hook straight into the yaml stream reading, and collect additional metadata. The fundamental thing here is that the RAML “model” (in the API) is a “compiled” model, rather than an “authoring/source code” model. Certain aspects from an “authoring/source code” model perspective, would be even harder to harvest, due to YAML’s nature (e.g. anchors/references).


#4

@gardea Thank you for this clarification.


#5

@christian_vogel Thank you for this clarification.