{"action":"opened","issue":{"url":"https://api.github.com/repos/go-swagger/go-swagger/issues/1601","repository_url":"https://api.github.com/repos/go-swagger/go-swagger","labels_url":"https://api.github.com/repos/go-swagger/go-swagger/issues/1601/labels{/name}","comments_url":"https://api.github.com/repos/go-swagger/go-swagger/issues/1601/comments","events_url":"https://api.github.com/repos/go-swagger/go-swagger/issues/1601/events","html_url":"https://github.com/go-swagger/go-swagger/issues/1601","id":338392576,"node_id":"MDU6SXNzdWUzMzgzOTI1NzY=","number":1601,"title":"Required properties with x-nullable:true cannot accept null values","user":{"login":"akhobov","id":35388,"node_id":"MDQ6VXNlcjM1Mzg4","avatar_url":"https://avatars2.githubusercontent.com/u/35388?v=4","gravatar_id":"","url":"https://api.github.com/users/akhobov","html_url":"https://github.com/akhobov","followers_url":"https://api.github.com/users/akhobov/followers","following_url":"https://api.github.com/users/akhobov/following{/other_user}","gists_url":"https://api.github.com/users/akhobov/gists{/gist_id}","starred_url":"https://api.github.com/users/akhobov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akhobov/subscriptions","organizations_url":"https://api.github.com/users/akhobov/orgs","repos_url":"https://api.github.com/users/akhobov/repos","events_url":"https://api.github.com/users/akhobov/events{/privacy}","received_events_url":"https://api.github.com/users/akhobov/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-07-05T00:05:03Z","updated_at":"2018-07-05T00:05:03Z","closed_at":null,"author_association":"NONE","body":"## Problem statement\r\nIn order to ensure that a field is included into responses (doesn't have `omitempty` struct field attribute) it should be listed in the required array. On the other hand if the same field can be `null` it should have `x-nullable: true` property set. This works fine for GET requests. However the field validation on POST/PUT requests considers the `null` value as invalid that leads to an error as follows:\r\n\r\n```\r\n{\r\n    \"code\": 602,\r\n    \"message\": \"field in body is required\"\r\n}\r\n```\r\n \r\nIt seems the culprit is the following code in the validateField() function that checks that a not default value is provided:\r\n```\r\n   if err := validate.Required(\"field\", \"body\", m.Field); err != nil {\r\n          return err\r\n      }\r\n```\r\n\r\nThe Swagger Specification 2.0 stipulates that the `required` property is taken directly from the JSON Schema definition and follows the same specifications. The [JSON Schema Validation](https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.4.3) document states the following:\r\n> 5.4.3.2.  Conditions for successful validation\r\n>\r\n>   An object instance is valid against this keyword if its property set\r\n>   contains all elements in this keyword's array value.\r\n\r\nCorrect me if I'm wrong but it doesn't state that properties should have certain values. Only that properties should be present in an object instance. This matches the `omitempty` attribute logic but not that validation code. \r\n\r\n## Swagger specification\r\n```\r\n  definitions:\r\n    foo:\r\n      type: object\r\n      required:\r\n        - field\r\n        - bar\r\n      properties:\r\n        field:\r\n          type: string\r\n          x-nullable: true\r\n        bar:\r\n          type: object\r\n          x-nullable: true\r\n          required:\r\n            - baz\r\n          properties:\r\n            baz:\r\n              type: string\r\n```\r\n\r\n\r\n## Steps to reproduce\r\n1. Generate server\r\n1. Run it\r\n1. Send POST or PUT request with an object that has the field set to `null`\r\n\r\n## Environment\r\nswagger version: 0.13.0  \r\ngo version: 1.10.2\r\nOS: Linux\r\n"}}
{"actor":{"display_login":"akhobov"}}