Skip to content

Commit

Permalink
fix: add unit to output of /cgi/nutrients.pl #9735
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanegigandet committed Feb 5, 2024
1 parent cdcdf05 commit 8427819
Show file tree
Hide file tree
Showing 7 changed files with 455 additions and 22 deletions.
4 changes: 4 additions & 0 deletions cgi/nutrients.pl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
if (defined $name) {
$current_ref->{name} = $name;
}
my $unit = get_property("nutrients", "zz:$onid", "unit:en") // 'g';
if (defined $unit) {
$current_ref->{unit} = $unit;
}

my $prefix_length = 0;
if ($nid =~ s/^--//g) {
Expand Down
54 changes: 33 additions & 21 deletions docs/api/ref/api-v3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,8 @@ paths:
schema:
type: string
example: '3017620422003'
- schema:
type: string
in: query
name: lc
description: '2 letter code of the language of the interface. Used for localizing some fields in returned values (e.g. knowledge panels). If not passed, the language may be inferred by the country of the user (passed through the cc field or inferred by the IP address).'
- schema:
type: string
in: query
name: cc
description: '2 letter code of the country of the user. Used for localizing some fields in returned values (e.g. knowledge panels). If not passed, the country may be inferred by the IP address of the request.'
- $ref: '#/components/parameters/cc'
- $ref: '#/components/parameters/lc'
- schema:
type: string
in: query
Expand Down Expand Up @@ -265,23 +257,14 @@ paths:
If a string is passed, an additional sort is done to put first suggestions that start with the string, followed by suggestions with a word that start with the string, and then suggestions that contain the string anywhere.
parameters:
- $ref: ./api.yml#/components/parameters/tagtype
- schema:
type: string
example: en
in: query
name: lc
description: 2 letter code of the language used for suggestions and for matching the input string
- $ref: '#/components/parameters/cc'
- $ref: '#/components/parameters/lc'
- schema:
type: string
example: pe
in: query
name: string
description: 'Optional string used to filter suggestions (useful for autocomplete). If passed, suggestions starting with the string will be returned first, followed by suggestions matching the string at the beginning of a word, and suggestions matching the string inside a word.'
- schema:
type: string
in: query
name: cc
description: '2 letter country code, used to return popular packaging shapes and materials for products sold in the country'
- schema:
type: string
example: yougurts
Expand All @@ -306,6 +289,8 @@ paths:
description: Alias for the "string" parameter provided for backward compatibility. "string" takes precedence.
'/api/v3/tag/{tagtype}/{tag_or_tagid}':
parameters:
- $ref: '#/components/parameters/cc'
- $ref: '#/components/parameters/lc'
- schema:
type: string
example: categories
Expand Down Expand Up @@ -364,6 +349,33 @@ paths:
Categories:
- Packaging stats for a category
components:
schemas:
parameters:
cc:
schema:
type: string
example: 'us'
in: query
name: cc
required: false
description: '2 letter code of the country of the user. Used for localizing some fields in returned values (e.g. knowledge panels). If not passed, the country may be inferred by the IP address of the request.'
lc:
schema:
type: string
example: 'fr'
in: query
name: lc
required: false
description: '2 letter code of the language of the user. Used for localizing some fields in returned values (e.g. knowledge panels). If not passed, the language may be inferred by the Accept-Language header of the request.'
code:
schema:
type: string
example: '4251105501381'
in: query
name: code
description: Barcode of the product
required: true
tags:
- name: Read Requests
- name: Write Requests
35 changes: 34 additions & 1 deletion docs/api/ref/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,24 @@ paths:
all packaging_shapes containing "fe" will be returned.
This is useful if you have a search in your application,
for a specific product field.
/cgi/nutrients.pl:
get:
summary: Get a nested list of nutrients that can be displayed in the nutrition facts table for a specific country and language
tags:
- Read Requests
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: ./responses/get_nutrients.yaml
operationId: get-cgi-nutrients.pl
parameters:
- $ref: '#/components/parameters/cc'
- $ref: '#/components/parameters/lc'
description: |
Used to display the nutrition facts table of a product, or to display a form to input those nutrition facts.
components:
schemas:
"Product-Base":
Expand Down Expand Up @@ -327,6 +345,22 @@ components:
in: query
name: id
required: true
cc:
schema:
type: string
example: 'us'
in: query
name: cc
required: false
description: '2 letter code of the country of the user. Used for localizing some fields in returned values (e.g. knowledge panels). If not passed, the country may be inferred by the IP address of the request.'
lc:
schema:
type: string
example: 'fr'
in: query
name: lc
required: false
description: '2 letter code of the language of the user. Used for localizing some fields in returned values (e.g. knowledge panels). If not passed, the language may be inferred by the Accept-Language header of the request.'
code:
schema:
type: string
Expand Down Expand Up @@ -363,7 +397,6 @@ components:
in: query
name: angle
required: true

sort_by:
schema:
type: string
Expand Down
1 change: 1 addition & 0 deletions docs/api/ref/responses/get_nutrients.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$ref: ../schemas/nutrients.yaml
Loading

0 comments on commit 8427819

Please sign in to comment.