bow-swift / bow-openapi

🌐 Functional HTTP client generator from an OpenAPI/Swagger specification.
https://openapi.bow-swift.io
Other
52 stars 1 forks source link

Generated client does not compile if UUID is redefined #40

Open RemiBardon opened 3 years ago

RemiBardon commented 3 years ago

Problem

For readability purposes, I redefined UUID in my OpenAPI 3 schemas.

components:
    schemas:
        UUID:
            description: A `UUID` (or `GUID`).
            type: string
            format: uuid
            example: ad959e79-55c3-4445-8c51-a74b6d52691a

This generates:

//
//  UUID.swift
//
//  Generated by bow-openapi
//  Copyright © 2021 Bow Authors. All rights reserved.
//

import Foundation

/// A `UUID` (or `GUID`).
public struct UUID: Codable {

}

(Note the '`' character not escaped by swagger-codegen by the way)

The problem is that you add an extension to Foundation's UUID in Extensions.swift:

extension UUID: JSONEncodable {
    func encodeToJSON() -> Any {
        return self.uuidString
    }
}

But due to the local redeclaration of UUID, this extension points to our public struct UUID: Codable. Therefore it generates a compilation error: Value of type 'UUID' has no member 'uuidString'.

Proposed solution

Do not redefine a type: string with format: uuid, and use Foundation's UUID instead.

Additional remarks

RemiBardon commented 3 years ago

For the moment, I'll change my UUID into an ID 💁🏻‍♂️