Skip to content

Conversation

@yelizhenden-mdb
Copy link
Collaborator

@yelizhenden-mdb yelizhenden-mdb commented Apr 4, 2025

Proposed changes

Jira ticket: CLOUDP-306582

  xgen-IPA-126-tag-names-should-use-title-case:
    description: |
      Tag names in the OpenAPI specification should use Title Case.

      ##### Implementation details
      Rule checks for the following conditions:
        - All tag names defined in the OpenAPI tags object should use Title Case 
        - Title Case means each word starts with an uppercase letter, and the rest are lowercase

Found 13 violations

Checklist

  • I have signed the MongoDB CLA
  • I have added tests that prove my fix is effective or that my feature works

Changes to Spectral

  • I have read the README file for Spectral Updates

Further comments

@yelizhenden-mdb yelizhenden-mdb marked this pull request as ready for review April 4, 2025 15:05
@yelizhenden-mdb yelizhenden-mdb requested a review from a team as a code owner April 4, 2025 15:05
Comment on lines 9 to 11
if (!tagName || tagName.trim().length === 0) {
return;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't want to error on non-existent names, I think you can remove this check and in the rule do:

given: $.tags[*].name

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$.tags[*].name this gives the name as input, but for exception level, I wanted to keep it at tag object level. Anyhow I changed the given to $.tags[?(@.name && @.name.length > 0)] to get the ones with non-empty name

Comment on lines 149 to 154
{
code: 'xgen-IPA-126-tag-names-should-use-title-case',
message: 'Tag name should use Title Case, found: "Push-Based Log Export".',
path: ['tags', '2'],
severity: DiagnosticSeverity.Warning,
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should allow dashes since Push-Based or Third-Party should be valid IMO

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can say that if the second word is capitalized in a hyphenated word, it is valid. This is your suggestion, am I correct?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added that support, and updated the unit tests accordingly

Comment on lines 155 to 160
{
code: 'xgen-IPA-126-tag-names-should-use-title-case',
message: 'Tag name should use Title Case, found: "AWS Clusters DNS".',
path: ['tags', '3'],
severity: DiagnosticSeverity.Warning,
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should allow capital case abbreviations/initialism as well, like API, AWS etc.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can construct a list of abbreviations to be ignored. Do you have any suggestions?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that could be good, from top of mind I'd propose:

  • AWS
  • GCP
  • IP
  • API
  • MongoDB
  • LDAP
  • DNS

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I included some ignoreList to maintain their casing, and some grammaticalWords to allow them in lowercase. Could you take a look and let me know how it sounds?

Comment on lines 34 to 37
const hyphenatedParts = wordGroup.split('-');
return hyphenatedParts.every((part) => {
if (part === '') return true; // Skip empty parts
if (ignoreList.includes(part)) return true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is a name like This -Name with a space beofre/after the dash, a part here could be empty, I think that should be considered invalid, WDYT?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree there should be no space, let me fix it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it, and added some test cases, let me know if I miss anything


// For regular words
if (ignoreList.includes(wordGroup)) return true;
if (grammaticalWords.includes(wordGroup)) return true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Nit] These should be for words that are not the first word, e.g. The Name and User of the Thing is valid, but the User would be invalid.

Suggested change
if (grammaticalWords.includes(wordGroup)) return true;
if (index !== 0 && grammaticalWords.includes(wordGroup)) return true;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense! Applied the suggestion, and added a unit test for it

const hyphenatedParts = wordGroup.split('-');
return hyphenatedParts.every((part) => {
if (ignoreList.includes(part)) return true;
if (grammaticalWords.includes(part)) return true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (grammaticalWords.includes(part)) return true;

[nit] There are probably no compound words (I think that's what it's called 😋 ) using dashes with words like "the" or "a"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's a good catch! Applied the suggestion, thanks!

Copy link
Collaborator

@lovisaberggren lovisaberggren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@yelizhenden-mdb yelizhenden-mdb merged commit 8f8c58a into main Apr 4, 2025
8 checks passed
@yelizhenden-mdb yelizhenden-mdb deleted the CLOUDP-306582 branch April 4, 2025 16:14
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.

2 participants