-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
fix(repository-json-schema): use correct behavior for hidden properties #10698
base: master
Are you sure you want to change the base?
fix(repository-json-schema): use correct behavior for hidden properties #10698
Conversation
Update emitted json schema to always omit properties marked as hidden at both model and property levels Signed-off-by: Taylor Coffelt <[email protected]>
continue; | ||
} | ||
|
||
if (meta.properties[p].hidden) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a model property has a hidden property, it is added to meta.settings.hiddenProperties. You probably don't need this check. The first condition should be enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried removing the check, and I'm not seeing the behavior you described.
The 'HiddenProperty' tests are now failing with the properties in the schema not removed. I tried debugging the unit test excludes one property when the property setting is set to hidden
and I'm seeing the SingleHiddenPropertyProduct
having no meta.settings
sub-properties available
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like that behavior only happens in packages/repository/src/decorators/model.decorator.ts
/ buildModelDefinition
.
This is run once on the start, but when the modelToJsonSchema
is called, the ModelMetadataHelper.getModelMetadata
is unable to locate the cached model. This causes it to rebuild the model meta (without the behavior from the buildModelDefinition
that adds the hidden properties to the model's settings.hiddenProperties
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, @taylorcoffelt. You are right. meta.settings.hiddenProperties is not populated with hidden properties here.
This change not only hides the properties from the response, it hides from the request body example too - which it shouldn't as we can post with hidden fields.
Secondly, the filters still show the hidden fields.
You can hide properties in the filter by filtering hidden fields here.
const hiddenProperties = modelCtor.definition.settings.hiddenProperties || [];
const originalProps = Object.keys(modelCtor.definition.properties);
const properties = originalProps.filter(prop => !hiddenProperties.includes(prop));
While you can remove the hidden properties from the responses in /rest-crud/src/crud-rest.controller.ts
.
@get('/{id}', {
...response.model(200, `${modelName} instance`, modelCtor, {
includeRelations: true,
}),
})
We can pass exclude as an array along with includeRelations.
Update emitted json schema to always omit properties marked as hidden at both model and property levels.
This also affects schema emitted for related models.
Currently,
hidden
properties are only omitted at the top level in the model schema. If a related model was included as part of the emitted schema, thehidden
behavior on the model or model properties would be ignored, and the entire nested schema emitted, defeating the purpose of the hidden fields, and requiring additional models / extra work to omit them from the emitted schema.Potentially Fixes #7517
Fixes #4495
Fixes #1914
Checklist
npm test
passes on your machinepackages/cli
were updatedexamples/*
were updated