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

nullable flag and enum has validation issues #697

Closed
schristley opened this issue Jun 23, 2023 · 2 comments · Fixed by #708
Closed

nullable flag and enum has validation issues #697

schristley opened this issue Jun 23, 2023 · 2 comments · Fixed by #708
Milestone

Comments

@schristley
Copy link
Member

schristley commented Jun 23, 2023

While working on airr-js, I was getting validation errors for fields with nullable: true and enum when the field value was null. I'm using the ajv package for validation, instead of custom written like our python library. Apparently, there has been various discussions about this as OpenAPI schema and JSON schema aren't 100% equivalent. From what I can gather, the conclusion was that null needs to be added to the enum list. When I do that, as shown below, then validation passes.

        sex:
            type: string
            enum:
                - male
                - female
                - pooled
                - hermaphrodite
                - intersex
                - "not collected"
                - "not applicable"
                - null
            nullable: true
            description: Biological sex of subject
            title: Sex
            example: female
            x-airr:
                miairr: important
                adc-query-support: true
                set: 1
                subset: subject
                name: Sex
                format: controlled vocabulary

This really only applies to the OpenAPI V3 spec. This is a simple fix but it might effect UIs that display those enum lists.

@schristley schristley added this to the AIRR 1.4.2 milestone Jun 23, 2023
@bcorrie
Copy link
Contributor

bcorrie commented Jun 28, 2023

Personally, I think that is dangerous. How do you differentiate that from me defining a field where "null" as a string is one of the allowed enum values. I think this would be a quite common use case. Similar to having "NA" or "None", "null" would be a relatively common string to find in an enum definition.

@schristley
Copy link
Member Author

If you want the string "null" then put quotes around it in the enum like so, the following allows both the null value and the string "null" as acceptable values.

        sex:
            type: string
            enum:
                - male
                - female
                - pooled
                - hermaphrodite
                - intersex
                - "not collected"
                - "not applicable"
                - "null"
                - null
            nullable: true
            description: Biological sex of subject
            title: Sex
            example: female
            x-airr:
                miairr: important
                adc-query-support: true
                set: 1
                subset: subject
                name: Sex
                format: controlled vocabulary

As OpenAPI is based on JSON schema spec, only null is a special value, stuff like "NA" and "None" are just strings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants