diff --git a/CHANGELOG.md b/CHANGELOG.md index 18630630..58000b39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.4.1-beta-5] - 2026-06-02 + +### Fixed + +- OAR028 - FilterParameterCheck - Rewritten to extend `AbstractQueryParameterCheck`. Fires exactly once per GET operation when `$filter` query parameter is absent; does not fire if `$filter` is present alongside other parameters; resolves `$filter` referenced via `$ref` to components. Covers ALL collection GET endpoints except `/me` paths, terminal `/{id}` paths and health-check paths (`status`, `health`, `ping`). + ## [1.4.1-beta-4] - 2026-05-31 ### Fixed diff --git a/pom.xml b/pom.xml index 1c739495..43f67785 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.apiaddicts.apitools.dosonarapi sonaropenapi-rules-community - 1.4.1-beta-4 + 1.4.1-beta-5 sonar-plugin SonarQube OpenAPI Community Rules diff --git a/src/main/java/apiaddicts/sonar/openapi/checks/examples/OAR031ExamplesCheck.java b/src/main/java/apiaddicts/sonar/openapi/checks/examples/OAR031ExamplesCheck.java index c98fdeae..e63b1aed 100644 --- a/src/main/java/apiaddicts/sonar/openapi/checks/examples/OAR031ExamplesCheck.java +++ b/src/main/java/apiaddicts/sonar/openapi/checks/examples/OAR031ExamplesCheck.java @@ -216,7 +216,8 @@ private void visitSchemaNode2(JsonNode responseNode) { if (props.isMissing() || !props.isObject()) return; props.propertyMap().forEach((key, propertyNode) -> { - if (propertyNode.get(EXAMPLE).isMissing()) { + JsonNode type = getType(propertyNode); + if (!type.isMissing() && !isObjectType(type) && !isArrayType(type) && !isSchemaCovered(propertyNode)) { addIssue(KEY, translate("OAR031.error-property"), handleExternalRef.getTrueNode(propertyNode.key())); } }); diff --git a/src/main/java/apiaddicts/sonar/openapi/checks/format/AbstractFormatCheck.java b/src/main/java/apiaddicts/sonar/openapi/checks/format/AbstractFormatCheck.java index af276003..5d4d728b 100644 --- a/src/main/java/apiaddicts/sonar/openapi/checks/format/AbstractFormatCheck.java +++ b/src/main/java/apiaddicts/sonar/openapi/checks/format/AbstractFormatCheck.java @@ -27,8 +27,13 @@ private void visitV2Node(JsonNode node) { JsonNode typeNode = node.get("type"); String type = typeNode.getTokenValue(); JsonNode formatNode = node.get("format"); - String format = formatNode.isMissing() ? null : formatNode.getTokenValue(); - validate(type, format, typeNode); + if (formatNode.isMissing()) { + validate(type, null, typeNode); + return; + } + String format = formatNode.getTokenValue(); + if (format == null || format.isBlank()) return; + validate(type, format.trim(), typeNode); } public abstract void validate(String type, String format, JsonNode typeNode); diff --git a/src/main/java/apiaddicts/sonar/openapi/checks/parameters/AbstractCollectionQueryParameterCheck.java b/src/main/java/apiaddicts/sonar/openapi/checks/parameters/AbstractCollectionQueryParameterCheck.java new file mode 100644 index 00000000..0eef8f02 --- /dev/null +++ b/src/main/java/apiaddicts/sonar/openapi/checks/parameters/AbstractCollectionQueryParameterCheck.java @@ -0,0 +1,30 @@ +package apiaddicts.sonar.openapi.checks.parameters; + +import org.apiaddicts.apitools.dosonarapi.sslr.yaml.grammar.JsonNode; + +public abstract class AbstractCollectionQueryParameterCheck extends AbstractQueryParameterCheck { + + protected AbstractCollectionQueryParameterCheck( + String ruleKey, + String messageKey, + String parameterName, + boolean applyToParameterizedPaths + ) { + super(ruleKey, messageKey, parameterName, applyToParameterizedPaths); + } + + @Override + public void visitNode(JsonNode node) { + if (!"get".equals(node.key().getTokenValue())) return; + + String path = getPath(node); + + if (endsWithPathParam(path)) return; + if (path.contains("/me/") || path.endsWith("/me")) return; + if (path.contains("status") || path.contains("health") || path.contains("ping")) return; + + if (!hasParameterInNode(node)) { + addIssue(ruleKey, translate(messageKey, parameterName), node.key()); + } + } +} diff --git a/src/main/java/apiaddicts/sonar/openapi/checks/parameters/AbstractQueryParameterCheck.java b/src/main/java/apiaddicts/sonar/openapi/checks/parameters/AbstractQueryParameterCheck.java index d8b133e0..c5f31e28 100644 --- a/src/main/java/apiaddicts/sonar/openapi/checks/parameters/AbstractQueryParameterCheck.java +++ b/src/main/java/apiaddicts/sonar/openapi/checks/parameters/AbstractQueryParameterCheck.java @@ -25,7 +25,7 @@ public abstract class AbstractQueryParameterCheck extends BaseCheck { protected final String ruleKey; protected final String messageKey; - protected final String parameterName; + protected String parameterName; protected final boolean applyToParameterizedPaths; protected Set paths; diff --git a/src/main/java/apiaddicts/sonar/openapi/checks/parameters/OAR020ExpandParameterCheck.java b/src/main/java/apiaddicts/sonar/openapi/checks/parameters/OAR020ExpandParameterCheck.java index 299b6369..fdac58e8 100644 --- a/src/main/java/apiaddicts/sonar/openapi/checks/parameters/OAR020ExpandParameterCheck.java +++ b/src/main/java/apiaddicts/sonar/openapi/checks/parameters/OAR020ExpandParameterCheck.java @@ -1,10 +1,9 @@ package apiaddicts.sonar.openapi.checks.parameters; -import org.apiaddicts.apitools.dosonarapi.sslr.yaml.grammar.JsonNode; import org.sonar.check.Rule; @Rule(key = OAR020ExpandParameterCheck.KEY) -public class OAR020ExpandParameterCheck extends AbstractQueryParameterCheck { +public class OAR020ExpandParameterCheck extends AbstractCollectionQueryParameterCheck { public static final String KEY = "OAR020"; private static final String MESSAGE = "OAR020.error"; @@ -13,19 +12,4 @@ public class OAR020ExpandParameterCheck extends AbstractQueryParameterCheck { public OAR020ExpandParameterCheck() { super(KEY, MESSAGE, PARAM_NAME, false); } - - @Override - public void visitNode(JsonNode node) { - if (!"get".equals(node.key().getTokenValue())) return; - - String path = getPath(node); - - if (endsWithPathParam(path)) return; - if (path.contains("/me/") || path.endsWith("/me")) return; - if (path.contains("status") || path.contains("health") || path.contains("ping")) return; - - if (!hasParameterInNode(node)) { - addIssue(ruleKey, translate(messageKey, parameterName), node.key()); - } - } } \ No newline at end of file diff --git a/src/main/java/apiaddicts/sonar/openapi/checks/parameters/OAR021ExcludeParameterCheck.java b/src/main/java/apiaddicts/sonar/openapi/checks/parameters/OAR021ExcludeParameterCheck.java index 19d8e1c1..a8b52bfc 100644 --- a/src/main/java/apiaddicts/sonar/openapi/checks/parameters/OAR021ExcludeParameterCheck.java +++ b/src/main/java/apiaddicts/sonar/openapi/checks/parameters/OAR021ExcludeParameterCheck.java @@ -1,10 +1,9 @@ package apiaddicts.sonar.openapi.checks.parameters; -import org.apiaddicts.apitools.dosonarapi.sslr.yaml.grammar.JsonNode; import org.sonar.check.Rule; @Rule(key = OAR021ExcludeParameterCheck.KEY) -public class OAR021ExcludeParameterCheck extends AbstractQueryParameterCheck { +public class OAR021ExcludeParameterCheck extends AbstractCollectionQueryParameterCheck { public static final String KEY = "OAR021"; private static final String MESSAGE = "OAR021.error"; @@ -13,19 +12,4 @@ public class OAR021ExcludeParameterCheck extends AbstractQueryParameterCheck { public OAR021ExcludeParameterCheck() { super(KEY, MESSAGE, PARAM_NAME, false); } - - @Override - public void visitNode(JsonNode node) { - if (!"get".equals(node.key().getTokenValue())) return; - - String path = getPath(node); - - if (endsWithPathParam(path)) return; - if (path.contains("/me/") || path.endsWith("/me")) return; - if (path.contains("status") || path.contains("health") || path.contains("ping")) return; - - if (!hasParameterInNode(node)) { - addIssue(ruleKey, translate(messageKey, parameterName), node.key()); - } - } } \ No newline at end of file diff --git a/src/main/java/apiaddicts/sonar/openapi/checks/parameters/OAR028FilterParameterCheck.java b/src/main/java/apiaddicts/sonar/openapi/checks/parameters/OAR028FilterParameterCheck.java index 9ddd2738..703e56e9 100644 --- a/src/main/java/apiaddicts/sonar/openapi/checks/parameters/OAR028FilterParameterCheck.java +++ b/src/main/java/apiaddicts/sonar/openapi/checks/parameters/OAR028FilterParameterCheck.java @@ -1,118 +1,30 @@ package apiaddicts.sonar.openapi.checks.parameters; -import java.util.Set; -import java.util.stream.Collectors; - -import org.apiaddicts.apitools.dosonarapi.api.v2.OpenApi2Grammar; -import org.apiaddicts.apitools.dosonarapi.api.v3.OpenApi3Grammar; -import org.apiaddicts.apitools.dosonarapi.api.v31.OpenApi31Grammar; -import org.apiaddicts.apitools.dosonarapi.api.v32.OpenApi32Grammar; import org.apiaddicts.apitools.dosonarapi.sslr.yaml.grammar.JsonNode; import org.sonar.check.Rule; import org.sonar.check.RuleProperty; -import apiaddicts.sonar.openapi.checks.BaseCheck; - -import com.google.common.collect.ImmutableSet; -import com.sonar.sslr.api.AstNode; -import com.sonar.sslr.api.AstNodeType; - -import java.util.Arrays; -import java.util.HashSet; @Rule(key = OAR028FilterParameterCheck.KEY) -public class OAR028FilterParameterCheck extends BaseCheck { +public class OAR028FilterParameterCheck extends AbstractCollectionQueryParameterCheck { public static final String KEY = "OAR028"; private static final String MESSAGE = "OAR028.error"; - private static final String DEFAULT_PATH = "/examples"; - private static final String PATH_STRATEGY = "/include"; - private static final String PARAM_NAME = "$filter"; - - private static final String PATH_STRATEGY_EXCLUDE = "/exclude"; - private static final String PATH_STRATEGY_INCLUDE = "/include"; - - @RuleProperty( - key = "paths", - description = "List of explicit paths to include/exclude from this rule separated by comma", - defaultValue = DEFAULT_PATH - ) - private String pathsStr = DEFAULT_PATH; - - @RuleProperty( - key = "pathValidationStrategy", - description = "Path validation strategy (include/exclude)", - defaultValue = PATH_STRATEGY - ) - private String pathCheckStrategy = PATH_STRATEGY; + private static final String DEFAULT_PARAM_NAME = "$filter"; @RuleProperty( key = "parameterName", - description = "Name of the parameter to be checked", - defaultValue = PARAM_NAME + description = "Name of the query parameter to be checked", + defaultValue = DEFAULT_PARAM_NAME ) - private String parameterName = PARAM_NAME; - - private Set paths; + private String filterParamName = DEFAULT_PARAM_NAME; - @Override - public Set subscribedKinds() { - return ImmutableSet.of(OpenApi2Grammar.PARAMETER, OpenApi3Grammar.PARAMETER, OpenApi31Grammar.PARAMETER, OpenApi32Grammar.PARAMETER); + public OAR028FilterParameterCheck() { + super(KEY, MESSAGE, DEFAULT_PARAM_NAME, false); } @Override protected void visitFile(JsonNode root) { - paths = parsePaths(pathsStr); + this.parameterName = filterParamName; super.visitFile(root); } - - @Override - public void visitNode(JsonNode node) { - visitParameterNode(node); - } - - public void visitParameterNode(JsonNode node) { - JsonNode inNode = node.get("in"); - JsonNode nameNode = node.get("name"); - - if (inNode != null && nameNode != null) { - if (!"query".equals(inNode.getTokenValue())) { - return; - } - String path = getPath(node); - if (shouldExcludePath(path) && !parameterName.equals(nameNode.getTokenValue())) { - addIssue(KEY, translate(MESSAGE, parameterName), nameNode); - } - } - } - - private String getPath(JsonNode node) { - StringBuilder pathBuilder = new StringBuilder(); - AstNode pathNode = node.getFirstAncestor(OpenApi2Grammar.PATH, OpenApi3Grammar.PATH, OpenApi31Grammar.PATH, OpenApi32Grammar.PATH); - if (pathNode != null) { - while (pathNode.getType() != OpenApi2Grammar.PATH && pathNode.getType() != OpenApi3Grammar.PATH && pathNode.getType() != OpenApi31Grammar.PATH && pathNode.getType() != OpenApi32Grammar.PATH) { - pathNode = pathNode.getParent(); - } - pathBuilder.append(((JsonNode) pathNode).key().getTokenValue()); - } - return pathBuilder.toString(); - } - - private boolean shouldExcludePath(String path) { - if (pathCheckStrategy.equals(PATH_STRATEGY_EXCLUDE)) { - return !paths.contains(path); - } else if (pathCheckStrategy.equals(PATH_STRATEGY_INCLUDE)) { - return paths.contains(path); - } - return false; - } - - private Set parsePaths(String pathsStr) { - if (!pathsStr.trim().isEmpty()) { - return Arrays.stream(pathsStr.split(",")) - .map(String::trim) - .collect(Collectors.toSet()); - } else { - return new HashSet<>(); - } - } -} \ No newline at end of file +} diff --git a/src/main/resources/org/sonar/l10n/es/openapi/rules/openapi/format/OAR037.html b/src/main/resources/org/sonar/l10n/es/openapi/rules/openapi/format/OAR037.html index 0485b8b9..7f3e14a0 100644 --- a/src/main/resources/org/sonar/l10n/es/openapi/rules/openapi/format/OAR037.html +++ b/src/main/resources/org/sonar/l10n/es/openapi/rules/openapi/format/OAR037.html @@ -20,9 +20,9 @@

Ejemplo de código no compatible (OpenAPI 2)

type: object properties: name: - type: string + type: string # No conforme {{OAR037: Las propiedades de tipo string deben definir un formato válido}} — format ausente date: - type: string + type: string # No conforme {{OAR037: Las propiedades de tipo string deben definir un formato válido}} — format inválido format: 'dd/mm/yyyy'

Solución compatible (OpenAPI 2)

@@ -66,9 +66,9 @@

Ejemplo de código no compatible (OpenAPI 3)

type: object properties: name: - type: string + type: string # No conforme {{OAR037: Las propiedades de tipo string deben definir un formato válido}} — format ausente date: - type: string + type: string # No conforme {{OAR037: Las propiedades de tipo string deben definir un formato válido}} — format inválido format: dd/mm/yyyy

Solución compatible (OpenAPI 3)

diff --git a/src/main/resources/org/sonar/l10n/es/openapi/rules/openapi/parameters/OAR028.html b/src/main/resources/org/sonar/l10n/es/openapi/rules/openapi/parameters/OAR028.html index 0319e27e..18e944be 100644 --- a/src/main/resources/org/sonar/l10n/es/openapi/rules/openapi/parameters/OAR028.html +++ b/src/main/resources/org/sonar/l10n/es/openapi/rules/openapi/parameters/OAR028.html @@ -1,4 +1,4 @@ -

The chosen parameter must be defined in this operation. By default, $filter

+

El parámetro de consulta $filter debe estar presente en las operaciones GET de colección. Se genera un único issue por operación a la que le falta el parámetro $filter.

Ejemplo de código no compatible (OpenAPI 2)

   swagger: "2.0"
@@ -7,15 +7,10 @@ 

Ejemplo de código no compatible (OpenAPI 2)

title: Swagger Petstore paths: /pets: - get: - parameters: - - in: query - name: other - type: array - items: - type: string + get: # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + parameters: - in: query - name: hola + name: other type: array items: type: string @@ -23,7 +18,7 @@

Ejemplo de código no compatible (OpenAPI 2)

206: description: Ok
-

Compliant Solution (OpenAPI 2)

+

Solución compatible (OpenAPI 2)

   swagger: "2.0"
   info:
@@ -38,16 +33,11 @@ 

Compliant Solution (OpenAPI 2)

type: array items: type: string - - in: query - name: $filter - type: array - items: - type: string responses: 206: description: Ok
-

Noncompliant Code Example (OpenAPI 3)

+

Ejemplo de código no compatible (OpenAPI 3)

   openapi: "3.0.0"
   info:
@@ -55,16 +45,10 @@ 

Noncompliant Code Example (OpenAPI 3)

title: Swagger Petstore paths: /pets: - get: - parameters: - - in: query - name: other - schema: - type: array - items: - type: string + get: # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + parameters: - in: query - name: select + name: other schema: type: array items: @@ -73,7 +57,7 @@

Noncompliant Code Example (OpenAPI 3)

206: description: Ok
-

Compliant Solution (OpenAPI 3)

+

Solución compatible (OpenAPI 3)

   openapi: "3.0.0"
   info:
@@ -89,13 +73,7 @@ 

Compliant Solution (OpenAPI 3)

type: array items: type: string - - in: query - name: $filter - schema: - type: array - items: - type: string responses: 206: description: Ok -
\ No newline at end of file + diff --git a/src/main/resources/org/sonar/l10n/openapi/rules/openapi/parameters/OAR028.html b/src/main/resources/org/sonar/l10n/openapi/rules/openapi/parameters/OAR028.html index 228f3060..d7e0171a 100644 --- a/src/main/resources/org/sonar/l10n/openapi/rules/openapi/parameters/OAR028.html +++ b/src/main/resources/org/sonar/l10n/openapi/rules/openapi/parameters/OAR028.html @@ -1,4 +1,4 @@ -

The chosen parameter must be defined in this operation. By default, $filter

+

The $filter query parameter must be present in GET collection operations. One issue is raised per operation missing the $filter parameter.

Noncompliant Code Example (OpenAPI 2)

   swagger: "2.0"
@@ -7,15 +7,10 @@ 

Noncompliant Code Example (OpenAPI 2)

title: Swagger Petstore paths: /pets: - get: - parameters: - - in: query - name: other # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} - type: array - items: - type: string + get: # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + parameters: - in: query - name: hola # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + name: other type: array items: type: string @@ -38,11 +33,6 @@

Compliant Solution (OpenAPI 2)

type: array items: type: string - - in: query - name: $filter - type: array - items: - type: string responses: 206: description: Ok @@ -55,16 +45,10 @@

Noncompliant Code Example (OpenAPI 3)

title: Swagger Petstore paths: /pets: - get: - parameters: - - in: query - name: other # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} - schema: - type: array - items: - type: string + get: # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + parameters: - in: query - name: select # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + name: other schema: type: array items: @@ -89,13 +73,7 @@

Compliant Solution (OpenAPI 3)

type: array items: type: string - - in: query - name: $filter - schema: - type: array - items: - type: string responses: 206: description: Ok -
\ No newline at end of file + diff --git a/src/test/java/apiaddicts/sonar/openapi/checks/examples/OAR031ExamplesCheckTest.java b/src/test/java/apiaddicts/sonar/openapi/checks/examples/OAR031ExamplesCheckTest.java index 5b1e4ce7..5cea16f8 100644 --- a/src/test/java/apiaddicts/sonar/openapi/checks/examples/OAR031ExamplesCheckTest.java +++ b/src/test/java/apiaddicts/sonar/openapi/checks/examples/OAR031ExamplesCheckTest.java @@ -90,6 +90,23 @@ public void verifyInV32NestedProperties() { verifyV32("nested-properties-examples.yaml"); } + @Test + public void verifyInV2AllOfSchema() { + verifyV2("allof-schema"); + } + @Test + public void verifyInV3AllOfSchema() { + verifyV3("allof-schema"); + } + @Test + public void verifyInV31AllOfSchema() { + verifyV31("allof-schema"); + } + @Test + public void verifyInV32AllOfSchema() { + verifyV32("allof-schema"); + } + @Override public void verifyRule() { assertRuleProperties("OAR031 - Examples - Responses, Request Body, Parameters and Properties must have an example defined", RuleType.BUG, Severity.MAJOR, tags("examples")); diff --git a/src/test/java/apiaddicts/sonar/openapi/checks/format/OAR037StringFormatCheckTest.java b/src/test/java/apiaddicts/sonar/openapi/checks/format/OAR037StringFormatCheckTest.java index ad43517b..ad561e9b 100644 --- a/src/test/java/apiaddicts/sonar/openapi/checks/format/OAR037StringFormatCheckTest.java +++ b/src/test/java/apiaddicts/sonar/openapi/checks/format/OAR037StringFormatCheckTest.java @@ -65,6 +65,11 @@ public void verifyInV32WithNested() { verifyV3("with-$ref"); } + @Test + public void verifyInV2BlankFormat() { + verifyV2("blank-format"); + } + @Override public void verifyParameters() { assertNumberOfParameters(1); diff --git a/src/test/java/apiaddicts/sonar/openapi/checks/parameters/OAR028FilterParameterCheckTest.java b/src/test/java/apiaddicts/sonar/openapi/checks/parameters/OAR028FilterParameterCheckTest.java index c37d4ca8..e2d9350f 100644 --- a/src/test/java/apiaddicts/sonar/openapi/checks/parameters/OAR028FilterParameterCheckTest.java +++ b/src/test/java/apiaddicts/sonar/openapi/checks/parameters/OAR028FilterParameterCheckTest.java @@ -160,9 +160,35 @@ public void verifyInV32HeaderIgnored() { verifyV32("header-ignored"); } + @Test + public void verifyInV2MeHealthPing() { + verifyV2("me-health-ping"); + } + @Test + public void verifyInV3MeHealthPing() { + verifyV3("me-health-ping"); + } + @Test + public void verifyInV31MeHealthPing() { + verifyV31("me-health-ping"); + } + @Test + public void verifyInV32MeHealthPing() { + verifyV32("me-health-ping"); + } + private void setField(String name, String value) { try { - java.lang.reflect.Field f = OAR028FilterParameterCheck.class.getDeclaredField(name); + java.lang.reflect.Field f = null; + Class clazz = check.getClass(); + while (clazz != null && f == null) { + try { + f = clazz.getDeclaredField(name); + } catch (NoSuchFieldException e) { + clazz = clazz.getSuperclass(); + } + } + if (f == null) throw new NoSuchFieldException(name); f.setAccessible(true); f.set(check, value); } catch (Exception e) { diff --git a/src/test/resources/checks/v2/examples/OAR031/allof-schema.json b/src/test/resources/checks/v2/examples/OAR031/allof-schema.json new file mode 100644 index 00000000..177244f6 --- /dev/null +++ b/src/test/resources/checks/v2/examples/OAR031/allof-schema.json @@ -0,0 +1,48 @@ +{ + "swagger" : "2.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "definitions" : { + "BaseEntity" : { + "type" : "object", + "properties" : { + "id" : { + "type" : "integer", + "example" : 1 + } + } + }, + "Pet" : { + "allOf" : [ { + "$ref" : "#/definitions/BaseEntity" + } ], + "properties" : { + "name" : { + "type" : "string", + "example" : "Fluffy" + } + } + } + }, + "paths" : { + "/pets" : { + "get" : { + "responses" : { + "200" : { + "description" : "Ok", + "schema" : { + "$ref" : "#/definitions/Pet" + }, + "examples" : { + "application/json" : { + "name" : "Fluffy" + } + } + } + } + } + } + } +} diff --git a/src/test/resources/checks/v2/examples/OAR031/allof-schema.yaml b/src/test/resources/checks/v2/examples/OAR031/allof-schema.yaml new file mode 100644 index 00000000..fefb074b --- /dev/null +++ b/src/test/resources/checks/v2/examples/OAR031/allof-schema.yaml @@ -0,0 +1,29 @@ +swagger: "2.0" +info: + version: 1.0.0 + title: Swagger Petstore +definitions: + BaseEntity: + type: object + properties: + id: + type: integer + example: 1 + Pet: + allOf: + - $ref: '#/definitions/BaseEntity' + properties: + name: + type: string + example: "Fluffy" +paths: + /pets: + get: + responses: + 200: + description: Ok + schema: + $ref: '#/definitions/Pet' + examples: + application/json: + name: Fluffy diff --git a/src/test/resources/checks/v2/examples/OAR031/valid.yaml b/src/test/resources/checks/v2/examples/OAR031/valid.yaml index 21990b09..abb84e89 100644 --- a/src/test/resources/checks/v2/examples/OAR031/valid.yaml +++ b/src/test/resources/checks/v2/examples/OAR031/valid.yaml @@ -51,7 +51,7 @@ definitions: size: type: integer example: 1 - pets: # Noncompliant {{OAR031: Properties must have an example defined}} + pets: type: array items: $ref: '#/definitions/pet' diff --git a/src/test/resources/checks/v2/examples/OAR031/without-examples.yaml b/src/test/resources/checks/v2/examples/OAR031/without-examples.yaml index b877dfa4..cfb67cc7 100644 --- a/src/test/resources/checks/v2/examples/OAR031/without-examples.yaml +++ b/src/test/resources/checks/v2/examples/OAR031/without-examples.yaml @@ -48,7 +48,7 @@ definitions: properties: size: # Noncompliant {{OAR031: Properties must have an example defined}} type: integer - pets: # Noncompliant {{OAR031: Properties must have an example defined}} + pets: type: array items: $ref: '#/definitions/pet' diff --git a/src/test/resources/checks/v2/format/OAR037/blank-format.json b/src/test/resources/checks/v2/format/OAR037/blank-format.json new file mode 100644 index 00000000..05b6299e --- /dev/null +++ b/src/test/resources/checks/v2/format/OAR037/blank-format.json @@ -0,0 +1,27 @@ +{ + "swagger" : "2.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/invoices" : { + "get" : { + "responses" : { + "200" : { + "description" : "A invoice.", + "schema" : { + "type" : "object", + "properties" : { + "blank_format" : { + "type" : "string", + "format" : "" + } + } + } + } + } + } + } + } +} diff --git a/src/test/resources/checks/v2/format/OAR037/blank-format.yaml b/src/test/resources/checks/v2/format/OAR037/blank-format.yaml new file mode 100644 index 00000000..00464338 --- /dev/null +++ b/src/test/resources/checks/v2/format/OAR037/blank-format.yaml @@ -0,0 +1,16 @@ +swagger: "2.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /invoices: + get: + responses: + 200: + description: A invoice. + schema: + type: object + properties: + blank_format: + type: string + format: "" diff --git a/src/test/resources/checks/v2/parameters/OAR028/exclude-noncompliant.json b/src/test/resources/checks/v2/parameters/OAR028/exclude-noncompliant.json index 01030ba9..6debb878 100644 --- a/src/test/resources/checks/v2/parameters/OAR028/exclude-noncompliant.json +++ b/src/test/resources/checks/v2/parameters/OAR028/exclude-noncompliant.json @@ -5,18 +5,18 @@ "title" : "Swagger Petstore" }, "paths" : { - "/status" : { - "get" : { + "/orders" : { + "get" : { # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} "parameters" : [ { "in" : "query", - "name" : "other", # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + "name" : "other", "type" : "array", "items" : { "type" : "string" } }, { "in" : "query", - "name" : "select", # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + "name" : "select", "type" : "array", "items" : { "type" : "string" diff --git a/src/test/resources/checks/v2/parameters/OAR028/exclude-noncompliant.yaml b/src/test/resources/checks/v2/parameters/OAR028/exclude-noncompliant.yaml index 5b5548d1..9f45515e 100644 --- a/src/test/resources/checks/v2/parameters/OAR028/exclude-noncompliant.yaml +++ b/src/test/resources/checks/v2/parameters/OAR028/exclude-noncompliant.yaml @@ -3,16 +3,16 @@ info: version: 1.0.0 title: Swagger Petstore paths: - /status: - get: + /orders: + get: # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} parameters: - in: query - name: other # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + name: other type: array items: type: string - in: query - name: select # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + name: select type: array items: type: string diff --git a/src/test/resources/checks/v2/parameters/OAR028/me-health-ping.json b/src/test/resources/checks/v2/parameters/OAR028/me-health-ping.json new file mode 100644 index 00000000..25e15525 --- /dev/null +++ b/src/test/resources/checks/v2/parameters/OAR028/me-health-ping.json @@ -0,0 +1,63 @@ +{ + "swagger" : "2.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/examples" : { + "post" : { + "responses" : { + "206" : { + "description" : "Ok" + } + } + } + }, + "/pets/{id}" : { + "get" : { + "responses" : { + "206" : { + "description" : "Ok" + } + } + } + }, + "/users/me" : { + "get" : { + "responses" : { + "206" : { + "description" : "Ok" + } + } + } + }, + "/users/me/settings" : { + "get" : { + "responses" : { + "206" : { + "description" : "Ok" + } + } + } + }, + "/health" : { + "get" : { + "responses" : { + "206" : { + "description" : "Ok" + } + } + } + }, + "/ping" : { + "get" : { + "responses" : { + "206" : { + "description" : "Ok" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v2/parameters/OAR028/me-health-ping.yaml b/src/test/resources/checks/v2/parameters/OAR028/me-health-ping.yaml new file mode 100644 index 00000000..50c39dc6 --- /dev/null +++ b/src/test/resources/checks/v2/parameters/OAR028/me-health-ping.yaml @@ -0,0 +1,35 @@ +swagger: "2.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /examples: + post: + responses: + 206: + description: Ok + /pets/{id}: + get: + responses: + 206: + description: Ok + /users/me: + get: + responses: + 206: + description: Ok + /users/me/settings: + get: + responses: + 206: + description: Ok + /health: + get: + responses: + 206: + description: Ok + /ping: + get: + responses: + 206: + description: Ok diff --git a/src/test/resources/checks/v2/parameters/OAR028/plain-without.json b/src/test/resources/checks/v2/parameters/OAR028/plain-without.json index 79714f09..030fcb40 100644 --- a/src/test/resources/checks/v2/parameters/OAR028/plain-without.json +++ b/src/test/resources/checks/v2/parameters/OAR028/plain-without.json @@ -6,17 +6,17 @@ }, "paths" : { "/examples" : { - "get" : { - "parameters" : [ { + "get" : { # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + "parameters" : [ { "in" : "query", - "name" : "other", # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + "name" : "other", "type" : "array", "items" : { "type" : "string" } }, { "in" : "query", - "name" : "hola", # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + "name" : "hola", "type" : "array", "items" : { "type" : "string" @@ -30,4 +30,4 @@ } } } -} \ No newline at end of file +} diff --git a/src/test/resources/checks/v2/parameters/OAR028/plain-without.yaml b/src/test/resources/checks/v2/parameters/OAR028/plain-without.yaml index 6f972993..80432464 100644 --- a/src/test/resources/checks/v2/parameters/OAR028/plain-without.yaml +++ b/src/test/resources/checks/v2/parameters/OAR028/plain-without.yaml @@ -4,18 +4,18 @@ info: title: Swagger Petstore paths: /examples: - get: - parameters: + get: # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + parameters: - in: query - name: other # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + name: other type: array items: type: string - in: query - name: hola # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + name: hola type: array items: type: string responses: 206: - description: Ok \ No newline at end of file + description: Ok diff --git a/src/test/resources/checks/v3/examples/OAR031/allof-schema.json b/src/test/resources/checks/v3/examples/OAR031/allof-schema.json new file mode 100644 index 00000000..92f78ec7 --- /dev/null +++ b/src/test/resources/checks/v3/examples/OAR031/allof-schema.json @@ -0,0 +1,55 @@ +{ + "openapi" : "3.0.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "components" : { + "schemas" : { + "BaseEntity" : { + "type" : "object", + "properties" : { + "id" : { + "type" : "integer", + "example" : 1 + } + } + }, + "Pet" : { + "allOf" : [ { + "$ref" : "#/components/schemas/BaseEntity" + } ], + "properties" : { + "name" : { + "type" : "string", + "example" : "Fluffy" + } + } + } + } + }, + "paths" : { + "/pets" : { + "get" : { + "responses" : { + "200" : { + "description" : "Ok", + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/Pet" + }, + "example" : { + "name" : "Fluffy" + } + } + } + }, + "204" : { + "description" : "No content" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v3/examples/OAR031/allof-schema.yaml b/src/test/resources/checks/v3/examples/OAR031/allof-schema.yaml new file mode 100644 index 00000000..d3ebc8df --- /dev/null +++ b/src/test/resources/checks/v3/examples/OAR031/allof-schema.yaml @@ -0,0 +1,33 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +components: + schemas: + BaseEntity: + type: object + properties: + id: + type: integer + example: 1 + Pet: + allOf: + - $ref: '#/components/schemas/BaseEntity' + properties: + name: + type: string + example: "Fluffy" +paths: + /pets: + get: + responses: + 200: + description: Ok + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + example: + name: Fluffy + 204: + description: No content diff --git a/src/test/resources/checks/v3/parameters/OAR028/components-param.json b/src/test/resources/checks/v3/parameters/OAR028/components-param.json index 38b3f30a..8e540684 100644 --- a/src/test/resources/checks/v3/parameters/OAR028/components-param.json +++ b/src/test/resources/checks/v3/parameters/OAR028/components-param.json @@ -8,7 +8,7 @@ "parameters" : { "filterParam" : { "in" : "query", - "name" : "other", + "name" : "$filter", "schema" : { "type" : "string" } @@ -18,6 +18,9 @@ "paths" : { "/examples" : { "get" : { + "parameters" : [ + { "$ref" : "#/components/parameters/filterParam" } + ], "responses" : { "200" : { "description" : "Ok" diff --git a/src/test/resources/checks/v3/parameters/OAR028/components-param.yaml b/src/test/resources/checks/v3/parameters/OAR028/components-param.yaml index 18bc4ac4..a553d250 100644 --- a/src/test/resources/checks/v3/parameters/OAR028/components-param.yaml +++ b/src/test/resources/checks/v3/parameters/OAR028/components-param.yaml @@ -6,12 +6,14 @@ components: parameters: filterParam: in: query - name: other + name: $filter schema: type: string paths: /examples: get: + parameters: + - $ref: '#/components/parameters/filterParam' responses: 200: description: Ok diff --git a/src/test/resources/checks/v3/parameters/OAR028/exclude-noncompliant.json b/src/test/resources/checks/v3/parameters/OAR028/exclude-noncompliant.json index ec73f987..67435d01 100644 --- a/src/test/resources/checks/v3/parameters/OAR028/exclude-noncompliant.json +++ b/src/test/resources/checks/v3/parameters/OAR028/exclude-noncompliant.json @@ -5,11 +5,11 @@ "title" : "Swagger Petstore" }, "paths" : { - "/status" : { - "get" : { + "/orders" : { + "get" : { # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} "parameters" : [ { "in" : "query", - "name" : "other", # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + "name" : "other", "schema" : { "type" : "array", "items" : { @@ -18,7 +18,7 @@ } }, { "in" : "query", - "name" : "select", # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + "name" : "select", "schema" : { "type" : "array", "items" : { diff --git a/src/test/resources/checks/v3/parameters/OAR028/exclude-noncompliant.yaml b/src/test/resources/checks/v3/parameters/OAR028/exclude-noncompliant.yaml index bc7139de..0d212700 100644 --- a/src/test/resources/checks/v3/parameters/OAR028/exclude-noncompliant.yaml +++ b/src/test/resources/checks/v3/parameters/OAR028/exclude-noncompliant.yaml @@ -3,17 +3,17 @@ info: version: 1.0.0 title: Swagger Petstore paths: - /status: - get: + /orders: + get: # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} parameters: - in: query - name: other # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + name: other schema: type: array items: type: string - in: query - name: select # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + name: select schema: type: array items: diff --git a/src/test/resources/checks/v3/parameters/OAR028/me-health-ping.json b/src/test/resources/checks/v3/parameters/OAR028/me-health-ping.json new file mode 100644 index 00000000..a257ab40 --- /dev/null +++ b/src/test/resources/checks/v3/parameters/OAR028/me-health-ping.json @@ -0,0 +1,63 @@ +{ + "openapi" : "3.0.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/examples" : { + "post" : { + "responses" : { + "206" : { + "description" : "Ok" + } + } + } + }, + "/pets/{id}" : { + "get" : { + "responses" : { + "206" : { + "description" : "Ok" + } + } + } + }, + "/users/me" : { + "get" : { + "responses" : { + "206" : { + "description" : "Ok" + } + } + } + }, + "/users/me/settings" : { + "get" : { + "responses" : { + "206" : { + "description" : "Ok" + } + } + } + }, + "/health" : { + "get" : { + "responses" : { + "206" : { + "description" : "Ok" + } + } + } + }, + "/ping" : { + "get" : { + "responses" : { + "206" : { + "description" : "Ok" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v3/parameters/OAR028/me-health-ping.yaml b/src/test/resources/checks/v3/parameters/OAR028/me-health-ping.yaml new file mode 100644 index 00000000..495e15e9 --- /dev/null +++ b/src/test/resources/checks/v3/parameters/OAR028/me-health-ping.yaml @@ -0,0 +1,35 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /examples: + post: + responses: + 206: + description: Ok + /pets/{id}: + get: + responses: + 206: + description: Ok + /users/me: + get: + responses: + 206: + description: Ok + /users/me/settings: + get: + responses: + 206: + description: Ok + /health: + get: + responses: + 206: + description: Ok + /ping: + get: + responses: + 206: + description: Ok diff --git a/src/test/resources/checks/v3/parameters/OAR028/plain-without.json b/src/test/resources/checks/v3/parameters/OAR028/plain-without.json index 56ec4af2..d1b165a9 100644 --- a/src/test/resources/checks/v3/parameters/OAR028/plain-without.json +++ b/src/test/resources/checks/v3/parameters/OAR028/plain-without.json @@ -6,10 +6,10 @@ }, "paths" : { "/examples" : { - "get" : { - "parameters" : [ { + "get" : { # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + "parameters" : [ { "in" : "query", - "name" : "other", # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + "name" : "other", "schema": { "type" : "array", "items" : { @@ -18,7 +18,7 @@ } }, { "in" : "query", - "name" : "select", # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + "name" : "select", "schema": { "type" : "array", "items" : { @@ -34,4 +34,4 @@ } } } -} \ No newline at end of file +} diff --git a/src/test/resources/checks/v3/parameters/OAR028/plain-without.yaml b/src/test/resources/checks/v3/parameters/OAR028/plain-without.yaml index e756f798..ddafd313 100644 --- a/src/test/resources/checks/v3/parameters/OAR028/plain-without.yaml +++ b/src/test/resources/checks/v3/parameters/OAR028/plain-without.yaml @@ -4,20 +4,20 @@ info: title: Swagger Petstore paths: /examples: - get: - parameters: + get: # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + parameters: - in: query - name: other # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + name: other schema: type: array items: type: string - in: query - name: select # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + name: select schema: type: array items: type: string responses: 206: - description: Ok \ No newline at end of file + description: Ok diff --git a/src/test/resources/checks/v31/examples/OAR031/allof-schema.json b/src/test/resources/checks/v31/examples/OAR031/allof-schema.json new file mode 100644 index 00000000..0155d35a --- /dev/null +++ b/src/test/resources/checks/v31/examples/OAR031/allof-schema.json @@ -0,0 +1,55 @@ +{ + "openapi" : "3.1.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "components" : { + "schemas" : { + "BaseEntity" : { + "type" : "object", + "properties" : { + "id" : { + "type" : "integer", + "example" : 1 + } + } + }, + "Pet" : { + "allOf" : [ { + "$ref" : "#/components/schemas/BaseEntity" + } ], + "properties" : { + "name" : { + "type" : "string", + "example" : "Fluffy" + } + } + } + } + }, + "paths" : { + "/pets" : { + "get" : { + "responses" : { + "200" : { + "description" : "Ok", + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/Pet" + }, + "example" : { + "name" : "Fluffy" + } + } + } + }, + "204" : { + "description" : "No content" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v31/examples/OAR031/allof-schema.yaml b/src/test/resources/checks/v31/examples/OAR031/allof-schema.yaml new file mode 100644 index 00000000..771b7e0d --- /dev/null +++ b/src/test/resources/checks/v31/examples/OAR031/allof-schema.yaml @@ -0,0 +1,33 @@ +openapi: "3.1.0" +info: + version: 1.0.0 + title: Swagger Petstore +components: + schemas: + BaseEntity: + type: object + properties: + id: + type: integer + example: 1 + Pet: + allOf: + - $ref: '#/components/schemas/BaseEntity' + properties: + name: + type: string + example: "Fluffy" +paths: + /pets: + get: + responses: + 200: + description: Ok + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + example: + name: Fluffy + 204: + description: No content diff --git a/src/test/resources/checks/v31/parameters/OAR028/components-param.json b/src/test/resources/checks/v31/parameters/OAR028/components-param.json index 6c2a7460..e2bdbec7 100644 --- a/src/test/resources/checks/v31/parameters/OAR028/components-param.json +++ b/src/test/resources/checks/v31/parameters/OAR028/components-param.json @@ -8,7 +8,7 @@ "parameters" : { "filterParam" : { "in" : "query", - "name" : "other", + "name" : "$filter", "schema" : { "type" : "string" } @@ -18,6 +18,9 @@ "paths" : { "/examples" : { "get" : { + "parameters" : [ + { "$ref" : "#/components/parameters/filterParam" } + ], "responses" : { "200" : { "description" : "Ok" diff --git a/src/test/resources/checks/v31/parameters/OAR028/components-param.yaml b/src/test/resources/checks/v31/parameters/OAR028/components-param.yaml index f9bd9cd6..bb953926 100644 --- a/src/test/resources/checks/v31/parameters/OAR028/components-param.yaml +++ b/src/test/resources/checks/v31/parameters/OAR028/components-param.yaml @@ -6,12 +6,14 @@ components: parameters: filterParam: in: query - name: other + name: $filter schema: type: string paths: /examples: get: + parameters: + - $ref: '#/components/parameters/filterParam' responses: 200: description: Ok diff --git a/src/test/resources/checks/v31/parameters/OAR028/exclude-noncompliant.json b/src/test/resources/checks/v31/parameters/OAR028/exclude-noncompliant.json index 5fa3e557..8d4f6f29 100644 --- a/src/test/resources/checks/v31/parameters/OAR028/exclude-noncompliant.json +++ b/src/test/resources/checks/v31/parameters/OAR028/exclude-noncompliant.json @@ -5,11 +5,11 @@ "title" : "Swagger Petstore" }, "paths" : { - "/status" : { - "get" : { + "/orders" : { + "get" : { # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} "parameters" : [ { "in" : "query", - "name" : "other", # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + "name" : "other", "schema" : { "type" : "array", "items" : { @@ -18,7 +18,7 @@ } }, { "in" : "query", - "name" : "select", # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + "name" : "select", "schema" : { "type" : "array", "items" : { diff --git a/src/test/resources/checks/v31/parameters/OAR028/exclude-noncompliant.yaml b/src/test/resources/checks/v31/parameters/OAR028/exclude-noncompliant.yaml index 3abbe1cf..e52b9300 100644 --- a/src/test/resources/checks/v31/parameters/OAR028/exclude-noncompliant.yaml +++ b/src/test/resources/checks/v31/parameters/OAR028/exclude-noncompliant.yaml @@ -3,17 +3,17 @@ info: version: 1.0.0 title: Swagger Petstore paths: - /status: - get: + /orders: + get: # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} parameters: - in: query - name: other # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + name: other schema: type: array items: type: string - in: query - name: select # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + name: select schema: type: array items: diff --git a/src/test/resources/checks/v31/parameters/OAR028/me-health-ping.json b/src/test/resources/checks/v31/parameters/OAR028/me-health-ping.json new file mode 100644 index 00000000..e23d51ba --- /dev/null +++ b/src/test/resources/checks/v31/parameters/OAR028/me-health-ping.json @@ -0,0 +1,63 @@ +{ + "openapi" : "3.1.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/examples" : { + "post" : { + "responses" : { + "206" : { + "description" : "Ok" + } + } + } + }, + "/pets/{id}" : { + "get" : { + "responses" : { + "206" : { + "description" : "Ok" + } + } + } + }, + "/users/me" : { + "get" : { + "responses" : { + "206" : { + "description" : "Ok" + } + } + } + }, + "/users/me/settings" : { + "get" : { + "responses" : { + "206" : { + "description" : "Ok" + } + } + } + }, + "/health" : { + "get" : { + "responses" : { + "206" : { + "description" : "Ok" + } + } + } + }, + "/ping" : { + "get" : { + "responses" : { + "206" : { + "description" : "Ok" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v31/parameters/OAR028/me-health-ping.yaml b/src/test/resources/checks/v31/parameters/OAR028/me-health-ping.yaml new file mode 100644 index 00000000..927f40dd --- /dev/null +++ b/src/test/resources/checks/v31/parameters/OAR028/me-health-ping.yaml @@ -0,0 +1,35 @@ +openapi: "3.1.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /examples: + post: + responses: + 206: + description: Ok + /pets/{id}: + get: + responses: + 206: + description: Ok + /users/me: + get: + responses: + 206: + description: Ok + /users/me/settings: + get: + responses: + 206: + description: Ok + /health: + get: + responses: + 206: + description: Ok + /ping: + get: + responses: + 206: + description: Ok diff --git a/src/test/resources/checks/v31/parameters/OAR028/plain-without.json b/src/test/resources/checks/v31/parameters/OAR028/plain-without.json index 3fca9b30..f265f5d3 100644 --- a/src/test/resources/checks/v31/parameters/OAR028/plain-without.json +++ b/src/test/resources/checks/v31/parameters/OAR028/plain-without.json @@ -6,10 +6,10 @@ }, "paths" : { "/examples" : { - "get" : { - "parameters" : [ { + "get" : { # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + "parameters" : [ { "in" : "query", - "name" : "other", # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + "name" : "other", "schema": { "type" : "array", "items" : { @@ -18,7 +18,7 @@ } }, { "in" : "query", - "name" : "select", # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + "name" : "select", "schema": { "type" : "array", "items" : { @@ -34,4 +34,4 @@ } } } -} \ No newline at end of file +} diff --git a/src/test/resources/checks/v31/parameters/OAR028/plain-without.yaml b/src/test/resources/checks/v31/parameters/OAR028/plain-without.yaml index 5d404776..ef729a42 100644 --- a/src/test/resources/checks/v31/parameters/OAR028/plain-without.yaml +++ b/src/test/resources/checks/v31/parameters/OAR028/plain-without.yaml @@ -4,20 +4,20 @@ info: title: Swagger Petstore paths: /examples: - get: - parameters: + get: # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + parameters: - in: query - name: other # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + name: other schema: type: array items: type: string - in: query - name: select # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + name: select schema: type: array items: type: string responses: 206: - description: Ok \ No newline at end of file + description: Ok diff --git a/src/test/resources/checks/v32/examples/OAR031/allof-schema.json b/src/test/resources/checks/v32/examples/OAR031/allof-schema.json new file mode 100644 index 00000000..48d27955 --- /dev/null +++ b/src/test/resources/checks/v32/examples/OAR031/allof-schema.json @@ -0,0 +1,55 @@ +{ + "openapi" : "3.2.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "components" : { + "schemas" : { + "BaseEntity" : { + "type" : "object", + "properties" : { + "id" : { + "type" : "integer", + "example" : 1 + } + } + }, + "Pet" : { + "allOf" : [ { + "$ref" : "#/components/schemas/BaseEntity" + } ], + "properties" : { + "name" : { + "type" : "string", + "example" : "Fluffy" + } + } + } + } + }, + "paths" : { + "/pets" : { + "get" : { + "responses" : { + "200" : { + "description" : "Ok", + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/Pet" + }, + "example" : { + "name" : "Fluffy" + } + } + } + }, + "204" : { + "description" : "No content" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v32/examples/OAR031/allof-schema.yaml b/src/test/resources/checks/v32/examples/OAR031/allof-schema.yaml new file mode 100644 index 00000000..388704e9 --- /dev/null +++ b/src/test/resources/checks/v32/examples/OAR031/allof-schema.yaml @@ -0,0 +1,33 @@ +openapi: "3.2.0" +info: + version: 1.0.0 + title: Swagger Petstore +components: + schemas: + BaseEntity: + type: object + properties: + id: + type: integer + example: 1 + Pet: + allOf: + - $ref: '#/components/schemas/BaseEntity' + properties: + name: + type: string + example: "Fluffy" +paths: + /pets: + get: + responses: + 200: + description: Ok + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + example: + name: Fluffy + 204: + description: No content diff --git a/src/test/resources/checks/v32/parameters/OAR028/components-param.json b/src/test/resources/checks/v32/parameters/OAR028/components-param.json index c73f7b32..4100117a 100644 --- a/src/test/resources/checks/v32/parameters/OAR028/components-param.json +++ b/src/test/resources/checks/v32/parameters/OAR028/components-param.json @@ -8,7 +8,7 @@ "parameters" : { "filterParam" : { "in" : "query", - "name" : "other", + "name" : "$filter", "schema" : { "type" : "string" } @@ -18,6 +18,9 @@ "paths" : { "/examples" : { "get" : { + "parameters" : [ + { "$ref" : "#/components/parameters/filterParam" } + ], "responses" : { "200" : { "description" : "Ok" diff --git a/src/test/resources/checks/v32/parameters/OAR028/components-param.yaml b/src/test/resources/checks/v32/parameters/OAR028/components-param.yaml index c1e954e8..3c123daa 100644 --- a/src/test/resources/checks/v32/parameters/OAR028/components-param.yaml +++ b/src/test/resources/checks/v32/parameters/OAR028/components-param.yaml @@ -6,12 +6,14 @@ components: parameters: filterParam: in: query - name: other + name: $filter schema: type: string paths: /examples: get: + parameters: + - $ref: '#/components/parameters/filterParam' responses: 200: description: Ok diff --git a/src/test/resources/checks/v32/parameters/OAR028/exclude-noncompliant.json b/src/test/resources/checks/v32/parameters/OAR028/exclude-noncompliant.json index 958ffb1a..dd5444b7 100644 --- a/src/test/resources/checks/v32/parameters/OAR028/exclude-noncompliant.json +++ b/src/test/resources/checks/v32/parameters/OAR028/exclude-noncompliant.json @@ -5,11 +5,11 @@ "title" : "Swagger Petstore" }, "paths" : { - "/status" : { - "get" : { + "/orders" : { + "get" : { # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} "parameters" : [ { "in" : "query", - "name" : "other", # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + "name" : "other", "schema" : { "type" : "array", "items" : { @@ -18,7 +18,7 @@ } }, { "in" : "query", - "name" : "select", # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + "name" : "select", "schema" : { "type" : "array", "items" : { diff --git a/src/test/resources/checks/v32/parameters/OAR028/exclude-noncompliant.yaml b/src/test/resources/checks/v32/parameters/OAR028/exclude-noncompliant.yaml index 343b26ef..95435d14 100644 --- a/src/test/resources/checks/v32/parameters/OAR028/exclude-noncompliant.yaml +++ b/src/test/resources/checks/v32/parameters/OAR028/exclude-noncompliant.yaml @@ -3,17 +3,17 @@ info: version: 1.0.0 title: Swagger Petstore paths: - /status: - get: + /orders: + get: # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} parameters: - in: query - name: other # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + name: other schema: type: array items: type: string - in: query - name: select # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + name: select schema: type: array items: diff --git a/src/test/resources/checks/v32/parameters/OAR028/me-health-ping.json b/src/test/resources/checks/v32/parameters/OAR028/me-health-ping.json new file mode 100644 index 00000000..400ffab2 --- /dev/null +++ b/src/test/resources/checks/v32/parameters/OAR028/me-health-ping.json @@ -0,0 +1,63 @@ +{ + "openapi" : "3.2.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/examples" : { + "post" : { + "responses" : { + "206" : { + "description" : "Ok" + } + } + } + }, + "/pets/{id}" : { + "get" : { + "responses" : { + "206" : { + "description" : "Ok" + } + } + } + }, + "/users/me" : { + "get" : { + "responses" : { + "206" : { + "description" : "Ok" + } + } + } + }, + "/users/me/settings" : { + "get" : { + "responses" : { + "206" : { + "description" : "Ok" + } + } + } + }, + "/health" : { + "get" : { + "responses" : { + "206" : { + "description" : "Ok" + } + } + } + }, + "/ping" : { + "get" : { + "responses" : { + "206" : { + "description" : "Ok" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v32/parameters/OAR028/me-health-ping.yaml b/src/test/resources/checks/v32/parameters/OAR028/me-health-ping.yaml new file mode 100644 index 00000000..8b22e1e8 --- /dev/null +++ b/src/test/resources/checks/v32/parameters/OAR028/me-health-ping.yaml @@ -0,0 +1,35 @@ +openapi: "3.2.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /examples: + post: + responses: + 206: + description: Ok + /pets/{id}: + get: + responses: + 206: + description: Ok + /users/me: + get: + responses: + 206: + description: Ok + /users/me/settings: + get: + responses: + 206: + description: Ok + /health: + get: + responses: + 206: + description: Ok + /ping: + get: + responses: + 206: + description: Ok diff --git a/src/test/resources/checks/v32/parameters/OAR028/plain-without.json b/src/test/resources/checks/v32/parameters/OAR028/plain-without.json index 6d78ca42..9936131d 100644 --- a/src/test/resources/checks/v32/parameters/OAR028/plain-without.json +++ b/src/test/resources/checks/v32/parameters/OAR028/plain-without.json @@ -6,10 +6,10 @@ }, "paths" : { "/examples" : { - "get" : { - "parameters" : [ { + "get" : { # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + "parameters" : [ { "in" : "query", - "name" : "other", # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + "name" : "other", "schema": { "type" : "array", "items" : { @@ -18,7 +18,7 @@ } }, { "in" : "query", - "name" : "select", # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + "name" : "select", "schema": { "type" : "array", "items" : { @@ -34,4 +34,4 @@ } } } -} \ No newline at end of file +} diff --git a/src/test/resources/checks/v32/parameters/OAR028/plain-without.yaml b/src/test/resources/checks/v32/parameters/OAR028/plain-without.yaml index 59f530dd..d31d6d18 100644 --- a/src/test/resources/checks/v32/parameters/OAR028/plain-without.yaml +++ b/src/test/resources/checks/v32/parameters/OAR028/plain-without.yaml @@ -4,20 +4,20 @@ info: title: Swagger Petstore paths: /examples: - get: - parameters: + get: # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + parameters: - in: query - name: other # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + name: other schema: type: array items: type: string - in: query - name: select # Noncompliant {{OAR028: $filter must be defined as a parameter in this operation}} + name: select schema: type: array items: type: string responses: 206: - description: Ok \ No newline at end of file + description: Ok