-
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
Emit schema with all model properties optional + allow partial updates via PATCH #3199
Conversation
7cef6f8
to
23f91c1
Compare
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.
Nice 💯. I have minor comments, otherwise LGTM.
@@ -15,6 +19,6 @@ export const enum MODEL_TYPE_KEYS { | |||
* Metadata key used to set or retrieve repository JSON Schema | |||
*/ | |||
export const JSON_SCHEMA_KEY = MetadataAccessor.create< | |||
{[options in MODEL_TYPE_KEYS]: JSONSchema}, |
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.
Any specific reason for removing this type check ?
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.
In the future, we will be adding more schema options like exclude
(see #2653). Because options can be combined, e.g. partial
with exclude
, the number of possible combinations (and thus cache) keys is growing fast. I find it impractical to enumerate all valid keys in a TypeScript enum type. We will need 4 entries now, 8 entries when we implement exclude
, 16 entries when we introduce another option, etc.
That's why I switched the indexer type from options in MODLE_TYPE_KEYS
to key: string
.
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.
Makes sense. But on the hindsight, I think we should find some other key representation than just strings concatenation. That will resolve the actual issue as well as keep the type checks. It can be done in future. Not required in this PR.
/** | ||
* TODO(semver-major) remove these constants in the next major version | ||
* @deprecated | ||
*/ |
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.
Can I ask why they're being removed?
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.
Of course you can! 😄
Cross-posting my comment from the discussion thread #3199 (comment):
In the future, we will be adding more schema options like
exclude
(see #2653). Because options can be combined, e.g.partial
withexclude
, the number of possible combinations (and thus cache) keys is growing fast. I find it impractical to enumerate all valid keys in a TypeScript enum type. We will need 4 entries now, 8 entries when we implementexclude
, 16 entries when we introduce another option, etc.That's why I switched the indexer type from
options in MODLE_TYPE_KEYS
tokey: string
.
I am going to improve this comment to tell developers to use buildModelCacheKey
instead.
* Set this flag to mark all model properties as optional. This is typically | ||
* used to describe request body of PATCH endpoints. | ||
*/ | ||
partial?: boolean; |
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.
In the future, we can support more options such as exclude
.
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.
Definitely, see e.g. #2653:
Allow Controller methods implementing CREATE operation to describe their input data as "a model without
id
and_rev
properties ". This story requires #2629 and #2631 to be implemented first.To emit schema with certain properties excluded, we should add a new schema-generation option called
exclude
& accepting a list of property names to remove from the schema. To allow TypeScript compiler to verify thatexclude
items are valid property names, we should leverage TypeScript generics andkeyof
keyword.
23f91c1
to
59f0dbc
Compare
@b-admike @nabdelgadir @raymondfeng @samarpanB Thank you for the review. I believe I have addressed your comments in 6e16780 and 59f0dbc. LGTY now? |
I like |
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.
👍
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.
Looks good to me 👍
Add a new option `partial: boolean` allowing callers of `getJsonSchema` and related helpers to request a model schema with all properties marked as optional. Signed-off-by: Miroslav Bajtoš <[email protected]>
Signed-off-by: Miroslav Bajtoš <[email protected]>
Signed-off-by: Miroslav Bajtoš <[email protected]>
…ATCH Signed-off-by: Miroslav Bajtoš <[email protected]>
59f0dbc
to
28cdc08
Compare
partial
.partial
option to describe request body parameter.See #2652, #1722 and #1179
Checklist
👉 Read and sign the CLA (Contributor License Agreement) 👈
npm test
passes on your machinepackages/cli
were updatedexamples/*
were updated👉 Check out how to submit a PR 👈