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: common fields rule (#747) #750
Conversation
Codecov Report
@@ Coverage Diff @@
## master #750 +/- ##
============================================
- Coverage 86.5% 86.27% -0.24%
- Complexity 959 964 +5
============================================
Files 168 168
Lines 2587 2601 +14
Branches 354 360 +6
============================================
+ Hits 2238 2244 +6
Misses 186 186
- Partials 163 171 +8
Continue to review full report at Codecov.
|
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.
Unfortunately, I do not get the selection of allSchemas()
so far, and the test didn't help to understand all cases. I fear we have to talk all cases over and adapt the tests.
assertThat(rule.checkField("modified", StringProperty("date-time"))).isNull() | ||
assertThat(rule.checkField("type", StringProperty())).isNull() | ||
fun `checkField matching should be case insensitive`() { | ||
assertThat(rule.checkField("iD", createSchema(INTEGER_TYPE, null))).isNotNull() |
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'm not sure whether it is wise to switch to a name that is not an exact match. I would suggest to remove the field conversion to lower case anyhow, as this is addressed by the snake_case
rule in the first place.
else null | ||
} | ||
fun checkField(name: String, property: Schema<Any>): String? = | ||
commonFields[name.toLowerCase()]?.let { (type, format) -> |
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.
Let's remove the lower case
conversion, as this failure is covered by the snake_case
check, and we expect exact name matches.
assertThat(rule.checkField("iD", createSchema(INTEGER_TYPE, null))).isNotNull() | ||
assertThat(rule.checkField("CREATED", createSchema(INTEGER_TYPE, null))).isNotNull() | ||
assertThat(rule.checkField("tYpE", createSchema(null, null))).isNotNull() | ||
assertThat(rule.checkField("CREated", createSchema(STRING_TYPE, "time"))).isNotNull() |
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.
By the way, we should introduce some synonyms rule: created
-> created_at
, modified
-> modified_at
.
schema: | ||
properties: | ||
id: | ||
"${'$'}ref": "#/components/schemas/CustomId" |
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.
Unfortunately, this is not the only allowed place for a reference.
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's a representative test - we don't want to test the resolve feature of the swagger-parser
.
e810c51
to
753d6e9
Compare
828c378
to
792faee
Compare
792faee
to
1e650b4
Compare
Now, the rule also checks all the nested properties recursively. @tkrop please have another look. |
👍 |
1 similar comment
👍 |
Related to #714
Fixes #747