API Definition¶
Main functions¶
The following three functions are meant for you to use primarily when parsing a RAML file/string.
-
ramlfications.parse(raml, config_file=None)¶ Module helper function to parse a RAML File. First loads the RAML file with
loader.RAMLLoaderthen parses withparser.parse_raml()to return araml.RAMLRootobject.Parameters: - raml – Either string path to the RAML file, a file object, or a string representation of RAML.
- config_file (str) – String path to desired config file, if any.
Returns: parsed API
Return type: RAMLRoot
Raises: - LoadRAMLError – If error occurred trying to load the RAML file
(see
loader.RAMLLoader) - InvalidRootNodeError – API metadata is invalid according to RAML specification.
- InvalidResourceNodeError –
API resource endpoint is invalid according to RAML specification.
- InvalidParameterError –
Named parameter is invalid according to RAML specification.
-
ramlfications.load(raml_file)¶ Module helper function to load a RAML File using
loader.RAMLLoader.Parameters: raml_file (str) – String path to RAML file Returns: loaded RAML Return type: dict Raises: LoadRAMLError – If error occurred trying to load the RAML file
-
ramlfications.loads(raml_string)¶ Module helper function to load a RAML File using
loader.RAMLLoader.Parameters: raml_string (str) – String of RAML data Returns: loaded RAML Return type: dict Raises: LoadRAMLError – If error occurred trying to load the RAML file
-
ramlfications.validate(raml, config_file=None)¶ Module helper function to validate a RAML File. First loads the RAML file with
loader.RAMLLoaderthen validates withvalidate.validate_raml().Parameters: - raml (str) – Either string path to the RAML file, a file object, or a string representation of RAML.
- config_file (str) – String path to desired config file, if any.
Returns: No return value if successful
Raises: - LoadRAMLError – If error occurred trying to load the RAML file
(see
loader.RAMLLoader) - InvalidRootNodeError –
API metadata is invalid according to RAML specification.
- InvalidResourceNodeError –
API resource endpoint is invalid according to RAML specification.
- InvalidParameterError –
Named parameter is invalid according to RAML specification.
- InvalidRAMLError –
RAML file is invalid according to RAML specification.
Core¶
Note
The following documentation is meant for understanding the underlying
ramlfications API. No need to interact directly with the modules,
classes, & functions below.
parser¶
-
ramlfications.parser.parse_raml(loaded_raml, config)¶ Parse loaded RAML file into RAML/Python objects.
Parameters: loaded_raml (RAMLDict) – OrderedDict of loaded RAML file Returns: raml.RootNodeobject.Raises: errors.InvalidRAMLErrorwhen RAML file is invalid
-
ramlfications.parser.create_root(raml, config)¶ Creates a Root Node based off of the RAML’s root section.
Parameters: raml (RAMLDict) – loaded RAML file Returns: raml.RootNodeobject with API root attributes set
-
ramlfications.parser.create_traits(raml_data, root)¶ Parse traits into
Traitobjects.Parameters: - raml_data (dict) – Raw RAML data
- root (RootNode) – Root Node
Returns: list of
raml.TraitNodeobjects
-
ramlfications.parser.create_resource_types(raml_data, root)¶ Parse resourceTypes into
ResourceTypeNodeobjects.Parameters: - raml_data (dict) – Raw RAML data
- root (RootNode) – Root Node
Returns: list of
raml.ResourceTypeNodeobjects
-
ramlfications.parser.create_resources(node, resources, root, parent)¶ Recursively traverses the RAML file via DFS to find each resource endpoint.
Parameters: - node (dict) – Dictionary of node to traverse
- resources (list) – List of collected
ResourceNodes - root (RootNode) – The
RootNodeof the API - parent (ResourceNode) – Parent
ResourceNodeof currentnode
Returns: List of
raml.ResourceNodeobjects.
-
ramlfications.parser.create_node(name, raw_data, method, parent, root)¶ Create a Resource Node object.
Parameters: - name (str) – Name of resource node
- raw_data (dict) – Raw RAML data associated with resource node
- method (str) – HTTP method associated with resource node
- parent (ResourceNode) – Parent node object of resource node, if any
- api (RootNode) – API
RootNodethat the resource node is attached to
Returns: raml.ResourceNodeobject
raml¶
-
class
ramlfications.raml.RootNode¶ API Root Node
-
raw¶ Ordered
dictof all raw data from the RAML file/string.
-
version¶ strof API version.
-
base_uri¶ strof API’s base URI.
-
base_uri_params¶ listof baseURIParameters for the base URI, orNone. The order ofbase_uri_paramswill follow the order defined in theRootNode.base_uri.
-
uri_params¶ listofURIParameters that can apply to all resources, orNone. The order ofuri_paramswill follow the order defined in theRootNode.base_uri.
-
protocols¶ listofstrs of API-supported protocols. If not defined, is inferred by protocol fromRootNode.base_uri.
-
title¶ strof API’s title.
-
docs¶ listofDocumentationobjects, orNone.
-
schemas¶ listofdicts, orNone.
-
media_type¶ strof default accepted request/response media type, orNone.
-
resource_types¶ listofResourceTypeNodeobjects, orNone.
-
security_schemas¶ listofSecuritySchemeobjects, orNone.
-
resources¶ listofResourceNodeobjects, orNone.
-
raml_obj¶ The
loader.RAMLDictobject.
-
Note
TraitNode, ResourceTypeNode, and
ResourceNode all inherit the following BaseNode
attributes:
-
class
ramlfications.raml.BaseNode¶ -
name¶ strname ofNode
-
raw¶ dictof the raw data of theNodefrom the RAML file/string
-
uri_params¶ listofNode’sURIParameterobjects, orNone. The order ofuri_paramswill follow the order defined in theResourceNode.absolute_uri.
-
base_uri_params¶ listofNode’s baseURIParameterobjects, orNone. The order ofbase_uri_paramswill follow the order defined in theResourceNode.absolute_uri.
-
query_params¶ listofNode’sQueryParameterobjects, orNone
-
form_params¶ listofNode’sFormParameterobjects, orNone.
-
description¶ strdescription ofNode.
-
protocols¶ listofstrs of supported protocols. Defaults toRootNode.protocols.
-
-
class
ramlfications.raml.TraitNode¶ Object representing a RAML Trait.
In addition to the
BaseNode-defined attributes,TraitNodealso has:-
usage¶ Usage of trait
-
-
class
ramlfications.raml.ResourceTypeNode¶ Object representing a RAML Resource Type.
In addition to the
BaseNode-defined attributes,ResourceTypeNodealso has:-
display_name¶ strof user-friendly name of resource type, defaults toBaseNode.name
-
type¶ strname of inheritedResourceTypeNodeobject, orNone.
-
usage¶ strusage of resource type, orNone
-
optional¶ boolresource type attributes inherited if applied resource defines method (i.e. there is a?in resource type method).
-
is_¶ listof assigned trait names (str), orNone
-
secured_by¶ listofstrs ordicts of assigned security scheme, orNone.If
str, then the name of the security scheme.If
dict, the key is the name of the scheme, the values are the parameters assigned (e.g. relevant OAuth 2 scopes).
-
security_schemes¶ listof assignedparameters.SecuritySchemeobjects, orNone.
-
-
class
ramlfications.raml.ResourceNode¶ -
parent¶ parent
ResourceNodeobject if any, orNone.
-
method¶ strHTTP method for resource, orNone.
-
display_name¶ strof user-friendly name of resource. Defaults toname.
-
path¶ strof relative path of resource.
-
absolute_uri¶ strconcatenation of absolute URI of resource:RootNode.base_uri+path.
-
is_¶ listofstrs ordicts of resource-assigned traits, orNone.
-
type¶ strof the name of the assigned resource type, orNone.
-
resource_type¶ The assigned
ResourceTypeNodeobject fromResourceNode.type, orNone
-
secured_by¶ listofstrs ordicts of resource-assigned security schemes, orNone.If a
str, the name of the security scheme.If a
dict, the key is the name of the scheme, the values are the parameters assigned (e.g. relevant OAuth 2 scopes).
-
security_schemes¶
-
Parameters¶
Note
The URIParameter, QueryParameter,
FormParameter, and Header objects all share the
same attributes.
-
class
ramlfications.parameters.URIParameter¶ URI parameter with properties defined by the RAML specification’s “Named Parameters” section, e.g.:
/foo/{id}whereidis the name of the URI parameter.
-
class
ramlfications.parameters.QueryParameter¶ Query parameter with properties defined by the RAML specification’s “Named Parameters” section, e.g.
/foo/bar?baz=123wherebazis the name of the query parameter.
-
class
ramlfications.parameters.FormParameter¶ Form parameter with properties defined by the RAML specification’s “Named Parameters” section. Example:
curl -X POST https://api.com/foo/bar -d baz=123where
bazis the Form Parameter name.
-
class
ramlfications.parameters.Header¶ Header with properties defined by the RAML spec’s ‘Named Parameters’ section, e.g.:
curl -H 'X-Some-Header: foobar' ...where
X-Some-Headeris the Header name.-
name¶ strof the name of parameter.
-
raw¶ dictof all raw data associated with the parameter from the RAML file/string.
-
description¶ strparameter description, orNone.
-
display_name¶ strof a user-friendly name for display or documentation purposes.If
displayNameis not specified in RAML data, defaults toname.
-
min_length¶ intof the parameter’s minimum number of characters, orNone.Note
Only applies when the parameter’s primative
typeisstring.
-
max_length¶ intof the parameter’s maximum number of characters, orNone.Note
Only applies when the parameter’s primative
typeisstring.
-
minimum¶ intof the parameter’s minimum value, orNone.Note
Only applies when the parameter’s primative
typeisintegerornumber.
-
maximum¶ intof the parmeter’s maximum value, orNone.Note
Only applies when the parameter’s primative
typeisintegerornumber.
-
example¶ Example value for parameter, or
None.Note
Attribute type of
examplewill match that oftype.
-
default¶ Default value for parameter, or
None.Note
Attribute type of
defaultwill match that oftype.
-
repeat¶ boolif parameter can be repeated. Defaults toFalse.
-
pattern¶ strof a regular expression that parameter of typestringmust match, orNoneif not set.
-
enum¶ listof valid parameter values, orNone.Note
Only applies when parameter’s primative
typeisstring.
-
type¶ strrepresentation of the primative type of parameter. Defaults tostringif not set.
-
required¶ boolif parameter is required.Note
Defaults to
TrueifURIParameter, else defaults toFalse.
-
-
class
ramlfications.parameters.Body¶ Body of the request/response.
-
mime_type¶ strof the accepted MIME media types for the body of the request/response.
-
raw¶ dictof all raw data associated with theBodyfrom the RAML file/string
-
schema¶ dictof body schema definition, orNoneif not set.Note
Can not be set if
mime_typeismultipart/form-dataorapplication/x-www-form-urlencoded
-
example¶ dictof example of schema, orNoneif not set.Note
Can not be set if
mime_typeismultipart/form-dataorapplication/x-www-form-urlencoded
-
form_params¶ listofFormParameterobjects accepted in the request body.Note
Must be set if
mime_typeismultipart/form-dataorapplication/x-www-form-urlencoded. Can not be used when schema and/or example is defined.
-
-
class
ramlfications.parameters.Response¶ Expected response parameters.
-
code¶ intof HTTP response code.
-
raw¶ dictof all raw data associated with theResponsefrom the RAML file/string
-
description¶ strof the response description, orNone.
-
method¶ strof HTTP request method associated with response.
-
-
class
ramlfications.parameters.Documentation¶ User documentation for the API.
-
title¶ strtitle of documentation
-
content¶ strcontent of documentation
-
-
class
ramlfications.parameters.SecurityScheme¶ Security scheme definition.
-
name¶ strname of security scheme.
-
raw¶ dictof all raw data associated with theSecuritySchemefrom the RAML file/string
-
type¶ strof type of authentication
-
described_by¶ Headers,Responses,QueryParameters, etc. that is needed/can be expected when using security scheme.
-
description¶ strdescription of security scheme.
-
settings¶ dictof security schema-specific information
-
-
class
ramlfications.parameters.Content(data)¶ Returns documentable content from the RAML file (e.g. Documentation content, description) in either raw or parsed form.
Parameters: data (str) – The raw/marked up content data. -
raw¶ Return raw Markdown/plain text written in the RAML file
-
html¶ Returns parsed Markdown into HTML
-
Loader¶
-
class
ramlfications.loader.RAMLLoader¶ Extends YAML loader to load RAML files with
!includetags.-
load(raml)¶ Loads the desired RAML file and returns data.
Parameters: raml – Either a string/unicode path to RAML file, a file object, or string-representation of RAML. Returns: Data from RAML file Return type: dict
-
Validate¶
Functions are used when instantiating the classes from ramlfications.raml.
-
ramlfications.validate.validate_mime_type(value)¶ Assert a valid MIME media type for request/response body.
Tree¶
-
ramlfications.tree.tree(load_obj, color, output, verbosity, validate, config)¶ Create a tree visualization of given RAML file.
Parameters: - load_obj (dict) – Loaded RAML File
- color (str) –
light,darkorNone(default) for the color output - output (str) – Path to output file, if given
- verbosity (str) – Level of verbosity to print out
Returns: ASCII Tree representation of API
Return type: stdout to screen or given file name
Raises: - InvalidRootNodeError –
API metadata is invalid according to RAML specification.
- InvalidResourceNodeError –
API resource endpoint is invalid according to RAML specification.
- InvalidParameterError –
Named parameter is invalid according to RAML specification.