Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: More plugins #5

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pids
*.pid
*.seed
*.pid.lock
*.sw[op]

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ A multi-package repository of useful Swagger UI plugins maintained by [@shockey]
## 👉 Available Plugins

- [`disable-try-it-out-without-servers`](https://github.com/shockey/swagger-ui-plugins/tree/master/packages/disable-try-it-out-without-servers): enter documentation-only mode when OAS 3.0 `servers` is empty or missing
- [`hide-empty-tags`](https://github.com/shockey/swagger-ui-plugins/tree/master/packages/hide-empty-tags): hide empty tags
- [`url-mutator`](https://github.com/shockey/swagger-ui-plugins/tree/master/packages/url-mutator): mechanism to override path, basePath and scheme for OpenAPI 2.x definitions
- [`disable-oas-spec-link`](https://github.com/shockey/swagger-ui-plugins/tree/master/packages/disable-oas-spec-link): prevent the display of the OpenAPI specification URL link

## Contributing

Expand All @@ -14,6 +17,10 @@ I will make releases of each plugin when/if your PR is accepted.

Please add yourself to the Contributors list below if you add a new plugin!

You can use the `npm run new-plugin` command to easily generate a new plugin skeleton from boilerplate. This should give you at least a reasonable head start on your plugin in a way that is generally compatible with the conventions in this library.

**One easy way to contribute is to copy over plugins found at https://github.com/swagger-api/swagger-ui/issues/5027#issuecomment-438745785.**

## Versioning

Each plugin uses [SemVer](http://semver.org/) for versioning.
Expand All @@ -23,6 +30,7 @@ A plugin's version is unrelated to its Swagger UI compatibility: compatible vers
## Contributors

* **Kyle Shockey**: *Initial work; plugin maintenance*
* **Kael Shipman**: *Plugin boilerplate and script; limited ports of other people's plugins from around the web.*

## Built With

Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@
"@babel/preset-env": "^7.1.0",
"babel-plugin-add-module-exports": "^1.0.0",
"lerna": "^3.4.3"
},
"scripts": {
"new-plugin": "./scripts/new-plugin.sh"
}
}
12 changes: 12 additions & 0 deletions packages/.boilerplate/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"ie": "11"
}
}
]
]
}
3 changes: 3 additions & 0 deletions packages/.boilerplate/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
build
*.sw[op]
47 changes: 47 additions & 0 deletions packages/.boilerplate/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Swagger UI '{proper-name}' Plugin
==================================================================

{long-desc}

## Usage

### Require

First, install the module with npm:
```
$ npm install --save swagger-ui-plugin-{name-kebab-case}
```

Next, require it in your client-side application:

```js
const {name-pascal-case}Plugin = require('swagger-ui-plugin-{name-kebab-case}');

SwaggerUI({
// your options here...
plugins: [
{name-pascal-case}Plugin
]
})
```

### `<script>`

```html
<!-- Load Swagger UI -->
<script src="https://unpkg.com/swagger-ui-dist/swagger-ui-bundle.js"> </script>
<!-- Load the {name-pascal-case} Plugin -->
<script src="https://unpkg.com/swagger-ui-plugin-{name-kebab-case}"> </script>

<script>
window.onload = function() {
SwaggerUI({
// your options here...
plugins: [
{name-pascal-case}Plugin
]
})
}
</script>
```

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

const swaggerUiPlugin{name-pascal-case} = require('..');

describe('swagger-ui-plugin-{name-kebab-case}', () => {
it('needs tests');
});
33 changes: 33 additions & 0 deletions packages/.boilerplate/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "swagger-ui-plugin-{name-kebab-case}",
"version": "1.0.0",
"description": "{short-desc}",
"author": "{author}",
"homepage": "https://github.com/shockey/swagger-ui-plugins#readme",
"license": "MIT",
"main": "build/index.js",
"directories": {
"build": "build",
"test": "__tests__"
},
"files": [
"build"
],
"repository": {
"type": "git",
"url": "git+https://github.com/shockey/swagger-ui-plugins.git"
},
"scripts": {
"build": "npx babel src -d build",
"prepublishOnly": "npm run build",
"test": "echo \"Error: run tests from root\" && exit 1"
},
"bugs": {
"url": "https://github.com/shockey/swagger-ui-plugins/issues"
},
"devDependencies": {
"@babel/cli": "^7.12.10",
"@babel/core": "^7.12.10",
"@babel/preset-env": "^7.12.11"
}
}
56 changes: 56 additions & 0 deletions packages/.boilerplate/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// From: https://raw.githubusercontent.com/chilts/umd-template/master/template.js
; ((f) => {
// module name and requires
var name = '{name-pascal-case}Plugin';
var requires = [];

// CommonJS
if (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
// see https://github.com/facebook/react/issues/3037
g = this;
}
g[name] = f.apply(null, requires.map(function (r) { return g[r]; }));
}

})(() => {
// Module source
return (system) => {
return {



/**
*
*
*
*
* Your plugin here
*
*
*
*
*/



}
};
});
12 changes: 12 additions & 0 deletions packages/disable-oas-spec-link/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"ie": "11"
}
}
]
]
}
3 changes: 3 additions & 0 deletions packages/disable-oas-spec-link/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
build
*.sw[op]
48 changes: 48 additions & 0 deletions packages/disable-oas-spec-link/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Swagger UI 'Disable Oas Spec Link' Plugin
==================================================================

Prevent the display of the OpenAPI specification URL link.

Original post: https://github.com/swagger-api/swagger-ui/issues/4171

## Usage

### Require

First, install the module with npm:
```
$ npm install --save swagger-ui-plugin-disable-oas-spec-link
```

Next, require it in your client-side application:

```js
const DisableOasSpecLinkPlugin = require('swagger-ui-plugin-disable-oas-spec-link');

SwaggerUI({
// your options here...
plugins: [
DisableOasSpecLinkPlugin
]
})
```

### `<script>`

```html
<!-- Load Swagger UI -->
<script src="https://unpkg.com/swagger-ui-dist/swagger-ui-bundle.js"> </script>
<!-- Load the DisableOasSpecLink Plugin -->
<script src="https://unpkg.com/swagger-ui-plugin-disable-oas-spec-link"> </script>

<script>
window.onload = function() {
SwaggerUI({
// your options here...
plugins: [
DisableOasSpecLinkPlugin
]
})
}
</script>
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

const swaggerUiPluginDisableOasSpecLink = require('..');

describe('swagger-ui-plugin-disable-oas-spec-link', () => {
it('needs tests');
});
33 changes: 33 additions & 0 deletions packages/disable-oas-spec-link/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "swagger-ui-plugin-disable-oas-spec-link",
"version": "1.0.0",
"description": "prevent the display of the OpenAPI specification URL link",
"author": "Mike Fidel @mikefidel",
"homepage": "https://github.com/shockey/swagger-ui-plugins#readme",
"license": "MIT",
"main": "build/index.js",
"directories": {
"build": "build",
"test": "__tests__"
},
"files": [
"build"
],
"repository": {
"type": "git",
"url": "git+https://github.com/shockey/swagger-ui-plugins.git"
},
"scripts": {
"build": "npx babel src -d build",
"prepublishOnly": "npm run build",
"test": "echo \"Error: run tests from root\" && exit 1"
},
"bugs": {
"url": "https://github.com/shockey/swagger-ui-plugins/issues"
},
"devDependencies": {
"@babel/cli": "^7.12.10",
"@babel/core": "^7.12.10",
"@babel/preset-env": "^7.12.11"
}
}
43 changes: 43 additions & 0 deletions packages/disable-oas-spec-link/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// From: https://raw.githubusercontent.com/chilts/umd-template/master/template.js
; ((f) => {
// module name and requires
var name = 'DisableOasSpecLinkPlugin';
var requires = [];

// CommonJS
if (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
// see https://github.com/facebook/react/issues/3037
g = this;
}
g[name] = f.apply(null, requires.map(function (r) { return g[r]; }));
}

})(() => {
// Module source
return (system) => {
return {
wrapComponents: {
InfoUrl: () => () => null,
InfoBasePath: () => () => null, // this hides the `Base Url` part too, if you want that
}
}
};
});
12 changes: 12 additions & 0 deletions packages/hide-empty-tags/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"ie": "11"
}
}
]
]
}
3 changes: 3 additions & 0 deletions packages/hide-empty-tags/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
build
*.sw[op]
Loading