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

TT-97 workaround for https://bugs.swift.org/browse/SR-1386 #159

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
32 changes: 16 additions & 16 deletions Specs/Petstore/generated/Swift/Sources/API.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

import Foundation

public struct Petstore {
public let version = "1.0.0"

public struct Config {
/// Whether to discard any errors when decoding optional properties
public static var safeOptionalDecoding = false

Expand All @@ -15,22 +16,21 @@ public struct Petstore {

/// Used to encode Dates when uses as string params
public static let dateEncodingFormatter = DateFormatter(formatString: "yyyy-MM-dd'T'HH:mm:ssZZZZZ")
}

public static let version = "1.0.0"

public enum Pets {}

public enum Server {

/** Test environment **/
public static func test(space: String = "main", version: String = "v1") -> String {
var url = "https://test.petstore.com/{version}/{space}"
url = url.replacingOccurrences(of: "{\(space)}", with: space)
url = url.replacingOccurrences(of: "{\(version)}", with: version)
return url
}
public enum Server {

/** Prod environment **/
public static let prod = "http://petstore.swagger.io/v1"
/** Test environment **/
public static func test(space: String = "main", version: String = "v1") -> String {
var url = "https://test.petstore.com/{version}/{space}"
url = url.replacingOccurrences(of: "{\(space)}", with: space)
url = url.replacingOccurrences(of: "{\(version)}", with: version)
return url
}

/** Prod environment **/
public static let prod = "http://petstore.swagger.io/v1"
}

/// Tags
public enum Pets {}
10 changes: 5 additions & 5 deletions Specs/Petstore/generated/Swift/Sources/Coding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ extension KeyedDecodingContainer {
do {
container = try nestedUnkeyedContainer(forKey: key)
} catch {
if Petstore.safeArrayDecoding {
if Config.safeArrayDecoding {
return array
} else {
throw error
Expand All @@ -134,7 +134,7 @@ extension KeyedDecodingContainer {
let element = try container.decode(T.self)
array.append(element)
} catch {
if Petstore.safeArrayDecoding {
if Config.safeArrayDecoding {
// hack to advance the current index
_ = try? container.decode(AnyCodable.self)
} else {
Expand All @@ -156,7 +156,7 @@ extension KeyedDecodingContainer {
}

fileprivate func decodeOptional<T>(_ closure: () throws -> T? ) throws -> T? {
if Petstore.safeOptionalDecoding {
if Config.safeOptionalDecoding {
do {
return try closure()
} catch {
Expand Down Expand Up @@ -306,7 +306,7 @@ extension DateDay {

extension Date {
func encode() -> Any {
return Petstore.dateEncodingFormatter.string(from: self)
return Config.dateEncodingFormatter.string(from: self)
}
}

Expand Down Expand Up @@ -334,7 +334,7 @@ extension Dictionary where Key == String, Value: RawRepresentable {
}
}

extension UUID {
extension Foundation.UUID {
func encode() -> Any {
return uuidString
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import Foundation

extension Petstore.Pets {
extension Pets {

/** Create a pet */
public enum CreatePets {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import Foundation

extension Petstore.Pets {
extension Pets {

/** List all pets */
public enum ListPets {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import Foundation

extension Petstore.Pets {
extension Pets {

/** Info for a specific pet */
public enum ShowPetById {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import Foundation

extension Petstore.Pets {
extension Pets {

/** Updates a pet in the store with form data */
public enum UpdatePetWithForm {
Expand Down
22 changes: 11 additions & 11 deletions Specs/PetstoreTest/generated/Swift/Sources/API.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
import Foundation

/** This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. */
public struct PetstoreTest {
public let version = "1.0.0"

public struct Config {
/// Whether to discard any errors when decoding optional properties
public static var safeOptionalDecoding = false

Expand All @@ -16,16 +17,15 @@ public struct PetstoreTest {

/// Used to encode Dates when uses as string params
public static let dateEncodingFormatter = DateFormatter(formatString: "yyyy-MM-dd'T'HH:mm:ssZZZZZ")
}

public static let version = "1.0.0"

public enum Fake {}
public enum Pet {}
public enum Store {}
public enum User {}

public enum Server {
public enum Server {

public static let main = "http://petstore.swagger.io:80/v2"
}
public static let main = "http://petstore.swagger.io:80/v2"
}

/// Tags
public enum Fake {}
public enum Pet {}
public enum Store {}
public enum User {}
10 changes: 5 additions & 5 deletions Specs/PetstoreTest/generated/Swift/Sources/Coding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ extension KeyedDecodingContainer {
do {
container = try nestedUnkeyedContainer(forKey: key)
} catch {
if PetstoreTest.safeArrayDecoding {
if Config.safeArrayDecoding {
return array
} else {
throw error
Expand All @@ -134,7 +134,7 @@ extension KeyedDecodingContainer {
let element = try container.decode(T.self)
array.append(element)
} catch {
if PetstoreTest.safeArrayDecoding {
if Config.safeArrayDecoding {
// hack to advance the current index
_ = try? container.decode(AnyCodable.self)
} else {
Expand All @@ -156,7 +156,7 @@ extension KeyedDecodingContainer {
}

fileprivate func decodeOptional<T>(_ closure: () throws -> T? ) throws -> T? {
if PetstoreTest.safeOptionalDecoding {
if Config.safeOptionalDecoding {
do {
return try closure()
} catch {
Expand Down Expand Up @@ -306,7 +306,7 @@ extension DateDay {

extension Date {
func encode() -> Any {
return PetstoreTest.dateEncodingFormatter.string(from: self)
return Config.dateEncodingFormatter.string(from: self)
}
}

Expand Down Expand Up @@ -334,7 +334,7 @@ extension Dictionary where Key == String, Value: RawRepresentable {
}
}

extension UUID {
extension Foundation.UUID {
func encode() -> Any {
return uuidString
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import Foundation

extension PetstoreTest.Fake {
extension Fake {

/** To test "client" model */
public enum TestClientModel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import Foundation

extension PetstoreTest.Fake {
extension Fake {

/** Fake endpoint for testing various parameters
假端點
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import Foundation

extension PetstoreTest.Fake {
extension Fake {

/** To test enum parameters */
public enum TestEnumParameters {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import Foundation

extension PetstoreTest.Pet {
extension Pet {

/** Add a new pet to the store */
public enum AddPet {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import Foundation

extension PetstoreTest.Pet {
extension Pet {

/** Deletes a pet */
public enum DeletePet {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import Foundation

extension PetstoreTest.Pet {
extension Pet {

/**
Finds Pets by status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import Foundation

extension PetstoreTest.Pet {
extension Pet {

/**
Finds Pets by tags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import Foundation

extension PetstoreTest.Pet {
extension Pet {

/**
Find pet by ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import Foundation

extension PetstoreTest.Pet {
extension Pet {

/** Update an existing pet */
public enum UpdatePet {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import Foundation

extension PetstoreTest.Pet {
extension Pet {

/** Updates a pet in the store with form data */
public enum UpdatePetWithForm {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import Foundation

extension PetstoreTest.Pet {
extension Pet {

/** uploads an image */
public enum UploadFile {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import Foundation

extension PetstoreTest.Store {
extension Store {

/**
Delete purchase order by ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import Foundation

extension PetstoreTest.Store {
extension Store {

/**
Returns pet inventories by status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import Foundation

extension PetstoreTest.Store {
extension Store {

/**
Find purchase order by ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import Foundation

extension PetstoreTest.Store {
extension Store {

/** Place an order for a pet */
public enum PlaceOrder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import Foundation

extension PetstoreTest.User {
extension User {

/**
Create user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import Foundation

extension PetstoreTest.User {
extension User {

/** Creates list of users with given input array */
public enum CreateUsersWithArrayInput {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import Foundation

extension PetstoreTest.User {
extension User {

/** Creates list of users with given input array */
public enum CreateUsersWithListInput {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import Foundation

extension PetstoreTest.User {
extension User {

/**
Delete user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import Foundation

extension PetstoreTest.User {
extension User {

/** Get user by user name */
public enum GetUserByName {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import Foundation

extension PetstoreTest.User {
extension User {

/** Logs user into the system */
public enum LoginUser {
Expand Down
Loading