-
Notifications
You must be signed in to change notification settings - Fork 9k
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
refactor: introduce function for getting Schema Object type #10330
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -635,3 +635,7 @@ const resolver = (arg1, arg2, arg3) => [arg1, JSON.stringify(arg2), JSON.stringi | |||||||||
export const memoizedCreateXMLExample = memoizeN(createXMLExample, resolver) | ||||||||||
|
||||||||||
export const memoizedSampleFromSchema = memoizeN(sampleFromSchema, resolver) | ||||||||||
|
||||||||||
export const getSchemaObjectTypeLabel = (label) => label | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The input is
Suggested change
But anyway we can make this point-free by: import identity from "lodash/identity"
export const getSchemaObjectTypeLabel = identity |
||||||||||
|
||||||||||
export const getSchemaObjectType = (schema) => schema.type ?? "any" | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be consistent with JSON Schema 2020-12 processing, can we make the fallback type the
Suggested change
Also, may I suggest to make this function safe:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preferred alternative: What if both the functions would have the following signature?
This would simplify their usage inside the code as it is now abstracted how the the type or label are computed from the schema. Instead of const typeLabel = fn.getSchemaObjectTypeLabel(immutableToJS(schema?.get("type"))) you'll end up having const typeLabel = fn.getSchemaObjectTypeLabel(immutableToJS(schema)) If you further abstract and allow the functions to consume immutable along with POJO, it can look like: const typeLabel = fn.getSchemaObjectTypeLabel(schema) NOTE: this applies both for Draft 5 and 2020-12 functions. |
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.
This looks a bit confusing. For getting a
typeLabel
we're usinggetSchemaObjectType
. For actualtype
we're usinggetSchemaObjectTypeLabel
. Shouldn't it be reversed?