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

Warning issued when an optional field does not allow nulls #535

Open
edmundadjei opened this issue Jan 24, 2023 · 3 comments
Open

Warning issued when an optional field does not allow nulls #535

edmundadjei opened this issue Jan 24, 2023 · 3 comments

Comments

@edmundadjei
Copy link

There appears to be no way of defining a non-null optional field, you get a validation/linting warning when you publish such a schema, but I feel this is perfectly valid.

I had to make lat/lon type ["number", "null"], but this is not valid, I do not want a null value to be passed in at all, in fact I want to a null value to fail validation for this location schema

        "location": {
          "description": "Place name and lat/Lon coordinates",
          "type": ["object", "null"],
          "properties": {
            "name": {
              "description": "The name of this location, city/town etc",
              "type": "string",
              "maxLength": 2048
            },
            "lat": {
              "description": "Latitude for the location",
              "type": ["number", "null"],
              "minimum": -90,
              "maximum": 90
            },
            "lon": {
              "description": "Longitude for the location",
              "type": ["number", "null"],
              "minimum": -180,
              "maximum": 180
            }
          },
          "required": [
            "name"
          ],
          "dependencies": {
            "lat": ["lon"],
            "lon": ["lat"]
          },
          "additionalProperties" : false
        }
@istreeter
Copy link

Hi @edmundadjei, I personally agree with you. I can think of situations where it is helpful to have an optional field, but to disallow explicit nulls.

The Iglu linters provide different levels of message: Info, Warning, and Error. In this case, I think you get a Warning, not an Error. With a Warning, you should be able to still publish the schema, so hopefully this issue hasn't completely blocked you. Please can you confirm that you are technically able to publish your schema, even though it gives you a Warning?

Error messages are slightly different -- if you get an Error then you are disallowed from publishing a schema, and it means your schema is not compatible with the Iglu system.

We probably need a review of which linter level is used for which message type. I am fairly confident that our Error messages are correct, but maybe we could do better at partitioning the Info and Warning messages.

@Rambo1377
Copy link

Rambo1377 commented Oct 26, 2024


@

@Rambo1377
Copy link


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

No branches or pull requests

3 participants