Skip to content

OpenAPI linter

Andriy Mykulyak edited this page Jun 10, 2023 · 7 revisions

Overview

This document describes the architecture of the fresha-openapi-lint tool.

Key parts

/openapi-lint
  /bin
    fresha-openapi-lint.js
  /src
    /formatters
    /linter
      Linter.ts
      LinterConfig.ts
      LintResult.ts
      ResultFormatter.ts
    /rules
      /fresha
      /jsonapi
      /openapi
    api.ts
    cli.ts
    types.ts
  • bin/fresha-openapi-lint.js - this file is run by npx fresha-openap-lint. All it does is to require build/cli.js (the transpiled version of the src/cli.ts)
  • src/api.ts - This is what gets required by import '@fresha/openapi-lint';, it exports the public API of the linter.
  • src/cli.ts - This is linter CLI. It:
    1. parses the command line
    2. loads linter configuration file and initializes a LinterConfig object
    3. constructs Linter and LintResult objects
    4. reads OpenAPI documents specified in the command line, and invokes Linter.run method on each of them
    5. creates a ResultFormatter instance and formats the linter result
  • src/types.ts - contains public types used in this package
  • src/formatters/ - contains result formatters
  • src/linter/ - contains implementation of the linter functionality
  • src/rules/ - contains built-in rules and rulesets
    • src/rules/openapi/ - generic OpenAPI 3.x rules
    • src/rules/jsonapi/ - generic JSON:API rules
    • src/rules/fresha/ - rules specific to Fresha

Command line options

  • --config <FILE> - path to the configuration file
  • --verbose - prints more information
  • --fix - automatically fix problems
  • --format <NAME> - use specified output format
  • --help - show help
  • --version - show package version
  • --init - initializes a configuration wizard that helps to create a config file
  • --max-warnings <N> - minimal number of warnings to trigger non-zero exit code
  • --print-config - prints configuration used
Clone this wiki locally