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

Generated client does not compile if UUID is redefined #40

Open
RemiBardon opened this issue Jan 24, 2021 · 1 comment
Open

Generated client does not compile if UUID is redefined #40

RemiBardon opened this issue Jan 24, 2021 · 1 comment

Comments

@RemiBardon
Copy link

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

  • There may be a problem with Date, which uses DateFormatter's func string(from date: Date) -> String. I defined DateTime, so I don't have the problem.
  • There could be problems with other Foundation types.
@RemiBardon
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant