-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
Tests/OpenAPIGeneratorTests/Resources/Docs/malformed-openapi.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# openapi: '3.1.0' -> Missing openapi version | ||
info: | ||
title: MalformedDocument | ||
version: 1.0.0 |
4 changes: 4 additions & 0 deletions
4
Tests/OpenAPIGeneratorTests/Resources/Docs/openapi-generator-config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
generate: | ||
- types | ||
- server | ||
accessModifier: internal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the SwiftOpenAPIGenerator open source project | ||
// | ||
// Copyright (c) 2023 Apple Inc. and the SwiftOpenAPIGenerator project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See CONTRIBUTORS.txt for the list of SwiftOpenAPIGenerator project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
import XCTest | ||
import _OpenAPIGeneratorCore | ||
import OpenAPIKit | ||
import ArgumentParser | ||
@testable import swift_openapi_generator | ||
|
||
final class Test_GenerateOptions: XCTestCase { | ||
|
||
var resourcesDirectory: URL! = nil | ||
|
||
/// Setup method called before the invocation of each test method in the class. | ||
override func setUpWithError() throws { | ||
resourcesDirectory = try XCTUnwrap( | ||
Bundle.module.url(forResource: "Resources", withExtension: nil), | ||
"Could not find reference test resources directory." | ||
) | ||
} | ||
|
||
func testRunGeneratorThrowsErrorDiagnostic() async throws { | ||
let outputDirectory = URL(fileURLWithPath: "/invalid/path") | ||
let docsDirectory = resourcesDirectory.appendingPathComponent("Docs") | ||
let docPath = docsDirectory.appendingPathComponent("malformed-openapi.yaml") | ||
let configPath = docsDirectory.appendingPathComponent("openapi-generator-config.yaml") | ||
|
||
let arguments = [docPath.path(), "--config", configPath.path] | ||
|
||
let originalArguments = CommandLine.arguments | ||
defer { CommandLine.arguments = originalArguments } | ||
CommandLine.arguments = arguments | ||
|
||
let generator = try _GenerateOptions.parse(arguments) | ||
|
||
do { | ||
try await generator.runGenerator(outputDirectory: outputDirectory, pluginSource: nil, isDryRun: false) | ||
XCTFail("Expected to throw an error, but it did not throw") | ||
} catch let diagnostic as Diagnostic { | ||
XCTAssertEqual(diagnostic.severity, .error, "Expected diagnostic severity to be `.error`") | ||
} catch { XCTFail("Expected to throw a Diagnostic `.error`, but threw a different error: \(error)") } | ||
} | ||
} |