-
Notifications
You must be signed in to change notification settings - Fork 49
Refactor URIDecoder/URIParser to improve handling of the deepObject style #127
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 11 commits into
apple:main
from
czechboy0:hd-uri-decoder-refactor-deepObject
Nov 21, 2024
Merged
Changes from 4 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4d6716f
Refactor URIDecoder/URIParser to improve handling of the deepObject s…
czechboy0 5b65724
Fix build errors
czechboy0 49eef87
More polish, added doc comments to the new code
czechboy0 c3d9ec3
Doc fixes
czechboy0 15d3124
Update Sources/OpenAPIRuntime/URICoder/Common/URIParsedTypes.swift
czechboy0 9cf9280
Update Sources/OpenAPIRuntime/URICoder/Common/URIParsedTypes.swift
czechboy0 78da857
Update Sources/OpenAPIRuntime/URICoder/Decoding/URIValueFromNodeDecod…
czechboy0 570666b
Merge branch 'main' into hd-uri-decoder-refactor-deepObject
czechboy0 331046f
PR feedback
czechboy0 66668b2
Merge branch 'main' into hd-uri-decoder-refactor-deepObject
czechboy0 1ea806a
PR feedback
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
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
22 changes: 22 additions & 0 deletions
22
Sources/OpenAPIRuntime/URICoder/Common/URIDecodedTypes.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,22 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the SwiftOpenAPIGenerator open source project | ||
// | ||
// Copyright (c) 2024 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
/// A primitive value produced by `URIValueFromNodeDecoder`. | ||
typealias URIDecodedPrimitive = URIParsedValue | ||
|
||
/// An array value produced by `URIValueFromNodeDecoder`. | ||
typealias URIDecodedArray = URIParsedValueArray | ||
|
||
/// A dictionary value produced by `URIValueFromNodeDecoder`. | ||
typealias URIDecodedDictionary = [Substring: URIParsedValueArray] |
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
27 changes: 0 additions & 27 deletions
27
Sources/OpenAPIRuntime/URICoder/Common/URIParsedNode.swift
This file was deleted.
Oops, something went wrong.
90 changes: 90 additions & 0 deletions
90
Sources/OpenAPIRuntime/URICoder/Common/URIParsedTypes.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,90 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 Foundation | ||
|
||
/// A component of a `URIParsedKey`. | ||
typealias URIParsedKeyComponent = String.SubSequence | ||
|
||
/// A parsed key for a parsed value. | ||
/// | ||
/// For example, `foo=bar` in a `form` string would parse the key as `foo` (single component). | ||
/// In an unexploded `form` string `root=foo,bar`, the key would be `root/foo` (two components). | ||
/// In a `simple` string `bar`, the key would be empty (0 components). | ||
struct URIParsedKey: Hashable { | ||
|
||
/// The individual string components. | ||
let components: [URIParsedKeyComponent] | ||
/// Creates a new parsed key. | ||
/// - Parameter components: The key components. | ||
init(_ components: [URIParsedKeyComponent]) { self.components = components } | ||
czechboy0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/// A new empty key. | ||
static var empty: Self { .init([]) } | ||
} | ||
|
||
/// A primitive value produced by `URIParser`. | ||
typealias URIParsedValue = String.SubSequence | ||
|
||
/// An array of primitive values produced by `URIParser`. | ||
typealias URIParsedValueArray = [URIParsedValue] | ||
czechboy0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/// A key-value produced by `URIParser`. | ||
struct URIParsedPair: Equatable { | ||
|
||
/// The key of the pair. | ||
/// | ||
/// In `foo=bar`, `foo` is the key. | ||
var key: URIParsedKey | ||
|
||
/// The value of the pair. | ||
/// | ||
/// In `foo=bar`, `bar` is the value. | ||
var value: URIParsedValue | ||
} | ||
|
||
/// An array of key-value pairs produced by `URIParser`. | ||
typealias URIParsedPairArray = [URIParsedPair] | ||
czechboy0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// MARK: - Extensions | ||
|
||
extension URIParsedKey: CustomStringConvertible { | ||
/// A textual representation of this instance. | ||
/// | ||
/// Calling this property directly is discouraged. Instead, convert an | ||
/// instance of any type to a string by using the `String(describing:)` | ||
/// initializer. This initializer works with any type, and uses the custom | ||
/// `description` property for types that conform to | ||
/// `CustomStringConvertible`: | ||
/// | ||
/// struct Point: CustomStringConvertible { | ||
/// let x: Int, y: Int | ||
/// | ||
/// var description: String { | ||
/// return "(\(x), \(y))" | ||
/// } | ||
/// } | ||
/// | ||
/// let p = Point(x: 21, y: 30) | ||
/// let s = String(describing: p) | ||
/// print(s) | ||
/// // Prints "(21, 30)" | ||
/// | ||
/// The conversion of `p` to a string in the assignment to `s` uses the | ||
/// `Point` type's `description` property. | ||
var description: String { | ||
czechboy0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if components.isEmpty { return "<empty>" } | ||
return components.joined(separator: "/") | ||
} | ||
} |
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
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
Oops, something went wrong.
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.