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(schema): improve titles, connect values & remove duplications #10
Conversation
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.
Dunno, I really don't like many of the changes in here...
Replicating the names of the object / enum in my opinion just adds clutter with no real benefit.
If you generate code surely a duplicate attribute name in unrelated classes surely shouldn't cause issues...
Feels like if a generator requires unique names, the duplication of the parent title should be done by the generator, not by the schema
"default": 0 | ||
} | ||
}, | ||
"additionalProperties": false |
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.
wouldn't additionalProperties
cause issues?
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.
Agree, to be safe and avoid unexpected problems let me remove them
@@ -7,17 +7,17 @@ | |||
{ | |||
"properties": { | |||
"t": { | |||
"title": "Time", | |||
"title": "Keyframe Time", |
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.
Not sure I agree with these, it's describing the keyframe, so why repeat it in the title of the properties?
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.
Because it's a generic name I wanted to create a unique title.
@@ -5,67 +5,67 @@ | |||
"description": "", | |||
"oneOf": [ | |||
{ | |||
"title": "Normal", | |||
"title": "Blend Mode Normal", |
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 definitely don't like repeating the enum name in its values to be honest
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 agree, it's not ideal, but then can you suggest a name? so we could avoid the generic names which may be created in other props
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.
What problem would it cause if "Normal" is used elsewhere too?
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.
answered in the comment below
"$schema": "https://json-schema.org/draft/2020-12/schema", | ||
"allOf": [ | ||
{ | ||
"const": "gf", |
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.
Why are these needed as separate constants? I think it adds complexity to the schema unnecessarily
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.
so we don't need to maintain the same values at many places. For example, gradient-fill-type
has been used in two files:
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.
dunno, seems like a lot of overhead
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.
but shouldn't we create this overhead if a value/property has been used in more than one place?
"const": 3 | ||
"default": 2, | ||
"properties": { | ||
"lj": { |
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.
Why switching this from an enum to a property?
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.
Because then we can maintain the same values at one place and reuse them as a $ref
. For example, I've included line-join into these 2 files:
- https://github.com/LottieFiles/lottie-docs/pull/10/files#diff-6842843da38497db2665d2144dd1dfb6a991303234eabfc1070497aa1872401dR8
- https://github.com/LottieFiles/lottie-docs/pull/10/files#diff-3cf937f1c26d726406b5d69a6f41cd0bbabe5905669c79bd070819a8d7f84291R11
but ofc I can keep only the const value in the file instead of moving the entire property.
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 think it's better to have lj
in the objects and $ref
pointing to only the values
"oneOf": [ | ||
{ | ||
"title": "Star", | ||
"title": "Star Type Default", |
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 don't think marking "Default" in the title is a good pattern
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 you please suggest a better name? because "Star Type" is taken in the parent's title above
Replicating the names of the parent object/enum is not ideal, please feel free to suggest better namings for generic titles.
It will not cause major issues, but the Interface and Type names will be off. For example, Normal1, Normal2, Time1, Time2, Type1, Type2 and etc. Currently, all auto-generator JSON-schema tools have a standard using the The Look forward to your reply, thanks ^^ |
But why would it use I've managed to generate code without these restrictions. To me it feels more of an issue with the generator than the schema. If two different objects have say a size attribute, it should be fine to have it called size for both rather than ellipseSize, rectangleSize. I don't understand why the code generator wants different names for all the properties. it should only be an issue if they can be in the same object... |
which tool did you use? let me have a look. All tools have limitations and conversions are not perfect. But all tools use
I agree but seems like these tools cannot handle complex schemas with many layers or the generators may not support a certain schema syntax.
Yes, the tools are not intuitive enough. Some tools treat
I guess all tools struggle with combining similar props because "the schemas listed in an allOf, anyOf or oneOf array know nothing of one another". Even though tools are not ideal right now for creating proper TS schema, we should treat Perhaps we should have a call for further discussion. |
I just parsed the JSON schema myself. I do use titles and it doesn't cause any issues, as they are unique for "classes" and the current ones work fine for property names https://gitlab.com/mattbas/python-lottie/-/blob/master/docs/json_schema.py#L586 The code there is a bit weird because it's for adding stuff to an existing lottie object model |
I'm closing the PR after our discussion. We agreed that we shouldn't update title names because it reduces human readability; the title names have been referenced in the documentation pages and they can be edited with a script before passing the schema to the auto-generator tools. The useful commits that improve value duplications will be cherry-picked and provided in separate PRs. |
All auto-generating Typescript tools such as https://github.com/quicktype/quicktype use
title
to name Interfaces or Types. Thus, it is very important how we name titles, so we could help others automate without editing. Thus, this PR is meant to improve existing titles' duplications and inconsistencies identified by running auto-generating-type tools. In addition, better titles would be more clear for readers.Changes:
s
andv
props2.1.
/animated-properties/animated
2.2.
/helpers/property-index
2.3.
/animated-properties/expression
2.4
/helpers/framerate
2.5
/helpers/name
2.6
/helpers/match-name
2.7
/helpers/three-dimensional
2.8 created files for each Shape
ty
key$ref
Suggestion: perhaps we can squash all commits before merging since there are so many of them