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

Invalid examples syntax in the filters parameter #140

Closed
datsirul opened this issue Jul 10, 2024 · 4 comments
Closed

Invalid examples syntax in the filters parameter #140

datsirul opened this issue Jul 10, 2024 · 4 comments

Comments

@datsirul
Copy link
Contributor

The model endpoint files define the filters parameter with an examples such as:

Existing Syntax:

examples:
  -   - variantcaller:GATK4.0

or

examples:
  -   - NCIT:C3222
  -   - OBI:0100058
      - NCIT:C4813

Here are all the locations this invalid syntax can be found:
https://github.com/search?q=repo%3Aga4gh-beacon%2Fbeacon-v2%20%22-%20%20%20-%22&type=code

Corrected Syntax:
The correct syntax for an array example should be:

example: [variantcaller:GATK4.0]

or

example: [NCIT:C3222, OBI:0100058, NCIT:C4813]

Reference:
OpenAPI Specification - Adding Examples

Note:
After fixing the .yaml files, the .json should be fixed as well by running the schema conversion script located in the bin folder.

@mbaudis
Copy link
Member

mbaudis commented Jul 10, 2024 via email

@datsirul
Copy link
Contributor Author

Thank you @mbaudis.
Some context - this was identified as part of the work we're doing to use the schema files with code generators. This syntax error is one we observed when trying to generate code based on the files.

To better illustrate the issue:

The current /analyses/endpoints.yaml file has the following code, and when opening the file in VSCode and having this extension installed, which verifies the OpenAPI syntax, we get the following error:

    filters:
      name: filters
      in: query
      schema:
        type: array
        items:
          type: string
        examples: # <-- Error: Property examples is not allowed. (yaml-schema: OpenAPI 3.0.X)
          -   - variantcaller:GATK4.0

As noted, the examples property is invalid there. If I de-indent it to be under filters, this shows another error:

    filters:
      name: filters
      in: query
      schema:
        type: array
        items:
          type: string
      examples:
          -   - variantcaller:GATK4.0 # <-- Error: Incorrect type. Expected "object(OpenAPI 3.0.X)". (yaml-schema: OpenAPI 3.0.X)

Because of the invalid syntax, this is a blocking issue for code generators like OpenAPI Generator which shows the following error and does not work:

Errors: 
        -attribute components.parameters.filters.[filters].schemas.examples is unexpected

For the examples be valid you would need to do something like this:

    filters:
      name: filters
      in: query
      schema:
        type: array
        items:
          type: string
      examples:
          example1:
             value: [variantcaller:GATK4.0]

Or change the examples to example.

@redmitry
Copy link
Collaborator

redmitry commented Jul 10, 2024

The Json Schema spec. defines "examples" as an array of values. In this case it is an array of arrays.
The problem where you wanna put the examples:

Json Schema:

filters:
    name: filters
    in: query
    schema:
        type: array
        items:
            type: string
        examples:
            -  - variantcaller:GATK4.0
               - variantcaller:GATK3.7

or OpenAPI parameter:

filters:
    name: filters
    in: query
    schema:
        type: array
        items:
            type: string
    example:
        - variantcaller:GATK4.0
        - variantcaller:GATK3.7

IMO should be the OpenAPI, as I don't believe tools analyze the schema for examples.

Correction:
Perfectly valid:

filters:
    name: filters
    in: query
    schema:
        type: array
        items:
            type: string
    examples:
        example1:
            description: some example
            value: [variantcaller:GATK4.0]

@mbaudis
Copy link
Member

mbaudis commented Jul 11, 2024

@datsirul @redmitry (Deleted earlier comment because not the right place for "kill OpenAPI" discussions here)

Oh well, for now it is probably best to fix the examples to the OpenAPI style, in the endpoints files only. But it is another argument for getting rid of OpenAPI and stick to JSON schema.

costero-e added a commit that referenced this issue Dec 12, 2024
Fixed invalid syntax in `examples` #140
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants