forked from swaggo/http-swagger
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ScriptSrcs to add extra scripts URLs to load
Summary: This allows importing plugins from local and external hosts. ``` r.Get("/swagger/*", httpSwagger.Handler( httpSwagger.ScriptSrc("/static/swagger-helper.js"), httpSwagger.ScriptSrc("https://unpkg.com/[email protected]/build/index.js"), httpSwagger.Plugins([]string{"DisableTryItOutWithoutServersPlugin"}, httpSwagger.URL("http://localhost:1323/swagger/doc.json"), //The url pointing to API definition )) ``` Closes swaggo#83 Test Plan: Updated existing tests. Added example in example/go-chi/
- Loading branch information
Showing
5 changed files
with
119 additions
and
58 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 |
---|---|---|
|
@@ -29,6 +29,10 @@ func main() { | |
r.Get("/swagger/*", httpSwagger.Handler( | ||
httpSwagger.BeforeScript("console.log('before 1')"), | ||
httpSwagger.BeforeScript("console.log('before 2')"), | ||
httpSwagger.ScriptSrc("https://unpkg.com/[email protected]/dist/htm.js"), | ||
httpSwagger.ScriptSrc("https://unpkg.com/[email protected]/umd/react.production.min.js"), | ||
httpSwagger.ScriptSrc("/static/myplugin.js"), | ||
httpSwagger.Plugins([]string{"MyPlugin"}), | ||
httpSwagger.URL("http://localhost:1323/swagger/doc.json"), //The url pointing to API definition | ||
)) | ||
|
||
|
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,80 @@ | ||
// Swagger UI Version: 4.15.5 | ||
|
||
'use strict'; | ||
|
||
function _typeof(obj) { | ||
if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { | ||
_typeof = function _typeof(obj) { | ||
return typeof obj; | ||
}; | ||
} else { | ||
_typeof = function _typeof(obj) { | ||
return obj && | ||
typeof Symbol === 'function' && | ||
obj.constructor === Symbol && | ||
obj !== Symbol.prototype | ||
? 'symbol' | ||
: typeof obj; | ||
}; | ||
} | ||
return _typeof(obj); | ||
} | ||
|
||
// From: https://raw.githubusercontent.com/chilts/umd-template/master/template.js | ||
(function (f) { | ||
// module name and requires | ||
var name = 'MyPlugin'; | ||
var requires = []; // CommonJS | ||
|
||
if ( | ||
(typeof exports === 'undefined' ? 'undefined' : _typeof(exports)) === 'object' && | ||
typeof module !== 'undefined' | ||
) { | ||
module.exports = f.apply( | ||
null, | ||
requires.map(function (r) { | ||
return require(r); | ||
}) | ||
); // RequireJS | ||
} else if (typeof define === 'function' && define.amd) { | ||
define(requires, f); // <script> | ||
} else { | ||
var g; | ||
|
||
if (typeof window !== 'undefined') { | ||
g = window; | ||
} else if (typeof global !== 'undefined') { | ||
g = global; | ||
} else if (typeof self !== 'undefined') { | ||
g = self; | ||
} else { | ||
// works providing we're not in "use strict"; | ||
// needed for Java 8 Nashorn | ||
// seee https://github.com/facebook/react/issues/3037 | ||
g = this; | ||
} | ||
|
||
g[name] = f.apply( | ||
null, | ||
requires.map(function (r) { | ||
return g[r]; | ||
}) | ||
); | ||
} | ||
})(function () { | ||
return function (system) { | ||
return { | ||
wrapComponents: { | ||
info: (Original, system) => (props) => { | ||
const html = htm.bind(React.createElement); | ||
// Uses https://github.com/developit/htm to render JSX. | ||
return html` | ||
<div> | ||
<h3>Hello world! I am above the Info component.</h3> | ||
<Original {...props} /> | ||
</div>`; | ||
} | ||
}, | ||
}; | ||
}; | ||
}); |
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