Skip to content

Conversation

crazytonyli
Copy link
Contributor

@crazytonyli crazytonyli commented Apr 11, 2024

Use #[uniffi(default = None)] to save us from passing nil to initialiser. I feel like we talked about default values before, but I can't remember the exact conversation. Let me know if you have any concerns.

Here is the generated Swift code
public struct UserCreateParams {
    /**
     * Login name for the user.
     */
    public let username: String
    /**
     * The email address for the user.
     */
    public let email: String
    /**
     * Password for the user (never included).
     */
    public let password: String
    /**
     * Display name for the user.
     */
    public let name: String?
    /**
     * First name for the user.
     */
    public let firstName: String?
    /**
     * Last name for the user.
     */
    public let lastName: String?
    /**
     * URL of the user.
     */
    public let url: String?
    /**
     * Description of the user.
     */
    public let description: String?
    /**
     * Locale for the user.
     * One of: , `en_US`
     */
    public let locale: String?
    /**
     * The nickname for the user.
     */
    public let nickname: String?
    /**
     * An alphanumeric identifier for the user.
     */
    public let slug: String?
    /**
     * Roles assigned to the user.
     */
    public let roles: [String]
    /**
     * Meta fields.
     */
    public let meta: String?

    // Default memberwise initializers are never public by default, so we
    // declare one manually.
    public init(
        /**
         * Login name for the user.
         */username: String, 
        /**
         * The email address for the user.
         */email: String, 
        /**
         * Password for the user (never included).
         */password: String, 
        /**
         * Display name for the user.
         */name: String? = nil, 
        /**
         * First name for the user.
         */firstName: String? = nil, 
        /**
         * Last name for the user.
         */lastName: String? = nil, 
        /**
         * URL of the user.
         */url: String? = nil, 
        /**
         * Description of the user.
         */description: String? = nil, 
        /**
         * Locale for the user.
         * One of: , `en_US`
         */locale: String? = nil, 
        /**
         * The nickname for the user.
         */nickname: String? = nil, 
        /**
         * An alphanumeric identifier for the user.
         */slug: String? = nil, 
        /**
         * Roles assigned to the user.
         */roles: [String], 
        /**
         * Meta fields.
         */meta: String? = nil) {
        self.username = username
        self.email = email
        self.password = password
        self.name = name
        self.firstName = firstName
        self.lastName = lastName
        self.url = url
        self.description = description
        self.locale = locale
        self.nickname = nickname
        self.slug = slug
        self.roles = roles
        self.meta = meta
    }
}
Here is the generated Kotlin code
data class UserCreateParams (
    /**
     * Login name for the user.
     */
    val `username`: kotlin.String,
    /**
     * The email address for the user.
     */
    val `email`: kotlin.String,
    /**
     * Password for the user (never included).
     */
    val `password`: kotlin.String,
    /**
     * Display name for the user.
     */
    val `name`: kotlin.String? = null,
    /**
     * First name for the user.
     */
    val `firstName`: kotlin.String? = null,
    /**
     * Last name for the user.
     */
    val `lastName`: kotlin.String? = null,
    /**
     * URL of the user.
     */
    val `url`: kotlin.String? = null,
    /**
     * Description of the user.
     */
    val `description`: kotlin.String? = null,
    /**
     * Locale for the user.
     * One of: , `en_US`
     */
    val `locale`: kotlin.String? = null,
    /**
     * The nickname for the user.
     */
    val `nickname`: kotlin.String? = null,
    /**
     * An alphanumeric identifier for the user.
     */
    val `slug`: kotlin.String? = null,
    /**
     * Roles assigned to the user.
     */
    val `roles`: List<kotlin.String>,
    /**
     * Meta fields.
     */
    val `meta`: kotlin.String? = null
) {

    companion object
}

Copy link
Contributor

@jkmassel jkmassel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If UniFFI can do this for us, I think we should let it!

@crazytonyli crazytonyli force-pushed the swift-package-users-defaults-to-nil branch from c76e549 to e391374 Compare April 16, 2024 22:11
@crazytonyli crazytonyli changed the base branch from swift-package-users to trunk April 16, 2024 22:12
@crazytonyli crazytonyli enabled auto-merge (squash) April 16, 2024 22:12
@crazytonyli crazytonyli merged commit a67171e into trunk Apr 16, 2024
@crazytonyli crazytonyli deleted the swift-package-users-defaults-to-nil branch April 16, 2024 22:16
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

Successfully merging this pull request may close these issues.

2 participants