1
- window . onload = function ( ) {
1
+ window . onload = ( ) => {
2
2
const data = JSON . parse ( document . getElementById ( 'swagger-data' ) . innerText ) ;
3
3
const ui = SwaggerUIBundle ( {
4
4
spec : data . spec ,
@@ -11,69 +11,48 @@ window.onload = function() {
11
11
plugins : [
12
12
SwaggerUIBundle . plugins . DownloadUrl
13
13
] ,
14
- layout : " StandaloneLayout"
14
+ layout : ' StandaloneLayout'
15
15
} ) ;
16
- window . ui = ui
17
- } ;
18
16
19
- /*$(function () {
20
- var data = JSON.parse($('#swagger-data').html());
21
- window.swaggerUi = new SwaggerUi({
22
- url: data.url,
23
- spec: data.spec,
24
- dom_id: 'swagger-ui-container',
25
- supportedSubmitMethods: ['get', 'post', 'put', 'delete'],
26
- onComplete: function() {
27
- if (data.oauth.enabled && 'function' === typeof initOAuth) {
28
- initOAuth({
29
- clientId: data.oauth.clientId,
30
- clientSecret: data.oauth.clientSecret,
31
- realm: data.oauth.type,
32
- appName: data.spec.info.title,
33
- scopeSeparator: ' ',
34
- additionalQueryStringParams: {}
35
- });
36
- }
17
+ if ( data . oauth . enabled ) {
18
+ ui . initOAuth ( {
19
+ clientId : data . oauth . clientId ,
20
+ clientSecret : data . oauth . clientSecret ,
21
+ realm : data . oauth . type ,
22
+ appName : data . spec . info . title ,
23
+ scopeSeparator : ' ' ,
24
+ additionalQueryStringParams : { }
25
+ } ) ;
26
+ }
37
27
38
- $('pre code').each(function(i, e) {
39
- hljs.highlightBlock(e)
40
- });
28
+ window . ui = ui ;
41
29
42
- if (data.operationId !== undefined) {
43
- var queryParameters = data.queryParameters;
44
- var domSelector = '#' + data.shortName+'_'+data.operationId;
30
+ if ( ! data . operationId ) return ;
45
31
46
- $(domSelector + ' form.sandbox input.parameter').each( function (i, e ) {
47
- var $e = $(e );
48
- var name = $e.attr('name') ;
32
+ const observer = new MutationObserver ( function ( mutations , self ) {
33
+ const op = document . getElementById ( `operations, ${ data . method } - ${ data . path } , ${ data . shortName } ` ) ;
34
+ if ( ! op ) return ;
49
35
50
- if (name in queryParameters) {
51
- $e.val(queryParameters[name]);
52
- }
53
- });
36
+ self . disconnect ( ) ;
54
37
55
- if (data.id) {
56
- $(domSelector + ' form.sandbox input[name="id"]').val(data.id);
57
- }
38
+ op . querySelector ( '.opblock-summary' ) . click ( ) ;
39
+ op . querySelector ( '.try-out__btn' ) . click ( ) ;
58
40
59
- $(domSelector + ' form.sandbox').submit();
60
- document.location.hash = '#!/' + data.shortName + '/' + data.operationId;
61
- }
62
- },
63
- onFailure: function() {
64
- log('Unable to Load SwaggerUI');
65
- },
66
- docExpansion: 'list',
67
- jsonEditor: false,
68
- defaultModelRendering: 'schema',
69
- showRequestHeaders: true
70
- });
71
-
72
- window.swaggerUi.load();
41
+ if ( data . id ) {
42
+ const inputId = op . querySelector ( '.parameters input[placeholder="id"]' ) . value = data . id ;
43
+ inputId . dispatchEvent ( new Event ( 'input' , { bubbles : true } ) ) ;
44
+ }
73
45
74
- function log() {
75
- if ('console' in window) {
76
- console.log.apply(console, arguments);
77
- }
46
+ for ( let input of op . querySelectorAll ( '.parameters input' ) ) {
47
+ if ( input . placeholder in data . queryParameters ) {
48
+ input . value = data . queryParameters [ input . placeholder ] ;
49
+ input . dispatchEvent ( new Event ( 'input' , { bubbles : true } ) ) ;
50
+ }
78
51
}
79
- });*/
52
+
53
+ op . querySelector ( '.execute' ) . click ( ) ;
54
+ op . scrollIntoView ( ) ;
55
+ } ) ;
56
+
57
+ observer . observe ( document , { childList : true , subtree : true } ) ;
58
+ } ;
0 commit comments