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

Using custom keywords? #51

Closed
firasdib opened this issue Nov 15, 2019 · 8 comments
Closed

Using custom keywords? #51

firasdib opened this issue Nov 15, 2019 · 8 comments

Comments

@firasdib
Copy link

AJV has support to add custom keywords, but I don't see any way of using these with fluent schema.

AJV will accept this:

{
  foo: {
    type: 'integer'
  },
  myKeyword: true,
}

but I have no idea how to do something like this in fluent-schema, if its even possible.

@aboutlo
Copy link
Collaborator

aboutlo commented Nov 15, 2019

fluent-schema doesn't support custom AJV keywords. we had a similar discussion here: #16

To be fair, I'm not sure if it's a good idea to add not standard keywords related to a specific validator (e.g. AJV).

Regardless can you give an example of API that would you like to use

@firasdib
Copy link
Author

@aboutlo Okay. I wanted to add a specific type/keyword to be able to manipulate the data to my needs in a generic way.

@aboutlo
Copy link
Collaborator

aboutlo commented Nov 20, 2019

maybe we could think something like that.

S.object()
  .prop('foo', S.integer())
  .prop('myKeyword', S.raw({true})

//cc @mcollina @Eomm

@Eomm
Copy link
Member

Eomm commented Nov 22, 2019

Is S.raw a type or could be attached like prop?

S.object()
  .prop('foo', S.integer())
  .prop('myKeyword', S.raw('true')
  .raw({$def:S.object().valueOf()})

And the input could be:

  • a json => an will be that will be spread
  • a string/bool/num => and will be used as value
    ?

@aboutlo
Copy link
Collaborator

aboutlo commented Nov 22, 2019

I imagined as a type in order to accept an arbitrary valid JSON.
In your example I don't get the benefit. it could be S.definition(S.raw({ foo: 'bar'}))

@firasdib
Copy link
Author

firasdib commented Dec 7, 2019

Unless I've missed something, adding support for this would allow us to use the nullable feature in AJV/OpenAPI, which I currently don't think is possible with fluent schema.

@aboutlo
Copy link
Collaborator

aboutlo commented Dec 7, 2019

Yes, any feature outside JSON Schema spec isn't currently supported

@aboutlo aboutlo mentioned this issue Dec 7, 2019
@aboutlo
Copy link
Collaborator

aboutlo commented Dec 7, 2019

Moved the conversation here: #55

@aboutlo aboutlo closed this as completed Dec 7, 2019
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

No branches or pull requests

3 participants