Skip to content

Latest commit

 

History

History

operation-summary-sentence-case

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Operation summary uses sentence casing

Authors:

What this does and why

What -- this rule enforces a consistent pattern of capitalization on Operation summaries.

Why -- "Sentence casing vs title casing" may be the "tabs vs spaces" of the writing world, but being consistent is often more important than being right. At Redocly, we prefer sentence casing for Operation summaries. By adding this configurable rule to our linter, we ensure our entire team writes them that way.

Code

Here's how the configurable rule looks in the redocly.yaml file:

rules:
  rule/operation-summary-sentence-case:
    subject:
      type: Operation
      property: summary
    message: "Operation summary must be sentence cased."
    assertions:
      pattern: /^[A-Z]+[^A-Z]+$/

Note

This rule can be repurposed for other fields with a single sentence, but not multiple sentences.

Rule explanation

This rule asserts that each Operation summary matches the regex defined in pattern. The regex we defined matches strings that:

  1. Start with an uppercase letter
  2. Are followed by 1+ characters that are not uppercase letters
  3. End with a character that is not an uppercase letter

Tip: Building a regex for your own rule? A tool like regexr can be quite useful.

Examples

Summaries with sentence casing (correct):

/zoo-tickets:
  post:
    summary: Buy zoo tickets
/zoo-ticket/{ticketId}:
  get:
    summary: Get zoo ticket

Summaries without sentence casing (incorrect):

/zoo-tickets:
  post:
    summary: Buy Zoo tickets
/zoo-ticket/{ticketId}:
  get:
    summary: get Zoo ticket

Excluding operations from the rule

Sometimes you might need an exception to the rule. For example, your Operation summary could have a proper noun or an acronym. You can do that using an ignore file.

Example - ignoring sentence casing

Pretend you have the following Operation and want to keep "QR" capitalized in the summary:

/tickets/{ticketId}/qr:
  get:
    summary: Get ticket QR code
  1. Verify your sentence casing rule is working correctly
  • Run npx @redocly/cli lint
  • Console should show error on Operation summary

The linting output from our example:

Operation summary must be sentence cased.

218 | /tickets/{ticketId}/qr:
219 |   get:
220 |     summary: Get ticket QR code
221 |     description: Return an image of your ticket with scannable QR code. Used for event entry.
222 |     operationId: getTicketCode

Error was generated by the rule/operation-summary-sentence-case rule.
  1. Generate an ignore file
  • Run npx @redocly/cli lint --generate-ignore-file
  • Console should confirm an ignore file was generated
  • A .redocly.lint-ignore.yaml was added to your code

The ignore file generated by our example:

# .redocly.lint-ignore.yaml
openapi.yaml:
  rule/operation-summary-sentence-case:
    - "#/paths/~1tickets~1{ticketId}~1qr/get/summary"
  1. Run the linter and verify your Operation summary is ignored
  • Run npx @redocly/cli lint
  • Console output should confirm valid OpenAPI description

The linting output from our example with ignore file added:

Woohoo! Your API description is valid. 🎉
1 problem is explicitly ignored.