seratch / notion-sdk-jvm

A Notion SDK for Any JVM Language
https://developers.notion.com/
MIT License
137 stars 25 forks source link

Ability to remove a database property (=delete table column) #121

Open TWiStErRob opened 1 year ago

TWiStErRob commented 1 year ago

I'm trying to call this API via the SDK: https://developers.notion.com/reference/update-property-schema-object#remove-a-property

UpdateDatabaseRequest is the request as far as I can see this doesn't allow for deleting: https://github.com/seratch/notion-sdk-jvm/blob/258488aee4801d85db3b0dc4f36d5257960d698e/core/src/main/kotlin/notion/api/v1/request/databases/UpdateDatabaseRequest.kt#L11

I tried to cheat the Kotlin type system, but the request sent was properties: {}:

fun NotionClient.removeDatabaseProperty(databaseId: String, propertyName: String) {
    this.updateDatabase(
        databaseId = databaseId,
        properties = @Suppress("UNCHECKED_CAST") (mapOf(propertyName to null) as Map<String, DatabasePropertySchema>)
    )
}

As far as I see the only option is to properly support this by allowing null:

-val properties: Map<String, DatabasePropertySchema>? = null,
+val properties: Map<String, DatabasePropertySchema?>? = null,

and also here:

https://github.com/seratch/notion-sdk-jvm/blob/258488aee4801d85db3b0dc4f36d5257960d698e/core/src/main/kotlin/notion/api/v1/endpoint/DatabasesSupport.kt#L69

The SDK will also need to configure Gson to serialize nulls, but only for this specific map type, see for example https://stackoverflow.com/a/60807602/253468 how to create a custom serializer.