Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 63 additions & 65 deletions dist/scripts/api-console-vendor.js

Large diffs are not rendered by default.

85 changes: 85 additions & 0 deletions dist/scripts/api-console-vendor.min.js

Large diffs are not rendered by default.

29 changes: 17 additions & 12 deletions dist/scripts/api-console.js
Original file line number Diff line number Diff line change
Expand Up @@ -1400,8 +1400,11 @@
},
controller: ['$scope', function($scope) {
function getParamType(definition) {
if ($scope.types) {
var type = RAML.Inspector.Types.findType(definition.type[0], $scope.types);
var currentType = definition.type[0];
var isNative = RAML.Inspector.Types.isNativeType(currentType);

if (!isNative && $scope.types) {
var type = RAML.Inspector.Types.findType(currentType, $scope.types);
return type ? type : definition;
} else {
return definition;
Expand Down Expand Up @@ -1436,7 +1439,12 @@
}

$scope.isFile = function (param) {
return param.type === 'file';
if (!Array.isArray(param.type)) {
param.type = [param.type];
}

var rootType = getParamType(param);
return rootType.type[0] === 'file';
};

$scope.isArray = function (param) {
Expand Down Expand Up @@ -2970,15 +2978,10 @@

$scope.hasFormParameters = $scope.context.bodyContent && $scope.context.bodyContent.selected ? $scope.methodInfo.body[$scope.context.bodyContent.selected].hasOwnProperty('formParameters') : undefined;


$scope.getFormModel = function(param) {
$scope.getExample = function(param) {
var definitions = $scope.context.bodyContent.definitions[$scope.context.bodyContent.selected];
if ($scope.hasFormParameters) {
return definitions.values[param.definitions[0].id];
} else if (definitions.contentType && param.name) {
var example = definitions.contentType[param.name].example;
return example ? [example] : example;
}
var example = definitions.contentType[param.name].example;
return example ? [example] : example;
};
}]
};
Expand Down Expand Up @@ -8321,7 +8324,9 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
" </span>\n" +
" </span>\n" +
"\n" +
" <raml-field context=\"context\" type=\"type\" types=\"types\" param=\"param\" model=\"getFormModel(param)\"></raml-field>\n" +
" <span ng-init=\"paramModel = getExample(param)\">\n" +
" <raml-field context=\"context\" type=\"type\" types=\"types\" param=\"param\" model=\"paramModel\"></raml-field>\n" +
" </span>\n" +
" </p>\n" +
" </div>\n" +
" </div>\n" +
Expand Down
7 changes: 7 additions & 0 deletions dist/scripts/api-console.min.js

Large diffs are not rendered by default.

14 changes: 11 additions & 3 deletions src/app/directives/raml-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
},
controller: ['$scope', function($scope) {
function getParamType(definition) {
if ($scope.types) {
var type = RAML.Inspector.Types.findType(definition.type[0], $scope.types);
var currentType = definition.type[0];
var isNative = RAML.Inspector.Types.isNativeType(currentType);

if (!isNative && $scope.types) {
var type = RAML.Inspector.Types.findType(currentType, $scope.types);
return type ? type : definition;
} else {
return definition;
Expand Down Expand Up @@ -52,7 +55,12 @@
}

$scope.isFile = function (param) {
return param.type === 'file';
if (!Array.isArray(param.type)) {
param.type = [param.type];
}

var rootType = getParamType(param);
return rootType.type[0] === 'file';
};

$scope.isArray = function (param) {
Expand Down
11 changes: 3 additions & 8 deletions src/app/directives/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -689,15 +689,10 @@

$scope.hasFormParameters = $scope.context.bodyContent && $scope.context.bodyContent.selected ? $scope.methodInfo.body[$scope.context.bodyContent.selected].hasOwnProperty('formParameters') : undefined;


$scope.getFormModel = function(param) {
$scope.getExample = function(param) {
var definitions = $scope.context.bodyContent.definitions[$scope.context.bodyContent.selected];
if ($scope.hasFormParameters) {
return definitions.values[param.definitions[0].id];
} else if (definitions.contentType && param.name) {
var example = definitions.contentType[param.name].example;
return example ? [example] : example;
}
var example = definitions.contentType[param.name].example;
return example ? [example] : example;
};
}]
};
Expand Down
4 changes: 3 additions & 1 deletion src/app/directives/sidebar.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ <h4 class="raml-console-sidebar-subhead">Body</h4>
</span>
</span>

<raml-field context="context" type="type" types="types" param="param" model="getFormModel(param)"></raml-field>
<span ng-init="paramModel = getExample(param)">
<raml-field context="context" type="type" types="types" param="param" model="paramModel"></raml-field>
</span>
</p>
</div>
</div>
Expand Down
7 changes: 5 additions & 2 deletions test/regression/assertions/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,15 @@ function Resource (poName) {
expect(panel.isPresent()).toBe(isOpen);
};

this.ifDisplayingProperties = function (resource, properties) {
this.ifDisplayingProperties = function (resource, propertiesName, propertiesType) {
var bodyProperties = this.po.getTryItBodyPanelParameters(resource);

properties.forEach(function (name, index) {
propertiesName.forEach(function (name, index) {
var property = bodyProperties.get(index);
expect(property.getText()).toContain(name);

var type = propertiesType[index];
expect(property.getText()).toContain(type);
});
};
}
Expand Down
14 changes: 14 additions & 0 deletions test/regression/assets/raml/resource-bodies-10.raml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
baseUri: http://localhost
title: Resource bodies

types:
userPicture:
type: file
fileTypes: ['image/jpeg', 'image/png']
maxLength: 307200

/test:
put:
body:
Expand All @@ -13,3 +19,11 @@ title: Resource bodies
type: string
required: true
example: blah

/test-root-types:
put:
body:
multipart/form-data:
properties:
one:
type: userPicture
20 changes: 17 additions & 3 deletions test/regression/standalone/directiveSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,24 @@ module.exports = function() {
// Act
browser.get('http://localhost:9000/directive-resource-bodies-10.html');

resourcePo.toggleResourceMethod(0, 0);
resourcePo.toggleResourceMethod(1, 0);

//Assert
assert.ifDisplayingProperties(1, ['one', 'two'], ['file', 'string']);
});

it('should display properties inheriting from root types for raml 1.0', function () {
// Arrange
var assert = assertions.create('resource');
var resourcePo = factory.create('resource');

// Act
browser.get('http://localhost:9000/directive-resource-bodies-10.html');

resourcePo.toggleResourceMethod(2, 0);

//Assert
assert.ifDisplayingProperties(0, ['one', 'two']);
assert.ifDisplayingProperties(2, ['one'], ['userPicture']);
});

it('should display formParameters for raml 0.8', function () {
Expand All @@ -295,7 +309,7 @@ module.exports = function() {
resourcePo.toggleResourceMethod(0, 0);

//Assert
assert.ifDisplayingProperties(0, ['one', 'two']);
assert.ifDisplayingProperties(0, ['one', 'two'], ['file', 'string']);
});
});
};