Skip to content

Commit

Permalink
docs: Improved descriptions and schema adjustments for API references (
Browse files Browse the repository at this point in the history
…#10976)

<!-- IMPORTANT CHECKLIST
Make sure you've done all the following (You can delete the checklist
before submitting)
- [X] PR title is prefixed by one of the following: feat, fix, docs,
style, refactor, test, build, ci, chore, revert, l10n, taxonomy
- [X] Code is well documented
- [ ] Include unit tests for new functionality
- [X] Code passes GitHub workflow checks in your branch
- [X] If you have multiple commits please combine them into one commit
by squashing them.
- [X] Read and understood the [contribution
guidelines](https://github.com/openfoodfacts/openfoodfacts-server/blob/main/CONTRIBUTING.md)
-->
### What

This pull request updates the API reference documentation files
(docs/api/ref/schemas/**/*.yaml) to:

- Improve clarity and detail by adding descriptions and comments to
properties and references.
- Address potential issues related to rapidoc and generator errors.
- Make adjustments to schema definitions for better accuracy.
- Added recursive references for Ingredient and Nutrient schemas in
api.yml to fix generator errors.
- Reorganized the structure of the image.yaml, image_role.yaml,
image_urls.yaml, nutrients.yaml, product_base.yaml,
product_ecoscore.yaml, product_extended.yaml, and product_tags.yaml
files for better clarity and maintainability.
- Updated pattern properties and refactored the structure of these YAML
files to ensure consistency and correctness.

We believe these changes will enhance the usability and understanding of
the API reference for developers.

Please review the changes and let us know if you have any feedback.

### SCREENSHOT


![image](https://github.com/user-attachments/assets/9837bcaa-0893-4aaa-aac9-692f998345d9)

---------

Co-authored-by: Stéphane Gigandet <[email protected]>
  • Loading branch information
shinjigi and stephanegigandet authored Nov 8, 2024
1 parent 8a40a64 commit eeefdf0
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 112 deletions.
5 changes: 4 additions & 1 deletion docs/api/ref/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,11 @@ components:
Product:
$ref: ./schemas/product.yaml
Ingredient:
# Added to fix some generator errors on $ref
# Added to fix some generator errors on recursive $ref
$ref: "./schemas/ingredient.yaml#/components/schemas/Ingredient"
Nutrient:
# Added to fix some generator errors on recursive $ref
$ref: "./schemas/nutrients.yaml#/components/schemas/Nutrient"
parameters:
id:
schema:
Expand Down
72 changes: 39 additions & 33 deletions docs/api/ref/schemas/image.yaml
Original file line number Diff line number Diff line change
@@ -1,34 +1,40 @@
type: object
title: image
description: |
This object represent an image that was uploaded to a product.
"imgid" is an integer which is a sequential number unique to each picture.
properties:
sizes:
type: object
description: |
The available image sizes for the product (both reduced and full).
The reduced images are the ones with numbers as the key( 100, 200 etc)
while the full images have `full` as the key.
properties:
full:
$ref: ./image_size.yaml
patternProperties:
"(?<image_size>100|400)":
description: |
properties of thumbnail of size `image_size`.
**TODO** explain how to compute name
components:
schemas:
Sizes:
type: object
description: |
The available image sizes for the product (both reduced and full).
The reduced images are the ones with numbers as the key( 100, 200 etc)
while the full images have `full` as the key.
properties:
full:
$ref: ./image_size.yaml
patternProperties:
"(?<image_size>100|400)":
description: |
properties of thumbnail of size `image_size`.
**TODO** explain how to compute name
For real type: see description of property `full`.
(Put this way because of a [bug in rapidoc](https://github.com/rapi-doc/RapiDoc/issues/880))
type: string
uploaded_t:
type: string
example: "1457680652"
description: |
The time the image was uploaded (as unix timestamp).
uploader:
type: string
example: openfoodfacts-contributors
description: |
The contributor that uploaded the image.
For real type: see description of property `full`.
(Put this way because of a [bug in rapidoc](https://github.com/rapi-doc/RapiDoc/issues/880))
type: string

Image:
type: object
title: image
description: |
This object represent an image that was uploaded to a product.
"imgid" is an integer which is a sequential number unique to each picture.
properties:
sizes:
$ref: "#/components/schemas/Sizes"
uploaded_t:
type: string
example: "1457680652"
description: |
The time the image was uploaded (as unix timestamp).
uploader:
type: string
example: openfoodfacts-contributors
description: |
The contributor that uploaded the image.
20 changes: 12 additions & 8 deletions docs/api/ref/schemas/image_role.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
components:
schemas:
ImageSize:
$ref: ./image_size.yaml
ImageRole:
title: image_role
type: object
Expand Down Expand Up @@ -29,7 +27,10 @@ components:
# - type: "boolean"
# - type: "string"
# enum: ["true", "false"]
type: "null"
type:
- "string"
- "boolean"
- "null"
examples:
- null
- "false"
Expand All @@ -46,21 +47,24 @@ components:
while the full images have `full` as the key.
properties:
"100":
$ref: "#/components/schemas/ImageSize"
$ref: ./image_size.yaml
"200":
$ref: "#/components/schemas/ImageSize"
$ref: ./image_size.yaml
"400":
$ref: "#/components/schemas/ImageSize"
$ref: ./image_size.yaml
full:
$ref: "#/components/schemas/ImageSize"
$ref: ./image_size.yaml
white_magic:
#TODO: should be replaced by something like this once full supported by generator
#oneOf:
# - type: "null"
# - type: "boolean"
# - type: "string"
# enum: ["true", "false"]
type: "null"
type:
- "string"
- "boolean"
- "null"
examples:
- null
- "false"
Expand Down
29 changes: 24 additions & 5 deletions docs/api/ref/schemas/image_urls.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
type: object
patternProperties:
'(?<language_code>\w\w)':
type: string
description: url of the image for language `language_code`
components:
schemas:
ImageUrls:
type: object
patternProperties:
'(?<language_code>\w\w)':
type: string
description: url of the image for language `language_code`
SelectedImage:
type: object
description: URLs of thumbnails image of image of type `image_type`
properties:
display:
description: |
Thumbnail urls of product image (front) adapted to display on product page
$ref: "#/components/schemas/ImageUrls"
small:
description: |
Thumbnail urls of product image (front) adapted to display on product list page
$ref: "#/components/schemas/ImageUrls"
thumb:
description: |
Thumbnail urls of product image (front) in smallest format
$ref: "#/components/schemas/ImageUrls"
45 changes: 22 additions & 23 deletions docs/api/ref/schemas/nutrients.yaml
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
components:
schemas:
type: object
Nutrient:
type: object
title: nutrient
properties:
id:
type: string
description: id of the nutrient
name:
type: string
description: Name of the nutrient in the requested language
important:
type: boolean
description: Indicates if the nutrient is always shown on the nutrition facts table
display_in_edit_form:
type: boolean
description: Indicates if the nutrient should be shown in the nutrition facts edit form
unit:
description: Default unit of the nutrient
$ref: "./nutrient_unit.yaml"
nutrients:
$ref: "#/components/schemas/Nutrients"
Nutrients:
type: array
description: |
Nutrients and sub-nutrients of a product, with their name and default unit.
(e.g. saturated-fat is a sub-nutrient of fat).
items:
type: object
title: nutrient
properties:
id:
type: string
description: id of the nutrient
name:
type: string
description: Name of the nutrient in the requested language
important:
type: boolean
description: Indicates if the nutrient is always shown on the nutrition facts table
display_in_edit_form:
type: boolean
description: Indicates if the nutrient should be shown in the nutrition facts edit form
unit:
$ref: "./nutrient_unit.yaml"
nutrients:
type: array
items:
# self recursive
$ref: "#/components/schemas/Nutrients/items"
$ref: "#/components/schemas/Nutrient"
3 changes: 1 addition & 2 deletions docs/api/ref/schemas/product_base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ properties:
and
A series of mask for the barcode
It helps retrieve barcodes starting by
example: |
["code-13","3017620422xxx","301762042xxxx","30176204xxxxx","3017620xxxxxx","301762xxxxxxx","30176xxxxxxxx","3017xxxxxxxxx","301xxxxxxxxxx","30xxxxxxxxxxx","3xxxxxxxxxxxx"]
examples: ["code-13","3017620422xxx","301762042xxxx","30176204xxxxx","3017620xxxxxx","301762xxxxxxx","30176xxxxxxxx","3017xxxxxxxxx","301xxxxxxxxxx","30xxxxxxxxxxx","3xxxxxxxxxxxx"]
generic_name:
type: string
description: |
Expand Down
1 change: 1 addition & 0 deletions docs/api/ref/schemas/product_ecoscore.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ properties:
and complementary data of interest.
properties:
adjustments:
title: product_ecoscore_adjustments
type: object
properties:
origins_of_ingredients:
Expand Down
28 changes: 11 additions & 17 deletions docs/api/ref/schemas/product_extended.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,25 +101,19 @@ properties:
type: object
description: |
Detail of ingredients or processing that makes the products having Nova 3 or 4
properties:
"3":
description: |
Markers of level 3
type: array
items:
type: array
description: |
This array has two element for each marker.
One
items:
type: string
"4":
description: |
Markers of level 4
propertyNames:
description: Markers of level 3, 4, ...
type: integer
enum: [3, 4]
additionalProperties:
type: array
items:
type: array
# minItems: 2
# maxItems: 2
items:
# same as above
$ref: "#/properties/nova_groups_markers/properties/3/items"
description: This array has two elements for each marker. The first element is the tag type of the marker (e.g. "ingredients", "additives", "categories"), and the second is the tag id in the taxonomy (e.g. "en:e471")
type: string

nucleotides_tags:
type: array
Expand Down
28 changes: 8 additions & 20 deletions docs/api/ref/schemas/product_images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ properties:
type: object
title: product_images_properties
properties:
1:
$ref: ./image.yaml
front:
$ref: "./image_role.yaml#/components/schemas/ImageRole"

additionalProperties:
$ref: "./image.yaml#/components/schemas/Image"
propertyNames:
type: integer

patternProperties:
'(?<imgid>\d+)':
description: |
Expand Down Expand Up @@ -50,24 +54,8 @@ properties:
This is very handy if you display the product to users.
properties:
front:
type: object
description: URLs of thumbnails image of image of type `image_type`
properties:
display:
description: |
Thumbnail urls of product image (front) adapted to display on product page
type: object
$ref: "image_urls.yaml"
small:
description: |
Thumbnail urls of product image (front) adapted to display on product list page
type: object
$ref: "image_urls.yaml"
thumb:
description: |
Thumbnail urls of product image (front) in smallest format
type: object
$ref: "image_urls.yaml"
$ref: "./image_urls.yaml#/components/schemas/SelectedImage"

patternProperties:
"(?<image_type>front|packaging|ingredients|nutrition|other)":
description: |
Expand Down
8 changes: 5 additions & 3 deletions docs/api/ref/schemas/product_tags.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ properties:
type: array
items:
type: string
example: ["2016-03-11", "2016-03", "2016"]
examples:
- - "2016-03-11"
- "2016-03"
- "2016"

manufacturing_places:
type: string
Expand All @@ -106,8 +109,7 @@ properties:
manufacturing_places_tags:
type: array
items:
type: object
title: manufacturing_places_tag
type: "string"
nova_groups_tags:
type: array
items:
Expand Down

0 comments on commit eeefdf0

Please sign in to comment.