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

v0.10.0 #500

Merged
merged 22 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,6 @@ like our _very kind_ sponsors:

[scalar](https://scalar.com)

<a href="https://zuplo.link/vacuum">
<picture>
<source media="(prefers-color-scheme: dark)" srcset=".github/sponsors/zuplo-dark.png">
<img alt="scalar" src=".github/sponsors/zuplo-light.png">
</picture>
</a>

[zuplo](https://zuplo.link/vacuum)


---

## Come chat with us
Expand All @@ -102,7 +92,17 @@ come say hi!

## Documentation

🔥 **New in** `v0.9+` 🔥 : **Built in Language Server**.
🔥 **New in** `v0.10+` 🔥 : **Quality release**.

v0.10 is a quality release, with a number of fixes and improvements to rule schemas, function names and more.
vacuum now powers [The OpenAPI doctor](https://pb33f.io/doctor/). To enable correct ruleset management and automation
a number of functions have been renamed, interfaces have been upgraded and rule functions schemas are now accurate.

This is a breaking change for anyone using vacuum as a library with custom rules.

---

`v0.9+` : **Built in Language Server**.

A new command is available `language-server`. This starts vacuum as an LSP compatible language server. Run vacuum
in your favorite IDE and get linting and validation as you type, in realtime.
Expand All @@ -112,8 +112,6 @@ Will support any LSP compatible editor, like VSCode, Sublime, vim, etc.
[Install the VSCode extension](https://marketplace.visualstudio.com/items?itemName=pb33f.vacuum)
[Learn more about the language-server command](https://quobix.com/vacuum/commands/language-server/)



---

`v0.8+` : **OpenAPI Bundler**.
Expand Down
5 changes: 5 additions & 0 deletions functions/core/alphabetical.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ func (a Alphabetical) GetSchema() model.RuleFunctionSchema {
}
}

// GetCategory returns the category of the Alphabetical rule.
func (a Alphabetical) GetCategory() string {
return model.FunctionCategoryCore
}

// RunRule will execute the Alphabetical rule, based on supplied context and a supplied []*yaml.Node slice.
func (a Alphabetical) RunRule(nodes []*yaml.Node, context model.RuleFunctionContext) []model.RuleFunctionResult {
var results []model.RuleFunctionResult
Expand Down
5 changes: 5 additions & 0 deletions functions/core/blank.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ func (b Blank) RunRule(nodes []*yaml.Node, context model.RuleFunctionContext) []
// return right away, nothing to do in here.
return nil
}

// GetCategory returns the category of the Blank rule.
func (b Blank) GetCategory() string {
return model.FunctionCategoryCore
}
11 changes: 9 additions & 2 deletions functions/core/casing.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ var casingTypes = []string{flat, camel, pascal, kebab, cobol, snake, macro}
// GetSchema returns a model.RuleFunctionSchema defining the schema of the Casing rule.
func (c Casing) GetSchema() model.RuleFunctionSchema {
return model.RuleFunctionSchema{
Name: "casing",
Required: []string{"type"},
Name: "casing",
Required: []string{"type"},
MinProperties: 1,
Properties: []model.RuleFunctionProperty{
{
Name: "type",
Expand All @@ -70,6 +71,12 @@ func (c Casing) GetSchema() model.RuleFunctionSchema {
}
}

// GetCategory returns the category of the Casing rule.
func (c Casing) GetCategory() string {
return model.FunctionCategoryCore

}

// RunRule will execute the Casing rule, based on supplied context and a supplied []*yaml.Node slice.
func (c Casing) RunRule(nodes []*yaml.Node, context model.RuleFunctionContext) []model.RuleFunctionResult {

Expand Down
5 changes: 5 additions & 0 deletions functions/core/defined.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ func (d Defined) GetSchema() model.RuleFunctionSchema {
}
}

// GetCategory returns the category of the Defined rule.
func (d Defined) GetCategory() string {
return model.FunctionCategoryCore
}

// RunRule will execute the Defined rule, based on supplied context and a supplied []*yaml.Node slice.
func (d Defined) RunRule(nodes []*yaml.Node, context model.RuleFunctionContext) []model.RuleFunctionResult {

Expand Down
7 changes: 6 additions & 1 deletion functions/core/enumeration.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@ func (e Enumeration) GetSchema() model.RuleFunctionSchema {
},
},
MinProperties: 1,
MaxProperties: 2,
MaxProperties: 10,
ErrorMessage: "'enumerate' needs 'values' to operate. A valid example of 'values' are: 'cake, egg, milk'",
}
}

// GetCategory returns the category of the Enumeration rule.
func (e Enumeration) GetCategory() string {
return model.FunctionCategoryCore
}

// RunRule will execute the Enumeration rule, based on supplied context and a supplied []*yaml.Node slice.
func (e Enumeration) RunRule(nodes []*yaml.Node, context model.RuleFunctionContext) []model.RuleFunctionResult {

Expand Down
5 changes: 5 additions & 0 deletions functions/core/falsy.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ func (f Falsy) GetSchema() model.RuleFunctionSchema {
}
}

// GetCategory returns the category of the Falsy rule.
func (f Falsy) GetCategory() string {
return model.FunctionCategoryCore
}

// RunRule will execute the Falsy rule, based on supplied context and a supplied []*yaml.Node slice.
func (f Falsy) RunRule(nodes []*yaml.Node, context model.RuleFunctionContext) []model.RuleFunctionResult {

Expand Down
7 changes: 6 additions & 1 deletion functions/core/length.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,15 @@ func (l Length) GetSchema() model.RuleFunctionSchema {
},
MinProperties: 1,
MaxProperties: 2,
ErrorMessage: "'length' needs 'min' or 'max' (or both) properties being set to operate",
ErrorMessage: "'length' needs 'min' or 'max' (or both) function options being set to operate",
}
}

// GetCategory returns the category of the Length rule.
func (l Length) GetCategory() string {
return model.FunctionCategoryCore
}

// RunRule will execute the Length rule, based on supplied context and a supplied []*yaml.Node slice.
func (l Length) RunRule(nodes []*yaml.Node, context model.RuleFunctionContext) []model.RuleFunctionResult {
var results []model.RuleFunctionResult
Expand Down
7 changes: 6 additions & 1 deletion functions/core/pattern.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,15 @@ func (p Pattern) GetSchema() model.RuleFunctionSchema {
},
MinProperties: 1,
MaxProperties: 2,
ErrorMessage: "'pattern' needs 'match' or 'notMatch' properties being set to operate",
ErrorMessage: "'pattern' needs 'match' or 'notMatch' function options being set to operate",
}
}

// GetCategory returns the category of the Pattern rule.
func (p Pattern) GetCategory() string {
return model.FunctionCategoryCore
}

// RunRule will execute the Pattern rule, based on supplied context and a supplied []*yaml.Node slice.
func (p Pattern) RunRule(nodes []*yaml.Node, context model.RuleFunctionContext) []model.RuleFunctionResult {

Expand Down
28 changes: 27 additions & 1 deletion functions/core/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,36 @@ type Schema struct {
// GetSchema returns a model.RuleFunctionSchema defining the schema of the OperationParameters rule.
func (sch Schema) GetSchema() model.RuleFunctionSchema {
return model.RuleFunctionSchema{
Name: "oas_schema",
Name: "schema",
Required: []string{"schema"},
MinProperties: 1,
Properties: []model.RuleFunctionProperty{
{
Name: "schema",
Description: "A valid JSON Schema object that will be used to validate",
},
{
Name: "unpack",
Description: "Treat the parent node as a document node and unpack it (default is false)",
},
{
Name: "forceValidation",
Description: "Force a failure if the field is not found (default is false)",
},
{
Name: "forceValidationOnCurrentNode",
Description: "Ignore the field value of the action, and validate the current node from JSON Path (default is false)",
},
},
ErrorMessage: "`schema` function needs a `schema` property to be supplied at a minimum",
}
}

// GetCategory returns the category of the OperationParameters rule.
func (sch Schema) GetCategory() string {
return model.FunctionCategoryCore
}

// RunRule will execute the Schema function
func (sch Schema) RunRule(nodes []*yaml.Node, context model.RuleFunctionContext) []model.RuleFunctionResult {

Expand Down
2 changes: 1 addition & 1 deletion functions/core/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

func TestOpenAPISchema_GetSchema(t *testing.T) {
def := Schema{}
assert.Equal(t, "oas_schema", def.GetSchema().Name)
assert.Equal(t, "schema", def.GetSchema().Name)
}

func TestOpenAPISchema_RunRule(t *testing.T) {
Expand Down
5 changes: 5 additions & 0 deletions functions/core/truthy.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ func (t Truthy) GetSchema() model.RuleFunctionSchema {
}
}

// GetCategory returns the category of the Truthy rule.
func (t Truthy) GetCategory() string {
return model.FunctionCategoryCore
}

// RunRule will execute the Truthy rule, based on supplied context and a supplied []*yaml.Node slice.
func (t *Truthy) RunRule(nodes []*yaml.Node, context model.RuleFunctionContext) []model.RuleFunctionResult {

Expand Down
5 changes: 5 additions & 0 deletions functions/core/undefined.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ func (u Undefined) GetSchema() model.RuleFunctionSchema {
}
}

// GetCategory returns the category of the Undefined rule.
func (u Undefined) GetCategory() string {
return model.FunctionCategoryCore
}

// RunRule will execute the Undefined rule, based on supplied context and a supplied []*yaml.Node slice.
func (u Undefined) RunRule(nodes []*yaml.Node, context model.RuleFunctionContext) []model.RuleFunctionResult {

Expand Down
10 changes: 8 additions & 2 deletions functions/core/xor.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ func (x Xor) GetSchema() model.RuleFunctionSchema {
Required: []string{"properties"},
Properties: []model.RuleFunctionProperty{
{
Name: "properties",
Description: "'xor' requires two values",
Name: "properties",
Description: "'xor' requires two values, examples of valid options are 'a, b'" +
" or '1, 2' etc (do not include quotes)",
},
},
MinProperties: 2,
Expand All @@ -34,6 +35,11 @@ func (x Xor) GetSchema() model.RuleFunctionSchema {
}
}

// GetCategory returns the category of the Xor rule.
func (x Xor) GetCategory() string {
return model.FunctionCategoryCore
}

// RunRule will execute the Xor rule, based on supplied context and a supplied []*yaml.Node slice.
func (x Xor) RunRule(nodes []*yaml.Node, context model.RuleFunctionContext) []model.RuleFunctionResult {

Expand Down
5 changes: 2 additions & 3 deletions functions/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func MapBuiltinFunctions() Functions {
funcs["schema"] = core.Schema{}

// add known OpenAPI rules
funcs["post-response-success"] = openapi_functions.PostResponseSuccess{}
funcs["postResponseSuccess"] = openapi_functions.PostResponseSuccess{}
funcs["oasOpSuccessResponse"] = openapi_functions.SuccessResponse{}
funcs["oasOpIdUnique"] = openapi_functions.UniqueOperationId{}
funcs["oasOpId"] = openapi_functions.OperationId{}
Expand All @@ -84,7 +84,6 @@ func MapBuiltinFunctions() Functions {
funcs["oasOperationTags"] = openapi_functions.OperationTags{}
funcs["oasOpFormDataConsumeCheck"] = openapi_functions.FormDataConsumeCheck{}
funcs["oasDiscriminator"] = openapi_functions.OAS2Discriminator{}
funcs["oasDiscriminator"] = openapi_functions.OAS2Discriminator{}
funcs["oasParamDescriptions"] = openapi_functions.ParameterDescription{}
funcs["oasOpSecurityDefined"] = openapi_functions.OperationSecurityDefined{}
funcs["oas2OpSecurityDefined"] = openapi_functions.OAS2OperationSecurityDefined{}
Expand Down Expand Up @@ -116,7 +115,7 @@ func MapBuiltinFunctions() Functions {
funcs["owaspIntegerLimit"] = owasp.IntegerLimit{}
funcs["owaspIntegerFormat"] = owasp.IntegerFormat{}
funcs["owaspNoAdditionalProperties"] = owasp.NoAdditionalProperties{}
funcs["owaspAdditionalPropertiesConstrained"] = owasp.AdditionalPropertiesConstrained{}
funcs["owaspNoAdditionalPropertiesConstrained"] = owasp.AdditionalPropertiesConstrained{}
funcs["owaspHostsHttps"] = owasp.HostsHttps{}

})
Expand Down
16 changes: 15 additions & 1 deletion functions/openapi/component_descriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,21 @@ type ComponentDescription struct {

// GetSchema returns a model.RuleFunctionSchema defining the schema of the ComponentDescription rule.
func (cd ComponentDescription) GetSchema() model.RuleFunctionSchema {
return model.RuleFunctionSchema{Name: "component_description"}
return model.RuleFunctionSchema{
Name: "oasComponentDescriptions",
Properties: []model.RuleFunctionProperty{
{
Name: "minWords",
Description: "Minimum number of words required in a description, defaults to '0'",
},
},
ErrorMessage: "'oasComponentDescriptions' function has invalid options supplied. Set the 'minWords' property to a valid integer",
}
}

// GetCategory returns the category of the ComponentDescription rule.
func (cd ComponentDescription) GetCategory() string {
return model.FunctionCategoryOpenAPI
}

// RunRule will execute the ComponentDescription rule, based on supplied context and a supplied []*yaml.Node slice.
Expand Down
2 changes: 1 addition & 1 deletion functions/openapi/component_descriptions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func TestComponentDescription_GetSchema(t *testing.T) {
def := ComponentDescription{}
assert.Equal(t, "component_description", def.GetSchema().Name)
assert.Equal(t, "oasComponentDescriptions", def.GetSchema().Name)
}

func TestComponentDescription_RunRule(t *testing.T) {
Expand Down
7 changes: 6 additions & 1 deletion functions/openapi/description_duplication.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ type DescriptionDuplication struct {

// GetSchema returns a model.RuleFunctionSchema defining the schema of the DescriptionDuplication rule.
func (dd DescriptionDuplication) GetSchema() model.RuleFunctionSchema {
return model.RuleFunctionSchema{Name: "description_duplication"}
return model.RuleFunctionSchema{Name: "oasDescriptionDuplication"}
}

// GetCategory returns the category of the DescriptionDuplication rule.
func (dd DescriptionDuplication) GetCategory() string {
return model.FunctionCategoryOpenAPI
}

// RunRule will execute the DescriptionDuplication rule, based on supplied context and a supplied []*yaml.Node slice.
Expand Down
2 changes: 1 addition & 1 deletion functions/openapi/description_duplication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func TestDescriptionDuplication_GetSchema(t *testing.T) {
def := DescriptionDuplication{}
assert.Equal(t, "description_duplication", def.GetSchema().Name)
assert.Equal(t, "oasDescriptionDuplication", def.GetSchema().Name)
}

func TestDescriptionDuplication_RunRule(t *testing.T) {
Expand Down
7 changes: 6 additions & 1 deletion functions/openapi/duplicated_enum_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ type DuplicatedEnum struct {
// GetSchema returns a model.RuleFunctionSchema defining the schema of the DuplicatedEnum rule.
func (de DuplicatedEnum) GetSchema() model.RuleFunctionSchema {
return model.RuleFunctionSchema{
Name: "duplicated_enum",
Name: "duplicatedEnum",
}
}

// GetCategory returns the category of the DuplicatedEnum rule.
func (de DuplicatedEnum) GetCategory() string {
return model.FunctionCategoryOpenAPI
}

// RunRule will execute the DuplicatedEnum rule, based on supplied context and a supplied []*yaml.Node slice.
func (de DuplicatedEnum) RunRule(_ []*yaml.Node, context model.RuleFunctionContext) []model.RuleFunctionResult {

Expand Down
2 changes: 1 addition & 1 deletion functions/openapi/duplicated_enum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func TestDuplicatedEnum_GetSchema(t *testing.T) {
def := DuplicatedEnum{}
assert.Equal(t, "duplicated_enum", def.GetSchema().Name)
assert.Equal(t, "duplicatedEnum", def.GetSchema().Name)
}

func TestDuplicatedEnum_RunRule(t *testing.T) {
Expand Down
7 changes: 6 additions & 1 deletion functions/openapi/examples_external_val.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ type ExamplesExternalCheck struct {

// GetSchema returns a model.RuleFunctionSchema defining the schema of the ComponentDescription rule.
func (eec ExamplesExternalCheck) GetSchema() model.RuleFunctionSchema {
return model.RuleFunctionSchema{Name: "examples_missing"}
return model.RuleFunctionSchema{Name: "oasExampleExternal"}
}

// GetCategory returns the category of the ComponentDescription rule.
func (eec ExamplesExternalCheck) GetCategory() string {
return model.FunctionCategoryOpenAPI
}

// RunRule will execute the ComponentDescription rule, based on supplied context and a supplied []*yaml.Node slice.
Expand Down
7 changes: 6 additions & 1 deletion functions/openapi/examples_missing.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ import (
type ExamplesMissing struct {
}

// GetCategory returns the category of the ExamplesMissing rule.
func (em ExamplesMissing) GetCategory() string {
return model.FunctionCategoryOpenAPI
}

// GetSchema returns a model.RuleFunctionSchema defining the schema of the ComponentDescription rule.
func (em ExamplesMissing) GetSchema() model.RuleFunctionSchema {
return model.RuleFunctionSchema{Name: "examples_missing"}
return model.RuleFunctionSchema{Name: "oasExampleMissing"}
}

// RunRule will execute the ComponentDescription rule, based on supplied context and a supplied []*yaml.Node slice.
Expand Down
Loading
Loading