Skip to content
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

Merged
merged 4 commits into from Jul 18, 2018
Merged

Conversation

maxim-tschumak
Copy link
Contributor

Related to #714
Fixes #747

@maxim-tschumak maxim-tschumak requested review from tkrop and a user July 10, 2018 12:59
@maxim-tschumak maxim-tschumak changed the title 747 fix common fields rule [work-in-progress] 747 fix common fields rule Jul 10, 2018
@codecov-io
Copy link

codecov-io commented Jul 10, 2018

Codecov Report

Merging #750 into master will decrease coverage by 0.23%.
The diff coverage is 70%.

Impacted file tree graph

@@             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
Impacted Files Coverage Δ Complexity Δ
...ver/src/main/java/de/zalando/zally/rule/Context.kt 79.16% <66.66%> (ø) 16 <4> (ø) ⬇️
...zalando/zally/rule/zalando/CommonFieldTypesRule.kt 72.72% <70.96%> (-22.01%) 19 <17> (+5)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f5dd57a...1e650b4. Read the comment docs.

@maxim-tschumak maxim-tschumak changed the title [work-in-progress] 747 fix common fields rule 747 fix common fields rule Jul 10, 2018
@maxim-tschumak maxim-tschumak changed the title 747 fix common fields rule fix: common fields rule Jul 11, 2018
@maxim-tschumak maxim-tschumak changed the title fix: common fields rule fix: common fields rule (#749) Jul 11, 2018
@maxim-tschumak maxim-tschumak changed the title fix: common fields rule (#749) fix: common fields rule (#747) Jul 11, 2018
Copy link
Member

@tkrop tkrop left a 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()
Copy link
Member

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) ->
Copy link
Member

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()
Copy link
Member

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"
Copy link
Member

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.

Copy link
Contributor Author

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.

@maxim-tschumak maxim-tschumak force-pushed the 747-fix-common-fields-rule branch 2 times, most recently from 828c378 to 792faee Compare July 18, 2018 11:39
@maxim-tschumak
Copy link
Contributor Author

maxim-tschumak commented Jul 18, 2018

Now, the rule also checks all the nested properties recursively. @tkrop please have another look.

@tkrop
Copy link
Member

tkrop commented Jul 18, 2018

👍

1 similar comment
@maxim-tschumak
Copy link
Contributor Author

👍

@maxim-tschumak maxim-tschumak merged commit b4877cb into master Jul 18, 2018
@maxim-tschumak maxim-tschumak deleted the 747-fix-common-fields-rule branch July 18, 2018 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants