33SwaggerEditor . controller ( 'TryOperation' , function ( $scope , formdataFilter ,
44 AuthManager , SchemaForm ) {
55
6- // configure SchemaForm directive
7- SchemaForm . options = {
8- theme : 'bootstrap3' ,
9-
10- /*jshint camelcase: false */
11- show_errors : true
12- } ;
13-
146 var specs = $scope . $parent . specs ;
157 var parameters = $scope . getParameters ( ) ;
168 var securityOptions = getSecurityOptions ( ) ;
@@ -31,6 +23,80 @@ SwaggerEditor.controller('TryOperation', function ($scope, formdataFilter,
3123 $scope . httpProtorcol = 'HTTP/1.1' ;
3224 $scope . locationHost = window . location . host ;
3325
26+ configureSchemaForm ( ) ;
27+
28+ /*
29+ * configure SchemaForm directive based on request schema
30+ */
31+ function configureSchemaForm ( ) {
32+ /*jshint camelcase: false */
33+
34+ var defaultOptions = {
35+ theme : 'bootstrap3' ,
36+ show_errors : true
37+ } ;
38+
39+ var looseOptions = {
40+ no_additional_properties : false ,
41+ disable_properties : false ,
42+ disable_edit_json : false
43+ } ;
44+
45+ var loose = isLoose ( ) ;
46+
47+ SchemaForm . options = _ . extend ( defaultOptions , loose ? looseOptions : { } ) ;
48+ }
49+
50+ /*
51+ * Determines if this request has a loose body parameter schema
52+ * A loose body parameter schema is a body parameter that allows additional
53+ * properties or has no properties object
54+ *
55+ * Note that "loose schema" is not a formal definition, we use this definition
56+ * here to determine type of form to render
57+ *
58+ * @returns {boolean }
59+ */
60+ function isLoose ( ) {
61+
62+ // loose schema is only for requests with body parameter
63+ if ( ! hasRequestBody ( ) ) {
64+ return false ;
65+ }
66+
67+ // we're accessing deep in the schema. many operations can fail here
68+ try {
69+
70+ for ( var p in $scope . requestSchema . properties . parameters . properties ) {
71+ var param = $scope . requestSchema . properties . parameters . properties [ p ] ;
72+ if ( param . in === 'body' ) {
73+
74+ // loose object
75+ if (
76+ param . type === 'object' &&
77+ ( param . additionalProperties ||
78+ _ . isEmpty ( param . properties ) )
79+ ) {
80+
81+ return true ;
82+ }
83+
84+ // loose array of objects
85+ if (
86+ param . type === 'array' &&
87+ ( param . items . additionalProperties ||
88+ _ . isEmpty ( param . items . properties ) )
89+ ) {
90+
91+ return true ;
92+ }
93+ }
94+ }
95+ } catch ( e ) { }
96+
97+ return false ;
98+ }
99+
34100 /*
35101 * Makes the request schema to generate the form in the template
36102 * The schema has all required attributes for making a call for this operation
0 commit comments