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

Extend the supported data types using types option #127

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

subeeshcbabu-zz
Copy link

It would be really cool to provide an option to extend the default and supported types.
This types option can be an easy fix/feature for anyone wanting to extend capabilities of the validator to - either define custom types for schema or trying to extend features of the existing validations.

One example of such a use case, would be Swagger file type.

@LinusU
Copy link
Collaborator

LinusU commented Oct 25, 2016

I don't think this is valid according to JSON schema? JSON doesn't have any "file" type so it seems strange to add it. I might be missing something though, but why not use { type: 'string', format: 'file' }?

@subeeshcbabu-zz
Copy link
Author

The idea is to use this module to validate response data for any specification that extends json schema. I really like this module and would love to use this for specs like swagger also. This option could be used by any spec that is extending json schema, not only swagger.

Adding an option to extend the supported types without changing the existing module is what I am proposing.

To answer your question on why I can't use a format file because swagger spec 2 has defined file as a type rather than a format.

@subeeshcbabu-zz
Copy link
Author

@LinusU - sorry to bug you with this, however any update on this?

@subeeshcbabu-zz
Copy link
Author

@LinusU any idea, if this PR would be accepted?

@LinusU
Copy link
Collaborator

LinusU commented Dec 13, 2016

Ultimately, it's up to mafintosh, but I think that the developers has misunderstood how json-schema works. "type": "file" should really be "type": "string", "format": "file". It doesn't make sense to extend json-schema with more types, because there aren't any more types in JSON.

I would really like to see a discussion with the Swagger people on why they chose to do this, because to me it seems wrong, and as far as I know, they aren't following the json schema specification.

For these reasons I'm not a big fan of merging this, I hope you can understand my point of view...

@subeeshcbabu-zz
Copy link
Author

Completely understand, why you have concerns supporting this. Agree that, Swagger should not have deviated from the json schema to define a type like file.
However, talking more about the context of this PR, the extension support clearly separates the Implementation to the user-land or to any one trying to wrap (to bridge the swagger to json schema gap) the is-my-json-valid module. I really want to use the awesome features of this module, and at the same time keep the additions out of this module.

@LinusU
Copy link
Collaborator

LinusU commented Dec 21, 2016

It would probably be quite easy to make a small function that "fixes" the schema before passing it to is-my-json-valid though. Look for type: 'file' and replace with type: 'string', format: 'file'

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

Successfully merging this pull request may close these issues.

3 participants