fuhrysteve / marshmallow-jsonschema

JSON Schema Draft v7 (http://json-schema.org/) formatting with marshmallow
MIT License
208 stars 73 forks source link

Dump partial loading schema still return required fields. #112

Open lehainam-dev opened 4 years ago

lehainam-dev commented 4 years ago

Hi everyone,

Thank @fuhrysteve for this awesome lib.

As using the lib, I find out that schema with partial loading does not parse correctly to JSON schema. It still has required fields even though it should not. Here is the example test.

from marshmallow import Schema, fields
from marshmallow_jsonschema import JSONSchema

class UserSchema(Schema):
    name = fields.String(required=True)
    email = fields.String(required=True)

schema = UserSchema(partial=True)

assert schema.load({}) == {}

required_fields = JSONSchema().dump(schema)['definitions']['UserSchema']['required']

print(required_fields)  # ['email', 'name']
assert required_fields == []

Expected results

Current results

I'm happy to investigate and make PR to this issue.

lehainam-dev commented 4 years ago

Wow that was quick, thanks for separated get_required method. I made a PR #113. I'm looking forward to your reply soon.