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

docs: YAML syntax in the data schema files #11220

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jforget
Copy link
Contributor

@jforget jforget commented Jan 9, 2025

docs: YAML syntax in the data schema files

This pull request applies to files

  docs/api/ref/schemas/api.yaml
  docs/api/ref/schemas/ecoscore-country-code.yaml
  docs/api/ref/schemas/product-nutriscore.yaml
  docs/api/ref/schemas/product-nutristion.yaml

Multi-line string

The api.yaml file contains the following specification:

components:
  securitySchemes:
    [ ... cut ... ]
    userAgentAuth:
      description: Authentication using User-Agent header
        User-Agent header in the format 'app_name/app_version (email)'
      type: apiKey
      in: header
      name: User-Agent

The description of userAgentAuth spans two lines, so it should be written as:

components:
  securitySchemes:
    [ ... cut ... ]
    userAgentAuth:
      description: |
        Authentication using User-Agent header
        User-Agent header in the format 'app_name/app_version (email)'
      type: apiKey
      in: header
      name: User-Agent

Array in JSON syntax

In a YAML file, an array can use the YAML syntax, i.e. each item on a separate line, with a dash prefix at a constant indent level, or use the JSON syntax, i.e. all items separated with a comma and the whole list enclose dwithin square brackets. Yet, with the YAML.pm Perl module, a JSON-syntax list should be on a single line. A multi-line JSON syntax triggers an error.

Therefore the lists:

components:
  schemas:
    EcoscoreCountryCode:
      type: string
      enum:
        [
          "ad",
          "al",
          "at",
          [ ... cut ... ]
          "world",
          "xk",
        ]

and

        id:
          type: string
          examples:
            [
              "energy",
              "sugars",
              "saturated_fat",
              "salt",
              "fiber",
              "fruits_vegetables_legumes",
            ]

and

        type: string
        enum:
          [
            "公斤",
            "公升",
            "kg",
            "кг",
            "l",
            "л",
            [ ... cut ... ]
            "gpg",
          ]

should be written as a single JSON line (rather cumbersome in two cases, not tested in the third case)

        id:
          type: string
          examples: [ "energy", "sugars", "saturated_fat", "salt", "fiber", "fruits_vegetables_legumes" ]

or with the YAML syntax (better):

components:
  schemas:
    EcoscoreCountryCode:
      type: string
      enum:
        - "ad"
        - "al"
        - "at"
        [ ... cut ... ]
        - "world"
        - "xk"

and

        id:
          type: string
          examples:
            - "energy"
            - "sugars"
            - "saturated_fat"
            - "salt"
            - "fiber"
            - "fruits_vegetables_legumes"

and

        type: string
        enum:
          - "公斤"
          - "公升"
          - "kg"
          - "кг"
          - "l"
          - "л"
          [ ... cut ... ]
          - "gpg"

Happy new year!

==========================================

This pull request applies to files

```
  docs/api/ref/schemas/api.yaml
  docs/api/ref/schemas/ecoscore-country-code.yaml
  docs/api/ref/schemas/product-nutriscore.yaml
  docs/api/ref/schemas/product-nutristion.yaml
```

Multi-line string
-----------------

The `api.yaml` file contains the following specification:

```
components:
  securitySchemes:
    [ ... cut ... ]
    userAgentAuth:
      description: Authentication using User-Agent header
        User-Agent header in the format 'app_name/app_version (email)'
      type: apiKey
      in: header
      name: User-Agent
```

The description of `userAgentAuth` spans two lines, so it should be written as:

```
components:
  securitySchemes:
    [ ... cut ... ]
    userAgentAuth:
      description: |
        Authentication using User-Agent header
        User-Agent header in the format 'app_name/app_version (email)'
      type: apiKey
      in: header
      name: User-Agent
```

Array in JSON syntax
--------------------

In a YAML file, an array can use  the YAML syntax, i.e. each item on a
separate line, with  a dash prefix at a constant  indent level, or use
the JSON syntax,  i.e. all items separated with a  comma and the whole
list enclose  dwithin square  brackets. Yet,  with the  `YAML.pm` Perl
module, a  JSON-syntax list should be  on a single line.  A multi-line
JSON syntax triggers an error.

Therefore the lists:

```
components:
  schemas:
    EcoscoreCountryCode:
      type: string
      enum:
        [
          "ad",
          "al",
          "at",
          [ ... cut ... ]
          "world",
          "xk",
        ]
```

and

```
        id:
          type: string
          examples:
            [
              "energy",
              "sugars",
              "saturated_fat",
              "salt",
              "fiber",
              "fruits_vegetables_legumes",
            ]
```

and

```
        type: string
        enum:
          [
            "公斤",
            "公升",
            "kg",
            "кг",
            "l",
            "л",
            [ ... cut ... ]
            "gpg",
          ]

```

should be  written as  a single  JSON line  (rather cumbersome  in two
cases, not tested in the third case)

```
        id:
          type: string
          examples: [ "energy", "sugars", "saturated_fat", "salt", "fiber", "fruits_vegetables_legumes" ]
```

or with the YAML syntax (better):

```
components:
  schemas:
    EcoscoreCountryCode:
      type: string
      enum:
        - "ad"
        - "al"
        - "at"
        [ ... cut ... ]
        - "world"
        - "xk"
```

and

```
        id:
          type: string
          examples:
            - "energy"
            - "sugars"
            - "saturated_fat"
            - "salt"
            - "fiber"
            - "fruits_vegetables_legumes"
```

and

```
        type: string
        enum:
          - "公斤"
          - "公升"
          - "kg"
          - "кг"
          - "l"
          - "л"
          [ ... cut ... ]
          - "gpg"
```

Happy new year!
@jforget jforget requested a review from a team as a code owner January 9, 2025 07:35
@github-actions github-actions bot added 📚 Documentation Documentation issues improve the project for everyone. 📚 OpenAPI labels Jan 9, 2025
Copy link

sonarqubecloud bot commented Jan 9, 2025

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 49.22%. Comparing base (0588976) to head (2b7c703).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #11220   +/-   ##
=======================================
  Coverage   49.22%   49.22%           
=======================================
  Files          78       78           
  Lines       22405    22405           
  Branches     5374     5374           
=======================================
  Hits        11028    11028           
  Misses      10020    10020           
  Partials     1357     1357           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📚 Documentation Documentation issues improve the project for everyone. 📚 OpenAPI
Development

Successfully merging this pull request may close these issues.

2 participants