Skip to main content

Import a RAML API

The RAML importer (raml) reads a RAML 1.0 REST API definition into the Catalog. Its types become types, and its resources and methods become operations. You can then search, version, diff and convert it like any other catalog item.

When to use it​

Use the RAML importer for an existing RAML 1.0 API, often one built for MuleSoft Anypoint. RAML has not been actively developed since 2016, so bring it in to catalog, lint and diff what you have, then move it to OpenAPI for new work. Import one self-contained file, or a set whose !includes and uses libraries are resolved for you.

At a glance​

StepWhereDetails
Import a .raml file or a file setImport to catalog → RAML, or apiome import ramlImport it
See what is resolved: includes, libraries, resource types and traitsThe catalog itemWhat the import resolves
Fix a refused setThe error code the import returnsWhen the import refuses a set
Lint against the RAML specification and hygiene rulesThe raml lint pack, on every importLint and validation
Compare two versions with the RAML breaking-change rulesTick two versions on the catalog item's Versions tabBreaking changes between versions
Migrate to an OpenAPI 3.1 projectConvert to OpenAPI Project on the catalog item, or apiome convert --to openapiMove to OpenAPI
Export back to RAMLExport on the catalog itemRAML from any source

RAML APIs are often split across files. The root document pulls in data types and examples with !include, and shared types with uses libraries:

#%RAML 1.0
title: Pet Store
uses:
common: libs/common.raml
types:
Pet: !include types/pet.raml
/pets/{petId}:
get:
responses:
404:
body:
type: common.Error

Apiome resolves those references with AMF, the AML Modeling Framework maintained for RAML, which ships with the server.

Import it​

Import the RAML like any other catalog format: in the import wizard (Import to catalog → RAML), over the REST API (see Import a specification), or from the CLI:

apiome import raml ./petstore.raml
apiome import raml ./bookstore-api/
  • One self-contained file. Upload, paste or link the .raml file.
  • A file set. Upload a .zip, .tar.gz or .tar that holds the root document and every file it includes or uses, in the same folders the !include and uses paths name. From the CLI, give the folder: it is packed into one archive with those folders.

The CLI's test fixtures, in apiome-cli/tests/fixtures/, include one of each: petstore-raml10.raml (types, a resource type and a trait in one file) and bookstore-raml-set/ (an !included type and a uses library in sibling folders).

What the import resolves​

  • Included types. A type pulled in with !include imports as that type (Pet above).
  • Library types. Each type of a uses library imports under its alias: common.Error. A field or body that names it links to it.
  • Inherited properties. A type that extends another (type: Auditable) imports with the properties it inherits.
  • Arrays. A field typed Pet[] or string[] keeps its item type.
  • Resource types and traits. A resource's type: and the is: traits on a resource or method are applied before the API is cataloged, with their <<parameters>> filled in. Each operation carries the headers, query parameters, bodies and responses they add, as if the method had declared them itself. A value the method declares wins over one it inherits.
  • Headers and every response. Request headers import as header parameters. A response with no body, such as 204, still imports under its status code.

For example, with a secured trait and a collection resource type:

traits:
secured:
headers:
Authorization: string
responses:
401:
body:
type: Error
resourceTypes:
collection:
get:
description: List <<resourcePathName>>.
responses:
200:
body:
type: <<item>>[]
/books:
type: { collection: { item: Book } }
is: [secured]

GET /books imports as List books., with an Authorization header and both a 200 response (Book[]) and a 401 response (Error).

The catalog item also records where the shape came from:

FieldWhereWhat it holds
raml_resource_typeOperation extrasThe resource type applied to the operation's resource, such as collection
raml_traitsOperation extrasThe traits applied to the operation, the method's own first, such as ["secured", "paging.pageable"]
raml_traitsAPI extrasEvery trait the API declares, library ones as alias.name
raml_resource_typesAPI extrasEvery resource type the API declares, library ones as alias.name

Resource types and traits from a uses library are applied too; they need AMF, like every set that uses a library.

The catalog item records which files it was built from (raml_source_files) and a hash of the resolved model (raml_amf_model_sha256). The hash comes from the resolved model, not the raw bytes, and does not depend on where the server unpacked the files, so importing the same files again gives the same hash.

When the import refuses a set​

CodeWhyWhat to do
INPUT_REFERENCE_UNRESOLVEDAn !include or uses names a file that is not in the upload, or a type name that is not defined.Add the missing file to the archive, or fix the type name.
INPUT_REFERENCE_UNRESOLVEDA reference is an absolute path, a URL, or a ../ path that leaves the uploaded files. Such files are never read.Copy the file into the archive and reference it with a relative path.
INPUT_SEMANTIC_INVALIDA set that includes or uses other files does not pass AMF's validation, for example a missing title. The message lists each problem with its file and line. A self-contained document imports instead, with each problem as a lint finding (see Lint and validation).Fix the reported lines.
ADAPTER_UNAVAILABLEThe document includes or uses other files, and this server has no AMF.Ask your administrator to deploy the standard image, which ships AMF.

On a server without AMF, a self-contained RAML document (no !include, no uses) still imports with the built-in reader, which applies the document's own resource types and traits the same way.

Lint and validation​

RAML items are linted by the raml pack, on top of the checks every catalog item gets.

AMF validation. On a server with AMF, every import is also run through AMF's validation of the RAML profile, the rules the RAML specification sets: an example that does not match its type, a default of the wrong type, a facet that does not fit. Each result is a lint finding at raml:<file>:<line>:<column>, its message starting with AMF's constraint name:

raml.shacl-violation raml:api.raml:21:1 example-validation-error: /id expected type: Integer, found: String
RuleSeverity
raml.shacl-violationerror
raml.shacl-warningwarning
raml.shacl-infoinfo

AMF builds no model for a document that does not pass, so:

  • a self-contained document with violations is read by the built-in reader instead, and imports with each violation as an error finding;
  • a set that includes or uses other files still cannot be imported until it passes (INPUT_SEMANTIC_INVALID, below), because only AMF can resolve it.

Hygiene. These checks run with or without AMF. AMF's RAML profile does not report them:

RuleSeverityWhat it catches
raml.undeclared-security-schemewarningA securedBy (API, resource or method) naming a scheme securitySchemes does not declare.
raml.unused-base-uri-parameterwarningA baseUriParameters entry that baseUri never uses.
raml.unused-uri-parameterwarningA resource's uriParameters entry that its path never uses.
raml.method-without-responseswarningA method that declares no response.

The hygiene checks read the root document as written: a scheme or parameter declared in an !included file, or a library scheme such as lib.oauth, is not checked.

Every problem is listed on the catalog item (raml_lint_issues, up to 50, with raml_lint_issue_count), each with its rule, path and message.

Breaking changes between versions​

RAML has no official compatibility rules, so Apiome grades the changes between two versions of a RAML catalog item with its own. Resource types and traits are already applied, so a trait that adds a parameter is graded as that parameter.

ChangeSeverityRule
A required parameter added to a methodBreakingraml.parameter-added-required
An optional parameter addedSaferaml.parameter-added-optional
A parameter removedDangerousraml.parameter-removed
A parameter made required / optionalBreaking / Saferaml.parameter-made-required / raml.parameter-made-optional
A parameter's type changedBreakingraml.parameter-type-changed
A required property added to a typeBreakingraml.property-added-required
An optional property (name?) addedSaferaml.property-added-optional
A property's type changedBreakingraml.property-type-changed
A property made required / optionalBreaking / Dangerousraml.property-made-required / raml.property-made-optional
An enum value removed / addedBreaking / Dangerousraml.enum-value-removed / raml.enum-value-added
Only an enum's order changedSaferaml.enum-reordered
Only the applied resource type or traits changedSaferaml.reuse-changed

A removed resource, method, response or type is breaking; a new one is safe.

Move to OpenAPI​

RAML is no longer actively developed. Once the API is in the catalog, convert it to an OpenAPI 3.1 project. Converting the item is the migration; there is no separate migrator.

  1. On the Catalog, open the RAML item and click “Convert to OpenAPI Project”.
  2. Review the preview: the RAML conversion pack converts each resource and method directly, at an expected tier of high.
  3. Confirm to create the OpenAPI project.

From the CLI, preview first, then convert:

apiome convert <item-id> --to openapi --dry-run --out openapi.json
apiome convert <item-id> --to openapi

The dry-run names the pack that produced the document and what RAML is known to lose:

Conversion pack: RAML (native projection).
- Known loss: Resource types and traits are applied, not preserved as reusable definitions.

Because resource types and traits are already applied when the RAML is imported, every operation in the OpenAPI document lists its own headers, parameters and responses, each under its status code. AMF resolves the RAML on import; the conversion itself is Apiome's own (see Per-format conversion packs). You can also export the item as OpenAPI without creating a project (see Export a specification).