Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial support for the Folksonomy Engine API #158

Open
8 of 13 tasks
Tracked by #218 ...
teolemon opened this issue May 7, 2021 · 11 comments · Fixed by #332
Open
8 of 13 tasks
Tracked by #218 ...

Add initial support for the Folksonomy Engine API #158

teolemon opened this issue May 7, 2021 · 11 comments · Fixed by #332

Comments

@teolemon
Copy link
Member

teolemon commented May 7, 2021

What

Add initial support for the Folksonomy Engine API (READ/WRITE), which will enable writing and reading custom information on products (like storing taste, franchises, whatever is possible…)

For more general info on the folksonomy engine

SDK auto-generation

We can autogenerate a SDK from https://api.folksonomy.openfoodfacts.org/openapi.json
https://medium.com/@rtlsilva/generating-dart-rest-api-client-libraries-using-openapi-generator-9b3dc517e68c

Routes

Screenshot

Capture d’écran 2021-11-27 à 14 23 00

Part of

  • Open Products Facts, New APIs
@teolemon
Copy link
Member Author

@monsieurtanuki
Copy link
Contributor

@teolemon I've just tried to use openapi-generator for Folksonomy.
Actually it generates a whole tree structure (here I asked to generate in api/folksonomy):
Capture d’écran 2021-12-16 à 14 18 16

Like a self-contained package. And I don't know how we could integrate that generated code into the existing project.

  • would we be better off starting a new dart project from scratch dedicated to folksonomy?
  • was the initial idea just to have the generator generate, then to steal the generated code as a once-in-a-lifetime start?
  • by the way for some reason the generated code is not null safe

@monsieurtanuki
Copy link
Contributor

Other aspect to consider: the rest of the off-dart library is based on "json serializable".
Using both "json serializable" and "openapi generator" on the same project may bring confusion.

Another remark: if folksonomy is actually included in the same project, we'd be better off with another dedicated file (folksonomy.dart) rather than openfoodfacts.dart and class OpenFoodAPIClient.

@teolemon
Copy link
Member Author

I have no issue making it a separate package. How good is the auto-generated code @monsieurtanuki ?
Also, if it's good, we could completely automate generation using GitHub Actions @M123-dev

@monsieurtanuki
Copy link
Contributor

Hi @teolemon!
Just to be sure: when you say a separate package you mean a separate project/library, or a separate folder inside off-dart?

Anyway, regardless, I can start locally a new project from scratch playing with openapi generator on folksonomy.

So far I could not play with the generated code that much because the code was not null safe compliant, which blocked compilation at an early stage. In a new project I'll have more freedom, regarding either the code generation parameters or the null safe status of the whole project.

Beyond the raw generated code, we'll probably have to add some fat.

Regarding an automated code generation, for the moment I copied the api json file to a local file, and then ran the generation. If we don't access the api json from an URL repeating the same process on the same local input file will result in the same generated files.

Work in progress...

@monsieurtanuki monsieurtanuki self-assigned this Dec 17, 2021
@M123-dev
Copy link
Member

We should somehow be able to generate it automatically, the only question is how good the generated code is. Especially something like null-safety is very important and as @monsieurtanuki pointed out there are some problems regarding that.

But yes I also don't think it makes sense to add this to the already big OpenFoodAPIClient. I would suggest that we create a separate package like openfoodfacts-folksonomy-dart and then we can go ahead and reference it from off-dart.

Somethink like platform dependet packages do it:

  • shared_preferences
    • shared_preferences_android
    • shared_preferences_ios

@teolemon
Copy link
Member Author

Currently enjoying the aftermath of my 3rd dose of vaccine 😖
@M123-dev @monsieurtanuki Should I create a separate repo ? is openfoodfacts-folksonomy-dart as suggested by @M123-dev ok ?

@M123-dev
Copy link
Member

Get well @teolemon, hope you feel better soon, let's just wait and see what @monsieurtanuki thinks of the idea and then we'll see.

monsieurtanuki added a commit to monsieurtanuki/openfoodfacts-dart that referenced this issue Dec 19, 2021
New files:
* `api_folksonomy_test.dart`: Tests around folksonomy
* `folksonomy.dart`: Client calls of the Folksonomy API (Open Food Facts)
* `KeyStats.dart`: Folksonomy: statistics around a tag key.
* `ProductList.dart`: Folksonomy: current value for a product and a tag key.
* `ProductStats.dart`: Folksonomy: statistics about the tag keys on a product.
* `ProductTag.dart`: Folksonomy product tag: for this barcode, that value is set for that key.

Impacted files:
* `HttpHelper.dart`: added "delete" and "put" requests
* `JsonHelper.dart`: added a helper method around timestamps
* `OpenFoodAPIConfiguration.dart`: added reference URIs for folksonomy
* `openfoodfacts.dart`: exported folksonomy files
* `UriHelper.dart`: added a helper method for folksonomy URIs
@monsieurtanuki
Copy link
Contributor

Hi guys! I hope @teolemon you feel better by now.

I've just coded folksonomy client in dart (cf. #332). It was so painful to use openapi generator that I tried to code it myself, and it was so easy that I continued.

I don't know that much about folksonomy and I don't know how relevant it would be to make a separate project, regarding the developers that would use it.

What I can say is:

  • it looks like folksonomy is designed to be very simple ("tag a custom key/value to a barcode")
  • I don't see how it should evolve dramatically - if the experiment around a custom key is successful it's probably going to be part of a new project
  • I mean, the code and its evolution looks easy to maintain, and btw it's what we're doing with off-dart - just maintain the field list (e.g. of Product) and let json serializable generate the painful coding
  • if we embed folksonomy in off-dart we probably give it more visibility
  • it's less maintenance

Less projects, less maintenance.
Less maintenance, less trouble.
Less trouble... less trouble.

monsieurtanuki added a commit to monsieurtanuki/openfoodfacts-dart that referenced this issue Dec 19, 2021
Impacted files:
* `api_folksonomy_test.dart`: removed unnecessary imports
* `HttpHelper.dart`: rolled back "delete" and "put" requests
monsieurtanuki added a commit to monsieurtanuki/openfoodfacts-dart that referenced this issue Dec 19, 2021
Impacted files:
* `api_saveProduct_test.dart`: unrelated test fine-tuning
monsieurtanuki added a commit to monsieurtanuki/openfoodfacts-dart that referenced this issue Dec 20, 2021
Impacted files:
* `api_folksonomy_test.dart`: refactored and added tests
* `folksonomy.dart`: fixed side-effects; refactored the comments
monsieurtanuki added a commit that referenced this issue Dec 20, 2021
New files:
* `api_folksonomy_test.dart`: Tests around folksonomy
* `api_saveProduct_test.dart`: unrelated test fine-tuning
* `folksonomy.dart`: Client calls of the Folksonomy API (Open Food Facts)
* `KeyStats.dart`: Folksonomy: statistics around a tag key.
* `ProductList.dart`: Folksonomy: current value for a product and a tag key.
* `ProductStats.dart`: Folksonomy: statistics about the tag keys on a product.
* `ProductTag.dart`: Folksonomy product tag: for this barcode, that value is set for that key.

Impacted files:
* `JsonHelper.dart`: added a helper method around timestamps
* `OpenFoodAPIConfiguration.dart`: added reference URIs for folksonomy
* `openfoodfacts.dart`: exported folksonomy files
* `UriHelper.dart`: added a helper method for folksonomy URIs
@monsieurtanuki monsieurtanuki linked a pull request Dec 20, 2021 that will close this issue
@monsieurtanuki
Copy link
Contributor

What's left after #332 are the methods around users and their private data, and the write methods.
Btw the TEST env does not seem to work for folksonomy; I tried api.folksonomy.openfoodfacts.net but with no success.

@M123-dev
Copy link
Member

I asked in the slack channel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

3 participants