swagger_ui_standalone 0.1.4 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +152 -21
- data/lib/swagger_ui_standalone/cli.rb +45 -5
- data/lib/swagger_ui_standalone/version.rb +1 -1
- data/lib/swagger_ui_standalone/zipball.rb +4 -5
- data/lib/swagger_ui_standalone.rb +3 -2
- metadata +5 -5
- /data/exe/{swagger-ui-standalone → swagger_ui_standalone} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f9afbe0a8118ee537a0d155bf5f25d262a5ebebcfff54f061d49b17fd79fbf2
|
4
|
+
data.tar.gz: 3f46be82ad2730a629d6f23225689bcc215e31af7e7d2c9f5588081eac8c919d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 992241f55e77a1819c8b8d1634560fcedc493de2b7f22db296b8600c63b7bd3f0803fa59d2fb53a19bf6dfa0249159f7d8685b06279a4dc4dddfe6758d48d905
|
7
|
+
data.tar.gz: 29e12b0f7b0f3c1a92555761691753bcd0484d6635360b4a2cb552abe94c06814093158db528cf148bd552845280dbaa4eb6959e450101b04c784c03af1c52a1
|
data/README.md
CHANGED
@@ -1,43 +1,174 @@
|
|
1
|
-
|
1
|
+
<div align="center">
|
2
2
|
|
3
|
-
|
3
|
+
# Swagger UI Standalone
|
4
4
|
|
5
|
-
|
5
|
+
[](https://badge.fury.io/rb/swagger_ui_standalone)
|
6
|
+
[](https://github.com/typisttech/swagger_ui_standalone/actions/workflows/main.yml)
|
7
|
+
[](https://github.com/typisttech/swagger_ui_standalone/blob/master/LICENSE.txt)
|
8
|
+
[](https://x.com/tangrufus)
|
9
|
+
[](https://bsky.app/profile/tangrufus.com)
|
10
|
+
[](https://github.com/sponsors/tangrufus)
|
11
|
+
[](https://typist.tech/contact/)
|
6
12
|
|
7
|
-
|
13
|
+
<p>
|
14
|
+
<strong>Generate standalone static Swagger UI sites from OpenAPI specifications.</strong>
|
15
|
+
<br>
|
16
|
+
<br>
|
17
|
+
Built with ♥ by <a href="https://typist.tech/">Typist Tech</a>
|
18
|
+
</p>
|
8
19
|
|
9
|
-
|
20
|
+
</div>
|
10
21
|
|
11
|
-
|
22
|
+
---
|
23
|
+
|
24
|
+
## Quick Start
|
12
25
|
|
13
26
|
```bash
|
14
|
-
|
27
|
+
# Install the gem
|
28
|
+
gem install swagger_ui_standalone
|
29
|
+
|
30
|
+
# Prepare some custom files
|
31
|
+
mkdir custom
|
32
|
+
|
33
|
+
## Download some OpenAPI specifications
|
34
|
+
wget https://raw.githubusercontent.com/github/rest-api-description/refs/heads/main/descriptions/api.github.com/api.github.com.yaml -O custom/github.yaml
|
35
|
+
wget https://validator.swagger.io/validator/openapi.json -O custom/validator.yaml
|
36
|
+
|
37
|
+
## Make a disallow all robots.txt file
|
38
|
+
cat > custom/robots.txt <<EOF
|
39
|
+
User-agent: *
|
40
|
+
Disallow: /
|
41
|
+
EOF
|
42
|
+
|
43
|
+
## Create custom swagger-initializer.js to override the default file
|
44
|
+
cat > custom/swagger-initializer.js <<EOF
|
45
|
+
window.onload = function() {
|
46
|
+
window.ui = SwaggerUIBundle({
|
47
|
+
urls: [
|
48
|
+
{name: "GitHub", url: "github.yaml"},
|
49
|
+
{name: "Validator", url: "validator.yaml"},
|
50
|
+
{name: "Petstore (External)", url: "https://petstore.swagger.io/v2/swagger.json"},
|
51
|
+
],
|
52
|
+
dom_id: '#swagger-ui',
|
53
|
+
deepLinking: true,
|
54
|
+
presets: [
|
55
|
+
SwaggerUIBundle.presets.apis,
|
56
|
+
SwaggerUIStandalonePreset
|
57
|
+
],
|
58
|
+
plugins: [
|
59
|
+
SwaggerUIBundle.plugins.DownloadUrl
|
60
|
+
],
|
61
|
+
layout: "StandaloneLayout"
|
62
|
+
});
|
63
|
+
};
|
64
|
+
EOF
|
65
|
+
|
66
|
+
# Generate a standalone static Swagger UI site into the output directory
|
67
|
+
swagger_ui_standalone generate --custom custom --output output
|
15
68
|
```
|
16
69
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
70
|
+
The `generate` command downloads the latest release of Swagger UI from GitHub and copy the `dist` directory to the `output` directory.
|
71
|
+
Then, the `custom` directory is copied as is, so you can add or overwrite files in the `output` directory.
|
72
|
+
|
73
|
+
```console
|
74
|
+
$ tree custom output
|
75
|
+
custom
|
76
|
+
├── github.yaml
|
77
|
+
├── robots.txt
|
78
|
+
├── swagger-initializer.js
|
79
|
+
└── validator.yaml
|
80
|
+
output
|
81
|
+
├── favicon-16x16.png
|
82
|
+
├── favicon-32x32.png
|
83
|
+
├── github.yaml
|
84
|
+
├── index.css
|
85
|
+
├── index.html
|
86
|
+
├── oauth2-redirect.html
|
87
|
+
├── robots.txt
|
88
|
+
├── swagger-initializer.js
|
89
|
+
├── swagger-ui-bundle.js
|
90
|
+
├── swagger-ui-bundle.js.map
|
91
|
+
├── swagger-ui-es-bundle-core.js
|
92
|
+
├── swagger-ui-es-bundle-core.js.map
|
93
|
+
├── swagger-ui-es-bundle.js
|
94
|
+
├── swagger-ui-es-bundle.js.map
|
95
|
+
├── swagger-ui-standalone-preset.js
|
96
|
+
├── swagger-ui-standalone-preset.js.map
|
97
|
+
├── swagger-ui.css
|
98
|
+
├── swagger-ui.css.map
|
99
|
+
├── swagger-ui.js
|
100
|
+
├── swagger-ui.js.map
|
101
|
+
└── validator.yaml
|
102
|
+
|
103
|
+
# Start a local web server to serve the static site with webrick
|
104
|
+
# See https://gist.github.com/willurd/5720255 for alternatives
|
105
|
+
$ gem install webrick
|
106
|
+
$ ruby -run -ehttpd output -p8000
|
21
107
|
```
|
22
108
|
|
23
109
|
## Usage
|
24
110
|
|
25
|
-
|
111
|
+
### `generate`
|
112
|
+
|
113
|
+
```console
|
114
|
+
$ swagger_ui_standalone help generate
|
115
|
+
Usage:
|
116
|
+
swagger_ui_standalone generate [options] --custom=DIRECTORY --output=DIRECTORY
|
26
117
|
|
27
|
-
|
118
|
+
Options:
|
119
|
+
--custom=DIRECTORY # Path to the directory containing custom files, which will be copied to the output directory
|
120
|
+
--output=DIRECTORY # Where to write the generated files
|
121
|
+
[--repo=OWNER/REPO] # GitHub repository to download in the format <owner/repo>
|
122
|
+
# Default: swagger-api/swagger-ui
|
123
|
+
[--ref=TAG|BRANCH|SHA] # Git reference to download (can be a tag, branch or commit SHA). Omit to use the latest release
|
124
|
+
[--force] # Overwrite files that already exist
|
28
125
|
|
29
|
-
|
126
|
+
Generate standalone static Swagger UI
|
127
|
+
```
|
128
|
+
|
129
|
+
### `download`
|
130
|
+
|
131
|
+
```console
|
132
|
+
$ swagger_ui_standalone help download
|
133
|
+
Usage:
|
134
|
+
swagger_ui_standalone download [options] --output=DIRECTORY
|
135
|
+
|
136
|
+
Options:
|
137
|
+
--output=DIRECTORY # Where to write the generated files
|
138
|
+
[--repo=OWNER/REPO] # GitHub repository to download in the format <owner/repo>
|
139
|
+
# Default: swagger-api/swagger-ui
|
140
|
+
[--ref=TAG|BRANCH|SHA] # Git reference to download (can be a tag, branch or commit SHA). Omit to use the latest release
|
141
|
+
[--force] # Overwrite files that already exist
|
142
|
+
|
143
|
+
Download standalone static Swagger UI source code
|
144
|
+
```
|
145
|
+
|
146
|
+
## Installation
|
147
|
+
|
148
|
+
Install the gem and add to the application's Gemfile by executing:
|
149
|
+
|
150
|
+
```bash
|
151
|
+
bundle add swagger_ui_standalone
|
152
|
+
```
|
153
|
+
|
154
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
155
|
+
|
156
|
+
```bash
|
157
|
+
gem install swagger_ui_standalone
|
158
|
+
```
|
30
159
|
|
31
|
-
|
160
|
+
## Credits
|
32
161
|
|
33
|
-
|
162
|
+
[`Swagger UI Standalone`](https://github.com/typisttech/swagger_ui_standalone) is a [Typist Tech](https://typist.tech) project and
|
163
|
+
maintained by [Tang Rufus](https://x.com/TangRufus), freelance developer [for hire](https://typist.tech/contact/).
|
34
164
|
|
35
|
-
|
165
|
+
Full list of contributors can be found [on GitHub](https://github.com/typisttech/swagger_ui_standalone/graphs/contributors).
|
36
166
|
|
37
|
-
## License
|
167
|
+
## Copyright and License
|
38
168
|
|
39
|
-
|
169
|
+
This project is a [free software](https://www.gnu.org/philosophy/free-sw.en.html) distributed under the terms of
|
170
|
+
the MIT license. For the full license, see [LICENSE](./LICENSE.txt).
|
40
171
|
|
41
|
-
##
|
172
|
+
## Contribute
|
42
173
|
|
43
|
-
|
174
|
+
Feedbacks / bug reports / pull requests are welcome.
|
@@ -5,13 +5,25 @@ require_relative "../swagger_ui_standalone"
|
|
5
5
|
|
6
6
|
module SwaggerUIStandalone
|
7
7
|
class CLI < Thor
|
8
|
+
include Thor::Actions
|
9
|
+
|
8
10
|
def self.exit_on_failure?
|
9
11
|
true
|
10
12
|
end
|
11
13
|
|
12
|
-
|
14
|
+
no_commands do
|
15
|
+
def copy_directory(source, destination, config = {})
|
16
|
+
absolute_source = File.absolute_path(source)
|
17
|
+
|
18
|
+
self.class.source_root File.dirname(absolute_source)
|
19
|
+
@source_paths = nil
|
20
|
+
|
21
|
+
directory File.basename(absolute_source), destination, config
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.define_download_options
|
13
26
|
option :output,
|
14
|
-
aliases: ["-o", "--out"],
|
15
27
|
type: :string,
|
16
28
|
desc: "Where to write the generated files",
|
17
29
|
banner: "DIRECTORY",
|
@@ -25,13 +37,41 @@ module SwaggerUIStandalone
|
|
25
37
|
type: :string,
|
26
38
|
banner: "TAG|BRANCH|SHA",
|
27
39
|
desc: "Git reference to download (can be a tag, branch or commit SHA). Omit to use the latest release"
|
40
|
+
option :force,
|
41
|
+
type: :boolean,
|
42
|
+
desc: "Overwrite files that already exist"
|
28
43
|
end
|
29
44
|
|
30
|
-
desc "
|
31
|
-
|
45
|
+
desc "generate [options]", "Generate standalone static Swagger UI"
|
46
|
+
option :custom,
|
47
|
+
type: :string,
|
48
|
+
desc: "Path to the directory containing custom files, which will be copied to the output directory",
|
49
|
+
banner: "DIRECTORY",
|
50
|
+
required: true
|
51
|
+
define_download_options
|
52
|
+
|
53
|
+
def generate
|
54
|
+
Dir.mktmpdir do |tmp_dir|
|
55
|
+
# We only want the dist directory.
|
56
|
+
tmp_dist_dir = File.join(tmp_dir, DIST_DIR)
|
57
|
+
|
58
|
+
SwaggerUIStandalone.download_source tmp_dir, repo: options.repo, ref: options.ref
|
59
|
+
copy_directory options[:custom], tmp_dist_dir, recursive: true, force: true, verbose: false
|
60
|
+
|
61
|
+
copy_directory tmp_dist_dir, options.output, recursive: true, force: options.force, verbose: true
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
desc "download [options]", "Download standalone static Swagger UI source code"
|
66
|
+
define_download_options
|
32
67
|
|
33
68
|
def download
|
34
|
-
|
69
|
+
Dir.mktmpdir do |tmp_dir|
|
70
|
+
SwaggerUIStandalone.download_source tmp_dir, repo: options.repo, ref: options.ref
|
71
|
+
|
72
|
+
# We only want the dist directory.
|
73
|
+
copy_directory File.join(tmp_dir, DIST_DIR), options.output, recursive: true, force: options.force, verbose: true
|
74
|
+
end
|
35
75
|
end
|
36
76
|
end
|
37
77
|
end
|
@@ -4,13 +4,12 @@ require "zip"
|
|
4
4
|
|
5
5
|
module SwaggerUIStandalone
|
6
6
|
module Zipball
|
7
|
-
def extract(path,
|
8
|
-
pattern = "*/#{content_directory}/**"
|
9
|
-
prefix = "#{content_directory}/"
|
10
|
-
|
7
|
+
def extract(path, pattern:, destination_directory:)
|
11
8
|
Zip::File.open(path) do |zip_file|
|
12
9
|
zip_file.glob(pattern).each do |entry|
|
13
|
-
|
10
|
+
# Remove the leading directory from the entry name
|
11
|
+
# e.g. "swagger-api-swagger-ui-3c4e5b7/dist/index.html" --> "dist/index.html"
|
12
|
+
i = entry.name.index("/") + 1
|
14
13
|
entry_path = entry.name[i..]
|
15
14
|
|
16
15
|
full_destination_path = File.join(destination_directory, entry_path)
|
@@ -11,10 +11,11 @@ module SwaggerUIStandalone
|
|
11
11
|
extend Zipball
|
12
12
|
|
13
13
|
SOURCE_REPO = "swagger-api/swagger-ui"
|
14
|
+
DIST_DIR = "dist"
|
14
15
|
|
15
|
-
def self.download_source(output_directory, repo: SOURCE_REPO, ref: nil,
|
16
|
+
def self.download_source(output_directory, repo: SOURCE_REPO, ref: nil, pattern: "*/#{DIST_DIR}/**")
|
16
17
|
url = ref.nil? ? latest_release_archive_link(repo) : archive_link(repo, ref)
|
17
18
|
zipball = download url
|
18
|
-
extract zipball,
|
19
|
+
extract zipball, pattern:, destination_directory: output_directory
|
19
20
|
end
|
20
21
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swagger_ui_standalone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Typist Tech Limited
|
@@ -84,7 +84,7 @@ email:
|
|
84
84
|
- opensource+swagger_ui_standalone@typist.tech
|
85
85
|
- tangrufus@gmail.com
|
86
86
|
executables:
|
87
|
-
-
|
87
|
+
- swagger_ui_standalone
|
88
88
|
extensions: []
|
89
89
|
extra_rdoc_files: []
|
90
90
|
files:
|
@@ -95,7 +95,7 @@ files:
|
|
95
95
|
- LICENSE.txt
|
96
96
|
- README.md
|
97
97
|
- Rakefile
|
98
|
-
- exe/
|
98
|
+
- exe/swagger_ui_standalone
|
99
99
|
- lib/swagger_ui_standalone.rb
|
100
100
|
- lib/swagger_ui_standalone/cli.rb
|
101
101
|
- lib/swagger_ui_standalone/github.rb
|
@@ -121,7 +121,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
121
121
|
requirements:
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: 3.
|
124
|
+
version: 3.2.0
|
125
125
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
126
|
requirements:
|
127
127
|
- - ">="
|
@@ -130,5 +130,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
130
|
requirements: []
|
131
131
|
rubygems_version: 3.6.7
|
132
132
|
specification_version: 4
|
133
|
-
summary: Generate standalone static
|
133
|
+
summary: Generate standalone static Swagger UI sites from OpenAPI specifications.
|
134
134
|
test_files: []
|
File without changes
|