flask-restplus icon indicating copy to clipboard operation
flask-restplus copied to clipboard

update json schema from draft v4 to draft v7

Open scphantm opened this issue 5 years ago • 2 comments

Code

schema_data = schema_json.get_json_schema_deref_object()
event_scheme = api.schema_model('event_schema', schema_data)
@build_ns.route("/build_start")
class BuildStartEvent(Resource):

    @build_ns.doc('create_todo')
    @build_ns.expect(event_scheme, validate=True)
    @build_ns.response(400, 'Input Values Malformed')
    def post(self):

Repro Steps (if applicable)

make the event schema schema_data a json schema v7

Expected Behavior

using the latest, you only support v4. There have been some major changes and upgrades to json schema to make it MUCH more useful. Your validate=True statement doesn't work with newer schemas because v4 doesn't support the allof or oneof, etc. tags within the schema. It lets things thru that it shouldn't.

Currently im having to do

from jsonschema import validate
validate(api.payload, schema=schema_data)

at the beginning of each method to make sure the json passes. kinda makes that validate irrelevant

scphantm avatar Nov 26 '19 19:11 scphantm

because v4 doesn't support the allof or oneof, etc. tags within the schema.

It is not True:

https://json-schema.org/draft-04/json-schema-validation.html#rfc.section.5.5.4 https://json-schema.org/draft-04/json-schema-validation.html#rfc.section.5.5.5

But anyway, Draft-7 provides some good stuff:

  • readOnly/writeOnly keywords which can be helpful for describing post and get requests with one schema
  • comments, propertyNames and const (actually, it was introduced by Draft-6, but anyway).

andreykurilin avatar Dec 03 '19 13:12 andreykurilin

Also it has the "if" "then" and "else" keywords which are really useful for validation!

aviau avatar Jul 10 '20 16:07 aviau