You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My hacky usage that I copied into my Kotlin Multiplatform [desktop, web, iOS, Android] project looks something like:
val scope = rememberCoroutineScope()
LaunchedEffect(barcode) {
try {
val product = scope.async {
openFoodFactsApi.productById(barcode)
}.await().product
With this one route I implemented by hand, obviously needs to be generated:
classHttpResponseException(valresponse:HttpResponse) : Exception(response.toString())
classOpenFoodFactsApi(privatevalclient:HttpClient) {
privateval base ="https://world.openfoodfacts.org/api/v3"suspendfunproductById(id:String): PatchApiV3ProductBarcode200Response {
val response:HttpResponse= client.get("$base/product/$id.json")
println("status = ${response.status}")
if (response.status.isSuccess())
return response.body()
throwHttpResponseException(response)
}
}
And yes I know PatchApiV3ProductBarcode200Response is the wrong type but actually it's the right type based on what GET returns. Happily using the code generated code with some find/replace focusing on switching to kotlinx for marshalling and avoiding the square moshi stuff. Writing it by hand would be painful! - All those attributes
Lots of weirdness from your OpenAPI schema. @teolemon not sure how you want to proceed. Like, for example, there's a bunch of commits where I've need to replace ints with floats like in your nutrition_score_warning_fruits_vegetables_nuts_estimate_from_ingredients_value& others.
The text was updated successfully, but these errors were encountered:
Related #3
Currently just copypasta around, but if there's interest then will create a new OpenAPI generator for ktor. For my WiP see https://github.com/SamuelMarks/openfoodfacts-kotlin-openapi
My hacky usage that I copied into my Kotlin Multiplatform [desktop, web, iOS, Android] project looks something like:
With this one route I implemented by hand, obviously needs to be generated:
And yes I know
PatchApiV3ProductBarcode200Response
is the wrong type but actually it's the right type based on what GET returns. Happily using the code generated code with some find/replace focusing on switching to kotlinx for marshalling and avoiding the square moshi stuff. Writing it by hand would be painful! - All those attributesLots of weirdness from your OpenAPI schema. @teolemon not sure how you want to proceed. Like, for example, there's a bunch of commits where I've need to replace
int
s withfloat
s like in yournutrition_score_warning_fruits_vegetables_nuts_estimate_from_ingredients_value
& others.The text was updated successfully, but these errors were encountered: