- Notifications
You must be signed in to change notification settings - Fork 151
Retain operation level parameters over path level ones #183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
czechboy0 merged 8 commits into apple:main from arthurcro:improve-operation-all-parameters Aug 11, 2023
Merged
Changes from 3 commits
Commits
Show all changes
8 commits Select commit Hold shift + click to select a range
08eaa10 Retain operation level parameters over path level ones
arthurcro 4594843 Improve code style
arthurcro 669910b Add allParameters tests
arthurcro a325434 Merge branch 'main' into improve-operation-all-parameters
arthurcro 35c99ff Improve test and fix override order
arthurcro 3a5b182 Restore correct parameters ordering
arthurcro a0d04b2 Add test for allParameters ordering
arthurcro 76b6475 Merge branch 'main' into improve-operation-all-parameters
czechboy0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
112 changes: 112 additions & 0 deletions 112 Tests/OpenAPIGeneratorCoreTests/Translator/Operations/Test_OperationDescription.swift
This file contains hidden or 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,112 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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 OpenAPIKit30 | ||
| import XCTest | ||
| @testable import _OpenAPIGeneratorCore | ||
| | ||
| final class Test_OperationDescription: Test_Core { | ||
| | ||
| func testAllParameters_duplicates_retainOnlyOperationParameters() throws { | ||
| let allParameters = try _test( | ||
| """ | ||
| openapi: "3.0.0" | ||
| info: | ||
| title: "Test" | ||
| version: "1.0.0" | ||
| paths: | ||
| /system: | ||
| get: | ||
| description: This is a unit test. | ||
| responses: | ||
| '200': | ||
| description: Success | ||
| parameters: | ||
| - name: test | ||
| in: query | ||
| schema: | ||
| type: string | ||
| parameters: | ||
| - name: test | ||
| in: query | ||
| schema: | ||
| type: integer | ||
| """ | ||
| ) | ||
| | ||
| XCTAssertEqual( | ||
| allParameters, | ||
| [.b(OpenAPI.Parameter(name: "test", context: .query(required: false), schema: .integer))] | ||
| ) | ||
| } | ||
czechboy0 marked this conversation as resolved. Show resolved Hide resolved | ||
| | ||
| func testAllParameters_duplicates_keepsDuplicatesAtDifferentLocation() throws { | ||
| let allParameters = try _test( | ||
| """ | ||
| openapi: "3.0.0" | ||
| info: | ||
| title: "Test" | ||
| version: "1.0.0" | ||
| paths: | ||
| /system: | ||
| get: | ||
| description: This is a unit test. | ||
| responses: | ||
| '200': | ||
| description: Success | ||
| parameters: | ||
| - name: test | ||
| in: query | ||
| schema: | ||
| type: string | ||
| parameters: | ||
| - name: test | ||
| in: path | ||
| required: true | ||
| schema: | ||
| type: integer | ||
| """ | ||
| ) | ||
| | ||
| XCTAssertEqual( | ||
| allParameters, | ||
| [ | ||
| .b(OpenAPI.Parameter(name: "test", context: .path, schema: .integer)), | ||
| .b(OpenAPI.Parameter(name: "test", context: .query(required: false), schema: .string)) | ||
| ] | ||
| ) | ||
| } | ||
| | ||
| private func _test(_ yaml: String) throws -> [UnresolvedParameter] { | ||
| let document = try YamsParser() | ||
| .parseOpenAPI( | ||
| .init( | ||
| absolutePath: URL(fileURLWithPath: "/foo.yaml"), | ||
| contents: Data(yaml.utf8) | ||
| ), | ||
| config: .init(mode: .types), | ||
| diagnostics: PrintingDiagnosticCollector() | ||
| ) | ||
| | ||
| guard let operationDescription = try OperationDescription.all( | ||
| from: document.paths, | ||
| in: document.components, | ||
| asSwiftSafeName: { $0 } | ||
| ).first else { | ||
| XCTFail("Unable to retrieve the operation description.") | ||
| return [] | ||
| } | ||
| | ||
| return try operationDescription.allParameters | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.