openapi3lint1

package
v1.7.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 21, 2021 License: MIT Imports: 12 Imported by: 0

README

OpenAPI 3 Lint

This is a Go-based OpenAPI 3 spec linter.

Why Spectrum Linter?

There are a few linters available.

The reasons this exists are:

  1. written in Go so its easy to use/modify for Go devs
  2. policy violations are grouped by rule, vs. line number for easier mitigation
  3. policy violations are identified by JSON Schema pointere vs. line number for easier identification when using merged files

Other Linters

There are other linters available. To date, Spectrum Linter hasn't beeen inspired by any of them, though there is a desire and effort to align on rule names and potentially rule definitions to achieve similar behavior.

  1. Mermade OAS-Kit - https://github.com/mermade/oas-kit
  2. https://mermade.github.io/oas-kit/default-rules.html
  3. https://mermade.github.io/oas-kit/linter-rules.html
  4. Spectral - https://github.com/stoplightio/spectral
  5. Inspired by Speccy
  6. Speccy - https://github.com/wework/speccy
  7. Inspired by OAS-Kit

Documentation

Index

Constants

View Source
const (
	// Optional
	RuleDatatypeIntFormatIsInt32OrInt64 = "datatype-int-format-int32-int64"
	RuleOpDescExist                     = "operation-description-exist"
	RuleOpIdExist                       = "operation-operationid-exist"
	RuleOpIdStyleCamelCase              = "operation-operationid-style-camelcase"
	RuleOpSummaryExist                  = "operation-summary-exist"
	RuleOpSummaryCaseFirstCapitalized   = "operation-summary-first-letter-capitalized"
	RuleOpTagsCountOneOnly              = "operation-tags-count-one"
	RulePathParamNameExist              = "path-param-name-exist"
	RulePathParamStyleCamelCase         = "path-param-style-camelcase"
	RuleSchemaPropEnumStylePascalCase   = "property-enum-style-pascalcase"
	RuleSchemaPropDescExist             = "property-description-exist"
	RuleSchemaObjectPropsExist          = "schema-object-properties-exist"
	RuleTagCaseFirstCapitalized         = "tag-case-first-capitalized"

	// Mandatory
	RuleOpParameterNameNonEmpty = "operation-parameter-name-non-empty"

	// Prefixes
	PrefixPathParam          = "path.param."
	PrefixSchemaPropertyEnum = "schema.property.enum.style."

	RuleInternalError = "internal.error"

	LocationPaths   = "#/paths"
	LocationSchemas = "#/components/schemas"
)
View Source
const (
	SeverityDisabled    = "disabled"
	SeverityError       = "error"
	SeverityHint        = "hint"
	SeverityInformation = "information"
	SeverityWarning     = "warning"
)

Variables

This section is empty.

Functions

func PointerCondense

func PointerCondense(s string) string

func PointerSubEscapeAll

func PointerSubEscapeAll(format string, vars ...interface{}) string

func RuleToCaseStyle

func RuleToCaseStyle(s string) string

Types

type Policy

type Policy struct {
	// contains filtered or unexported fields
}

func NewPolicySimple

func NewPolicySimple(rules []string) Policy

func (*Policy) HasPathItemRules

func (pol *Policy) HasPathItemRules() bool

func (*Policy) HasRule

func (pol *Policy) HasRule(rule string) bool

func (*Policy) HasRulePrefix

func (pol *Policy) HasRulePrefix(prefix string) bool

func (*Policy) HasSchemaEnumStyleRules

func (pol *Policy) HasSchemaEnumStyleRules() bool

func (*Policy) RulesWithPrefix

func (pol *Policy) RulesWithPrefix(prefix string) []string

func (*Policy) Validate

func (pol *Policy) Validate() error

type PolicyRule

type PolicyRule struct {
	Name         string
	StringFormat string
}

type PolicyViolation

type PolicyViolation struct {
	RuleName  string
	RuleType  string
	Violation string
	Value     string
	Location  string
	Data      map[string]string
}

type PolicyViolationLocations

type PolicyViolationLocations struct {
	RuleName  string
	Locations []string
}

func (*PolicyViolationLocations) Finalize

func (vl *PolicyViolationLocations) Finalize()

type PolicyViolationsSet

type PolicyViolationsSet struct {
	RuleName   string
	Violations []PolicyViolation
}

func NewPolicyViolationsSet

func NewPolicyViolationsSet(ruleName string) PolicyViolationsSet

func (*PolicyViolationsSet) Count

func (set *PolicyViolationsSet) Count() uint

func (*PolicyViolationsSet) Locations

type PolicyViolationsSets

type PolicyViolationsSets struct {
	ByRule map[string]PolicyViolationsSet
}

func NewPolicyViolationsSets

func NewPolicyViolationsSets() PolicyViolationsSets

func ParametersCheck

func ParametersCheck(params oas3.Parameters, jsPointerParameters string, rules Policy) PolicyViolationsSets

func SpecCheckDataTypesFormats

func SpecCheckDataTypesFormats(spec *oas3.Swagger, ruleset Policy) PolicyViolationsSets

func SpecCheckOperations

func SpecCheckOperations(spec *oas3.Swagger, ruleset Policy) PolicyViolationsSets

func SpecCheckPathItems

func SpecCheckPathItems(spec *oas3.Swagger, rules Policy) PolicyViolationsSets

func SpecCheckSchemaObjectPropsExist

func SpecCheckSchemaObjectPropsExist(spec *oas3.Swagger) PolicyViolationsSets

func SpecCheckSchemaPropertyEnumCaseStyle

func SpecCheckSchemaPropertyEnumCaseStyle(spec *oas3.Swagger, rule string) PolicyViolationsSets

func SpecCheckSchemas

func SpecCheckSchemas(spec *oas3.Swagger, rules Policy) PolicyViolationsSets

func SpecCheckViolations

func SpecCheckViolations(spec *oas3.Swagger, rules Policy) (PolicyViolationsSets, error)

func (*PolicyViolationsSets) AddSimple

func (sets *PolicyViolationsSets) AddSimple(ruleName, location, value string)

func (*PolicyViolationsSets) Count

func (sets *PolicyViolationsSets) Count() uint

func (*PolicyViolationsSets) LocationsByRule

func (sets *PolicyViolationsSets) LocationsByRule() ViolationLocationsByRuleSet

func (*PolicyViolationsSets) UpsertSet

func (sets *PolicyViolationsSets) UpsertSet(upsertSet PolicyViolationsSet) error

func (*PolicyViolationsSets) UpsertSets

func (sets *PolicyViolationsSets) UpsertSets(upsertSets PolicyViolationsSets) error

type PolicyViolationsSetsByFile

type PolicyViolationsSetsByFile struct {
	Sets map[string]PolicyViolationsSets
}

func NewPolicyViolationsSetsByFile

func NewPolicyViolationsSetsByFile() PolicyViolationsSetsByFile

func (*PolicyViolationsSetsByFile) Count

func (byFile *PolicyViolationsSetsByFile) Count() uint

func (*PolicyViolationsSetsByFile) LocationsByRule

func (byFile *PolicyViolationsSetsByFile) LocationsByRule(filenameOnly, skipEmpty bool) map[string]ViolationLocationsByRuleSet

type Rule

type Rule struct {
	Name     string
	Severity string
	Func     func(spec *oas3.Swagger, ruleset Policy) PolicyViolationsSets
}

type SpecCheckViolationsFunc

type SpecCheckViolationsFunc func(spec *oas3.Swagger, rules Policy) PolicyViolationsSets

type ViolationLocationsByRuleSet

type ViolationLocationsByRuleSet struct {
	ViolationLocationsByRule map[string][]string
}

func (*ViolationLocationsByRuleSet) Condense

func (vlrs *ViolationLocationsByRuleSet) Condense()

func (*ViolationLocationsByRuleSet) Count

func (vlrs *ViolationLocationsByRuleSet) Count() uint

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL