Skip to content

Generated client does not compile if UUID is redefined #40

@RemiBardon

Description

@RemiBardon

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions