swaggerizer 0.1.1__py3-none-any.whl

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.
@@ -0,0 +1,3 @@
1
+ __all__ = ["__version__"]
2
+ __version__ = "0.1.0"
3
+
swaggerizer/cli.py ADDED
@@ -0,0 +1,121 @@
1
+ import argparse, os, shutil
2
+ from .helpers.create_project import Swaggerizer
3
+ from .helpers.html_exporter import HTMLExporter
4
+ from .helpers.json2yaml_converter import json2YamlConverter
5
+ from .helpers.yaml2json_converter import yaml2JsonConverter
6
+ from .helpers.validator import validator
7
+
8
+
9
+ def checkCreateOutputDir(output_arg):
10
+ # Create output directory if needed
11
+ output_dir = os.path.dirname(output_arg)
12
+ if output_dir and not os.path.exists(output_dir):
13
+ os.makedirs(output_dir)
14
+
15
+
16
+ def main():
17
+ parser = argparse.ArgumentParser(
18
+ description="Swaggerize your API documentation.",
19
+ formatter_class=argparse.RawTextHelpFormatter
20
+ )
21
+ parser.add_argument(
22
+ "operation",
23
+ metavar="OPERATION",
24
+ choices=["create", "export", "json2yaml", "yaml2json", "validate"],
25
+ help=("Available operations:\n"
26
+ " create = Create new modularized OpenAPI docs project\n"
27
+ " export = Export OpenAPI YAML file as HTML\n"
28
+ " json2yaml = Convert OpenAPI JSON file to YAML\n"
29
+ " yaml2json = Convert OpenAPI YAML file to JSON\n"
30
+ " validate = Validate basic JSON or YAML format"
31
+ )
32
+ )
33
+ parser.add_argument(
34
+ "-i", "--input",
35
+ metavar="IN_FILE",
36
+ default=None,
37
+ help=("Input file or path. Default value per operation:\n"
38
+ " create = './openapi.yaml'\n"
39
+ " export = './openapi.yaml'\n"
40
+ " json2yaml = './openapi.json'\n"
41
+ " yaml2json = './openapi.yaml'"
42
+ )
43
+ )
44
+ parser.add_argument(
45
+ "-o", "--output",
46
+ metavar="OUT_FILE",
47
+ default=None,
48
+ help=("Output file or path. Default value per operation:\n"
49
+ " export = '{IN_FILE}.html'\n"
50
+ " json2yaml = '{IN_FILE}.yaml'\n"
51
+ " yaml2json = '{IN_FILE}.json'"
52
+ )
53
+
54
+ )
55
+ parser.add_argument(
56
+ "-t", "--type",
57
+ metavar="FILE_TYPE",
58
+ default=None,
59
+ choices=["json", "yaml"],
60
+ help=("File type for validate operation. Omit to get type\n"
61
+ "from file extension. Possible values:\n"
62
+ " json = Validate basic JSON format.\n"
63
+ " yaml = Validate basic YAML format."
64
+ )
65
+ )
66
+
67
+ # Parse arguments
68
+ args = parser.parse_args()
69
+
70
+ # Handle the requested operation
71
+ if args.operation == "create":
72
+ # Define default input
73
+ args.input = args.input or "openapi.yaml"
74
+
75
+ # Swaggerize it
76
+ project = Swaggerizer(args.input)
77
+ project.create()
78
+
79
+ elif args.operation == "export":
80
+ # Define default input
81
+ args.input = args.input or "openapi.yaml"
82
+
83
+ # Make sure output dir exists if specified
84
+ if args.output:
85
+ checkCreateOutputDir(args.output)
86
+
87
+ # Export the HTML
88
+ exporter = HTMLExporter(args.input, args.output)
89
+ exporter.export()
90
+
91
+ elif args.operation == "json2yaml":
92
+ # Define default input
93
+ args.input = args.input or "openapi.json"
94
+
95
+ # Make sure output dir exists if specified
96
+ if args.output:
97
+ checkCreateOutputDir(args.output)
98
+
99
+ # Convert the JSON to YAML
100
+ converter = json2YamlConverter(args.input, args.output)
101
+ converter.convert()
102
+
103
+ elif args.operation == "yaml2json":
104
+ # Define default input
105
+ args.input = args.input or "openapi.yaml"
106
+
107
+ # Make sure output dir exists if specified
108
+ if args.output:
109
+ checkCreateOutputDir(args.output)
110
+
111
+ # Convert the YAML to JSON
112
+ converter = yaml2JsonConverter(args.input, args.output)
113
+ converter.convert()
114
+
115
+ elif args.operation == "validate":
116
+ # Define default input
117
+ args.input = args.input or "openapi.yaml"
118
+
119
+ # Validate the file
120
+ validator.validate(args.input, args.type)
121
+
@@ -0,0 +1,70 @@
1
+ /************************************************************************/
2
+ /* top header */
3
+ /************************************************************************/
4
+
5
+ .swagger-ui .topbar {
6
+ /* header bar */
7
+ /* display: none; */
8
+ background-color: #353535;
9
+ padding: 5px 0;
10
+ }
11
+
12
+ .topbar .download-url-wrapper {
13
+ /* search input */
14
+ visibility: hidden;
15
+ }
16
+
17
+ .topbar .topbar-wrapper > .link > img {
18
+ /* default logo */
19
+ display: none;
20
+ }
21
+
22
+ .topbar .topbar-wrapper > .link::before {
23
+ /* custom logo (as base64-encoded SVG) */
24
+ content: url("data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAyNy41LjAsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjxzdmcgdmVyc2lvbj0iMS4xIiBpZD0iTGF5ZXJfMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgeD0iMHB4IiB5PSIwcHgiDQoJIHZpZXdCb3g9IjAgMCA2NDAgNTEyIiBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCA2NDAgNTEyOyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+DQo8c3R5bGUgdHlwZT0idGV4dC9jc3MiPg0KCS5zdDB7ZmlsbDojMDA2MDk4O30NCjwvc3R5bGU+DQo8cGF0aCBjbGFzcz0ic3QwIiBkPSJNMzkyLjgsMS4yYy0xNy00LjktMzQuNyw1LTM5LjYsMjJsLTEyOCw0NDhjLTQuOSwxNyw1LDM0LjcsMjIsMzkuNnMzNC43LTUsMzkuNi0yMmwxMjgtNDQ4DQoJQzQxOS43LDIzLjgsNDA5LjgsNi4xLDM5Mi44LDEuMkwzOTIuOCwxLjJ6IE00NzMuNCwxMjEuM2MtMTIuNSwxMi41LTEyLjUsMzIuOCwwLDQ1LjNsODkuMyw4OS40bC04OS40LDg5LjQNCgljLTEyLjUsMTIuNS0xMi41LDMyLjgsMCw0NS4zczMyLjgsMTIuNSw0NS4zLDBsMTEyLTExMmMxMi41LTEyLjUsMTIuNS0zMi44LDAtNDUuM2wtMTEyLTExMkM1MDYuMSwxMDguOSw0ODUuOCwxMDguOSw0NzMuNCwxMjEuMw0KCUw0NzMuNCwxMjEuM3ogTTE2Ni43LDEyMS4zYy0xMi41LTEyLjUtMzIuOC0xMi41LTQ1LjMsMGwtMTEyLDExMmMtMTIuNSwxMi41LTEyLjUsMzIuOCwwLDQ1LjNsMTEyLDExMmMxMi41LDEyLjUsMzIuOCwxMi41LDQ1LjMsMA0KCXMxMi41LTMyLjgsMC00NS4zTDc3LjMsMjU2bDg5LjQtODkuNEMxNzkuMiwxNTQuMSwxNzkuMiwxMzMuOCwxNjYuNywxMjEuM0wxNjYuNywxMjEuM3oiLz4NCjwvc3ZnPg0K");
25
+ display: inline-block;
26
+ width: 50px;
27
+ height: 50px;
28
+ margin-top: 10px;
29
+ }
30
+
31
+ .topbar .topbar-wrapper > .link:after {
32
+ /* custom header text */
33
+ content: "swaggerized";
34
+ font-style: italic;
35
+ margin-left: 15px;
36
+ font-weight: 400;
37
+ font-size: 30px;
38
+ line-height: 38px;
39
+ color: #CCAF46;
40
+ }
41
+
42
+ /************************************************************************/
43
+ /* content area */
44
+ /************************************************************************/
45
+
46
+ .swagger-ui .info {
47
+ /* main container */
48
+ margin: 35px 0;
49
+ }
50
+
51
+ .swagger-ui .info h2.title {
52
+ /* page title */
53
+ }
54
+
55
+ .swagger-ui .info h2.title span > small:first-of-type {
56
+ /* title pill 1 */
57
+ display: none;
58
+ }
59
+
60
+ .swagger-ui .info h2.title span > small:first-of-type {
61
+ /* title pill 1 */
62
+ display: none;
63
+ }
64
+
65
+ .swagger-ui .info h2.title span > small.version-stamp {
66
+ /* version stamp title pill */
67
+ display: none;
68
+ }
69
+
70
+ /* (etc...) */
@@ -0,0 +1,17 @@
1
+ all: test
2
+
3
+ test:
4
+ rm -f openapi-test.yaml
5
+ (echo "########## AUTO-GENERATED FILE: DO NOT EDIT! ##########" >> openapi-test.yaml)
6
+ cat 0_intro/*.yaml >> openapi-test.yaml
7
+ (echo "paths:" >> openapi-test.yaml)
8
+ cat 1_endpoints/*.yaml >> openapi-test.yaml
9
+ (echo "components:" >> openapi-test.yaml)
10
+ cat 2_components/*.yaml >> openapi-test.yaml
11
+ cat 3_misc/*.yaml >> openapi-test.yaml
12
+
13
+ final-build:
14
+ cp openapi-test.yaml ../FINAL_BUILD_TARGET
15
+
16
+ clean:
17
+ rm -f openapi-test.yaml