File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed
Sources/swift-openapi-generator Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,9 @@ struct _FilterCommand: AsyncParsableCommand {
36
36
@Option ( help: " Path to a YAML configuration file. " )
37
37
var config : URL
38
38
39
+ @Option ( help: " Output format, either \( OutputFormat . yaml. rawValue) or \( OutputFormat . json. rawValue) . " )
40
+ var outputFormat : OutputFormat = . yaml
41
+
39
42
@Argument ( help: " Path to the OpenAPI document, either in YAML or JSON. " )
40
43
var docPath : URL
41
44
@@ -54,7 +57,14 @@ struct _FilterCommand: AsyncParsableCommand {
54
57
return
55
58
}
56
59
let filteredDocument = try timing ( " Filtering document " , documentFilter. filter ( document) )
57
- FileHandle . standardOutput. write ( try YAMLEncoder ( ) . encode ( filteredDocument) )
60
+ switch outputFormat {
61
+ case . yaml:
62
+ FileHandle . standardOutput. write ( try YAMLEncoder ( ) . encode ( filteredDocument) )
63
+ case . json:
64
+ let encoder = JSONEncoder ( )
65
+ encoder. outputFormatting = [ . prettyPrinted, . withoutEscapingSlashes]
66
+ FileHandle . standardOutput. write ( try encoder. encode ( filteredDocument) )
67
+ }
58
68
}
59
69
}
60
70
@@ -80,3 +90,8 @@ private let sampleConfig = _UserConfig(
80
90
schemas: [ " Greeting " ]
81
91
)
82
92
)
93
+
94
+ enum OutputFormat : String , ExpressibleByArgument {
95
+ case json
96
+ case yaml
97
+ }
You can’t perform that action at this time.
0 commit comments