Skip to content
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

Introduce URIEncoder and URIDecoder types #41

Merged
merged 20 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
238 changes: 0 additions & 238 deletions Sources/OpenAPIRuntime/Coding/URISerializer.swift

This file was deleted.

36 changes: 36 additions & 0 deletions Sources/OpenAPIRuntime/URICoder/Common/URICodeCodingKey.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//===----------------------------------------------------------------------===//
//
// 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

/// The coding key.
struct URICoderCodingKey: CodingKey {
var stringValue: String
var intValue: Int?

init(stringValue: String) {
self.stringValue = stringValue
self.intValue = nil
}

init(intValue: Int) {
self.stringValue = "\(intValue)"
self.intValue = intValue
}

init(_ key: some CodingKey) {
self.stringValue = key.stringValue
self.intValue = key.intValue
}
}
72 changes: 72 additions & 0 deletions Sources/OpenAPIRuntime/URICoder/Common/URICoderConfiguration.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//===----------------------------------------------------------------------===//
//
// 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 bag of configuration values used by the URI parser and serializer.
struct URICoderConfiguration {

// TODO: Wrap in a struct, as this will grow.
// https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#style-values
enum Style {
case simple
case form
}

var style: Style
var explode: Bool
var spaceEscapingCharacter: String

private init(style: Style, explode: Bool, spaceEscapingCharacter: String) {
self.style = style
self.explode = explode
self.spaceEscapingCharacter = spaceEscapingCharacter
}

static let formExplode: Self = .init(
style: .form,
explode: true,
spaceEscapingCharacter: "%20"
czechboy0 marked this conversation as resolved.
Show resolved Hide resolved
)

static let formUnexplode: Self = .init(
style: .form,
explode: false,
spaceEscapingCharacter: "%20"
)

static let simpleExplode: Self = .init(
style: .simple,
explode: true,
spaceEscapingCharacter: "%20"
)

static let simpleUnexplode: Self = .init(
style: .simple,
explode: false,
spaceEscapingCharacter: "%20"
)

static let formDataExplode: Self = .init(
style: .form,
explode: true,
spaceEscapingCharacter: "+"
)

static let formDataUnexplode: Self = .init(
style: .form,
explode: false,
spaceEscapingCharacter: "+"
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import Foundation

enum URINode: Equatable {
enum URIEncodedNode: Equatable {

case unset
case primitive(Primitive)
Expand All @@ -29,7 +29,7 @@ enum URINode: Equatable {
}
}

extension URINode {
extension URIEncodedNode {

enum InsertionError: Swift.Error {
case settingPrimitiveValueAgain
Expand Down
20 changes: 20 additions & 0 deletions Sources/OpenAPIRuntime/URICoder/Common/URIParsedNode.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===----------------------------------------------------------------------===//
//
// 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

typealias URIParsedKey = String.SubSequence
typealias URIParsedValue = String.SubSequence
typealias URIParsedValueArray = [URIParsedValue]
typealias URIParsedNode = [URIParsedKey: URIParsedValueArray]
Loading