Skip to content

Commit 7465766

Browse files
committed
Add yml file extension support
1 parent cfe0780 commit 7465766

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

Plugins/OpenAPIGenerator/plugin.swift

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,20 @@ struct SwiftOpenAPIGeneratorPlugin {
2828
"Incompatible target called '\(targetName)'. Only Swift source targets can be used with the Swift OpenAPI generator plugin."
2929
case .noConfigFound(let targetName):
3030
return
31-
"No config found in the target named '\(targetName)'. Add a file called 'openapi-generator-config.yaml' to the target's source directory. See documentation for details."
31+
"No config found in the target named '\(targetName)'. Add a file called 'openapi-generator-config.yaml' or 'openapi-generator-config.yml' to the target's source directory. See documentation for details."
3232
case .noDocumentFound(let targetName):
3333
return
34-
"No OpenAPI document found in the target named '\(targetName)'. Add a file called 'openapi.yaml' or 'openapi.json' (can also be a symlink) to the target's source directory. See documentation for details."
34+
"No OpenAPI document found in the target named '\(targetName)'. Add a file called 'openapi.yaml', 'openapi.yml' or 'openapi.json' (can also be a symlink) to the target's source directory. See documentation for details."
3535
}
3636
}
3737

3838
var errorDescription: String? {
3939
description
4040
}
4141
}
42+
43+
private var supportedConfigFiles: Set<String> { Set(["yaml", "yml"].map { "openapi-generator-config." + $0 }) }
44+
private var supportedDocFiles: Set<String> { Set(["yaml", "yml", "json"].map { "openapi." + $0 }) }
4245

4346
func createBuildCommands(
4447
pluginWorkDirectory: PackagePlugin.Path,
@@ -47,21 +50,14 @@ struct SwiftOpenAPIGeneratorPlugin {
4750
targetName: String
4851
) throws -> [Command] {
4952
let inputFiles = sourceFiles
50-
guard let config = inputFiles.first(where: { $0.path.lastComponent == "openapi-generator-config.yaml" })?.path
51-
else {
53+
guard let config = inputFiles.first(where: {
54+
supportedConfigFiles.contains($0.path.lastComponent)
55+
})?.path else {
5256
throw Error.noConfigFound(targetName: targetName)
5357
}
54-
guard
55-
let doc = inputFiles.first(where: {
56-
switch $0.path.lastComponent {
57-
case "openapi.yaml", "openapi.json":
58-
return true
59-
default:
60-
return false
61-
}
62-
})?
63-
.path
64-
else {
58+
guard let doc = inputFiles.first(where: {
59+
supportedDocFiles.contains($0.path.lastComponent)
60+
})?.path else {
6561
throw Error.noDocumentFound(targetName: targetName)
6662
}
6763
let genSourcesDir = pluginWorkDirectory.appending("GeneratedSources")

Sources/swift-openapi-generator/Documentation.docc/Articles/Configuring-the-generator.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ The command-line tool also uses the same configuration file.
1010

1111
### Create a configuration file
1212

13-
The configuration file is named `openapi-generator-config.yaml` and must exist in the target source directory.
13+
The configuration file is named `openapi-generator-config.yaml` or `openapi-generator-config.yml` and must exist in the target source directory.
14+
15+
> In the following tutorial, we will use `openapi-generator-config.yaml` as an example.
1416
1517
```
1618
.

scripts/check-license-headers.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@ read -ra PATHS_TO_CHECK_FOR_LICENSE <<< "$( \
6262
":(exclude)**/Package.resolved" \
6363
":(exclude)**/README.md" \
6464
":(exclude)**/openapi.yaml" \
65+
":(exclude)**/openapi.yml" \
6566
":(exclude)**/petstore.yaml" \
6667
":(exclude)**/openapi-generator-config.yaml" \
68+
":(exclude)**/openapi-generator-config.yml" \
6769
| xargs -0 \
6870
)"
6971

0 commit comments

Comments
 (0)