-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow types to be defined by bare type expressions
- Loading branch information
Showing
3 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#%RAML 1.0 | ||
|
||
types: | ||
Org: | ||
type: object | ||
properties: | ||
name: string | ||
phone_number: | ||
type: string | ||
pattern: "\\d(-?\\d)+" | ||
|
||
Organization: Org | ||
|
||
# TODO: Arrays using [] notations not yet implemented. | ||
# Organizations: Organization[] | ||
|
||
Snake: | ||
type: object | ||
properties: | ||
length: | ||
type: integer | ||
description: Length in centimeters. | ||
|
||
Python: | ||
type: Snake | ||
properties: | ||
kind: | ||
type: string | ||
enum: | ||
- Aspidites | ||
- Ball | ||
- Burmese | ||
- Carpet | ||
- Green tree | ||
- Liasis | ||
- Morelia | ||
- Reticulated | ||
- Spotted | ||
|
||
Boa: | ||
type: Snake | ||
properties: | ||
kind: | ||
type: string | ||
enum: | ||
- Argentine | ||
- Common northern | ||
- Ecuadorian | ||
- Red-tailed | ||
- Tumbes Peru | ||
|
||
# TODO: Union types not yet implemented. | ||
# FunPet: Python | Boa |
62 changes: 62 additions & 0 deletions
62
tests/integration/data_types/test_data_type_expressions.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import absolute_import, division, print_function | ||
""" | ||
Tests for handling of data type expressions in RAML 1.0. | ||
""" | ||
|
||
import os | ||
import pytest | ||
|
||
from ramlfications.parser import parse_raml | ||
from ramlfications.config import setup_config | ||
from ramlfications.utils import load_file | ||
|
||
from tests.base import RAML_10 | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def api(): | ||
ramlfile = os.path.join(RAML_10, "data_types/data_type_expressions.raml") | ||
loaded_raml = load_file(ramlfile) | ||
conffile = os.path.join(RAML_10, "test-config.ini") | ||
config = setup_config(conffile) | ||
return parse_raml(loaded_raml, config) | ||
|
||
|
||
def get_named_type(api, name): | ||
t, = api.types.filter_by(name=name) | ||
return t | ||
|
||
|
||
def test_definition_by_expression(api): | ||
typeobj = get_named_type(api, "Organization") | ||
assert typeobj.example is None | ||
assert typeobj.examples is None | ||
assert typeobj.name == "Organization" | ||
assert typeobj.type == "Org" | ||
assert typeobj.description.raw == "" | ||
assert typeobj.display_name == "Organization" | ||
|
||
|
||
def test_array_definition_by_expression(api): | ||
pytest.skip("Union types not yet implemented.") | ||
typeobj = get_named_type(api, "Organizations") | ||
assert typeobj.example is None | ||
assert typeobj.examples is None | ||
assert typeobj.name == "Organizations" | ||
assert typeobj.description.raw == "" | ||
assert typeobj.display_name == "Organizations" | ||
# TODO: Figure out what this should look like. | ||
# assert typeobj.type == "Organization[]" | ||
|
||
|
||
def test_definition_by_union_expression(api): | ||
pytest.skip("Union types not yet implemented.") | ||
typeobj = get_named_type(api, "FunPet") | ||
assert typeobj.example is None | ||
assert typeobj.examples is None | ||
assert typeobj.name == "FunPet" | ||
assert typeobj.type == "Python | Boa" | ||
assert typeobj.description.raw == "" | ||
assert typeobj.display_name == "FunPet" |