zymlabs / nswag-fluentvalidation

Use FluentValidation rules instead of ComponentModel attributes to define swagger schema.
MIT License
59 stars 13 forks source link

NotNull() issue #4

Closed bcronje closed 4 years ago

bcronje commented 4 years ago

Using NotNull() or NotEmpty() adds required to the schema, but still leaves the property "nullable" setting to true. See example below, name has a FluentValidation rule of NotNull, it gets added to the required array, but still has "nullable": true in the schema:

"Company": {
  "type": "object",
  "additionalProperties": false,
  "required": [
    "name"
  ],
  "properties": {
    "name": {
      "type": "string",
      "maxLength": 128,
      "minLength": 1,
      "nullable": true
    }
  }
}

Is this expected behavior? On the other hand, if I use the JsonProperty required attribute then nullable is false, which is what I would expect.

geoffreytran commented 4 years ago

Makes sense, it should mark the nullable attribute also to false.

I've gotten the fix ready, but I'm currently debating on whether to push it as version 0.3.0 or to bump to 1.0 due to the nature that the change could break downstream code relying on nullable currently being true. Given that we're not on 1.0 yet perhaps a minor revision bump is adequate for the bugfix.

bcronje commented 4 years ago

@geoffreytran that is awesome! Now I can get rid of JsonProperty attributes all together. Personally I'm happy with either 0.3.0 or 1.0 whichever way you want to go. Thank you for this library, I think it is a great enhancement to NSwag.

geoffreytran commented 4 years ago

@bcronje Thanks, it's pushed as 0.2.1. You should be good to go!

bcronje commented 4 years ago

Great stuff, thank you!