Good-day guys, So i'm using openapi to generate so...
# android
p
Good-day guys, So i'm using openapi to generate some kotlin-client code, however i want to be able to use the models as Entity for android ROOM, is there a way to go around this? The models are data classes so i can't extend them
c
Not to my knowledge... When I used OpenAPI in the past we typically mapped the objects generated by the tool into ones we had had control over which would then be used to persist locally
Even if it is possible, I would be cautious as the spec changing could result in the entity changing which would require a migration anyway
p
Thanks for your response.... So this is somewhat correct?
Copy code
@Entity(tableName = "deliveries")
data class DeliveryEntity(val delivery: Delivery)
Where
Delivery
is the generated model @Cody Engel
c
I don't think
Delivery
is a valid data type for SQLite
But the basic idea is correct though... I would probably make the primary constructor a secondary one, the primary one would have the relevant values from
Delivery
as properties
So something like...
Copy code
@Entity(tableName = "person")
data class PersonEntity(val firstName: String, val lastName: String) {
    constructor(person: Person) : this(person.firstName, person.lastName)
}
p
I think for
Delivery
it can be an
@Embedded
type for SQLite, however i'm yet to try it out.. However, i think your solution is quite cleaner, aside that i have to write so much properties for the PersonEntity which already exist in Person...
c
Embedded would work, but it'd essentially put you in the same spot as just making the generated model an Entity. If the spec changes you'll need to do a database migration (or allow for the database to be cleared on upgrade).
p
@Cody Engel Alright, thanks much!
🙇🏻‍♂️ 1