-
Notifications
You must be signed in to change notification settings - Fork 31
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
Exclude fields using config #28
Comments
Hey, @jonathon-m Interesting idea. But I suggest don't do it in so direct way. The Library allows to build schema for each single query:
See examples:
In many cases it is more correct approach to generate a schema. The second reason is that "to exclude from the JSONSchema" is an effect, but is not a cause. So it is more correct approach to mark sensitive fields with something like: So, what do you think? |
Hey @DScheglov thanks for the response 😄 I agree with your approach of |
I'm going to add required functionality with some "post-processing" utilities. const { Schema } = require('mongoose-schema-jsonschema')(require('mongoose'));
const { postProcess } = require('mongoose-schema-jsonschema/post-process');
const BookSchema = new Schema({
title: { type: String, required: true },
year: Number,
author: { type: Schema.Types.ObjectId, required: true, ref: 'Person' },
});
const jsonSchema = postProcess(BookSchema.jsonSchema())
.exclude('title', 'author')
.select('year')
.map((path, schema) => replaceSchema(path, schema))
.done();
// also will be available the curried api:
// see: https://babeljs.io/docs/en/babel-plugin-proposal-pipeline-operator
const { select, exclude, map } = require('mongoose-schema-jsonschema/post-process');
const jsonSchema2 = BookSchema.jsonSchema()
|> exclude('title', 'author')
|> select('year')
|> map((path, schema) => replaceSchema(path, schema)); Have any thoughts around that? |
This is perfect. |
Hey,
I'd like to be able to mark fields for exclusion from the generated schema.
Some of my models have sensitive data which is not sent to end users via my API. Adding
excludeFromJSONSchema: true
or something similar in my model definitions would cover this use case 👍If you can provide a hint about how you'd want this implemented I'm happy to make a pull request.
Cheers!
The text was updated successfully, but these errors were encountered: