Skip to content
This repository was archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #456 from mulesoft/qa
Browse files Browse the repository at this point in the history
Qa
agustinlg authored Nov 8, 2016
2 parents ec4d346 + de9bddc commit 6d72a14
Showing 13 changed files with 250 additions and 311 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -14,6 +14,10 @@
* [Notes API](http://static-anypoint-mulesoft-com.s3.amazonaws.com/API_examples_notebooks/raml-design3.html)
* [Congo API for Drone Delivery](http://static-anypoint-mulesoft-com.s3.amazonaws.com/API_examples_notebooks/raml-design2.html)

## API Designer online

There is an online preview version of the API Designer, open the last stable version [here](http://mulesoft.github.io/api-designer/dists/master/latest/) or check out a [different branch](http://mulesoft.github.io/api-designer/).

## Running Locally

```
7 changes: 5 additions & 2 deletions app/scripts/controllers/mocking-service-controller.js
Original file line number Diff line number Diff line change
@@ -80,18 +80,21 @@
function getMock() {
loading(mockingService.getMock($scope.fileBrowser.selectedFile)
.then(setMock)
.then(function() {
if ($scope.mock) { addBaseUri(); }
})
);
}

function createMock() {
loading(mockingService.createMock($scope.fileBrowser.selectedFile, $scope.fileBrowser.selectedFile.ramlExpanded)
loading(mockingService.createMock($scope.fileBrowser.selectedFile, $scope.fileBrowser.selectedFile.raml)
.then(setMock)
.then(addBaseUri)
);
}

function updateMock() {
mockingService.updateMock($scope.fileBrowser.selectedFile, $scope.fileBrowser.selectedFile.ramlExpanded)
mockingService.updateMock($scope.fileBrowser.selectedFile, $scope.fileBrowser.selectedFile.raml)
.then(setMock)
;
}
20 changes: 7 additions & 13 deletions app/scripts/controllers/raml-editor-main.js
Original file line number Diff line number Diff line change
@@ -158,21 +158,16 @@
$scope.loadRaml(file.contents, file.path).then(
// success
safeApplyWrapper($scope, function success(api) {
// hack: we have to make a full copy of an object because console modifies
// it later and makes it unusable for mocking service
var raml = ramlParserAdapter.expandApiToJSON(api);
var ramlExpanded = ramlParserAdapter.expandApiToJSON(api, true);

ramlExpander.expandRaml(ramlExpanded);
ramlExpander.expandRaml(raml);

$scope.fileBrowser.selectedFile.raml = raml;
$scope.fileBrowser.selectedFile.ramlExpanded = ramlExpanded;

$rootScope.$broadcast('event:raml-parsed', raml, ramlExpanded);
$rootScope.$broadcast('event:raml-parsed', raml);

// a success, but with warnings
if (api.errors().length > 0) {
$rootScope.$broadcast('event:raml-parser-error', {parserErrors: api.errors()});
// a success, but with warnings (takes to long... skip for now until improvements on parser)
var errors = api.errors();
if (errors.length > 0) {
$rootScope.$broadcast('event:raml-parser-error', {parserErrors: errors});
}
}),

@@ -183,9 +178,8 @@
);
});

$scope.$on('event:raml-parsed', safeApplyWrapper($scope, function onRamlParser(event, raml, ramlExpanded) {
$scope.$on('event:raml-parsed', safeApplyWrapper($scope, function onRamlParser(event, raml) {
$scope.raml = raml;
$scope.ramlExpanded = ramlExpanded;
$scope.title = raml && raml.title;
$scope.version = raml && raml.version;
$scope.currentError = undefined;
19 changes: 19 additions & 0 deletions app/scripts/services/mocking-service-client.js
Original file line number Diff line number Diff line change
@@ -20,7 +20,26 @@
return url;
};

function cleanBaseUri(mock) {
var baseUri = mock.baseUri;
var mocksQuantity = baseUri.match(/mocks/g).length;

if (mocksQuantity > 1) {
var mocks = 'mocks/';

for (var i = mocksQuantity; i > 1; i--) {
var from = baseUri.indexOf(mocks);
var to = baseUri.indexOf('/', from + mocks.length);
baseUri = baseUri.substring(0, from) + baseUri.substring(to + 1, baseUri.length);
}

}
mock.baseUri = baseUri;
}

self.simplifyMock = function simplifyMock(mock) {
if (mock.baseUri) { cleanBaseUri(mock); }

return {
id: mock.id,
baseUri: mock.baseUri,
15 changes: 3 additions & 12 deletions app/scripts/services/raml-parser-adapter.js
Original file line number Diff line number Diff line change
@@ -30,18 +30,9 @@
};
}

function expandApiToJSON(api, expandFlag) {
api = api.expand ? api.expand(expandFlag) : api;
var apiJSON = api.toJSON(jsonOptions);
if (api.uses && api.uses()) {
apiJSON.uses = {};
api.uses().forEach(function (usesItem) {
var libraryAST = usesItem.ast();
libraryAST = libraryAST.expand ? libraryAST.expand() : libraryAST;
apiJSON.uses[usesItem.key()] = libraryAST.toJSON(jsonOptions);
});
}
return apiJSON;
function expandApiToJSON(api) {
api = api.expand ? api.expand(true) : api;
return api.toJSON(jsonOptions);
}

/**
3 changes: 2 additions & 1 deletion app/views/raml-editor-file-browser.tmpl.html
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@
</div>

<ul ui-tree-nodes ng-if="node.isDirectory" ng-class="{hidden: collapsed}" ng-model="node.children">
<li ui-tree-node ng-repeat="node in node.children" ng-include="'file-item.html'" data-collapsed="node.collapsed">
<li ui-tree-node ng-repeat="node in node.children" ng-include="'file-item.html'" data-collapsed="node.collapsed" data-path="{{node.path}}">
</li>
</ul>
</script>
@@ -27,6 +27,7 @@
<ul ui-tree-nodes ng-model="homeDirectory.children" id="tree-root">
<ui-tree-dummy-node class="top"></ui-tree-dummy-node>
<li ui-tree-node ng-repeat="node in homeDirectory.children" ng-include="'file-item.html'" data-collapsed="node.collapsed"
data-path="{{node.path}}"
ng-drag-enter="node.collapsed = false"
ng-drag-leave="node.collapsed = true"></li>
<ui-tree-dummy-node class="bottom" ng-click="fileBrowser.select(homeDirectory)"></ui-tree-dummy-node>
2 changes: 1 addition & 1 deletion app/views/raml-editor-main.tmpl.html
Original file line number Diff line number Diff line change
@@ -65,7 +65,7 @@ <h1>

<div ng-show="getIsConsoleVisible()" role="preview-wrapper" class="raml-console-embedded">
<raml-console
raml="ramlExpanded"
raml="raml"
options="{
singleView: true,
disableThemeSwitcher: true,
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "api-designer",
"version": "0.1.12",
"version": "0.1.13",
"repository": {
"type": "git",
"url": "https://github.com/mulesoft/api-designer.git"
403 changes: 189 additions & 214 deletions dist/scripts/api-designer.js

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions dist/scripts/api-designer.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "api-designer",
"version": "0.1.12",
"version": "0.1.13",
"description": "A web editor for creating and sharing RAML API specifications",
"repository": {
"type": "git",
48 changes: 0 additions & 48 deletions test/spec/raml-parser-adapter.js
Original file line number Diff line number Diff line change
@@ -30,54 +30,6 @@ describe('RAML Parser adapter', function () {
);
});

it('should parse the expand with out flag the RAML file with title and uses', function (done) {
var file = {
name: 'api.raml',
path: '/api.raml',
contents: [
'#%RAML 1.0',
'title: My RAML',
'uses:',
' lib: library.raml',
'/myResource:',
' get:',
' body:',
' application/json:',
' type: lib.MyType'
].join('\n')
};

var lib = {
name: 'library.raml',
path: '/library.raml',
contents: [
'#%RAML 1.0 Library',
'usage: Defines types',
'types:',
' MyType:',
' properties:',
' name: string',
' address: string'
].join('\n')
};

var loadPath = ramlParserAdapter.loadPathUnwrapped('/api.raml', function (path) {
var content;
if (path === file.path) { content = file.contents; }
if (path === lib.path) { content = lib.contents; }

return Promise.resolve(content ? content : '');
});

loadPath.then(
function (api) {
var raml = ramlParserAdapter.expandApiToJSON(api, false);
raml.uses.lib.types[0].MyType.name.should.be.equal('MyType');
done();
}
);
});

it('should parse the expand with out flag the RAML file with title and types', function (done) {
var file = {
name: 'api.raml',
2 changes: 1 addition & 1 deletion test/spec/services/mocking-service-client.js
Original file line number Diff line number Diff line change
@@ -171,7 +171,7 @@ describe('mockingServiceClient', function () {
angular.toJson({
id: 'id',
manageKey: 'manageKey',
baseUri: 'baseUri'
baseUri: 'baseUri/mocks/'
}),

// headers

0 comments on commit 6d72a14

Please sign in to comment.