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

Question: nullable & optional/required marks #1775

Closed
raderio opened this issue Dec 10, 2018 · 7 comments
Closed

Question: nullable & optional/required marks #1775

raderio opened this issue Dec 10, 2018 · 7 comments

Comments

@raderio
Copy link

raderio commented Dec 10, 2018

Can we represent in specification that a field is non-nullable & optional?
this mean, or we send a data for the field, or just do not send the field in request, null is not allowed.
{"foo": "bar", "baz": true} is allowed
{"baz": true} is allowed, because is optional
{"foo": null, "baz": true} is NOT allowed, because is non-nullable

Basically null has the meaning of "this property existed before, and I want to nullify its value". If there's no value, or the value needs not change (for requests, for example), it just shouldn't be sent.

@MikeRalphson
Copy link
Member

Non-nullable and optional is the default in a schema object for properties.

@raderio
Copy link
Author

raderio commented Dec 10, 2018

If non-nullable and optional is default, how to represent nullable and required?

@raderio
Copy link
Author

raderio commented Dec 10, 2018

From https://swagger.io/docs/specification/data-models/data-types/
At the moment is

type: integer
nullable: true

what I am searching/needed

type: integer
nullable: false
required: false

@raderio
Copy link
Author

raderio commented Dec 10, 2018

As I understand, it will be like

{
  "type": "object",
  "properties": {
    "counter": {
      "type": "integer",
      "nullable": true,
    },
   "required": [
      "counter"
   ]
}

Am I correct?

@handrews
Copy link
Member

@tedepstein is there more to say here given the nullable clarifications? I think @raderio's last comment was correct so this can probably be closed?

@tedepstein
Copy link
Contributor

@handrews, yes, I think it can be closed.

@raderio, I think the proposed clarification of nullable in the 3.0.3 patch release should be helpful to explain how nullable interacts with other keywords.

A few things in particular:

  • Untyped properties are nullable by default.
  • Typed properties are non-nullable by default, but can be made nullable with nullable: true.
  • All properties are optional by default.
  • Optionality and nullability are separate, independent behaviors. A property can be any of the four combinations of optional/required, nullable/non-nullable.

@handrews
Copy link
Member

We agreed to close this and apparently I forgot to actually close it 🤦

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

4 participants