Skip to content
New issue

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

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

Already on GitHub? # to your account

docs: YAML syntax in the data schema files #11220

Closed
wants to merge 1 commit into 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.

@jforget
Copy link
Contributor Author

jforget commented Jan 15, 2025

Please disregard this pull request.

After checking the YAML files with Perl module YAML.pm 1.31, I havec
checked them again with Perl module YAML::XS v0.902.0. All files check
OK, even api.yaml, ecoscore-country-code.yaml,
product-nutriscore.yaml and product-nutristion.yaml.

Therefore, I will switch to YAML::XS and close the pull request.

Sorry for the noise.

@jforget jforget closed this Jan 15, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
📚 Documentation Documentation issues improve the project for everyone. 📚 OpenAPI
Development

Successfully merging this pull request may close these issues.

2 participants