- Los scopes disponibles se definen al final del documento de definición, a nivel raíz. Se definen mediante la siguiente estructura: + Un scope incorrecto puede causar problemas al importar la definición de la API en WSO2 o permitir que cualquier usuario invoque el endpoint.
--x-wso2-security: - apim: - x-wso2-scopes: - - name: Nombre_scope_1 - description: "" - key: Etiqueta_scope_1 - roles: "Role_1, Role_2, …, Role_n" - - name: Nombre_scope_2> - description: "" - key: Etiqueta_scope_2 - roles: "Role_1,Role_2,…,Role_n" -
- Cada elemento del array x-wso2-scopes contiene los siguientes elementos: + El x-scope de la operación debe coincidir con el name de un scope declarado. El key del scope nunca se tiene en cuenta.
-swagger: "2.0" diff --git a/src/main/resources/org/sonar/l10n/es/openapi/rules/openapi/apim/wso2/OAR041.html b/src/main/resources/org/sonar/l10n/es/openapi/rules/openapi/apim/wso2/OAR041.html index 949d12c0..bea3a1bf 100644 --- a/src/main/resources/org/sonar/l10n/es/openapi/rules/openapi/apim/wso2/OAR041.html +++ b/src/main/resources/org/sonar/l10n/es/openapi/rules/openapi/apim/wso2/OAR041.html @@ -1,34 +1,20 @@ -- Los scopes disponibles se definen al final del documento de definición, a nivel raíz. Se definen mediante la siguiente estructura: -
+El uso de un scope (
+x-scope) en una operación siempre requiere que se defina también un tipo de autenticación (x-auth-type).Ejemplo de código no compatible
+swagger: "2.0" x-wso2-security: apim: - x-wso2-scopes: - - name: Nombre_scope_1 - description: "" - key: Etiqueta_scope_1 - roles: "Role_1, Role_2, …, Role_n" - - name: Nombre_scope_2> - description: "" - key: Etiqueta_scope_2 - roles: "Role_1,Role_2,…,Role_n" + x-wso2-scopes: + - name: read + key: read + roles: READ_ROLE + description: Allows users to view records +paths: + /pets: + get: + x-scope: read-- Cada elemento del array x-wso2-scopes contiene los siguientes elementos: -
-
swagger: "2.0" x-wso2-security: @@ -42,10 +28,11 @@-Noncompliant
/pets: get: x-scope: read + x-auth-type: "Application & Application User"
-swagger: "2.0"
+openapi: "3.0.0"
x-wso2-security:
apim:
x-wso2-scopes:
@@ -57,5 +44,20 @@ Compliant
/pets:
get:
x-scope: read
- x-aut-type: "Application & Application User"
++openapi: "3.0.0" +x-wso2-security: + apim: + x-wso2-scopes: + - name: read + key: read + roles: READ_ROLE + description: Allows users to view records +paths: + /pets: + get: + x-scope: read + x-auth-type: "Application & Application User" +\ No newline at end of file diff --git a/src/main/resources/org/sonar/l10n/es/openapi/rules/openapi/apim/wso2/OAR041.json b/src/main/resources/org/sonar/l10n/es/openapi/rules/openapi/apim/wso2/OAR041.json index 81bd0427..d9ab20a9 100644 --- a/src/main/resources/org/sonar/l10n/es/openapi/rules/openapi/apim/wso2/OAR041.json +++ b/src/main/resources/org/sonar/l10n/es/openapi/rules/openapi/apim/wso2/OAR041.json @@ -1,5 +1,5 @@ { - "title": "OAR041 - UndefinedAuthTypeForWso2Scope - El uso de x-scope require del uso de x-auth-type", + "title": "OAR041 - UndefinedAuthTypeForWso2Scope - El uso de x-scope requiere del uso de x-auth-type", "type": "VULNERABILITY", "status": "ready", "remediation": { diff --git a/src/main/resources/org/sonar/l10n/es/openapi/rules/openapi/core/OAR043.html b/src/main/resources/org/sonar/l10n/es/openapi/rules/openapi/core/OAR043.html deleted file mode 100644 index c611114f..00000000 --- a/src/main/resources/org/sonar/l10n/es/openapi/rules/openapi/core/OAR043.html +++ /dev/null @@ -1,190 +0,0 @@ -
El archivo con la especificación OpenAPI no puede contener líneas vacías, esto impedirá su análisis.
-
-{
- "swagger": "2.0",
- "info": {
- "title": "Ejemplo de API",
- "version": "1.0.0"
- },
- "paths": {
- "/clientes": {
- "get": {
- "summary": "Obtenci\u00f3n de una colecci\u00f3n de clientes",
- "description": "Permite obtener una colecci\u00f3n de clientes.\nPor ejemplo: /usuarios o /expedientes.\nPuede admitir cabeceras, *query parameters* y el objeto $filter en el body.\n\n**Scope Oauth:** clientes_sc_consulta\n",
- "responses": {
- "200": {
- "description": "OK"
- }
- }
- }
- }
- }
-}
-
--swagger: "2.0" -info: - title: Ejemplo de API - version: 1.0.0 -paths: - - /clientes: - - get: - # 'summary': Es OBLIGATORIO usar este elemento en todos los paths. Se trata de una breve descripción del endpoint - summary: Obtención de una colección de clientes - # 'description': es OBLIGATORIO que el contenido de este campo esté cumplimentado y difiera del del campo 'summary' - # Debe darse una descripción lo más detallada posible de la funcionalidad del endpoint sin describir la lógica de negocio. - # Si el endpoint está protegido por un scope Oauth debe indicarse cuál és en la descripción. - description: | - Permite obtener una colección de clientes. - Por ejemplo: /usuarios o /expedientes. - Puede admitir cabeceras, *query parameters* y el objeto $filter en el body. - - **Scope Oauth:** clientes_sc_consulta - - responses: - 200: - description: OK --
-{
- "swagger": "2.0",
- "info": {
- "title": "Ejemplo de API",
- "version": "1.0.0"
- },
- "paths": {
- "/clientes": {
- "get": {
- "summary": "Obtenci\u00f3n de una colecci\u00f3n de clientes",
- "description": "Permite obtener una colecci\u00f3n de clientes.\nPor ejemplo: /usuarios o /expedientes.\nPuede admitir cabeceras, *query parameters* y el objeto $filter en el body.\n**Scope Oauth:** clientes_sc_consulta\n",
- "responses": {
- "200": {
- "description": "OK"
- }
- }
- }
- }
- }
-}
-
--swagger: "2.0" -info: - title: Ejemplo de API - version: 1.0.0 -paths: - /clientes: - get: - # 'summary': Es OBLIGATORIO usar este elemento en todos los paths. Se trata de una breve descripción del endpoint - summary: Obtención de una colección de clientes - # 'description': es OBLIGATORIO que el contenido de este campo esté cumplimentado y difiera del del campo 'summary' - # Debe darse una descripción lo más detallada posible de la funcionalidad del endpoint sin describir la lógica de negocio. - # Si el endpoint está protegido por un scope Oauth debe indicarse cuál és en la descripción. - description: | - Permite obtener una colección de clientes. - Por ejemplo: /usuarios o /expedientes. - Puede admitir cabeceras, *query parameters* y el objeto $filter en el body. - **Scope Oauth:** clientes_sc_consulta - responses: - 200: - description: OK --
-{
- "openapi": "3.0.1",
- "info": {
- "title": "Ejemplo de API",
- "version": "1.0.0"
- },
- "paths": {
- "/clientes": {
- "get": {
- "summary": "Obtenci\u00f3n de una colecci\u00f3n de clientes",
- "description": "Permite obtener una colecci\u00f3n de clientes.\nPor ejemplo: /usuarios o /expedientes.\nPuede admitir cabeceras, *query parameters* y el objeto $filter en el body.\n\n**Scope Oauth:** clientes_sc_consulta\n",
- "responses": {
- "200": {
- "description": "OK"
- }
- }
- }
- }
- }
-}
-
--openapi: 3.0.1 - -info: - title: Ejemplo de API - version: 1.0.0 - -paths: - - /clientes: - - get: - summary: Obtención de una colección de clientes - description: | - Permite obtener una colección de clientes. - Por ejemplo: /usuarios o /expedientes. - Puede admitir cabeceras, *query parameters* y el objeto $filter en el body. - - **Scope Oauth:** clientes_sc_consulta - responses: - 200: - description: OK --
-{
- "openapi": "3.0.1",
- "info": {
- "title": "Ejemplo de API",
- "version": "1.0.0"
- },
- "paths": {
- "/clientes": {
- "get": {
- "summary": "Obtenci\u00f3n de una colecci\u00f3n de clientes",
- "description": "Permite obtener una colecci\u00f3n de clientes.\nPor ejemplo: /usuarios o /expedientes.\nPuede admitir cabeceras, *query parameters* y el objeto $filter en el body.\n**Scope Oauth:** clientes_sc_consulta\n",
- "responses": {
- "200": {
- "description": "OK"
- }
- }
- }
- }
- }
-}
-
--openapi: 3.0.1 -info: - title: Ejemplo de API - version: 1.0.0 -paths: - /clientes: - get: - summary: Obtención de una colección de clientes - description: | - Permite obtener una colección de clientes. - Por ejemplo: /usuarios o /expedientes. - Puede admitir cabeceras, *query parameters* y el objeto $filter en el body. - **Scope Oauth:** clientes_sc_consulta - responses: - 200: - description: OK -\ No newline at end of file diff --git a/src/main/resources/org/sonar/l10n/es/openapi/rules/openapi/core/OAR043.json b/src/main/resources/org/sonar/l10n/es/openapi/rules/openapi/core/OAR043.json deleted file mode 100644 index b9eb829f..00000000 --- a/src/main/resources/org/sonar/l10n/es/openapi/rules/openapi/core/OAR043.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "title": "OAR043 - ParsingError - El archivo no puede ser analizado", - "type": "BUG", - "status": "ready", - "remediation": { - "func": "Constant\/Issue", - "constantCost": "30min" - }, - "tags": [ - "core" - ], - "defaultSeverity": "BLOCKER" -} diff --git a/src/main/resources/org/sonar/l10n/es/openapi/rules/openapi/operations/OAR043.html b/src/main/resources/org/sonar/l10n/es/openapi/rules/openapi/operations/OAR043.html index 7e145323..a12302b8 100644 --- a/src/main/resources/org/sonar/l10n/es/openapi/rules/openapi/operations/OAR043.html +++ b/src/main/resources/org/sonar/l10n/es/openapi/rules/openapi/operations/OAR043.html @@ -1,116 +1,53 @@ -
El archivo con la especificación OpenAPI no puede contener líneas vacías, esto impedirá su análisis.
-Este archivo no es una definición válida de OpenAPI o Swagger. Esto incluye tanto documentos que un parser estricto ni siquiera puede cargar (sintaxis YAML o JSON mal formada) como documentos que sí cargan pero que no superan la validación estructural de la especificación.
+
-{
- "swagger": "2.0",
- "info": {
- "title": "Ejemplo de API",
- "version": "1.0.0"
- },
- "paths": {
- "/clientes": {
- "get": {
- "summary": "Obtenci\u00f3n de una colecci\u00f3n de clientes",
- "description": "Permite obtener una colecci\u00f3n de clientes.\nPor ejemplo: /usuarios o /expedientes.\nPuede admitir cabeceras, *query parameters* y el objeto $filter en el body.\n\n**Scope Oauth:** clientes_sc_consulta\n",
- "responses": {
- "200": {
- "description": "OK"
- }
- }
- }
- }
- }
-}
-
--swagger: "2.0" -info: - title: Ejemplo de API - version: 1.0.0 -paths: - - /clientes: - - get: - # 'summary': Es OBLIGATORIO usar este elemento en todos los paths. Se trata de una breve descripción del endpoint - summary: Obtención de una colección de clientes - # 'description': es OBLIGATORIO que el contenido de este campo esté cumplimentado y difiera del del campo 'summary' - # Debe darse una descripción lo más detallada posible de la funcionalidad del endpoint sin describir la lógica de negocio. - # Si el endpoint está protegido por un scope Oauth debe indicarse cuál és en la descripción. - description: | - Permite obtener una colección de clientes. - Por ejemplo: /usuarios o /expedientes. - Puede admitir cabeceras, *query parameters* y el objeto $filter en el body. - - **Scope Oauth:** clientes_sc_consulta - - responses: - 200: - description: OK --
-swagger: "2.0"
-info:
+openapi: "3.0.0"
+info:
title: Ejemplo de API
- version: 1.0.0
+ version: "1.0.0"
paths:
- /clientes:
+ /pets:
get:
- # 'summary': Es OBLIGATORIO usar este elemento en todos los paths. Se trata de una breve descripción del endpoint
- summary: Obtención de una colección de clientes
- # 'description': es OBLIGATORIO que el contenido de este campo esté cumplimentado y difiera del del campo 'summary'
- # Debe darse una descripción lo más detallada posible de la funcionalidad del endpoint sin describir la lógica de negocio.
- # Si el endpoint está protegido por un scope Oauth debe indicarse cuál és en la descripción.
- description: |
- Permite obtener una colección de clientes.
- Por ejemplo: /usuarios o /expedientes.
- Puede admitir cabeceras, *query parameters* y el objeto $filter en el body.
- **Scope Oauth:** clientes_sc_consulta
responses:
200:
description: OK
+ "400":
+ description: Bad Request
-
-openapi: 3.0.1
-
+openapi: "3.0.0"
info:
title: Ejemplo de API
- version: 1.0.0
-
+ version: "1.0.0"
paths:
-
- /clientes:
-
+ /pets:
get:
- summary: Obtención de una colección de clientes
- description: |
- Permite obtener una colección de clientes.
- Por ejemplo: /usuarios o /expedientes.
- Puede admitir cabeceras, *query parameters* y el objeto $filter en el body.
-
- **Scope Oauth:** clientes_sc_consulta
responses:
- 200:
+ "200":
description: OK
+ "400":
+ description: Bad Request
-
-openapi: 3.0.1
-info:
- title: Ejemplo de API
- version: 1.0.0
-paths:
- /clientes:
- get:
- summary: Obtención de una colección de clientes
- description: |
- Permite obtener una colección de clientes.
- Por ejemplo: /usuarios o /expedientes.
- Puede admitir cabeceras, *query parameters* y el objeto $filter en el body.
- **Scope Oauth:** clientes_sc_consulta
- responses:
- 200:
- description: OK
+{
+ "openapi": "3.0.0",
+ "info": {
+ "title": "Ejemplo de API",
+ "version": "1.0.0",
+ },
+ "paths": {}
+}
+
+{
+ "openapi": "3.0.0",
+ "info": {
+ "title": "Ejemplo de API",
+ "version": "1.0.0"
+ },
+ "paths": {}
+}
+
\ No newline at end of file
diff --git a/src/main/resources/org/sonar/l10n/es/openapi/rules/openapi/operations/OAR043.json b/src/main/resources/org/sonar/l10n/es/openapi/rules/openapi/operations/OAR043.json
index 02a6e096..6ca56a29 100644
--- a/src/main/resources/org/sonar/l10n/es/openapi/rules/openapi/operations/OAR043.json
+++ b/src/main/resources/org/sonar/l10n/es/openapi/rules/openapi/operations/OAR043.json
@@ -1,5 +1,5 @@
{
- "title": "OAR043 - ParsingError - El archivo no puede ser analizado",
+ "title": "OAR043 - ParsingError - El archivo no puede ser analizado o no supera la validación estructural",
"type": "BUG",
"status": "ready",
"remediation": {
diff --git a/src/main/resources/org/sonar/l10n/openapi/rules/openapi/apim/wso2/OAR005.html b/src/main/resources/org/sonar/l10n/openapi/rules/openapi/apim/wso2/OAR005.html
index 97c4df10..a3176ec1 100644
--- a/src/main/resources/org/sonar/l10n/openapi/rules/openapi/apim/wso2/OAR005.html
+++ b/src/main/resources/org/sonar/l10n/openapi/rules/openapi/apim/wso2/OAR005.html
@@ -1,4 +1,5 @@
A wrong scope may cause problems to import the API definition into WSO2 or allow all users to call the endpoint.
+The operation x-scope must match the name of a declared scope. The scope key is never taken into account.
swagger: "2.0" diff --git a/src/main/resources/org/sonar/l10n/openapi/rules/openapi/apim/wso2/OAR041.html b/src/main/resources/org/sonar/l10n/openapi/rules/openapi/apim/wso2/OAR041.html index 689f891f..6e4c8b37 100644 --- a/src/main/resources/org/sonar/l10n/openapi/rules/openapi/apim/wso2/OAR041.html +++ b/src/main/resources/org/sonar/l10n/openapi/rules/openapi/apim/wso2/OAR041.html @@ -28,7 +28,7 @@Compliant Solution
/pets: get: x-scope: read - x-aut-type: "Application & Application User" + x-auth-type: "Application & Application User"
@@ -59,5 +59,5 @@\ No newline at end of file diff --git a/src/main/resources/org/sonar/l10n/openapi/rules/openapi/core/OAR043.html b/src/main/resources/org/sonar/l10n/openapi/rules/openapi/core/OAR043.html deleted file mode 100644 index 6d8aedb8..00000000 --- a/src/main/resources/org/sonar/l10n/openapi/rules/openapi/core/OAR043.html +++ /dev/null @@ -1 +0,0 @@ -Compliant Solution (OpenAPI 3)
/pets: get: x-scope: read - x-aut-type: "Application & Application User" + x-auth-type: "Application & Application User"
This file is not a valid OpenAPI or Swagger definition.
diff --git a/src/main/resources/org/sonar/l10n/openapi/rules/openapi/core/OAR043.json b/src/main/resources/org/sonar/l10n/openapi/rules/openapi/core/OAR043.json deleted file mode 100644 index 9b62772f..00000000 --- a/src/main/resources/org/sonar/l10n/openapi/rules/openapi/core/OAR043.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "title": "OAR043 - ParsingError - OpenAPI file cannot be parsed", - "type": "BUG", - "status": "ready", - "remediation": { - "func": "Constant\/Issue", - "constantCost": "30min" - }, - "tags": [ - "core" - ], - "defaultSeverity": "BLOCKER" -} diff --git a/src/main/resources/org/sonar/l10n/openapi/rules/openapi/examples/OAR031.html b/src/main/resources/org/sonar/l10n/openapi/rules/openapi/examples/OAR031.html index c20f54bc..7a862915 100644 --- a/src/main/resources/org/sonar/l10n/openapi/rules/openapi/examples/OAR031.html +++ b/src/main/resources/org/sonar/l10n/openapi/rules/openapi/examples/OAR031.html @@ -1,6 +1,6 @@The examples can help developers to understand the response data structure and representation.
Examples are validated as four independent levels: response, request body, parameter and property. The response, request-body and parameter levels require an example declared at the media-type or schema root; examples nested inside individual properties do not satisfy them. 204 responses are excluded.
Each level can be enabled or disabled independently with the rule parameters validate-response, validate-request-body, validate-parameter and validate-property (all enabled by default).
Each level can be enabled or disabled independently with the rule parameters validateResponse, validateRequestBody, validateParameter and validateProperty (all enabled by default).
swagger: "2.0" @@ -87,7 +87,7 @@Noncompliant Code Example (OpenAPI 3)
/pets: get: responses: - 206: # Noncompliant {{OAR031: Responses must have one or more examples defined}} + 206: # Noncompliant {{OAR031: Response must have an example defined}} description: Pet list content: application/json: @@ -98,14 +98,14 @@Noncompliant Code Example (OpenAPI 3)
pet: type: object properties: - name: # Noncompliant {{OAR031: Properties must have an example defined}} + name: # Noncompliant {{OAR031: Property 'name' is missing an example.}} type: string - type: # Noncompliant {{OAR031: Properties must have an example defined}} + type: # Noncompliant {{OAR031: Property 'type' is missing an example.}} type: string pets: type: object properties: - size: # Noncompliant {{OAR031: Properties must have an example defined}} + size: # Noncompliant {{OAR031: Property 'size' is missing an example.}} type: integer pets: type: array diff --git a/src/main/resources/org/sonar/l10n/openapi/rules/openapi/format/OAR007.html b/src/main/resources/org/sonar/l10n/openapi/rules/openapi/format/OAR007.html index 09f6c98c..5a748ea2 100644 --- a/src/main/resources/org/sonar/l10n/openapi/rules/openapi/format/OAR007.html +++ b/src/main/resources/org/sonar/l10n/openapi/rules/openapi/format/OAR007.html @@ -1,5 +1,5 @@ -When defining an API, the request data formats must be defined.
-For OpenAPI 2 specify at least a MIME Type understood by the API in the "consumes" keyword is mandatory.
+When defining an API, the response data formats must be defined.
+For OpenAPI 2 specify at least a MIME Type understood by the API in the "produces" keyword is mandatory.
For OpenAPI 3 specify at least a Media Type in the content of the response body is mandatory.
Noncompliant Code Example (OpenAPI 2)
diff --git a/src/main/resources/org/sonar/l10n/openapi/rules/openapi/operations/OAR043.html b/src/main/resources/org/sonar/l10n/openapi/rules/openapi/operations/OAR043.html index b2e384a4..21ae94bc 100644 --- a/src/main/resources/org/sonar/l10n/openapi/rules/openapi/operations/OAR043.html +++ b/src/main/resources/org/sonar/l10n/openapi/rules/openapi/operations/OAR043.html @@ -1 +1,53 @@ -This file is not a valid OpenAPI or Swagger definition.
\ No newline at end of file +This file is not a valid OpenAPI or Swagger definition. This includes documents that a strict parser cannot even load (malformed YAML or JSON syntax) as well as documents that load but fail the structural validation of the specification.
+Noncompliant Code Example (broken YAML indentation)
++openapi: "3.0.0" +info: + title: Example API + version: "1.0.0" +paths: + /pets: + get: + responses: + 200: + description: OK + "400": + description: Bad Request ++Compliant Solution
++openapi: "3.0.0" +info: + title: Example API + version: "1.0.0" +paths: + /pets: + get: + responses: + "200": + description: OK + "400": + description: Bad Request ++Noncompliant Code Example (trailing comma in JSON)
++{ + "openapi": "3.0.0", + "info": { + "title": "Example API", + "version": "1.0.0", + }, + "paths": {} +} ++Compliant Solution
++{ + "openapi": "3.0.0", + "info": { + "title": "Example API", + "version": "1.0.0" + }, + "paths": {} +} +\ No newline at end of file diff --git a/src/main/resources/org/sonar/l10n/openapi/rules/openapi/operations/OAR043.json b/src/main/resources/org/sonar/l10n/openapi/rules/openapi/operations/OAR043.json index 1910e884..4ecc73f9 100644 --- a/src/main/resources/org/sonar/l10n/openapi/rules/openapi/operations/OAR043.json +++ b/src/main/resources/org/sonar/l10n/openapi/rules/openapi/operations/OAR043.json @@ -1,5 +1,5 @@ { - "title": "OAR043 - ParsingError - OpenAPI file cannot be parsed", + "title": "OAR043 - ParsingError - OpenAPI file cannot be parsed or fails structural validation", "type": "BUG", "status": "ready", "remediation": { diff --git a/src/test/java/apiaddicts/sonar/openapi/checks/apim/wso2/OAR005UndefinedWso2ScopeUseCheckTest.java b/src/test/java/apiaddicts/sonar/openapi/checks/apim/wso2/OAR005UndefinedWso2ScopeUseCheckTest.java index d569214d..493e6652 100644 --- a/src/test/java/apiaddicts/sonar/openapi/checks/apim/wso2/OAR005UndefinedWso2ScopeUseCheckTest.java +++ b/src/test/java/apiaddicts/sonar/openapi/checks/apim/wso2/OAR005UndefinedWso2ScopeUseCheckTest.java @@ -72,6 +72,254 @@ public void verifyInV32WithCorrectOperationScope() { verifyV32("with-correct-operation-scope"); } + @Test + public void verifyInV2WithRefSecurity() { + verifyV2("with-ref-security"); + } + @Test + public void verifyInV3WithRefSecurity() { + verifyV3("with-ref-security"); + } + @Test + public void verifyInV31WithRefSecurity() { + verifyV31("with-ref-security"); + } + @Test + public void verifyInV32WithRefSecurity() { + verifyV32("with-ref-security"); + } + + @Test + public void verifyInV2WithChainedRefSecurity() { + verifyV2("with-chained-ref-security"); + } + @Test + public void verifyInV3WithChainedRefSecurity() { + verifyV3("with-chained-ref-security"); + } + @Test + public void verifyInV31WithChainedRefSecurity() { + verifyV31("with-chained-ref-security"); + } + @Test + public void verifyInV32WithChainedRefSecurity() { + verifyV32("with-chained-ref-security"); + } + + @Test + public void verifyInV2WithScopesAsMap() { + verifyV2("with-scopes-as-map"); + } + @Test + public void verifyInV3WithScopesAsMap() { + verifyV3("with-scopes-as-map"); + } + @Test + public void verifyInV31WithScopesAsMap() { + verifyV31("with-scopes-as-map"); + } + @Test + public void verifyInV32WithScopesAsMap() { + verifyV32("with-scopes-as-map"); + } + + @Test + public void verifyInV2WithRefScope() { + verifyV2("with-ref-scope"); + } + @Test + public void verifyInV3WithRefScope() { + verifyV3("with-ref-scope"); + } + @Test + public void verifyInV31WithRefScope() { + verifyV31("with-ref-scope"); + } + @Test + public void verifyInV32WithRefScope() { + verifyV32("with-ref-scope"); + } + + @Test + public void verifyInV2WithScopeKeyNotName() { + verifyV2("with-scope-key-not-name"); + } + @Test + public void verifyInV3WithScopeKeyNotName() { + verifyV3("with-scope-key-not-name"); + } + @Test + public void verifyInV31WithScopeKeyNotName() { + verifyV31("with-scope-key-not-name"); + } + @Test + public void verifyInV32WithScopeKeyNotName() { + verifyV32("with-scope-key-not-name"); + } + + @Test + public void verifyInV2WithoutSecurity() { + verifyV2("without-security"); + } + @Test + public void verifyInV3WithoutSecurity() { + verifyV3("without-security"); + } + @Test + public void verifyInV31WithoutSecurity() { + verifyV31("without-security"); + } + @Test + public void verifyInV32WithoutSecurity() { + verifyV32("without-security"); + } + + @Test + public void verifyInV3WithNullSecurity() { + verifyV3("with-null-security.yaml"); + } + + @Test + public void verifyInV3WithScalarSecurity() { + verifyV3("with-scalar-security.yaml"); + } + + @Test + public void verifyInV3WithArraySecurity() { + verifyV3("with-array-security.yaml"); + } + + @Test + public void verifyInV3WithoutApim() { + verifyV3("without-apim.yaml"); + } + + @Test + public void verifyInV3WithNullApim() { + verifyV3("with-null-apim.yaml"); + } + + @Test + public void verifyInV3WithoutScopes() { + verifyV3("without-scopes.yaml"); + } + + @Test + public void verifyInV3WithNullScopes() { + verifyV3("with-null-scopes.yaml"); + } + + @Test + public void verifyInV3WithEmptyArrayScopes() { + verifyV3("with-empty-array-scopes.yaml"); + } + + @Test + public void verifyInV3WithEmptyObjectScopes() { + verifyV3("with-empty-object-scopes.yaml"); + } + + @Test + public void verifyInV3WithScalarScopes() { + verifyV3("with-scalar-scopes.yaml"); + } + + @Test + public void verifyInV3WithCyclicRefSecurity() { + verifyV3("with-cyclic-ref-security.yaml"); + } + + @Test + public void verifyInV3WithDanglingRefSecurity() { + verifyV3("with-dangling-ref-security.yaml"); + } + + @Test + public void verifyInV3WithMalformedScopes() { + verifyV3("with-malformed-scopes.yaml"); + } + + @Test + public void verifyInV3WithXScopeNullSpellings() { + verifyV3("with-x-scope-null-spellings.yaml"); + } + + @Test + public void verifyInV3WithXScopeScalarTypes() { + verifyV3("with-x-scope-scalar-types.yaml"); + } + + @Test + public void verifyInV3WithXScopeCollections() { + verifyV3("with-x-scope-collections.yaml"); + } + + @Test + public void verifyInV3WithXScopeBlockCollections() { + verifyV3("with-x-scope-block-collections.yaml"); + } + + @Test + public void verifyInV2WithAllVerbs() { + verifyV2("with-all-verbs"); + } + @Test + public void verifyInV3WithAllVerbs() { + verifyV3("with-all-verbs"); + } + @Test + public void verifyInV31WithAllVerbs() { + verifyV31("with-all-verbs"); + } + @Test + public void verifyInV32WithAllVerbs() { + verifyV32("with-all-verbs"); + } + + @Test + public void verifyInV3WithCallbackOperations() { + verifyV3("with-callback-operations"); + } + @Test + public void verifyInV31WithCallbackOperations() { + verifyV31("with-callback-operations"); + } + @Test + public void verifyInV32WithCallbackOperations() { + verifyV32("with-callback-operations"); + } + + @Test + public void verifyInV31WithWebhookOperations() { + verifyV31("with-webhook-operations"); + } + @Test + public void verifyInV32WithWebhookOperations() { + verifyV32("with-webhook-operations"); + } + + @Test + public void verifyInV32WithAdditionalOperations() { + verifyV32("with-additional-operations"); + } + + @Test + public void verifyInV2Extensive() { + verifyV2("extensive-api"); + } + @Test + public void verifyInV3Extensive() { + verifyV3("extensive-api"); + } + @Test + public void verifyInV31Extensive() { + verifyV31("extensive-api"); + } + @Test + public void verifyInV32Extensive() { + verifyV32("extensive-api"); + } + @Override public void verifyRule() { assertRuleProperties("OAR005 - UndefinedWso2ScopeUse - WSO2 scope definition does not exists", RuleType.VULNERABILITY, Severity.BLOCKER, tags("api-manager", "vulnerability", "wso2")); 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 4f7f624d..667c257a 100644 --- a/src/test/java/apiaddicts/sonar/openapi/checks/examples/OAR031ExamplesCheckTest.java +++ b/src/test/java/apiaddicts/sonar/openapi/checks/examples/OAR031ExamplesCheckTest.java @@ -95,6 +95,16 @@ public void verifyInV32NestedProperties() { public void verifyInV2AllOfSchema() { verifyV2("allof-schema"); } + + @Test + public void verifyInV2AllOfSchemaMissingExample() { + verifyV2("allof-schema-missing-example.yaml"); + } + + @Test + public void verifyInV2OrphanSchema() { + verifyV2("orphan-schema.yaml"); + } @Test public void verifyInV3AllOfSchema() { verifyV3("allof-schema"); @@ -108,6 +118,32 @@ public void verifyInV32AllOfSchema() { verifyV32("allof-schema"); } + @Test + public void verifyInV3AllOfSchemaMissingExample() { + verifyV3("allof-schema-missing-example.yaml"); + } + @Test + public void verifyInV31AllOfSchemaMissingExample() { + verifyV31("allof-schema-missing-example.yaml"); + } + @Test + public void verifyInV32AllOfSchemaMissingExample() { + verifyV32("allof-schema-missing-example.yaml"); + } + + @Test + public void verifyInV3OrphanSchema() { + verifyV3("orphan-schema.yaml"); + } + @Test + public void verifyInV31OrphanSchema() { + verifyV31("orphan-schema.yaml"); + } + @Test + public void verifyInV32OrphanSchema() { + verifyV32("orphan-schema.yaml"); + } + @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/OAR007UndefinedResponseMediaTypeCheckTest.java b/src/test/java/apiaddicts/sonar/openapi/checks/format/OAR007UndefinedResponseMediaTypeCheckTest.java index 2b4eb51c..559a31a4 100644 --- a/src/test/java/apiaddicts/sonar/openapi/checks/format/OAR007UndefinedResponseMediaTypeCheckTest.java +++ b/src/test/java/apiaddicts/sonar/openapi/checks/format/OAR007UndefinedResponseMediaTypeCheckTest.java @@ -38,6 +38,11 @@ public void verifyInV2WithoutAnything() { verifyV2("without-anything"); } + @Test + public void verifyInV2WithSpecificPut() { + verifyV2("with-specific-put"); + } + @Test public void verifyInV3WithoutAnything() { verifyV3("without-anything"); @@ -51,6 +56,110 @@ public void verifyInV32WithoutAnything() { verifyV32("without-anything"); } + @Test + public void verifyInV3WithSpecific() { + verifyV3("with-specific"); + } + @Test + public void verifyInV31WithSpecific() { + verifyV31("with-specific"); + } + @Test + public void verifyInV32WithSpecific() { + verifyV32("with-specific"); + } + + @Test + public void verifyInV3WithMultipleOperations() { + verifyV3("with-multiple-operations"); + } + @Test + public void verifyInV31WithMultipleOperations() { + verifyV31("with-multiple-operations"); + } + @Test + public void verifyInV32WithMultipleOperations() { + verifyV32("with-multiple-operations"); + } + + @Test + public void verifyInV3WithDefaultAndRef() { + verifyV3("with-default-and-ref"); + } + @Test + public void verifyInV31WithDefaultAndRef() { + verifyV31("with-default-and-ref"); + } + @Test + public void verifyInV32WithDefaultAndRef() { + verifyV32("with-default-and-ref"); + } + + @Test + public void verifyInV3WithWrongRef() { + verifyV3("with-wrong-ref"); + } + @Test + public void verifyInV31WithWrongRef() { + verifyV31("with-wrong-ref"); + } + @Test + public void verifyInV32WithWrongRef() { + verifyV32("with-wrong-ref"); + } + + @Test + public void verifyInV3WithChainedRef() { + verifyV3("with-chained-ref"); + } + @Test + public void verifyInV31WithChainedRef() { + verifyV31("with-chained-ref"); + } + @Test + public void verifyInV32WithChainedRef() { + verifyV32("with-chained-ref"); + } + + @Test + public void verifyInV3WithExternalRef() { + verifyV3("with-external-ref"); + } + @Test + public void verifyInV31WithExternalRef() { + verifyV31("with-external-ref"); + } + @Test + public void verifyInV32WithExternalRef() { + verifyV32("with-external-ref"); + } + + @Test + public void verifyInV3With204Response() { + verifyV3("with-204-response"); + } + @Test + public void verifyInV31With204Response() { + verifyV31("with-204-response"); + } + @Test + public void verifyInV32With204Response() { + verifyV32("with-204-response"); + } + + @Test + public void verifyInV3WithDefaultResponseKey() { + verifyV3("with-default-response-key"); + } + @Test + public void verifyInV31WithDefaultResponseKey() { + verifyV31("with-default-response-key"); + } + @Test + public void verifyInV32WithDefaultResponseKey() { + verifyV32("with-default-response-key"); + } + @Override public void verifyRule() { assertRuleProperties("OAR007 - UndefinedResponseMediaType - APIs must define response media types supported by the API", RuleType.BUG, Severity.BLOCKER, tags("format")); diff --git a/src/test/java/apiaddicts/sonar/openapi/checks/format/OAR010DefaultResponseMediaTypeCheckTest.java b/src/test/java/apiaddicts/sonar/openapi/checks/format/OAR010DefaultResponseMediaTypeCheckTest.java index f18c65a5..8cea8c98 100644 --- a/src/test/java/apiaddicts/sonar/openapi/checks/format/OAR010DefaultResponseMediaTypeCheckTest.java +++ b/src/test/java/apiaddicts/sonar/openapi/checks/format/OAR010DefaultResponseMediaTypeCheckTest.java @@ -49,6 +49,11 @@ public void verifyInV2WithoutAnything() { verifyV2("without-anything"); } + @Test + public void verifyInV2WithDefaultMixedCase() { + verifyV2("with-default-mixed-case"); + } + @Test public void verifyInV3WithDefault() { verifyV3("with-default-and-$ref"); @@ -127,6 +132,50 @@ public void verifyInV32WithoutAnything() { verifyV32("without-anything"); } + @Test + public void verifyInV3WithDefaultMixedCase() { + verifyV3("with-default-mixed-case"); + } + @Test + public void verifyInV31WithDefaultMixedCase() { + verifyV31("with-default-mixed-case"); + } + @Test + public void verifyInV32WithDefaultMixedCase() { + verifyV32("with-default-mixed-case"); + } + + @Test + public void verifyInV3WithWrongDefaultAndRef() { + verifyV3("with-wrong-default-and-ref"); + } + @Test + public void verifyInV31WithWrongDefaultAndRef() { + verifyV31("with-wrong-default-and-ref"); + } + @Test + public void verifyInV32WithWrongDefaultAndRef() { + verifyV32("with-wrong-default-and-ref"); + } + + @Test + public void verifyInV3With204Response() { + verifyV3("with-204-response"); + } + @Test + public void verifyInV31With204Response() { + verifyV31("with-204-response"); + } + @Test + public void verifyInV32With204Response() { + verifyV32("with-204-response"); + } + + @Test + public void verifyInV3WithExternalRef() { + verifyV3("with-external-ref"); + } + @Override public void verifyRule() { assertRuleProperties("OAR010 - DefaultResponseMediaType - Should indicate the default response media type", RuleType.BUG, Severity.MINOR, tags("format")); diff --git a/src/test/java/apiaddicts/sonar/openapi/checks/parameters/OAR026TotalParameterDefaultValueCheckTest.java b/src/test/java/apiaddicts/sonar/openapi/checks/parameters/OAR026TotalParameterDefaultValueCheckTest.java index c1c619a2..155db84d 100644 --- a/src/test/java/apiaddicts/sonar/openapi/checks/parameters/OAR026TotalParameterDefaultValueCheckTest.java +++ b/src/test/java/apiaddicts/sonar/openapi/checks/parameters/OAR026TotalParameterDefaultValueCheckTest.java @@ -63,6 +63,21 @@ public void verifyInV2WithoutParameters() { verifyV2("without-parameters"); } + @Test + public void verifyInV2PostOperationWith$total() { + verifyV2("post-with-$total-with-defval-true"); + } + + @Test + public void verifyInV2HeaderParamWith$total() { + verifyV2("header-with-$total-with-defval-true"); + } + + @Test + public void verifyInV2With$refUnreferencedWith$total() { + verifyV2("with-$ref-unreferenced-with-$total-with-defval-true"); + } + @Test public void verifyInV3With$totalWithDefvalFalse() { verifyV3("plain-with-$total-with-defval-false"); @@ -107,15 +122,142 @@ public void verifyInV2WithoutParameters() { public void verifyInV3WithoutParameters() { verifyV3("without-parameters"); } + + @Test + public void verifyInV3PostOperationWith$total() { + verifyV3("post-with-$total-with-defval-true"); + } + + @Test + public void verifyInV3HeaderParamWith$total() { + verifyV3("header-with-$total-with-defval-true"); + } + + @Test + public void verifyInV3With$refUnreferencedWith$total() { + verifyV3("with-$ref-unreferenced-with-$total-with-defval-true"); + } + + @Test + public void verifyInV31With$totalWithDefvalFalse() { + verifyV31("plain-with-$total-with-defval-false"); + } + + @Test + public void verifyInV31With$totalWithDefvalTrue() { + verifyV31("plain-with-$total-with-defval-true"); + } + + @Test + public void verifyInV31With$totalWithoutDefval() { + verifyV31("plain-with-$total-without-defval"); + } + + @Test + public void verifyInV31Without$total() { + verifyV31("plain-without-$total"); + } + + @Test + public void verifyInV31With$refWith$totalWithDefvalFalse() { + verifyV31("with-$ref-with-$total-with-defval-false"); + } + + @Test + public void verifyInV31With$refWith$totalWithDefvalTrue() { + verifyV31("with-$ref-with-$total-with-defval-true"); + } + + @Test + public void verifyInV31With$refWith$totalWithoutDefval() { + verifyV31("with-$ref-with-$total-without-defval"); + } + + @Test + public void verifyInV31With$refWithout$total() { + verifyV31("with-$ref-without-$total"); + } + @Test public void verifyInV31WithoutParameters() { verifyV31("without-parameters"); } + + @Test + public void verifyInV31PostOperationWith$total() { + verifyV31("post-with-$total-with-defval-true"); + } + + @Test + public void verifyInV31HeaderParamWith$total() { + verifyV31("header-with-$total-with-defval-true"); + } + + @Test + public void verifyInV31With$refUnreferencedWith$total() { + verifyV31("with-$ref-unreferenced-with-$total-with-defval-true"); + } + + @Test + public void verifyInV32With$totalWithDefvalFalse() { + verifyV32("plain-with-$total-with-defval-false"); + } + + @Test + public void verifyInV32With$totalWithDefvalTrue() { + verifyV32("plain-with-$total-with-defval-true"); + } + + @Test + public void verifyInV32With$totalWithoutDefval() { + verifyV32("plain-with-$total-without-defval"); + } + + @Test + public void verifyInV32Without$total() { + verifyV32("plain-without-$total"); + } + + @Test + public void verifyInV32With$refWith$totalWithDefvalFalse() { + verifyV32("with-$ref-with-$total-with-defval-false"); + } + + @Test + public void verifyInV32With$refWith$totalWithDefvalTrue() { + verifyV32("with-$ref-with-$total-with-defval-true"); + } + + @Test + public void verifyInV32With$refWith$totalWithoutDefval() { + verifyV32("with-$ref-with-$total-without-defval"); + } + + @Test + public void verifyInV32With$refWithout$total() { + verifyV32("with-$ref-without-$total"); + } + @Test public void verifyInV32WithoutParameters() { verifyV32("without-parameters"); } + @Test + public void verifyInV32PostOperationWith$total() { + verifyV32("post-with-$total-with-defval-true"); + } + + @Test + public void verifyInV32HeaderParamWith$total() { + verifyV32("header-with-$total-with-defval-true"); + } + + @Test + public void verifyInV32With$refUnreferencedWith$total() { + verifyV32("with-$ref-unreferenced-with-$total-with-defval-true"); + } + @Override public void verifyRule() { assertRuleProperties("OAR026 - TotalParameterDefaultValue - The $total parameter default value should be false", RuleType.BUG, Severity.CRITICAL, tags("parameters")); diff --git a/src/test/resources/checks/v2/apim/wso2/OAR005/extensive-api.json b/src/test/resources/checks/v2/apim/wso2/OAR005/extensive-api.json new file mode 100644 index 00000000..ea7a8928 --- /dev/null +++ b/src/test/resources/checks/v2/apim/wso2/OAR005/extensive-api.json @@ -0,0 +1,241 @@ +{ + "swagger" : "2.0", + "info" : { + "version" : "2.1.0", + "title" : "Retail Storefront API", + "description" : "Public-facing REST API for the retail storefront covering product catalog browsing, order placement, account management, and platform administration." + }, + "paths" : { + "/catalog/products" : { + "get" : { + "operationId" : "get_catalog_products", + "summary" : "List products", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "CATALOG_SC_READ" + }, + "post" : { + "operationId" : "post_catalog_products", + "summary" : "Create a product", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "CATALOG_SC_WRITE" + } + }, + "/catalog/products/{productId}" : { + "get" : { + "operationId" : "get_catalog_products_productId", + "summary" : "Get a product", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "CATALOG_SC_READ" + }, + "put" : { + "operationId" : "put_catalog_products_productId", + "summary" : "Replace a product", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "CATALOG_SC_WRITE" + }, + "delete" : { + "operationId" : "delete_catalog_products_productId", + "summary" : "Delete a product", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "CATALOG_SC_WRITE" + } + }, + "/orders" : { + "get" : { + "operationId" : "get_orders", + "summary" : "List orders", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "ORDERS_SC_READ" + }, + "post" : { + "operationId" : "post_orders", + "summary" : "Place an order", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "ORDERS_SC_WRITE" + } + }, + "/orders/{orderId}" : { + "get" : { + "operationId" : "get_orders_orderId", + "summary" : "Get an order", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "ORDERS_SC_READ" + }, + "delete" : { + "operationId" : "delete_orders_orderId", + "summary" : "Cancel an order", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "ORDERS_SC_WRITE" + } + }, + "/account/profile" : { + "get" : { + "operationId" : "get_account_profile", + "summary" : "Get the caller's profile", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "ACCOUNT_SC_READ" + }, + "put" : { + "operationId" : "put_account_profile", + "summary" : "Update the caller's profile - undeclared scope", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "ACCOUNT_SC_WRITE" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + }, + "/admin/users" : { + "get" : { + "operationId" : "get_admin_users", + "summary" : "List platform users - matches key not name", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "admin_all" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "post" : { + "operationId" : "post_admin_users", + "summary" : "Create a platform user", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "ADMIN_SC_ALL" + } + }, + "/admin/audit-log" : { + "get" : { + "operationId" : "get_admin_audit-log", + "summary" : "Read the audit log", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "ADMIN_SC_ALL" + } + } + }, + "x-wso2-security" : { + "apim" : { + "x-wso2-scopes" : [ { + "name" : "CATALOG_SC_READ", + "key" : "catalog_read", + "roles" : "ROLE_CATALOG_READ", + "description" : "Allows users to browse the product catalog" + }, { + "name" : "CATALOG_SC_WRITE", + "key" : "catalog_write", + "roles" : "ROLE_CATALOG_WRITE", + "description" : "Allows users to create or update products" + }, { + "name" : "ORDERS_SC_READ", + "key" : "orders_read", + "roles" : "ROLE_ORDERS_READ", + "description" : "Allows users to view orders" + }, { + "name" : "ORDERS_SC_WRITE", + "key" : "orders_write", + "roles" : "ROLE_ORDERS_WRITE", + "description" : "Allows users to place or cancel orders" + }, { + "name" : "ACCOUNT_SC_READ", + "key" : "account_read", + "roles" : "ROLE_ACCOUNT_READ", + "description" : "Allows users to view their own account" + }, { + "name" : "ADMIN_SC_ALL", + "key" : "admin_all", + "roles" : "ROLE_ADMIN", + "description" : "Full administrative access" + } ] + } + } +} diff --git a/src/test/resources/checks/v2/apim/wso2/OAR005/extensive-api.yaml b/src/test/resources/checks/v2/apim/wso2/OAR005/extensive-api.yaml new file mode 100644 index 00000000..1477fc6a --- /dev/null +++ b/src/test/resources/checks/v2/apim/wso2/OAR005/extensive-api.yaml @@ -0,0 +1,167 @@ +swagger: "2.0" +info: + version: 2.1.0 + title: Retail Storefront API + description: Public-facing REST API for the retail storefront covering product catalog browsing, order placement, account management, and platform administration. +paths: + /catalog/products: + get: + operationId: get_catalog_products + summary: List products + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: CATALOG_SC_READ + post: + operationId: post_catalog_products + summary: Create a product + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: CATALOG_SC_WRITE + /catalog/products/{productId}: + get: + operationId: get_catalog_products_productId + summary: Get a product + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: CATALOG_SC_READ + put: + operationId: put_catalog_products_productId + summary: Replace a product + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: CATALOG_SC_WRITE + delete: + operationId: delete_catalog_products_productId + summary: Delete a product + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: CATALOG_SC_WRITE + /orders: + get: + operationId: get_orders + summary: List orders + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: ORDERS_SC_READ + post: + operationId: post_orders + summary: Place an order + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: ORDERS_SC_WRITE + /orders/{orderId}: + get: + operationId: get_orders_orderId + summary: Get an order + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: ORDERS_SC_READ + delete: + operationId: delete_orders_orderId + summary: Cancel an order + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: ORDERS_SC_WRITE + /account/profile: + get: + operationId: get_account_profile + summary: Get the caller's profile + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: ACCOUNT_SC_READ + put: + operationId: put_account_profile + summary: Update the caller's profile - undeclared scope + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: ACCOUNT_SC_WRITE # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + /admin/users: + get: + operationId: get_admin_users + summary: List platform users - matches key not name + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: admin_all # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + post: + operationId: post_admin_users + summary: Create a platform user + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: ADMIN_SC_ALL + /admin/audit-log: + get: + operationId: get_admin_audit-log + summary: Read the audit log + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: ADMIN_SC_ALL + +x-wso2-security: + apim: + x-wso2-scopes: + - name: CATALOG_SC_READ + key: catalog_read + roles: ROLE_CATALOG_READ + description: Allows users to browse the product catalog + - name: CATALOG_SC_WRITE + key: catalog_write + roles: ROLE_CATALOG_WRITE + description: Allows users to create or update products + - name: ORDERS_SC_READ + key: orders_read + roles: ROLE_ORDERS_READ + description: Allows users to view orders + - name: ORDERS_SC_WRITE + key: orders_write + roles: ROLE_ORDERS_WRITE + description: Allows users to place or cancel orders + - name: ACCOUNT_SC_READ + key: account_read + roles: ROLE_ACCOUNT_READ + description: Allows users to view their own account + - name: ADMIN_SC_ALL + key: admin_all + roles: ROLE_ADMIN + description: Full administrative access diff --git a/src/test/resources/checks/v2/apim/wso2/OAR005/with-all-verbs.json b/src/test/resources/checks/v2/apim/wso2/OAR005/with-all-verbs.json new file mode 100644 index 00000000..9f34cfee --- /dev/null +++ b/src/test/resources/checks/v2/apim/wso2/OAR005/with-all-verbs.json @@ -0,0 +1,77 @@ +{ + "swagger" : "2.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/a" : { + "x-scope" : "scope_one", + "get" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "put" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "delete" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "options" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "head" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "patch" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + } + }, + "x-wso2-security" : { + "apim" : { + "x-wso2-scopes" : [ { + "name" : "scope_one", + "key" : "scope_one", + "roles" : "role_one" + } ] + } + } +} diff --git a/src/test/resources/checks/v2/apim/wso2/OAR005/with-all-verbs.yaml b/src/test/resources/checks/v2/apim/wso2/OAR005/with-all-verbs.yaml new file mode 100644 index 00000000..358bc36f --- /dev/null +++ b/src/test/resources/checks/v2/apim/wso2/OAR005/with-all-verbs.yaml @@ -0,0 +1,49 @@ +swagger: "2.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /a: + x-scope: scope_one + get: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + put: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + post: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + delete: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + options: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + head: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + patch: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + +x-wso2-security: + apim: + x-wso2-scopes: + - name: scope_one + key: scope_one + roles: role_one diff --git a/src/test/resources/checks/v2/apim/wso2/OAR005/with-chained-ref-security.json b/src/test/resources/checks/v2/apim/wso2/OAR005/with-chained-ref-security.json new file mode 100644 index 00000000..c4866112 --- /dev/null +++ b/src/test/resources/checks/v2/apim/wso2/OAR005/with-chained-ref-security.json @@ -0,0 +1,50 @@ +{ + "swagger" : "2.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/pets" : { + "get" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_two" + }, + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + } + }, + "x-wso2-security" : { + "$ref" : "#/x-wso2-definitions/alias" + }, + "x-wso2-definitions" : { + "alias" : { + "$ref" : "#/x-wso2-definitions/security" + }, + "security" : { + "apim" : { + "x-wso2-scopes" : [ { + "name" : "scope_one", + "description" : "scope_one", + "key" : "scope_one", + "roles" : "role_one" + }, { + "name" : "scope_two", + "description" : "scope_two", + "key" : "scope_two", + "roles" : "role_two" + } ] + } + } + } +} diff --git a/src/test/resources/checks/v2/apim/wso2/OAR005/with-chained-ref-security.yaml b/src/test/resources/checks/v2/apim/wso2/OAR005/with-chained-ref-security.yaml new file mode 100644 index 00000000..c80432d1 --- /dev/null +++ b/src/test/resources/checks/v2/apim/wso2/OAR005/with-chained-ref-security.yaml @@ -0,0 +1,33 @@ +swagger: "2.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + get: + responses: + 200: + description: Ok + x-scope: scope_two + post: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + +x-wso2-security: + $ref: "#/x-wso2-definitions/alias" +x-wso2-definitions: + alias: + $ref: "#/x-wso2-definitions/security" + security: + apim: + x-wso2-scopes: + - name: scope_one + description: scope_one + key: scope_one + roles: role_one + - name: scope_two + description: scope_two + key: scope_two + roles: role_two diff --git a/src/test/resources/checks/v2/apim/wso2/OAR005/with-ref-scope.json b/src/test/resources/checks/v2/apim/wso2/OAR005/with-ref-scope.json new file mode 100644 index 00000000..2038f1e4 --- /dev/null +++ b/src/test/resources/checks/v2/apim/wso2/OAR005/with-ref-scope.json @@ -0,0 +1,55 @@ +{ + "swagger" : "2.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/pets" : { + "get" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_one" + }, + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_two" + }, + "put" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + } + }, + "x-wso2-security" : { + "apim" : { + "x-wso2-scopes" : [ { + "name" : "scope_one", + "description" : "scope_one", + "key" : "scope_one", + "roles" : "role_one" + }, { + "$ref" : "#/x-wso2-definitions/scopeTwo" + } ] + } + }, + "x-wso2-definitions" : { + "scopeTwo" : { + "name" : "scope_two", + "description" : "scope_two", + "key" : "scope_two", + "roles" : "role_two" + } + } +} diff --git a/src/test/resources/checks/v2/apim/wso2/OAR005/with-ref-scope.yaml b/src/test/resources/checks/v2/apim/wso2/OAR005/with-ref-scope.yaml new file mode 100644 index 00000000..6e21fea4 --- /dev/null +++ b/src/test/resources/checks/v2/apim/wso2/OAR005/with-ref-scope.yaml @@ -0,0 +1,36 @@ +swagger: "2.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + get: + responses: + 200: + description: Ok + x-scope: scope_one + post: + responses: + 200: + description: Ok + x-scope: scope_two + put: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + +x-wso2-security: + apim: + x-wso2-scopes: + - name: scope_one + description: scope_one + key: scope_one + roles: role_one + - $ref: "#/x-wso2-definitions/scopeTwo" +x-wso2-definitions: + scopeTwo: + name: scope_two + description: scope_two + key: scope_two + roles: role_two diff --git a/src/test/resources/checks/v2/apim/wso2/OAR005/with-ref-security.json b/src/test/resources/checks/v2/apim/wso2/OAR005/with-ref-security.json new file mode 100644 index 00000000..498b2903 --- /dev/null +++ b/src/test/resources/checks/v2/apim/wso2/OAR005/with-ref-security.json @@ -0,0 +1,47 @@ +{ + "swagger" : "2.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/pets" : { + "get" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_two" + }, + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + } + }, + "x-wso2-security" : { + "$ref" : "#/x-wso2-definitions/security" + }, + "x-wso2-definitions" : { + "security" : { + "apim" : { + "x-wso2-scopes" : [ { + "name" : "scope_one", + "description" : "scope_one", + "key" : "scope_one", + "roles" : "role_one" + }, { + "name" : "scope_two", + "description" : "scope_two", + "key" : "scope_two", + "roles" : "role_two" + } ] + } + } + } +} diff --git a/src/test/resources/checks/v2/apim/wso2/OAR005/with-ref-security.yaml b/src/test/resources/checks/v2/apim/wso2/OAR005/with-ref-security.yaml new file mode 100644 index 00000000..1f5d9318 --- /dev/null +++ b/src/test/resources/checks/v2/apim/wso2/OAR005/with-ref-security.yaml @@ -0,0 +1,31 @@ +swagger: "2.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + get: + responses: + 200: + description: Ok + x-scope: scope_two + post: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + +x-wso2-security: + $ref: "#/x-wso2-definitions/security" +x-wso2-definitions: + security: + apim: + x-wso2-scopes: + - name: scope_one + description: scope_one + key: scope_one + roles: role_one + - name: scope_two + description: scope_two + key: scope_two + roles: role_two diff --git a/src/test/resources/checks/v2/apim/wso2/OAR005/with-scope-key-not-name.json b/src/test/resources/checks/v2/apim/wso2/OAR005/with-scope-key-not-name.json new file mode 100644 index 00000000..82040f6b --- /dev/null +++ b/src/test/resources/checks/v2/apim/wso2/OAR005/with-scope-key-not-name.json @@ -0,0 +1,37 @@ +{ + "swagger" : "2.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/pets" : { + "get" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "catalogue_read" + }, + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "read" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + } + }, + "x-wso2-security" : { + "apim" : { + "x-wso2-scopes" : [ { + "name" : "catalogue_read", + "description" : "catalogue_read", + "key" : "read", + "roles" : "role_one" + } ] + } + } +} diff --git a/src/test/resources/checks/v2/apim/wso2/OAR005/with-scope-key-not-name.yaml b/src/test/resources/checks/v2/apim/wso2/OAR005/with-scope-key-not-name.yaml new file mode 100644 index 00000000..aa81780b --- /dev/null +++ b/src/test/resources/checks/v2/apim/wso2/OAR005/with-scope-key-not-name.yaml @@ -0,0 +1,24 @@ +swagger: "2.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + get: + responses: + 200: + description: Ok + x-scope: catalogue_read + post: + responses: + 200: + description: Ok + x-scope: read # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + +x-wso2-security: + apim: + x-wso2-scopes: + - name: catalogue_read + description: catalogue_read + key: read + roles: role_one diff --git a/src/test/resources/checks/v2/apim/wso2/OAR005/with-scopes-as-map.json b/src/test/resources/checks/v2/apim/wso2/OAR005/with-scopes-as-map.json new file mode 100644 index 00000000..ffb790f6 --- /dev/null +++ b/src/test/resources/checks/v2/apim/wso2/OAR005/with-scopes-as-map.json @@ -0,0 +1,66 @@ +{ + "swagger" : "2.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/pets" : { + "get" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "read_scope" + }, + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "read" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "put" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "write_scope" + }, + "delete" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + } + }, + "x-wso2-security" : { + "apim" : { + "x-wso2-scopes" : { + "read" : { + "name" : "read_scope", + "key" : "read", + "roles" : "ROLE_READ", + "description" : "Allows users to read the catalogue" + }, + "write" : { + "$ref" : "#/x-wso2-definitions/writeScope" + } + } + } + }, + "x-wso2-definitions" : { + "writeScope" : { + "name" : "write_scope", + "key" : "write", + "roles" : "ROLE_WRITE", + "description" : "Allows users to write the catalogue" + } + } +} diff --git a/src/test/resources/checks/v2/apim/wso2/OAR005/with-scopes-as-map.yaml b/src/test/resources/checks/v2/apim/wso2/OAR005/with-scopes-as-map.yaml new file mode 100644 index 00000000..4fce63a7 --- /dev/null +++ b/src/test/resources/checks/v2/apim/wso2/OAR005/with-scopes-as-map.yaml @@ -0,0 +1,43 @@ +swagger: "2.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + get: + responses: + 200: + description: Ok + x-scope: read_scope + post: + responses: + 200: + description: Ok + x-scope: read # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + put: + responses: + 200: + description: Ok + x-scope: write_scope + delete: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + +x-wso2-security: + apim: + x-wso2-scopes: + read: + name: read_scope + key: read + roles: ROLE_READ + description: Allows users to read the catalogue + write: + $ref: "#/x-wso2-definitions/writeScope" +x-wso2-definitions: + writeScope: + name: write_scope + key: write + roles: ROLE_WRITE + description: Allows users to write the catalogue diff --git a/src/test/resources/checks/v2/apim/wso2/OAR005/without-security.json b/src/test/resources/checks/v2/apim/wso2/OAR005/without-security.json new file mode 100644 index 00000000..ed4974f3 --- /dev/null +++ b/src/test/resources/checks/v2/apim/wso2/OAR005/without-security.json @@ -0,0 +1,26 @@ +{ + "swagger" : "2.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/pets" : { + "get" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_one" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v2/apim/wso2/OAR005/without-security.yaml b/src/test/resources/checks/v2/apim/wso2/OAR005/without-security.yaml new file mode 100644 index 00000000..9eaae866 --- /dev/null +++ b/src/test/resources/checks/v2/apim/wso2/OAR005/without-security.yaml @@ -0,0 +1,15 @@ +swagger: "2.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + get: + responses: + 200: + description: Ok + x-scope: scope_one # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + post: + responses: + 200: + description: Ok diff --git a/src/test/resources/checks/v2/examples/OAR031/allof-schema-missing-example.yaml b/src/test/resources/checks/v2/examples/OAR031/allof-schema-missing-example.yaml new file mode 100644 index 00000000..fbf92f9a --- /dev/null +++ b/src/test/resources/checks/v2/examples/OAR031/allof-schema-missing-example.yaml @@ -0,0 +1,28 @@ +swagger: "2.0" +info: + version: 1.0.0 + title: Swagger Petstore +definitions: + BaseEntity: + type: object + properties: + id: # Noncompliant {{OAR031: Property 'id' is missing an example.}} + type: integer + 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/externalref.yaml b/src/test/resources/checks/v2/examples/OAR031/externalref.yaml index 18b488c1..102e8d94 100644 --- a/src/test/resources/checks/v2/examples/OAR031/externalref.yaml +++ b/src/test/resources/checks/v2/examples/OAR031/externalref.yaml @@ -10,14 +10,14 @@ paths: /users: get: responses: - 200: # Noncompliant {{OAR031: Responses must have one or more examples defined}} + 200: # Noncompliant {{OAR031: Response must have an example defined}} description: OK schema: type: array items: $ref: '#/definitions/User' 400: - $ref: >- # Noncompliant {{OAR031: Responses must have one or more examples defined}} + $ref: >- # Noncompliant {{OAR031: Response must have an example defined}} http://localhost:18089/OAR031.yaml#/components/responses/server_error_response /users/{userId}: get: @@ -27,7 +27,7 @@ paths: required: true type: string responses: - 200: # Noncompliant {{OAR031: Responses must have one or more examples defined}} + 200: # Noncompliant {{OAR031: Response must have an example defined}} description: A single user schema: $ref: '#/definitions/User' @@ -41,8 +41,10 @@ definitions: name: type: string example: "John" + # `Error` is intentionally never referenced by any path: it exercises the + # orphan-schema exclusion (property-level checks only cover reachable schemas). Error: type: object properties: - message: # Noncompliant {{OAR031: Properties must have an example defined}} + message: type: string \ No newline at end of file diff --git a/src/test/resources/checks/v2/examples/OAR031/nested-properties-examples.yaml b/src/test/resources/checks/v2/examples/OAR031/nested-properties-examples.yaml index 6b0b4816..defbd10c 100644 --- a/src/test/resources/checks/v2/examples/OAR031/nested-properties-examples.yaml +++ b/src/test/resources/checks/v2/examples/OAR031/nested-properties-examples.yaml @@ -6,7 +6,7 @@ paths: /profile: put: parameters: - - name: body # Noncompliant {{OAR031: Parameters must have one or more examples defined}} + - name: body # Noncompliant {{OAR031: Parameter 'body' must have an example defined}} in: body required: true schema: @@ -34,5 +34,5 @@ paths: type: string example: "28001" responses: - 200: # Noncompliant {{OAR031: Responses must have one or more examples defined}} + 200: # Noncompliant {{OAR031: Response must have an example defined}} description: OK \ No newline at end of file diff --git a/src/test/resources/checks/v2/examples/OAR031/orphan-schema.yaml b/src/test/resources/checks/v2/examples/OAR031/orphan-schema.yaml new file mode 100644 index 00000000..f4f1f1dd --- /dev/null +++ b/src/test/resources/checks/v2/examples/OAR031/orphan-schema.yaml @@ -0,0 +1,28 @@ +swagger: "2.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + get: + responses: + 200: + description: Ok + schema: + $ref: '#/definitions/pet' + examples: + application/json: + name: Fluffy +definitions: + pet: + type: object + properties: + name: + type: string + example: "Fluffy" + # Never referenced by any path - must not be flagged (orphan-schema exclusion). + UnusedSchema: + type: object + properties: + unused_field: + type: string diff --git a/src/test/resources/checks/v2/examples/OAR031/valid.json b/src/test/resources/checks/v2/examples/OAR031/valid.json index ae8000e6..ed1ab2da 100644 --- a/src/test/resources/checks/v2/examples/OAR031/valid.json +++ b/src/test/resources/checks/v2/examples/OAR031/valid.json @@ -84,7 +84,7 @@ } }, "responses" : { - "server_error_response" : { # Noncompliant {{OAR031: Responses must have one or more examples defined}} + "server_error_response" : { # Noncompliant {{OAR031: Response must have an example defined}} "description" : "Default error response", "schema" : { "type" : "object", diff --git a/src/test/resources/checks/v2/examples/OAR031/without-examples.json b/src/test/resources/checks/v2/examples/OAR031/without-examples.json index 4e6beec9..c38288bd 100644 --- a/src/test/resources/checks/v2/examples/OAR031/without-examples.json +++ b/src/test/resources/checks/v2/examples/OAR031/without-examples.json @@ -11,7 +11,7 @@ "204": { "description": "No content" }, - "206" : { # Noncompliant {{OAR031: Responses must have one or more examples defined}} + "206" : { # Noncompliant {{OAR031: Response must have an example defined}} "description" : "Pet list", "schema" : { "$ref" : "#/definitions/pets" @@ -29,7 +29,7 @@ "$ref" : "#/parameters/id" } ], "responses" : { - "200" : { # Noncompliant {{OAR031: Responses must have one or more examples defined}} + "200" : { # Noncompliant {{OAR031: Response must have an example defined}} "description" : "One pet", "schema" : { "$ref" : "#/definitions/pet" @@ -57,10 +57,10 @@ "pet" : { "type" : "object", "properties" : { - "name" : { # Noncompliant {{OAR031: Properties must have an example defined}} + "name" : { # Noncompliant {{OAR031: Property 'name' is missing an example.}} "type" : "string" }, - "type" : { # Noncompliant {{OAR031: Properties must have an example defined}} + "type" : { # Noncompliant {{OAR031: Property 'type' is missing an example.}} "type" : "string" } } @@ -68,7 +68,7 @@ "pets" : { "type" : "object", "properties" : { - "size" : { # Noncompliant {{OAR031: Properties must have an example defined}} + "size" : { # Noncompliant {{OAR031: Property 'size' is missing an example.}} "type" : "integer" }, "pets" : { @@ -81,12 +81,12 @@ } }, "responses" : { - "server_error_response" : { # Noncompliant {{OAR031: Responses must have one or more examples defined}} + "server_error_response" : { # Noncompliant {{OAR031: Response must have an example defined}} "description" : "Default error response", "schema" : { "type" : "object", "properties" : { - "error" : { # Noncompliant {{OAR031: Properties must have an example defined}} + "error" : { # Noncompliant {{OAR031: Property 'error' is missing an example.}} "type" : "string" } } 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 cfb67cc7..8f2e2edf 100644 --- a/src/test/resources/checks/v2/examples/OAR031/without-examples.yaml +++ b/src/test/resources/checks/v2/examples/OAR031/without-examples.yaml @@ -8,7 +8,7 @@ paths: responses: 204: description: No content - 206: # Noncompliant {{OAR031: Responses must have one or more examples defined}} + 206: # Noncompliant {{OAR031: Response must have an example defined}} description: Pet list schema: $ref: '#/definitions/pets' @@ -19,7 +19,7 @@ paths: parameters: - $ref: "#/parameters/id" responses: - 200: # Noncompliant {{OAR031: Responses must have one or more examples defined}} + 200: # Noncompliant {{OAR031: Response must have an example defined}} description: One pet schema: $ref: "#/definitions/pet" @@ -39,24 +39,24 @@ definitions: pet: type: object properties: - name: # Noncompliant {{OAR031: Properties must have an example defined}} + name: # Noncompliant {{OAR031: Property 'name' is missing an example.}} type: string - type: # Noncompliant {{OAR031: Properties must have an example defined}} + type: # Noncompliant {{OAR031: Property 'type' is missing an example.}} type: string pets: type: object properties: - size: # Noncompliant {{OAR031: Properties must have an example defined}} + size: # Noncompliant {{OAR031: Property 'size' is missing an example.}} type: integer pets: type: array items: $ref: '#/definitions/pet' responses: - server_error_response: # Noncompliant {{OAR031: Responses must have one or more examples defined}} + server_error_response: # Noncompliant {{OAR031: Response must have an example defined}} description: Default error response schema: type: object properties: - error: # Noncompliant {{OAR031: Properties must have an example defined}} + error: # Noncompliant {{OAR031: Property 'error' is missing an example.}} type: string \ No newline at end of file diff --git a/src/test/resources/checks/v2/format/OAR007/with-specific-put.json b/src/test/resources/checks/v2/format/OAR007/with-specific-put.json new file mode 100644 index 00000000..8b798cb3 --- /dev/null +++ b/src/test/resources/checks/v2/format/OAR007/with-specific-put.json @@ -0,0 +1,21 @@ +{ + "swagger": "2.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore" + }, + "paths": { + "/pets": { + "put": { + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "Ok" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v2/format/OAR007/with-specific-put.yaml b/src/test/resources/checks/v2/format/OAR007/with-specific-put.yaml new file mode 100644 index 00000000..21362e15 --- /dev/null +++ b/src/test/resources/checks/v2/format/OAR007/with-specific-put.yaml @@ -0,0 +1,13 @@ +swagger: "2.0" +info: + version: 1.0.0 + title: Swagger Petstore + +paths: + /pets: + put: + produces: + - application/json + responses: + 200: + description: Ok diff --git a/src/test/resources/checks/v2/format/OAR010/with-default-mixed-case.json b/src/test/resources/checks/v2/format/OAR010/with-default-mixed-case.json new file mode 100644 index 00000000..30267930 --- /dev/null +++ b/src/test/resources/checks/v2/format/OAR010/with-default-mixed-case.json @@ -0,0 +1,21 @@ +{ + "swagger": "2.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore" + }, + "paths": { + "/pets": { + "post": { + "produces": [ + "Application/JSON" + ], + "responses": { + "200": { + "description": "Ok" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v2/format/OAR010/with-default-mixed-case.yaml b/src/test/resources/checks/v2/format/OAR010/with-default-mixed-case.yaml new file mode 100644 index 00000000..c954d326 --- /dev/null +++ b/src/test/resources/checks/v2/format/OAR010/with-default-mixed-case.yaml @@ -0,0 +1,13 @@ +swagger: "2.0" +info: + version: 1.0.0 + title: Swagger Petstore + +paths: + /pets: + post: + produces: + - Application/JSON + responses: + 200: + description: Ok diff --git a/src/test/resources/checks/v2/parameters/OAR026/header-with-$total-with-defval-true.json b/src/test/resources/checks/v2/parameters/OAR026/header-with-$total-with-defval-true.json new file mode 100644 index 00000000..c8e9d445 --- /dev/null +++ b/src/test/resources/checks/v2/parameters/OAR026/header-with-$total-with-defval-true.json @@ -0,0 +1,24 @@ +{ + "swagger" : "2.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/pets" : { + "get" : { + "parameters" : [ { + "in" : "header", + "name" : "$total", + "type" : "boolean", + "default" : true + } ], + "responses" : { + "206" : { + "description" : "Ok" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v2/parameters/OAR026/header-with-$total-with-defval-true.yaml b/src/test/resources/checks/v2/parameters/OAR026/header-with-$total-with-defval-true.yaml new file mode 100644 index 00000000..6a2b4dfd --- /dev/null +++ b/src/test/resources/checks/v2/parameters/OAR026/header-with-$total-with-defval-true.yaml @@ -0,0 +1,15 @@ +swagger: "2.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + get: + parameters: + - in: header + name: $total + type: boolean + default: true + responses: + 206: + description: Ok diff --git a/src/test/resources/checks/v2/parameters/OAR026/plain-with-$total-without-defval.json b/src/test/resources/checks/v2/parameters/OAR026/plain-with-$total-without-defval.json index 75b84003..1eae98e3 100644 --- a/src/test/resources/checks/v2/parameters/OAR026/plain-with-$total-without-defval.json +++ b/src/test/resources/checks/v2/parameters/OAR026/plain-with-$total-without-defval.json @@ -14,7 +14,7 @@ "items" : { "type" : "string" } - }, { # Noncompliant {{OAR026: The $total parameter default value should be false}} + }, { "in" : "query", "name" : "$total", "type" : "boolean" diff --git a/src/test/resources/checks/v2/parameters/OAR026/plain-with-$total-without-defval.yaml b/src/test/resources/checks/v2/parameters/OAR026/plain-with-$total-without-defval.yaml index b3f78a09..8c52f6e3 100644 --- a/src/test/resources/checks/v2/parameters/OAR026/plain-with-$total-without-defval.yaml +++ b/src/test/resources/checks/v2/parameters/OAR026/plain-with-$total-without-defval.yaml @@ -11,7 +11,7 @@ paths: type: array items: type: string - - in: query # Noncompliant {{OAR026: The $total parameter default value should be false}} + - in: query name: $total type: boolean responses: diff --git a/src/test/resources/checks/v2/parameters/OAR026/post-with-$total-with-defval-true.json b/src/test/resources/checks/v2/parameters/OAR026/post-with-$total-with-defval-true.json new file mode 100644 index 00000000..83837ae9 --- /dev/null +++ b/src/test/resources/checks/v2/parameters/OAR026/post-with-$total-with-defval-true.json @@ -0,0 +1,24 @@ +{ + "swagger" : "2.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/pets" : { + "post" : { + "parameters" : [ { + "in" : "query", + "name" : "$total", + "type" : "boolean", + "default" : true + } ], + "responses" : { + "201" : { + "description" : "Created" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v2/parameters/OAR026/post-with-$total-with-defval-true.yaml b/src/test/resources/checks/v2/parameters/OAR026/post-with-$total-with-defval-true.yaml new file mode 100644 index 00000000..ee010c1e --- /dev/null +++ b/src/test/resources/checks/v2/parameters/OAR026/post-with-$total-with-defval-true.yaml @@ -0,0 +1,15 @@ +swagger: "2.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + post: + parameters: + - in: query + name: $total + type: boolean + default: true + responses: + 201: + description: Created diff --git a/src/test/resources/checks/v2/parameters/OAR026/with-$ref-unreferenced-with-$total-with-defval-true.json b/src/test/resources/checks/v2/parameters/OAR026/with-$ref-unreferenced-with-$total-with-defval-true.json new file mode 100644 index 00000000..45ec80db --- /dev/null +++ b/src/test/resources/checks/v2/parameters/OAR026/with-$ref-unreferenced-with-$total-with-defval-true.json @@ -0,0 +1,26 @@ +{ + "swagger" : "2.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "parameters" : { + "total" : { + "in" : "query", + "name" : "$total", + "type" : "boolean", + "default" : true + } + }, + "paths" : { + "/pets" : { + "get" : { + "responses" : { + "206" : { + "description" : "Ok" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v2/parameters/OAR026/with-$ref-unreferenced-with-$total-with-defval-true.yaml b/src/test/resources/checks/v2/parameters/OAR026/with-$ref-unreferenced-with-$total-with-defval-true.yaml new file mode 100644 index 00000000..5de71af2 --- /dev/null +++ b/src/test/resources/checks/v2/parameters/OAR026/with-$ref-unreferenced-with-$total-with-defval-true.yaml @@ -0,0 +1,16 @@ +swagger: "2.0" +info: + version: 1.0.0 + title: Swagger Petstore +parameters: + total: + in: query + name: $total + type: boolean + default: true +paths: + /pets: + get: + responses: + 206: + description: Ok diff --git a/src/test/resources/checks/v2/parameters/OAR026/with-$ref-with-$total-without-defval.json b/src/test/resources/checks/v2/parameters/OAR026/with-$ref-with-$total-without-defval.json index 7c43ee1c..52632ee9 100644 --- a/src/test/resources/checks/v2/parameters/OAR026/with-$ref-with-$total-without-defval.json +++ b/src/test/resources/checks/v2/parameters/OAR026/with-$ref-with-$total-without-defval.json @@ -13,7 +13,7 @@ "type" : "string" } }, - "total" : { # Noncompliant {{OAR026: The $total parameter default value should be false}} + "total" : { "in" : "query", "name" : "$total", "type" : "boolean" diff --git a/src/test/resources/checks/v2/parameters/OAR026/with-$ref-with-$total-without-defval.yaml b/src/test/resources/checks/v2/parameters/OAR026/with-$ref-with-$total-without-defval.yaml index 9c6b56e2..663e7277 100644 --- a/src/test/resources/checks/v2/parameters/OAR026/with-$ref-with-$total-without-defval.yaml +++ b/src/test/resources/checks/v2/parameters/OAR026/with-$ref-with-$total-without-defval.yaml @@ -9,7 +9,7 @@ parameters: type: array items: type: string - total: # Noncompliant {{OAR026: The $total parameter default value should be false}} + total: in: query name: $total type: boolean diff --git a/src/test/resources/checks/v3/apim/wso2/OAR005/extensive-api.json b/src/test/resources/checks/v3/apim/wso2/OAR005/extensive-api.json new file mode 100644 index 00000000..62484806 --- /dev/null +++ b/src/test/resources/checks/v3/apim/wso2/OAR005/extensive-api.json @@ -0,0 +1,241 @@ +{ + "openapi" : "3.0.0", + "info" : { + "version" : "2.1.0", + "title" : "Retail Storefront API", + "description" : "Public-facing REST API for the retail storefront covering product catalog browsing, order placement, account management, and platform administration." + }, + "paths" : { + "/catalog/products" : { + "get" : { + "operationId" : "get_catalog_products", + "summary" : "List products", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "CATALOG_SC_READ" + }, + "post" : { + "operationId" : "post_catalog_products", + "summary" : "Create a product", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "CATALOG_SC_WRITE" + } + }, + "/catalog/products/{productId}" : { + "get" : { + "operationId" : "get_catalog_products_productId", + "summary" : "Get a product", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "CATALOG_SC_READ" + }, + "put" : { + "operationId" : "put_catalog_products_productId", + "summary" : "Replace a product", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "CATALOG_SC_WRITE" + }, + "delete" : { + "operationId" : "delete_catalog_products_productId", + "summary" : "Delete a product", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "CATALOG_SC_WRITE" + } + }, + "/orders" : { + "get" : { + "operationId" : "get_orders", + "summary" : "List orders", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "ORDERS_SC_READ" + }, + "post" : { + "operationId" : "post_orders", + "summary" : "Place an order", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "ORDERS_SC_WRITE" + } + }, + "/orders/{orderId}" : { + "get" : { + "operationId" : "get_orders_orderId", + "summary" : "Get an order", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "ORDERS_SC_READ" + }, + "delete" : { + "operationId" : "delete_orders_orderId", + "summary" : "Cancel an order", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "ORDERS_SC_WRITE" + } + }, + "/account/profile" : { + "get" : { + "operationId" : "get_account_profile", + "summary" : "Get the caller's profile", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "ACCOUNT_SC_READ" + }, + "put" : { + "operationId" : "put_account_profile", + "summary" : "Update the caller's profile - undeclared scope", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "ACCOUNT_SC_WRITE" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + }, + "/admin/users" : { + "get" : { + "operationId" : "get_admin_users", + "summary" : "List platform users - matches key not name", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "admin_all" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "post" : { + "operationId" : "post_admin_users", + "summary" : "Create a platform user", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "ADMIN_SC_ALL" + } + }, + "/admin/audit-log" : { + "get" : { + "operationId" : "get_admin_audit-log", + "summary" : "Read the audit log", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "ADMIN_SC_ALL" + } + } + }, + "x-wso2-security" : { + "apim" : { + "x-wso2-scopes" : [ { + "name" : "CATALOG_SC_READ", + "key" : "catalog_read", + "roles" : "ROLE_CATALOG_READ", + "description" : "Allows users to browse the product catalog" + }, { + "name" : "CATALOG_SC_WRITE", + "key" : "catalog_write", + "roles" : "ROLE_CATALOG_WRITE", + "description" : "Allows users to create or update products" + }, { + "name" : "ORDERS_SC_READ", + "key" : "orders_read", + "roles" : "ROLE_ORDERS_READ", + "description" : "Allows users to view orders" + }, { + "name" : "ORDERS_SC_WRITE", + "key" : "orders_write", + "roles" : "ROLE_ORDERS_WRITE", + "description" : "Allows users to place or cancel orders" + }, { + "name" : "ACCOUNT_SC_READ", + "key" : "account_read", + "roles" : "ROLE_ACCOUNT_READ", + "description" : "Allows users to view their own account" + }, { + "name" : "ADMIN_SC_ALL", + "key" : "admin_all", + "roles" : "ROLE_ADMIN", + "description" : "Full administrative access" + } ] + } + } +} diff --git a/src/test/resources/checks/v3/apim/wso2/OAR005/extensive-api.yaml b/src/test/resources/checks/v3/apim/wso2/OAR005/extensive-api.yaml new file mode 100644 index 00000000..669fc5ad --- /dev/null +++ b/src/test/resources/checks/v3/apim/wso2/OAR005/extensive-api.yaml @@ -0,0 +1,167 @@ +openapi: "3.0.0" +info: + version: 2.1.0 + title: Retail Storefront API + description: Public-facing REST API for the retail storefront covering product catalog browsing, order placement, account management, and platform administration. +paths: + /catalog/products: + get: + operationId: get_catalog_products + summary: List products + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: CATALOG_SC_READ + post: + operationId: post_catalog_products + summary: Create a product + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: CATALOG_SC_WRITE + /catalog/products/{productId}: + get: + operationId: get_catalog_products_productId + summary: Get a product + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: CATALOG_SC_READ + put: + operationId: put_catalog_products_productId + summary: Replace a product + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: CATALOG_SC_WRITE + delete: + operationId: delete_catalog_products_productId + summary: Delete a product + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: CATALOG_SC_WRITE + /orders: + get: + operationId: get_orders + summary: List orders + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: ORDERS_SC_READ + post: + operationId: post_orders + summary: Place an order + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: ORDERS_SC_WRITE + /orders/{orderId}: + get: + operationId: get_orders_orderId + summary: Get an order + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: ORDERS_SC_READ + delete: + operationId: delete_orders_orderId + summary: Cancel an order + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: ORDERS_SC_WRITE + /account/profile: + get: + operationId: get_account_profile + summary: Get the caller's profile + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: ACCOUNT_SC_READ + put: + operationId: put_account_profile + summary: Update the caller's profile - undeclared scope + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: ACCOUNT_SC_WRITE # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + /admin/users: + get: + operationId: get_admin_users + summary: List platform users - matches key not name + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: admin_all # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + post: + operationId: post_admin_users + summary: Create a platform user + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: ADMIN_SC_ALL + /admin/audit-log: + get: + operationId: get_admin_audit-log + summary: Read the audit log + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: ADMIN_SC_ALL + +x-wso2-security: + apim: + x-wso2-scopes: + - name: CATALOG_SC_READ + key: catalog_read + roles: ROLE_CATALOG_READ + description: Allows users to browse the product catalog + - name: CATALOG_SC_WRITE + key: catalog_write + roles: ROLE_CATALOG_WRITE + description: Allows users to create or update products + - name: ORDERS_SC_READ + key: orders_read + roles: ROLE_ORDERS_READ + description: Allows users to view orders + - name: ORDERS_SC_WRITE + key: orders_write + roles: ROLE_ORDERS_WRITE + description: Allows users to place or cancel orders + - name: ACCOUNT_SC_READ + key: account_read + roles: ROLE_ACCOUNT_READ + description: Allows users to view their own account + - name: ADMIN_SC_ALL + key: admin_all + roles: ROLE_ADMIN + description: Full administrative access diff --git a/src/test/resources/checks/v3/apim/wso2/OAR005/with-all-verbs.json b/src/test/resources/checks/v3/apim/wso2/OAR005/with-all-verbs.json new file mode 100644 index 00000000..f5588a67 --- /dev/null +++ b/src/test/resources/checks/v3/apim/wso2/OAR005/with-all-verbs.json @@ -0,0 +1,85 @@ +{ + "openapi" : "3.0.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/a" : { + "x-scope" : "scope_one", + "get" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "put" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "delete" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "options" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "head" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "patch" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "trace" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + } + }, + "x-wso2-security" : { + "apim" : { + "x-wso2-scopes" : [ { + "name" : "scope_one", + "key" : "scope_one", + "roles" : "role_one" + } ] + } + } +} diff --git a/src/test/resources/checks/v3/apim/wso2/OAR005/with-all-verbs.yaml b/src/test/resources/checks/v3/apim/wso2/OAR005/with-all-verbs.yaml new file mode 100644 index 00000000..50261884 --- /dev/null +++ b/src/test/resources/checks/v3/apim/wso2/OAR005/with-all-verbs.yaml @@ -0,0 +1,54 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /a: + x-scope: scope_one + get: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + put: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + post: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + delete: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + options: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + head: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + patch: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + trace: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + +x-wso2-security: + apim: + x-wso2-scopes: + - name: scope_one + key: scope_one + roles: role_one diff --git a/src/test/resources/checks/v3/apim/wso2/OAR005/with-array-security.yaml b/src/test/resources/checks/v3/apim/wso2/OAR005/with-array-security.yaml new file mode 100644 index 00000000..64e6a744 --- /dev/null +++ b/src/test/resources/checks/v3/apim/wso2/OAR005/with-array-security.yaml @@ -0,0 +1,18 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /a: + get: + responses: + 200: + description: Ok + x-scope: scope_one # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + /b: + get: + responses: + 200: + description: Ok +x-wso2-security: [] + diff --git a/src/test/resources/checks/v3/apim/wso2/OAR005/with-callback-operations.json b/src/test/resources/checks/v3/apim/wso2/OAR005/with-callback-operations.json new file mode 100644 index 00000000..e3da2608 --- /dev/null +++ b/src/test/resources/checks/v3/apim/wso2/OAR005/with-callback-operations.json @@ -0,0 +1,72 @@ +{ + "openapi" : "3.0.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/a" : { + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_one", + "callbacks" : { + "onEvent" : { + "'{$request.body#/callbackUrl}'" : { + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five", # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + "callbacks" : { + "onNested" : { + "'{$request.body#/nestedUrl}'" : { + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_six" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + } + } + } + } + } + } + } + } + } + }, + "components" : { + "callbacks" : { + "sharedCallback" : { + "'{$request.body#/callbackUrl}'" : { + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_seven" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + } + } + } + }, + "x-wso2-security" : { + "apim" : { + "x-wso2-scopes" : [ { + "name" : "scope_one", + "key" : "scope_one", + "roles" : "role_one" + } ] + } + } +} diff --git a/src/test/resources/checks/v3/apim/wso2/OAR005/with-callback-operations.yaml b/src/test/resources/checks/v3/apim/wso2/OAR005/with-callback-operations.yaml new file mode 100644 index 00000000..6077bdbd --- /dev/null +++ b/src/test/resources/checks/v3/apim/wso2/OAR005/with-callback-operations.yaml @@ -0,0 +1,43 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /a: + post: + responses: + 200: + description: Ok + x-scope: scope_one + callbacks: + onEvent: + '{$request.body#/callbackUrl}': + post: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + callbacks: + onNested: + '{$request.body#/nestedUrl}': + post: + responses: + 200: + description: Ok + x-scope: scope_six # Noncompliant {{OAR005: WSO2 scope definition does not exists}} +components: + callbacks: + sharedCallback: + '{$request.body#/callbackUrl}': + post: + responses: + 200: + description: Ok + x-scope: scope_seven # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + +x-wso2-security: + apim: + x-wso2-scopes: + - name: scope_one + key: scope_one + roles: role_one diff --git a/src/test/resources/checks/v3/apim/wso2/OAR005/with-chained-ref-security.json b/src/test/resources/checks/v3/apim/wso2/OAR005/with-chained-ref-security.json new file mode 100644 index 00000000..260b93ae --- /dev/null +++ b/src/test/resources/checks/v3/apim/wso2/OAR005/with-chained-ref-security.json @@ -0,0 +1,50 @@ +{ + "openapi" : "3.0.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/pets" : { + "get" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_two" + }, + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + } + }, + "x-wso2-security" : { + "$ref" : "#/x-wso2-definitions/alias" + }, + "x-wso2-definitions" : { + "alias" : { + "$ref" : "#/x-wso2-definitions/security" + }, + "security" : { + "apim" : { + "x-wso2-scopes" : [ { + "name" : "scope_one", + "description" : "scope_one", + "key" : "scope_one", + "roles" : "role_one" + }, { + "name" : "scope_two", + "description" : "scope_two", + "key" : "scope_two", + "roles" : "role_two" + } ] + } + } + } +} diff --git a/src/test/resources/checks/v3/apim/wso2/OAR005/with-chained-ref-security.yaml b/src/test/resources/checks/v3/apim/wso2/OAR005/with-chained-ref-security.yaml new file mode 100644 index 00000000..d1c9cff1 --- /dev/null +++ b/src/test/resources/checks/v3/apim/wso2/OAR005/with-chained-ref-security.yaml @@ -0,0 +1,33 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + get: + responses: + 200: + description: Ok + x-scope: scope_two + post: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + +x-wso2-security: + $ref: "#/x-wso2-definitions/alias" +x-wso2-definitions: + alias: + $ref: "#/x-wso2-definitions/security" + security: + apim: + x-wso2-scopes: + - name: scope_one + description: scope_one + key: scope_one + roles: role_one + - name: scope_two + description: scope_two + key: scope_two + roles: role_two diff --git a/src/test/resources/checks/v3/apim/wso2/OAR005/with-cyclic-ref-security.yaml b/src/test/resources/checks/v3/apim/wso2/OAR005/with-cyclic-ref-security.yaml new file mode 100644 index 00000000..92925adc --- /dev/null +++ b/src/test/resources/checks/v3/apim/wso2/OAR005/with-cyclic-ref-security.yaml @@ -0,0 +1,24 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /a: + get: + responses: + 200: + description: Ok + x-scope: scope_one # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + /b: + get: + responses: + 200: + description: Ok +x-wso2-security: + $ref: "#/x-wso2-definitions/securityA" +x-wso2-definitions: + securityA: + $ref: "#/x-wso2-definitions/securityB" + securityB: + $ref: "#/x-wso2-definitions/securityA" + diff --git a/src/test/resources/checks/v3/apim/wso2/OAR005/with-dangling-ref-security.yaml b/src/test/resources/checks/v3/apim/wso2/OAR005/with-dangling-ref-security.yaml new file mode 100644 index 00000000..01fd7d47 --- /dev/null +++ b/src/test/resources/checks/v3/apim/wso2/OAR005/with-dangling-ref-security.yaml @@ -0,0 +1,26 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /a: + get: + responses: + 200: + description: Ok + x-scope: scope_one # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + /b: + get: + responses: + 200: + description: Ok +x-wso2-security: + $ref: "#/x-wso2-definitions/missing" +x-wso2-definitions: + present: + apim: + x-wso2-scopes: + - name: scope_other + key: scope_other + roles: role_other + diff --git a/src/test/resources/checks/v3/apim/wso2/OAR005/with-empty-array-scopes.yaml b/src/test/resources/checks/v3/apim/wso2/OAR005/with-empty-array-scopes.yaml new file mode 100644 index 00000000..8d2f3826 --- /dev/null +++ b/src/test/resources/checks/v3/apim/wso2/OAR005/with-empty-array-scopes.yaml @@ -0,0 +1,20 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /a: + get: + responses: + 200: + description: Ok + x-scope: scope_one # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + /b: + get: + responses: + 200: + description: Ok +x-wso2-security: + apim: + x-wso2-scopes: [] + diff --git a/src/test/resources/checks/v3/apim/wso2/OAR005/with-empty-object-scopes.yaml b/src/test/resources/checks/v3/apim/wso2/OAR005/with-empty-object-scopes.yaml new file mode 100644 index 00000000..e815be8b --- /dev/null +++ b/src/test/resources/checks/v3/apim/wso2/OAR005/with-empty-object-scopes.yaml @@ -0,0 +1,20 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /a: + get: + responses: + 200: + description: Ok + x-scope: scope_one # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + /b: + get: + responses: + 200: + description: Ok +x-wso2-security: + apim: + x-wso2-scopes: {} + diff --git a/src/test/resources/checks/v3/apim/wso2/OAR005/with-malformed-scopes.yaml b/src/test/resources/checks/v3/apim/wso2/OAR005/with-malformed-scopes.yaml new file mode 100644 index 00000000..6e03e645 --- /dev/null +++ b/src/test/resources/checks/v3/apim/wso2/OAR005/with-malformed-scopes.yaml @@ -0,0 +1,57 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /a: + get: + responses: + 200: + description: Ok + x-scope: scope_one + put: + responses: + 200: + description: Ok + x-scope: no_name # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + post: + responses: + 200: + description: Ok + x-scope: null_name # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + delete: + responses: + 200: + description: Ok + x-scope: empty_name # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + options: + responses: + 200: + description: Ok + x-scope: plain_scalar_element # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + head: + responses: + 200: + description: Ok + x-scope: array_element # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + +x-wso2-security: + apim: + x-wso2-scopes: + - name: scope_one + key: scope_one + roles: role_one + description: A well formed scope + - key: no_name + roles: role_two + description: No name property at all + - name: null + key: null_name + roles: role_three + description: Null name + - name: + key: empty_name + roles: role_four + description: Name with no value + - plain_scalar_element + - [array_element] diff --git a/src/test/resources/checks/v3/apim/wso2/OAR005/with-null-apim.yaml b/src/test/resources/checks/v3/apim/wso2/OAR005/with-null-apim.yaml new file mode 100644 index 00000000..ff80f556 --- /dev/null +++ b/src/test/resources/checks/v3/apim/wso2/OAR005/with-null-apim.yaml @@ -0,0 +1,19 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /a: + get: + responses: + 200: + description: Ok + x-scope: scope_one # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + /b: + get: + responses: + 200: + description: Ok +x-wso2-security: + apim: null + diff --git a/src/test/resources/checks/v3/apim/wso2/OAR005/with-null-scopes.yaml b/src/test/resources/checks/v3/apim/wso2/OAR005/with-null-scopes.yaml new file mode 100644 index 00000000..50a7649a --- /dev/null +++ b/src/test/resources/checks/v3/apim/wso2/OAR005/with-null-scopes.yaml @@ -0,0 +1,20 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /a: + get: + responses: + 200: + description: Ok + x-scope: scope_one # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + /b: + get: + responses: + 200: + description: Ok +x-wso2-security: + apim: + x-wso2-scopes: null + diff --git a/src/test/resources/checks/v3/apim/wso2/OAR005/with-null-security.yaml b/src/test/resources/checks/v3/apim/wso2/OAR005/with-null-security.yaml new file mode 100644 index 00000000..56297463 --- /dev/null +++ b/src/test/resources/checks/v3/apim/wso2/OAR005/with-null-security.yaml @@ -0,0 +1,18 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /a: + get: + responses: + 200: + description: Ok + x-scope: scope_one # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + /b: + get: + responses: + 200: + description: Ok +x-wso2-security: null + diff --git a/src/test/resources/checks/v3/apim/wso2/OAR005/with-ref-scope.json b/src/test/resources/checks/v3/apim/wso2/OAR005/with-ref-scope.json new file mode 100644 index 00000000..93e31a8d --- /dev/null +++ b/src/test/resources/checks/v3/apim/wso2/OAR005/with-ref-scope.json @@ -0,0 +1,55 @@ +{ + "openapi" : "3.0.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/pets" : { + "get" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_one" + }, + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_two" + }, + "put" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + } + }, + "x-wso2-security" : { + "apim" : { + "x-wso2-scopes" : [ { + "name" : "scope_one", + "description" : "scope_one", + "key" : "scope_one", + "roles" : "role_one" + }, { + "$ref" : "#/x-wso2-definitions/scopeTwo" + } ] + } + }, + "x-wso2-definitions" : { + "scopeTwo" : { + "name" : "scope_two", + "description" : "scope_two", + "key" : "scope_two", + "roles" : "role_two" + } + } +} diff --git a/src/test/resources/checks/v3/apim/wso2/OAR005/with-ref-scope.yaml b/src/test/resources/checks/v3/apim/wso2/OAR005/with-ref-scope.yaml new file mode 100644 index 00000000..e9272308 --- /dev/null +++ b/src/test/resources/checks/v3/apim/wso2/OAR005/with-ref-scope.yaml @@ -0,0 +1,36 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + get: + responses: + 200: + description: Ok + x-scope: scope_one + post: + responses: + 200: + description: Ok + x-scope: scope_two + put: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + +x-wso2-security: + apim: + x-wso2-scopes: + - name: scope_one + description: scope_one + key: scope_one + roles: role_one + - $ref: "#/x-wso2-definitions/scopeTwo" +x-wso2-definitions: + scopeTwo: + name: scope_two + description: scope_two + key: scope_two + roles: role_two diff --git a/src/test/resources/checks/v3/apim/wso2/OAR005/with-ref-security.json b/src/test/resources/checks/v3/apim/wso2/OAR005/with-ref-security.json new file mode 100644 index 00000000..8d4b2f83 --- /dev/null +++ b/src/test/resources/checks/v3/apim/wso2/OAR005/with-ref-security.json @@ -0,0 +1,47 @@ +{ + "openapi" : "3.0.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/pets" : { + "get" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_two" + }, + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + } + }, + "x-wso2-security" : { + "$ref" : "#/x-wso2-definitions/security" + }, + "x-wso2-definitions" : { + "security" : { + "apim" : { + "x-wso2-scopes" : [ { + "name" : "scope_one", + "description" : "scope_one", + "key" : "scope_one", + "roles" : "role_one" + }, { + "name" : "scope_two", + "description" : "scope_two", + "key" : "scope_two", + "roles" : "role_two" + } ] + } + } + } +} diff --git a/src/test/resources/checks/v3/apim/wso2/OAR005/with-ref-security.yaml b/src/test/resources/checks/v3/apim/wso2/OAR005/with-ref-security.yaml new file mode 100644 index 00000000..58cec9c0 --- /dev/null +++ b/src/test/resources/checks/v3/apim/wso2/OAR005/with-ref-security.yaml @@ -0,0 +1,31 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + get: + responses: + 200: + description: Ok + x-scope: scope_two + post: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + +x-wso2-security: + $ref: "#/x-wso2-definitions/security" +x-wso2-definitions: + security: + apim: + x-wso2-scopes: + - name: scope_one + description: scope_one + key: scope_one + roles: role_one + - name: scope_two + description: scope_two + key: scope_two + roles: role_two diff --git a/src/test/resources/checks/v3/apim/wso2/OAR005/with-scalar-scopes.yaml b/src/test/resources/checks/v3/apim/wso2/OAR005/with-scalar-scopes.yaml new file mode 100644 index 00000000..73621af2 --- /dev/null +++ b/src/test/resources/checks/v3/apim/wso2/OAR005/with-scalar-scopes.yaml @@ -0,0 +1,20 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /a: + get: + responses: + 200: + description: Ok + x-scope: scope_one # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + /b: + get: + responses: + 200: + description: Ok +x-wso2-security: + apim: + x-wso2-scopes: read + diff --git a/src/test/resources/checks/v3/apim/wso2/OAR005/with-scalar-security.yaml b/src/test/resources/checks/v3/apim/wso2/OAR005/with-scalar-security.yaml new file mode 100644 index 00000000..b6380e7f --- /dev/null +++ b/src/test/resources/checks/v3/apim/wso2/OAR005/with-scalar-security.yaml @@ -0,0 +1,18 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /a: + get: + responses: + 200: + description: Ok + x-scope: scope_one # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + /b: + get: + responses: + 200: + description: Ok +x-wso2-security: none + diff --git a/src/test/resources/checks/v3/apim/wso2/OAR005/with-scope-key-not-name.json b/src/test/resources/checks/v3/apim/wso2/OAR005/with-scope-key-not-name.json new file mode 100644 index 00000000..38dafeb3 --- /dev/null +++ b/src/test/resources/checks/v3/apim/wso2/OAR005/with-scope-key-not-name.json @@ -0,0 +1,37 @@ +{ + "openapi" : "3.0.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/pets" : { + "get" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "catalogue_read" + }, + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "read" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + } + }, + "x-wso2-security" : { + "apim" : { + "x-wso2-scopes" : [ { + "name" : "catalogue_read", + "description" : "catalogue_read", + "key" : "read", + "roles" : "role_one" + } ] + } + } +} diff --git a/src/test/resources/checks/v3/apim/wso2/OAR005/with-scope-key-not-name.yaml b/src/test/resources/checks/v3/apim/wso2/OAR005/with-scope-key-not-name.yaml new file mode 100644 index 00000000..dfe73644 --- /dev/null +++ b/src/test/resources/checks/v3/apim/wso2/OAR005/with-scope-key-not-name.yaml @@ -0,0 +1,24 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + get: + responses: + 200: + description: Ok + x-scope: catalogue_read + post: + responses: + 200: + description: Ok + x-scope: read # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + +x-wso2-security: + apim: + x-wso2-scopes: + - name: catalogue_read + description: catalogue_read + key: read + roles: role_one diff --git a/src/test/resources/checks/v3/apim/wso2/OAR005/with-scopes-as-map.json b/src/test/resources/checks/v3/apim/wso2/OAR005/with-scopes-as-map.json new file mode 100644 index 00000000..612864ed --- /dev/null +++ b/src/test/resources/checks/v3/apim/wso2/OAR005/with-scopes-as-map.json @@ -0,0 +1,66 @@ +{ + "openapi" : "3.0.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/pets" : { + "get" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "read_scope" + }, + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "read" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "put" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "write_scope" + }, + "delete" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + } + }, + "x-wso2-security" : { + "apim" : { + "x-wso2-scopes" : { + "read" : { + "name" : "read_scope", + "key" : "read", + "roles" : "ROLE_READ", + "description" : "Allows users to read the catalogue" + }, + "write" : { + "$ref" : "#/x-wso2-definitions/writeScope" + } + } + } + }, + "x-wso2-definitions" : { + "writeScope" : { + "name" : "write_scope", + "key" : "write", + "roles" : "ROLE_WRITE", + "description" : "Allows users to write the catalogue" + } + } +} diff --git a/src/test/resources/checks/v3/apim/wso2/OAR005/with-scopes-as-map.yaml b/src/test/resources/checks/v3/apim/wso2/OAR005/with-scopes-as-map.yaml new file mode 100644 index 00000000..ed635286 --- /dev/null +++ b/src/test/resources/checks/v3/apim/wso2/OAR005/with-scopes-as-map.yaml @@ -0,0 +1,43 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + get: + responses: + 200: + description: Ok + x-scope: read_scope + post: + responses: + 200: + description: Ok + x-scope: read # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + put: + responses: + 200: + description: Ok + x-scope: write_scope + delete: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + +x-wso2-security: + apim: + x-wso2-scopes: + read: + name: read_scope + key: read + roles: ROLE_READ + description: Allows users to read the catalogue + write: + $ref: "#/x-wso2-definitions/writeScope" +x-wso2-definitions: + writeScope: + name: write_scope + key: write + roles: ROLE_WRITE + description: Allows users to write the catalogue diff --git a/src/test/resources/checks/v3/apim/wso2/OAR005/with-x-scope-block-collections.yaml b/src/test/resources/checks/v3/apim/wso2/OAR005/with-x-scope-block-collections.yaml new file mode 100644 index 00000000..6267f884 --- /dev/null +++ b/src/test/resources/checks/v3/apim/wso2/OAR005/with-x-scope-block-collections.yaml @@ -0,0 +1,25 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /a: + get: + responses: + 200: + description: Ok + x-scope: + - scope_one # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + put: + responses: + 200: + description: Ok + x-scope: + name: scope_one # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + +x-wso2-security: + apim: + x-wso2-scopes: + - name: scope_one + key: scope_one + roles: role_one diff --git a/src/test/resources/checks/v3/apim/wso2/OAR005/with-x-scope-collections.yaml b/src/test/resources/checks/v3/apim/wso2/OAR005/with-x-scope-collections.yaml new file mode 100644 index 00000000..b39e467b --- /dev/null +++ b/src/test/resources/checks/v3/apim/wso2/OAR005/with-x-scope-collections.yaml @@ -0,0 +1,33 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /a: + get: + responses: + 200: + description: Ok + x-scope: [] # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + put: + responses: + 200: + description: Ok + x-scope: {} # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + post: + responses: + 200: + description: Ok + x-scope: [scope_one] # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + delete: + responses: + 200: + description: Ok + x-scope: {name: scope_one} # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + +x-wso2-security: + apim: + x-wso2-scopes: + - name: scope_one + key: scope_one + roles: role_one diff --git a/src/test/resources/checks/v3/apim/wso2/OAR005/with-x-scope-null-spellings.yaml b/src/test/resources/checks/v3/apim/wso2/OAR005/with-x-scope-null-spellings.yaml new file mode 100644 index 00000000..2b0f5e99 --- /dev/null +++ b/src/test/resources/checks/v3/apim/wso2/OAR005/with-x-scope-null-spellings.yaml @@ -0,0 +1,49 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /a: + get: + responses: + 200: + description: Ok + x-scope: null # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + put: + responses: + 200: + description: Ok + x-scope: ~ # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + post: + responses: + 200: + description: Ok + x-scope: Null # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + delete: + responses: + 200: + description: Ok + x-scope: NULL # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + options: + responses: + 200: + description: Ok + x-scope: "null" + head: + responses: + 200: + description: Ok + x-scope: + trace: + responses: + 200: + description: Ok + x-scope: "" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + +x-wso2-security: + apim: + x-wso2-scopes: + - name: "null" + key: quoted_null + roles: role_null + description: A scope whose name is the literal text null diff --git a/src/test/resources/checks/v3/apim/wso2/OAR005/with-x-scope-scalar-types.yaml b/src/test/resources/checks/v3/apim/wso2/OAR005/with-x-scope-scalar-types.yaml new file mode 100644 index 00000000..015fa8b7 --- /dev/null +++ b/src/test/resources/checks/v3/apim/wso2/OAR005/with-x-scope-scalar-types.yaml @@ -0,0 +1,54 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /a: + get: + responses: + 200: + description: Ok + x-scope: scope_one + put: + responses: + 200: + description: Ok + x-scope: "scope_one" + post: + responses: + 200: + description: Ok + x-scope: "" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + delete: + responses: + 200: + description: Ok + x-scope: 42 + options: + responses: + 200: + description: Ok + x-scope: 7 # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + head: + responses: + 200: + description: Ok + x-scope: true + trace: + responses: + 200: + description: Ok + x-scope: false # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + +x-wso2-security: + apim: + x-wso2-scopes: + - name: scope_one + key: scope_one + roles: role_one + - name: 42 + key: num_scope + roles: role_num + - name: true + key: bool_scope + roles: role_bool diff --git a/src/test/resources/checks/v3/apim/wso2/OAR005/without-apim.yaml b/src/test/resources/checks/v3/apim/wso2/OAR005/without-apim.yaml new file mode 100644 index 00000000..8f7a667f --- /dev/null +++ b/src/test/resources/checks/v3/apim/wso2/OAR005/without-apim.yaml @@ -0,0 +1,20 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /a: + get: + responses: + 200: + description: Ok + x-scope: scope_one # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + /b: + get: + responses: + 200: + description: Ok +x-wso2-security: + other: + x-wso2-scopes: [] + diff --git a/src/test/resources/checks/v3/apim/wso2/OAR005/without-scopes.yaml b/src/test/resources/checks/v3/apim/wso2/OAR005/without-scopes.yaml new file mode 100644 index 00000000..5421c457 --- /dev/null +++ b/src/test/resources/checks/v3/apim/wso2/OAR005/without-scopes.yaml @@ -0,0 +1,19 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /a: + get: + responses: + 200: + description: Ok + x-scope: scope_one # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + /b: + get: + responses: + 200: + description: Ok +x-wso2-security: + apim: {} + diff --git a/src/test/resources/checks/v3/apim/wso2/OAR005/without-security.json b/src/test/resources/checks/v3/apim/wso2/OAR005/without-security.json new file mode 100644 index 00000000..33930da4 --- /dev/null +++ b/src/test/resources/checks/v3/apim/wso2/OAR005/without-security.json @@ -0,0 +1,26 @@ +{ + "openapi" : "3.0.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/pets" : { + "get" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_one" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v3/apim/wso2/OAR005/without-security.yaml b/src/test/resources/checks/v3/apim/wso2/OAR005/without-security.yaml new file mode 100644 index 00000000..469e5f38 --- /dev/null +++ b/src/test/resources/checks/v3/apim/wso2/OAR005/without-security.yaml @@ -0,0 +1,15 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + get: + responses: + 200: + description: Ok + x-scope: scope_one # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + post: + responses: + 200: + description: Ok diff --git a/src/test/resources/checks/v3/examples/OAR031/allof-schema-missing-example.yaml b/src/test/resources/checks/v3/examples/OAR031/allof-schema-missing-example.yaml new file mode 100644 index 00000000..9080133a --- /dev/null +++ b/src/test/resources/checks/v3/examples/OAR031/allof-schema-missing-example.yaml @@ -0,0 +1,32 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +components: + schemas: + BaseEntity: + type: object + properties: + id: # Noncompliant {{OAR031: Property 'id' is missing an example.}} + type: integer + 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/externalref.yaml b/src/test/resources/checks/v3/examples/OAR031/externalref.yaml index e747a397..24da3812 100644 --- a/src/test/resources/checks/v3/examples/OAR031/externalref.yaml +++ b/src/test/resources/checks/v3/examples/OAR031/externalref.yaml @@ -14,7 +14,7 @@ paths: summary: Get all users description: Returns a list of users. responses: - '200': # Noncompliant {{OAR031: Responses must have one or more examples defined}} + '200': # Noncompliant {{OAR031: Response must have an example defined}} description: A JSON array of user objects content: application/json: @@ -23,7 +23,7 @@ paths: items: $ref: '#/components/schemas/User' '400': - $ref: >- # Noncompliant {{OAR031: Responses must have one or more examples defined}} + $ref: >- # Noncompliant {{OAR031: Response must have an example defined}} http://localhost:18089/OAR031.yaml#/components/responses/server_error_response /users/{userId}: get: @@ -40,14 +40,14 @@ paths: name: Puppy type: dog responses: - '200': # Noncompliant {{OAR031: Responses must have one or more examples defined}} + '200': # Noncompliant {{OAR031: Response must have an example defined}} description: A single user object content: application/json: schema: $ref: '#/components/schemas/User' '400': - $ref: >- # Noncompliant {{OAR031: Responses must have one or more examples defined}} + $ref: >- # Noncompliant {{OAR031: Response must have an example defined}} http://localhost:18089/OAR031.yaml#/components/responses/server_error_response components: schemas: diff --git a/src/test/resources/checks/v3/examples/OAR031/nested-properties-examples.yaml b/src/test/resources/checks/v3/examples/OAR031/nested-properties-examples.yaml index 9a67dda1..0f027b25 100644 --- a/src/test/resources/checks/v3/examples/OAR031/nested-properties-examples.yaml +++ b/src/test/resources/checks/v3/examples/OAR031/nested-properties-examples.yaml @@ -6,7 +6,7 @@ paths: /profile: put: summary: Update user profile - requestBody: # Noncompliant {{OAR031: Request body must have one or more examples defined}} + requestBody: # Noncompliant {{OAR031: Request body must have an example defined}} required: true content: application/json: @@ -35,5 +35,5 @@ paths: type: string example: "28001" responses: - '200': # Noncompliant {{OAR031: Responses must have one or more examples defined}} + '200': # Noncompliant {{OAR031: Response must have an example defined}} description: OK \ No newline at end of file diff --git a/src/test/resources/checks/v3/examples/OAR031/orphan-schema.yaml b/src/test/resources/checks/v3/examples/OAR031/orphan-schema.yaml new file mode 100644 index 00000000..9ed22c0d --- /dev/null +++ b/src/test/resources/checks/v3/examples/OAR031/orphan-schema.yaml @@ -0,0 +1,32 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + get: + responses: + 200: + description: Ok + content: + application/json: + schema: + $ref: '#/components/schemas/pet' + example: + name: Fluffy + 204: + description: No content +components: + schemas: + pet: + type: object + properties: + name: + type: string + example: "Fluffy" + # Never referenced by any path - must not be flagged (orphan-schema exclusion). + UnusedSchema: + type: object + properties: + unused_field: + type: string diff --git a/src/test/resources/checks/v3/examples/OAR031/without-examples.yaml b/src/test/resources/checks/v3/examples/OAR031/without-examples.yaml index ec8cd2a0..eec0c9a7 100644 --- a/src/test/resources/checks/v3/examples/OAR031/without-examples.yaml +++ b/src/test/resources/checks/v3/examples/OAR031/without-examples.yaml @@ -6,7 +6,7 @@ paths: /pets: get: responses: - 206: # Noncompliant {{OAR031: Responses must have one or more examples defined}} + 206: # Noncompliant {{OAR031: Response must have an example defined}} description: Pet list content: application/json: @@ -16,7 +16,7 @@ paths: $ref: "#/components/responses/server_error_response" /pets/{id}: parameters: - - in: query # Noncompliant {{OAR031: Parameters must have one or more examples defined}} + - in: query # Noncompliant {{OAR031: Parameter '$start' must have an example defined}} name: $start schema: type: integer @@ -24,7 +24,7 @@ paths: parameters: - $ref: "#/components/parameters/id" responses: - 200: # Noncompliant {{OAR031: Responses must have one or more examples defined}} + 200: # Noncompliant {{OAR031: Response must have an example defined}} description: One pet content: application/json: @@ -35,8 +35,8 @@ paths: components: parameters: - id: - in: path # Noncompliant {{OAR031: Parameters must have one or more examples defined}} + id: # Noncompliant {{OAR031: Parameter 'id' must have an example defined}} + in: path name: id schema: type: integer @@ -48,26 +48,26 @@ components: pet: type: object properties: - name: # Noncompliant {{OAR031: Properties must have an example defined}} + name: # Noncompliant {{OAR031: Property 'name' is missing an example.}} type: string - type: # Noncompliant {{OAR031: Properties must have an example defined}} + type: # Noncompliant {{OAR031: Property 'type' is missing an example.}} type: string pets: type: object properties: - size: # Noncompliant {{OAR031: Properties must have an example defined}} + size: # Noncompliant {{OAR031: Property 'size' is missing an example.}} type: integer pets: type: array items: $ref: '#/components/schemas/pet' responses: - server_error_response: # Noncompliant {{OAR031: Responses must have one or more examples defined}} + server_error_response: # Noncompliant {{OAR031: Response must have an example defined}} description: Default error response content: application/json: schema: type: object properties: - error: # Noncompliant {{OAR031: Properties must have an example defined}} + error: # Noncompliant {{OAR031: Property 'error' is missing an example.}} type: string \ No newline at end of file diff --git a/src/test/resources/checks/v3/format/OAR007/with-204-response.json b/src/test/resources/checks/v3/format/OAR007/with-204-response.json new file mode 100644 index 00000000..619f4f86 --- /dev/null +++ b/src/test/resources/checks/v3/format/OAR007/with-204-response.json @@ -0,0 +1,18 @@ +{ + "openapi": "3.0.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore" + }, + "paths": { + "/pets": { + "delete": { + "responses": { + "204": { + "description": "No Content" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v3/format/OAR007/with-204-response.yaml b/src/test/resources/checks/v3/format/OAR007/with-204-response.yaml new file mode 100644 index 00000000..e323bc65 --- /dev/null +++ b/src/test/resources/checks/v3/format/OAR007/with-204-response.yaml @@ -0,0 +1,10 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + delete: + responses: + '204': + description: No Content diff --git a/src/test/resources/checks/v3/format/OAR007/with-chained-ref.json b/src/test/resources/checks/v3/format/OAR007/with-chained-ref.json new file mode 100644 index 00000000..9f44591c --- /dev/null +++ b/src/test/resources/checks/v3/format/OAR007/with-chained-ref.json @@ -0,0 +1,28 @@ +{ + "openapi": "3.0.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore" + }, + "components": { + "responses": { + "A": { + "$ref": "#/components/responses/B" + }, + "B": { # Noncompliant {{OAR007: Section content is mandatory}} + "description": "No content defined" + } + } + }, + "paths": { + "/pets": { + "put": { + "responses": { + "200": { + "$ref": "#/components/responses/A" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v3/format/OAR007/with-chained-ref.yaml b/src/test/resources/checks/v3/format/OAR007/with-chained-ref.yaml new file mode 100644 index 00000000..b507aa65 --- /dev/null +++ b/src/test/resources/checks/v3/format/OAR007/with-chained-ref.yaml @@ -0,0 +1,16 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +components: + responses: + A: + $ref: '#/components/responses/B' + B: # Noncompliant {{OAR007: Section content is mandatory}} + description: No content defined +paths: + /pets: + put: + responses: + '200': + $ref: '#/components/responses/A' diff --git a/src/test/resources/checks/v3/format/OAR007/with-default-and-ref.json b/src/test/resources/checks/v3/format/OAR007/with-default-and-ref.json new file mode 100644 index 00000000..d962e59d --- /dev/null +++ b/src/test/resources/checks/v3/format/OAR007/with-default-and-ref.json @@ -0,0 +1,28 @@ +{ + "openapi": "3.0.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore" + }, + "components": { + "responses": { + "PetsResponse": { + "description": "OK", + "content": { + "application/json": {} + } + } + } + }, + "paths": { + "/pets": { + "put": { + "responses": { + "200": { + "$ref": "#/components/responses/PetsResponse" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v3/format/OAR007/with-default-and-ref.yaml b/src/test/resources/checks/v3/format/OAR007/with-default-and-ref.yaml new file mode 100644 index 00000000..c0fa3518 --- /dev/null +++ b/src/test/resources/checks/v3/format/OAR007/with-default-and-ref.yaml @@ -0,0 +1,16 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +components: + responses: + PetsResponse: + description: OK + content: + application/json: {} +paths: + /pets: + put: + responses: + '200': + $ref: '#/components/responses/PetsResponse' diff --git a/src/test/resources/checks/v3/format/OAR007/with-default-response-key.json b/src/test/resources/checks/v3/format/OAR007/with-default-response-key.json new file mode 100644 index 00000000..c350e397 --- /dev/null +++ b/src/test/resources/checks/v3/format/OAR007/with-default-response-key.json @@ -0,0 +1,19 @@ +{ + "openapi": "3.0.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore" + }, + "paths": { + "/pets": { + "post": { + "responses": { + "default": { # Noncompliant {{OAR007: Section content is mandatory}} + "description": "Unexpected error", + "content": {} + } + } + } + } + } +} diff --git a/src/test/resources/checks/v3/format/OAR007/with-default-response-key.yaml b/src/test/resources/checks/v3/format/OAR007/with-default-response-key.yaml new file mode 100644 index 00000000..b20f7779 --- /dev/null +++ b/src/test/resources/checks/v3/format/OAR007/with-default-response-key.yaml @@ -0,0 +1,11 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + post: + responses: + default: # Noncompliant {{OAR007: Section content is mandatory}} + description: Unexpected error + content: {} diff --git a/src/test/resources/checks/v3/format/OAR007/with-external-ref.json b/src/test/resources/checks/v3/format/OAR007/with-external-ref.json new file mode 100644 index 00000000..f683b50d --- /dev/null +++ b/src/test/resources/checks/v3/format/OAR007/with-external-ref.json @@ -0,0 +1,18 @@ +{ + "openapi": "3.0.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore" + }, + "paths": { + "/pets": { + "put": { + "responses": { + "200": { + "$ref": "http://localhost:18089/OAR007.yaml#/components/responses/SuccessResponse" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v3/format/OAR007/with-external-ref.yaml b/src/test/resources/checks/v3/format/OAR007/with-external-ref.yaml new file mode 100644 index 00000000..84ec98f9 --- /dev/null +++ b/src/test/resources/checks/v3/format/OAR007/with-external-ref.yaml @@ -0,0 +1,11 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + put: + responses: + '200': + $ref: >- + http://localhost:18089/OAR007.yaml#/components/responses/SuccessResponse diff --git a/src/test/resources/checks/v3/format/OAR007/with-multiple-operations.json b/src/test/resources/checks/v3/format/OAR007/with-multiple-operations.json new file mode 100644 index 00000000..682a2222 --- /dev/null +++ b/src/test/resources/checks/v3/format/OAR007/with-multiple-operations.json @@ -0,0 +1,53 @@ +{ + "openapi": "3.0.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore" + }, + "paths": { + "/pets": { + "get": { + "responses": { + "200": { + "description": "Ok", + "content": { + "application/json": {} + } + }, + "204": { + "description": "No Content" + } + } + }, + "post": { + "responses": { + "201": { # Noncompliant {{OAR007: Section content is mandatory}} + "description": "Created" + } + } + } + }, + "/owners": { + "put": { + "responses": { + "200": { + "description": "Ok", + "content": { + "application/xml": {} + } + }, + "400": { # Noncompliant {{OAR007: Section content is mandatory}} + "description": "Bad Request" + } + } + }, + "delete": { + "responses": { + "204": { + "description": "No Content" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v3/format/OAR007/with-multiple-operations.yaml b/src/test/resources/checks/v3/format/OAR007/with-multiple-operations.yaml new file mode 100644 index 00000000..d6f3fb5f --- /dev/null +++ b/src/test/resources/checks/v3/format/OAR007/with-multiple-operations.yaml @@ -0,0 +1,31 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + get: + responses: + '200': + description: Ok + content: + application/json: {} + '204': + description: No Content + post: + responses: + '201': # Noncompliant {{OAR007: Section content is mandatory}} + description: Created + /owners: + put: + responses: + '200': + description: Ok + content: + application/xml: {} + '400': # Noncompliant {{OAR007: Section content is mandatory}} + description: Bad Request + delete: + responses: + '204': + description: No Content diff --git a/src/test/resources/checks/v3/format/OAR007/with-specific.json b/src/test/resources/checks/v3/format/OAR007/with-specific.json new file mode 100644 index 00000000..f32afc92 --- /dev/null +++ b/src/test/resources/checks/v3/format/OAR007/with-specific.json @@ -0,0 +1,21 @@ +{ + "openapi": "3.0.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore" + }, + "paths": { + "/pets": { + "put": { + "responses": { + "200": { + "description": "Ok", + "content": { + "application/json": {} + } + } + } + } + } + } +} diff --git a/src/test/resources/checks/v3/format/OAR007/with-specific.yaml b/src/test/resources/checks/v3/format/OAR007/with-specific.yaml new file mode 100644 index 00000000..ff100bb5 --- /dev/null +++ b/src/test/resources/checks/v3/format/OAR007/with-specific.yaml @@ -0,0 +1,12 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + put: + responses: + '200': + description: Ok + content: + application/json: {} diff --git a/src/test/resources/checks/v3/format/OAR007/with-wrong-ref.json b/src/test/resources/checks/v3/format/OAR007/with-wrong-ref.json new file mode 100644 index 00000000..7d523b2e --- /dev/null +++ b/src/test/resources/checks/v3/format/OAR007/with-wrong-ref.json @@ -0,0 +1,25 @@ +{ + "openapi": "3.0.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore" + }, + "components": { + "responses": { + "PetsResponse": { # Noncompliant {{OAR007: Section content is mandatory}} + "description": "No content defined" + } + } + }, + "paths": { + "/pets": { + "put": { + "responses": { + "200": { + "$ref": "#/components/responses/PetsResponse" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v3/format/OAR007/with-wrong-ref.yaml b/src/test/resources/checks/v3/format/OAR007/with-wrong-ref.yaml new file mode 100644 index 00000000..6ff09a2e --- /dev/null +++ b/src/test/resources/checks/v3/format/OAR007/with-wrong-ref.yaml @@ -0,0 +1,14 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +components: + responses: + PetsResponse: # Noncompliant {{OAR007: Section content is mandatory}} + description: No content defined +paths: + /pets: + put: + responses: + '200': + $ref: '#/components/responses/PetsResponse' diff --git a/src/test/resources/checks/v3/format/OAR010/with-204-response.json b/src/test/resources/checks/v3/format/OAR010/with-204-response.json new file mode 100644 index 00000000..b6328902 --- /dev/null +++ b/src/test/resources/checks/v3/format/OAR010/with-204-response.json @@ -0,0 +1,27 @@ +{ + "openapi": "3.0.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore" + }, + "paths": { + "/pets": { + "post": { + "responses": { + "200": { + "description": "Ok", + "content": { + "application/json": {} + } + }, + "204": { + "description": "No Content", + "content": { + "application/xml": {} + } + } + } + } + } + } +} diff --git a/src/test/resources/checks/v3/format/OAR010/with-204-response.yaml b/src/test/resources/checks/v3/format/OAR010/with-204-response.yaml new file mode 100644 index 00000000..257dd57b --- /dev/null +++ b/src/test/resources/checks/v3/format/OAR010/with-204-response.yaml @@ -0,0 +1,16 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + post: + responses: + '200': + description: Ok + content: + application/json: {} + '204': + description: No Content + content: + application/xml: {} diff --git a/src/test/resources/checks/v3/format/OAR010/with-default-mixed-case.json b/src/test/resources/checks/v3/format/OAR010/with-default-mixed-case.json new file mode 100644 index 00000000..8ced2d72 --- /dev/null +++ b/src/test/resources/checks/v3/format/OAR010/with-default-mixed-case.json @@ -0,0 +1,21 @@ +{ + "openapi": "3.0.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore" + }, + "paths": { + "/pets": { + "post": { + "responses": { + "200": { + "description": "Ok", + "content": { + "Application/JSON": {} + } + } + } + } + } + } +} diff --git a/src/test/resources/checks/v3/format/OAR010/with-default-mixed-case.yaml b/src/test/resources/checks/v3/format/OAR010/with-default-mixed-case.yaml new file mode 100644 index 00000000..5758d03b --- /dev/null +++ b/src/test/resources/checks/v3/format/OAR010/with-default-mixed-case.yaml @@ -0,0 +1,12 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + post: + responses: + '200': + description: Ok + content: + Application/JSON: {} diff --git a/src/test/resources/checks/v3/format/OAR010/with-external-ref.json b/src/test/resources/checks/v3/format/OAR010/with-external-ref.json new file mode 100644 index 00000000..c5603828 --- /dev/null +++ b/src/test/resources/checks/v3/format/OAR010/with-external-ref.json @@ -0,0 +1,18 @@ +{ + "openapi": "3.0.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore" + }, + "paths": { + "/pets": { + "post": { + "responses": { + "200": { + "$ref": "http://localhost:18089/OAR010.yaml#/components/responses/SuccessResponse" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v3/format/OAR010/with-external-ref.yaml b/src/test/resources/checks/v3/format/OAR010/with-external-ref.yaml new file mode 100644 index 00000000..fa887704 --- /dev/null +++ b/src/test/resources/checks/v3/format/OAR010/with-external-ref.yaml @@ -0,0 +1,11 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + post: + responses: + '200': + $ref: >- + http://localhost:18089/OAR010.yaml#/components/responses/SuccessResponse diff --git a/src/test/resources/checks/v3/format/OAR010/with-wrong-default-and-ref.json b/src/test/resources/checks/v3/format/OAR010/with-wrong-default-and-ref.json new file mode 100644 index 00000000..0d842352 --- /dev/null +++ b/src/test/resources/checks/v3/format/OAR010/with-wrong-default-and-ref.json @@ -0,0 +1,28 @@ +{ + "openapi": "3.0.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore" + }, + "components": { + "responses": { + "XmlOnlyResponse": { + "description": "OK", + "content": { # Noncompliant {{OAR010: Should indicate the default response media type}} + "application/xml": {} + } + } + } + }, + "paths": { + "/pets": { + "post": { + "responses": { + "200": { + "$ref": "#/components/responses/XmlOnlyResponse" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v3/format/OAR010/with-wrong-default-and-ref.yaml b/src/test/resources/checks/v3/format/OAR010/with-wrong-default-and-ref.yaml new file mode 100644 index 00000000..53a3b8e4 --- /dev/null +++ b/src/test/resources/checks/v3/format/OAR010/with-wrong-default-and-ref.yaml @@ -0,0 +1,16 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +components: + responses: + XmlOnlyResponse: + description: OK + content: # Noncompliant {{OAR010: Should indicate the default response media type}} + application/xml: {} +paths: + /pets: + post: + responses: + '200': + $ref: '#/components/responses/XmlOnlyResponse' diff --git a/src/test/resources/checks/v3/parameters/OAR026/header-with-$total-with-defval-true.json b/src/test/resources/checks/v3/parameters/OAR026/header-with-$total-with-defval-true.json new file mode 100644 index 00000000..5387f7ac --- /dev/null +++ b/src/test/resources/checks/v3/parameters/OAR026/header-with-$total-with-defval-true.json @@ -0,0 +1,26 @@ +{ + "openapi" : "3.0.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/pets" : { + "get" : { + "parameters" : [ { + "in" : "header", + "name" : "$total", + "schema" : { + "type" : "boolean", + "default" : true + } + } ], + "responses" : { + "206" : { + "description" : "Ok" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v3/parameters/OAR026/header-with-$total-with-defval-true.yaml b/src/test/resources/checks/v3/parameters/OAR026/header-with-$total-with-defval-true.yaml new file mode 100644 index 00000000..e3a6097e --- /dev/null +++ b/src/test/resources/checks/v3/parameters/OAR026/header-with-$total-with-defval-true.yaml @@ -0,0 +1,16 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + get: + parameters: + - in: header + name: $total + schema: + type: boolean + default: true + responses: + 206: + description: Ok diff --git a/src/test/resources/checks/v3/parameters/OAR026/plain-with-$total-without-defval.json b/src/test/resources/checks/v3/parameters/OAR026/plain-with-$total-without-defval.json index d756597f..46579305 100644 --- a/src/test/resources/checks/v3/parameters/OAR026/plain-with-$total-without-defval.json +++ b/src/test/resources/checks/v3/parameters/OAR026/plain-with-$total-without-defval.json @@ -16,7 +16,7 @@ "type" : "string" } } - }, { # Noncompliant {{OAR026: The $total parameter default value should be false}} + }, { "in" : "query", "name" : "$total", "schema": { diff --git a/src/test/resources/checks/v3/parameters/OAR026/plain-with-$total-without-defval.yaml b/src/test/resources/checks/v3/parameters/OAR026/plain-with-$total-without-defval.yaml index c2580dc0..c9eb7ad3 100644 --- a/src/test/resources/checks/v3/parameters/OAR026/plain-with-$total-without-defval.yaml +++ b/src/test/resources/checks/v3/parameters/OAR026/plain-with-$total-without-defval.yaml @@ -12,7 +12,7 @@ paths: type: array items: type: string - - in: query # Noncompliant {{OAR026: The $total parameter default value should be false}} + - in: query name: $total schema: type: boolean diff --git a/src/test/resources/checks/v3/parameters/OAR026/post-with-$total-with-defval-true.json b/src/test/resources/checks/v3/parameters/OAR026/post-with-$total-with-defval-true.json new file mode 100644 index 00000000..8366d62e --- /dev/null +++ b/src/test/resources/checks/v3/parameters/OAR026/post-with-$total-with-defval-true.json @@ -0,0 +1,26 @@ +{ + "openapi" : "3.0.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/pets" : { + "post" : { + "parameters" : [ { + "in" : "query", + "name" : "$total", + "schema" : { + "type" : "boolean", + "default" : true + } + } ], + "responses" : { + "201" : { + "description" : "Created" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v3/parameters/OAR026/post-with-$total-with-defval-true.yaml b/src/test/resources/checks/v3/parameters/OAR026/post-with-$total-with-defval-true.yaml new file mode 100644 index 00000000..b1de7fb3 --- /dev/null +++ b/src/test/resources/checks/v3/parameters/OAR026/post-with-$total-with-defval-true.yaml @@ -0,0 +1,16 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + post: + parameters: + - in: query + name: $total + schema: + type: boolean + default: true + responses: + 201: + description: Created diff --git a/src/test/resources/checks/v3/parameters/OAR026/with-$ref-unreferenced-with-$total-with-defval-true.json b/src/test/resources/checks/v3/parameters/OAR026/with-$ref-unreferenced-with-$total-with-defval-true.json new file mode 100644 index 00000000..7fd799f0 --- /dev/null +++ b/src/test/resources/checks/v3/parameters/OAR026/with-$ref-unreferenced-with-$total-with-defval-true.json @@ -0,0 +1,30 @@ +{ + "openapi" : "3.0.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "components" : { + "parameters" : { + "total" : { + "in" : "query", + "name" : "$total", + "schema" : { + "type" : "boolean", + "default" : true + } + } + } + }, + "paths" : { + "/pets" : { + "get" : { + "responses" : { + "206" : { + "description" : "Ok" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v3/parameters/OAR026/with-$ref-unreferenced-with-$total-with-defval-true.yaml b/src/test/resources/checks/v3/parameters/OAR026/with-$ref-unreferenced-with-$total-with-defval-true.yaml new file mode 100644 index 00000000..ad5a0bbe --- /dev/null +++ b/src/test/resources/checks/v3/parameters/OAR026/with-$ref-unreferenced-with-$total-with-defval-true.yaml @@ -0,0 +1,18 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +components: + parameters: + total: + in: query + name: $total + schema: + type: boolean + default: true +paths: + /pets: + get: + responses: + 206: + description: Ok diff --git a/src/test/resources/checks/v3/parameters/OAR026/with-$ref-with-$total-without-defval.json b/src/test/resources/checks/v3/parameters/OAR026/with-$ref-with-$total-without-defval.json index 9c5ef562..dc7533fc 100644 --- a/src/test/resources/checks/v3/parameters/OAR026/with-$ref-with-$total-without-defval.json +++ b/src/test/resources/checks/v3/parameters/OAR026/with-$ref-with-$total-without-defval.json @@ -16,7 +16,7 @@ } } }, - "total" : { # Noncompliant {{OAR026: The $total parameter default value should be false}} + "total" : { "in" : "query", "name" : "$total", "schema": { diff --git a/src/test/resources/checks/v3/parameters/OAR026/with-$ref-with-$total-without-defval.yaml b/src/test/resources/checks/v3/parameters/OAR026/with-$ref-with-$total-without-defval.yaml index 68f5a74b..702bb880 100644 --- a/src/test/resources/checks/v3/parameters/OAR026/with-$ref-with-$total-without-defval.yaml +++ b/src/test/resources/checks/v3/parameters/OAR026/with-$ref-with-$total-without-defval.yaml @@ -11,7 +11,7 @@ components: type: array items: type: string - total: # Noncompliant {{OAR026: The $total parameter default value should be false}} + total: in: query name: $total schema: diff --git a/src/test/resources/checks/v31/apim/OAR005/extensive-api.json b/src/test/resources/checks/v31/apim/OAR005/extensive-api.json new file mode 100644 index 00000000..1f4512a9 --- /dev/null +++ b/src/test/resources/checks/v31/apim/OAR005/extensive-api.json @@ -0,0 +1,241 @@ +{ + "openapi" : "3.1.0", + "info" : { + "version" : "2.1.0", + "title" : "Retail Storefront API", + "description" : "Public-facing REST API for the retail storefront covering product catalog browsing, order placement, account management, and platform administration." + }, + "paths" : { + "/catalog/products" : { + "get" : { + "operationId" : "get_catalog_products", + "summary" : "List products", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "CATALOG_SC_READ" + }, + "post" : { + "operationId" : "post_catalog_products", + "summary" : "Create a product", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "CATALOG_SC_WRITE" + } + }, + "/catalog/products/{productId}" : { + "get" : { + "operationId" : "get_catalog_products_productId", + "summary" : "Get a product", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "CATALOG_SC_READ" + }, + "put" : { + "operationId" : "put_catalog_products_productId", + "summary" : "Replace a product", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "CATALOG_SC_WRITE" + }, + "delete" : { + "operationId" : "delete_catalog_products_productId", + "summary" : "Delete a product", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "CATALOG_SC_WRITE" + } + }, + "/orders" : { + "get" : { + "operationId" : "get_orders", + "summary" : "List orders", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "ORDERS_SC_READ" + }, + "post" : { + "operationId" : "post_orders", + "summary" : "Place an order", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "ORDERS_SC_WRITE" + } + }, + "/orders/{orderId}" : { + "get" : { + "operationId" : "get_orders_orderId", + "summary" : "Get an order", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "ORDERS_SC_READ" + }, + "delete" : { + "operationId" : "delete_orders_orderId", + "summary" : "Cancel an order", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "ORDERS_SC_WRITE" + } + }, + "/account/profile" : { + "get" : { + "operationId" : "get_account_profile", + "summary" : "Get the caller's profile", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "ACCOUNT_SC_READ" + }, + "put" : { + "operationId" : "put_account_profile", + "summary" : "Update the caller's profile - undeclared scope", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "ACCOUNT_SC_WRITE" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + }, + "/admin/users" : { + "get" : { + "operationId" : "get_admin_users", + "summary" : "List platform users - matches key not name", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "admin_all" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "post" : { + "operationId" : "post_admin_users", + "summary" : "Create a platform user", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "ADMIN_SC_ALL" + } + }, + "/admin/audit-log" : { + "get" : { + "operationId" : "get_admin_audit-log", + "summary" : "Read the audit log", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "ADMIN_SC_ALL" + } + } + }, + "x-wso2-security" : { + "apim" : { + "x-wso2-scopes" : [ { + "name" : "CATALOG_SC_READ", + "key" : "catalog_read", + "roles" : "ROLE_CATALOG_READ", + "description" : "Allows users to browse the product catalog" + }, { + "name" : "CATALOG_SC_WRITE", + "key" : "catalog_write", + "roles" : "ROLE_CATALOG_WRITE", + "description" : "Allows users to create or update products" + }, { + "name" : "ORDERS_SC_READ", + "key" : "orders_read", + "roles" : "ROLE_ORDERS_READ", + "description" : "Allows users to view orders" + }, { + "name" : "ORDERS_SC_WRITE", + "key" : "orders_write", + "roles" : "ROLE_ORDERS_WRITE", + "description" : "Allows users to place or cancel orders" + }, { + "name" : "ACCOUNT_SC_READ", + "key" : "account_read", + "roles" : "ROLE_ACCOUNT_READ", + "description" : "Allows users to view their own account" + }, { + "name" : "ADMIN_SC_ALL", + "key" : "admin_all", + "roles" : "ROLE_ADMIN", + "description" : "Full administrative access" + } ] + } + } +} diff --git a/src/test/resources/checks/v31/apim/OAR005/extensive-api.yaml b/src/test/resources/checks/v31/apim/OAR005/extensive-api.yaml new file mode 100644 index 00000000..b788d01f --- /dev/null +++ b/src/test/resources/checks/v31/apim/OAR005/extensive-api.yaml @@ -0,0 +1,167 @@ +openapi: "3.1.0" +info: + version: 2.1.0 + title: Retail Storefront API + description: Public-facing REST API for the retail storefront covering product catalog browsing, order placement, account management, and platform administration. +paths: + /catalog/products: + get: + operationId: get_catalog_products + summary: List products + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: CATALOG_SC_READ + post: + operationId: post_catalog_products + summary: Create a product + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: CATALOG_SC_WRITE + /catalog/products/{productId}: + get: + operationId: get_catalog_products_productId + summary: Get a product + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: CATALOG_SC_READ + put: + operationId: put_catalog_products_productId + summary: Replace a product + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: CATALOG_SC_WRITE + delete: + operationId: delete_catalog_products_productId + summary: Delete a product + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: CATALOG_SC_WRITE + /orders: + get: + operationId: get_orders + summary: List orders + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: ORDERS_SC_READ + post: + operationId: post_orders + summary: Place an order + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: ORDERS_SC_WRITE + /orders/{orderId}: + get: + operationId: get_orders_orderId + summary: Get an order + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: ORDERS_SC_READ + delete: + operationId: delete_orders_orderId + summary: Cancel an order + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: ORDERS_SC_WRITE + /account/profile: + get: + operationId: get_account_profile + summary: Get the caller's profile + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: ACCOUNT_SC_READ + put: + operationId: put_account_profile + summary: Update the caller's profile - undeclared scope + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: ACCOUNT_SC_WRITE # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + /admin/users: + get: + operationId: get_admin_users + summary: List platform users - matches key not name + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: admin_all # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + post: + operationId: post_admin_users + summary: Create a platform user + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: ADMIN_SC_ALL + /admin/audit-log: + get: + operationId: get_admin_audit-log + summary: Read the audit log + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: ADMIN_SC_ALL + +x-wso2-security: + apim: + x-wso2-scopes: + - name: CATALOG_SC_READ + key: catalog_read + roles: ROLE_CATALOG_READ + description: Allows users to browse the product catalog + - name: CATALOG_SC_WRITE + key: catalog_write + roles: ROLE_CATALOG_WRITE + description: Allows users to create or update products + - name: ORDERS_SC_READ + key: orders_read + roles: ROLE_ORDERS_READ + description: Allows users to view orders + - name: ORDERS_SC_WRITE + key: orders_write + roles: ROLE_ORDERS_WRITE + description: Allows users to place or cancel orders + - name: ACCOUNT_SC_READ + key: account_read + roles: ROLE_ACCOUNT_READ + description: Allows users to view their own account + - name: ADMIN_SC_ALL + key: admin_all + roles: ROLE_ADMIN + description: Full administrative access diff --git a/src/test/resources/checks/v31/apim/OAR005/with-all-verbs.json b/src/test/resources/checks/v31/apim/OAR005/with-all-verbs.json new file mode 100644 index 00000000..219d8f44 --- /dev/null +++ b/src/test/resources/checks/v31/apim/OAR005/with-all-verbs.json @@ -0,0 +1,85 @@ +{ + "openapi" : "3.1.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/a" : { + "x-scope" : "scope_one", + "get" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "put" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "delete" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "options" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "head" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "patch" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "trace" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + } + }, + "x-wso2-security" : { + "apim" : { + "x-wso2-scopes" : [ { + "name" : "scope_one", + "key" : "scope_one", + "roles" : "role_one" + } ] + } + } +} diff --git a/src/test/resources/checks/v31/apim/OAR005/with-all-verbs.yaml b/src/test/resources/checks/v31/apim/OAR005/with-all-verbs.yaml new file mode 100644 index 00000000..d74abfcd --- /dev/null +++ b/src/test/resources/checks/v31/apim/OAR005/with-all-verbs.yaml @@ -0,0 +1,54 @@ +openapi: "3.1.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /a: + x-scope: scope_one + get: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + put: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + post: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + delete: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + options: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + head: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + patch: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + trace: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + +x-wso2-security: + apim: + x-wso2-scopes: + - name: scope_one + key: scope_one + roles: role_one diff --git a/src/test/resources/checks/v31/apim/OAR005/with-callback-operations.json b/src/test/resources/checks/v31/apim/OAR005/with-callback-operations.json new file mode 100644 index 00000000..29fab7f4 --- /dev/null +++ b/src/test/resources/checks/v31/apim/OAR005/with-callback-operations.json @@ -0,0 +1,72 @@ +{ + "openapi" : "3.1.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/a" : { + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_one", + "callbacks" : { + "onEvent" : { + "'{$request.body#/callbackUrl}'" : { + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five", # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + "callbacks" : { + "onNested" : { + "'{$request.body#/nestedUrl}'" : { + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_six" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + } + } + } + } + } + } + } + } + } + }, + "components" : { + "callbacks" : { + "sharedCallback" : { + "'{$request.body#/callbackUrl}'" : { + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_seven" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + } + } + } + }, + "x-wso2-security" : { + "apim" : { + "x-wso2-scopes" : [ { + "name" : "scope_one", + "key" : "scope_one", + "roles" : "role_one" + } ] + } + } +} diff --git a/src/test/resources/checks/v31/apim/OAR005/with-callback-operations.yaml b/src/test/resources/checks/v31/apim/OAR005/with-callback-operations.yaml new file mode 100644 index 00000000..b40822e3 --- /dev/null +++ b/src/test/resources/checks/v31/apim/OAR005/with-callback-operations.yaml @@ -0,0 +1,43 @@ +openapi: "3.1.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /a: + post: + responses: + 200: + description: Ok + x-scope: scope_one + callbacks: + onEvent: + '{$request.body#/callbackUrl}': + post: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + callbacks: + onNested: + '{$request.body#/nestedUrl}': + post: + responses: + 200: + description: Ok + x-scope: scope_six # Noncompliant {{OAR005: WSO2 scope definition does not exists}} +components: + callbacks: + sharedCallback: + '{$request.body#/callbackUrl}': + post: + responses: + 200: + description: Ok + x-scope: scope_seven # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + +x-wso2-security: + apim: + x-wso2-scopes: + - name: scope_one + key: scope_one + roles: role_one diff --git a/src/test/resources/checks/v31/apim/OAR005/with-chained-ref-security.json b/src/test/resources/checks/v31/apim/OAR005/with-chained-ref-security.json new file mode 100644 index 00000000..6e69412f --- /dev/null +++ b/src/test/resources/checks/v31/apim/OAR005/with-chained-ref-security.json @@ -0,0 +1,50 @@ +{ + "openapi" : "3.1.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/pets" : { + "get" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_two" + }, + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + } + }, + "x-wso2-security" : { + "$ref" : "#/x-wso2-definitions/alias" + }, + "x-wso2-definitions" : { + "alias" : { + "$ref" : "#/x-wso2-definitions/security" + }, + "security" : { + "apim" : { + "x-wso2-scopes" : [ { + "name" : "scope_one", + "description" : "scope_one", + "key" : "scope_one", + "roles" : "role_one" + }, { + "name" : "scope_two", + "description" : "scope_two", + "key" : "scope_two", + "roles" : "role_two" + } ] + } + } + } +} diff --git a/src/test/resources/checks/v31/apim/OAR005/with-chained-ref-security.yaml b/src/test/resources/checks/v31/apim/OAR005/with-chained-ref-security.yaml new file mode 100644 index 00000000..c6ebb0f1 --- /dev/null +++ b/src/test/resources/checks/v31/apim/OAR005/with-chained-ref-security.yaml @@ -0,0 +1,33 @@ +openapi: "3.1.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + get: + responses: + 200: + description: Ok + x-scope: scope_two + post: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + +x-wso2-security: + $ref: "#/x-wso2-definitions/alias" +x-wso2-definitions: + alias: + $ref: "#/x-wso2-definitions/security" + security: + apim: + x-wso2-scopes: + - name: scope_one + description: scope_one + key: scope_one + roles: role_one + - name: scope_two + description: scope_two + key: scope_two + roles: role_two diff --git a/src/test/resources/checks/v31/apim/OAR005/with-ref-scope.json b/src/test/resources/checks/v31/apim/OAR005/with-ref-scope.json new file mode 100644 index 00000000..62234c28 --- /dev/null +++ b/src/test/resources/checks/v31/apim/OAR005/with-ref-scope.json @@ -0,0 +1,55 @@ +{ + "openapi" : "3.1.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/pets" : { + "get" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_one" + }, + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_two" + }, + "put" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + } + }, + "x-wso2-security" : { + "apim" : { + "x-wso2-scopes" : [ { + "name" : "scope_one", + "description" : "scope_one", + "key" : "scope_one", + "roles" : "role_one" + }, { + "$ref" : "#/x-wso2-definitions/scopeTwo" + } ] + } + }, + "x-wso2-definitions" : { + "scopeTwo" : { + "name" : "scope_two", + "description" : "scope_two", + "key" : "scope_two", + "roles" : "role_two" + } + } +} diff --git a/src/test/resources/checks/v31/apim/OAR005/with-ref-scope.yaml b/src/test/resources/checks/v31/apim/OAR005/with-ref-scope.yaml new file mode 100644 index 00000000..017514ad --- /dev/null +++ b/src/test/resources/checks/v31/apim/OAR005/with-ref-scope.yaml @@ -0,0 +1,36 @@ +openapi: "3.1.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + get: + responses: + 200: + description: Ok + x-scope: scope_one + post: + responses: + 200: + description: Ok + x-scope: scope_two + put: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + +x-wso2-security: + apim: + x-wso2-scopes: + - name: scope_one + description: scope_one + key: scope_one + roles: role_one + - $ref: "#/x-wso2-definitions/scopeTwo" +x-wso2-definitions: + scopeTwo: + name: scope_two + description: scope_two + key: scope_two + roles: role_two diff --git a/src/test/resources/checks/v31/apim/OAR005/with-ref-security.json b/src/test/resources/checks/v31/apim/OAR005/with-ref-security.json new file mode 100644 index 00000000..e21f46b8 --- /dev/null +++ b/src/test/resources/checks/v31/apim/OAR005/with-ref-security.json @@ -0,0 +1,47 @@ +{ + "openapi" : "3.1.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/pets" : { + "get" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_two" + }, + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + } + }, + "x-wso2-security" : { + "$ref" : "#/x-wso2-definitions/security" + }, + "x-wso2-definitions" : { + "security" : { + "apim" : { + "x-wso2-scopes" : [ { + "name" : "scope_one", + "description" : "scope_one", + "key" : "scope_one", + "roles" : "role_one" + }, { + "name" : "scope_two", + "description" : "scope_two", + "key" : "scope_two", + "roles" : "role_two" + } ] + } + } + } +} diff --git a/src/test/resources/checks/v31/apim/OAR005/with-ref-security.yaml b/src/test/resources/checks/v31/apim/OAR005/with-ref-security.yaml new file mode 100644 index 00000000..6391da4e --- /dev/null +++ b/src/test/resources/checks/v31/apim/OAR005/with-ref-security.yaml @@ -0,0 +1,31 @@ +openapi: "3.1.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + get: + responses: + 200: + description: Ok + x-scope: scope_two + post: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + +x-wso2-security: + $ref: "#/x-wso2-definitions/security" +x-wso2-definitions: + security: + apim: + x-wso2-scopes: + - name: scope_one + description: scope_one + key: scope_one + roles: role_one + - name: scope_two + description: scope_two + key: scope_two + roles: role_two diff --git a/src/test/resources/checks/v31/apim/OAR005/with-scope-key-not-name.json b/src/test/resources/checks/v31/apim/OAR005/with-scope-key-not-name.json new file mode 100644 index 00000000..ce2403ae --- /dev/null +++ b/src/test/resources/checks/v31/apim/OAR005/with-scope-key-not-name.json @@ -0,0 +1,37 @@ +{ + "openapi" : "3.1.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/pets" : { + "get" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "catalogue_read" + }, + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "read" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + } + }, + "x-wso2-security" : { + "apim" : { + "x-wso2-scopes" : [ { + "name" : "catalogue_read", + "description" : "catalogue_read", + "key" : "read", + "roles" : "role_one" + } ] + } + } +} diff --git a/src/test/resources/checks/v31/apim/OAR005/with-scope-key-not-name.yaml b/src/test/resources/checks/v31/apim/OAR005/with-scope-key-not-name.yaml new file mode 100644 index 00000000..7bd94393 --- /dev/null +++ b/src/test/resources/checks/v31/apim/OAR005/with-scope-key-not-name.yaml @@ -0,0 +1,24 @@ +openapi: "3.1.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + get: + responses: + 200: + description: Ok + x-scope: catalogue_read + post: + responses: + 200: + description: Ok + x-scope: read # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + +x-wso2-security: + apim: + x-wso2-scopes: + - name: catalogue_read + description: catalogue_read + key: read + roles: role_one diff --git a/src/test/resources/checks/v31/apim/OAR005/with-scopes-as-map.json b/src/test/resources/checks/v31/apim/OAR005/with-scopes-as-map.json new file mode 100644 index 00000000..c00db5f5 --- /dev/null +++ b/src/test/resources/checks/v31/apim/OAR005/with-scopes-as-map.json @@ -0,0 +1,66 @@ +{ + "openapi" : "3.1.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/pets" : { + "get" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "read_scope" + }, + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "read" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "put" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "write_scope" + }, + "delete" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + } + }, + "x-wso2-security" : { + "apim" : { + "x-wso2-scopes" : { + "read" : { + "name" : "read_scope", + "key" : "read", + "roles" : "ROLE_READ", + "description" : "Allows users to read the catalogue" + }, + "write" : { + "$ref" : "#/x-wso2-definitions/writeScope" + } + } + } + }, + "x-wso2-definitions" : { + "writeScope" : { + "name" : "write_scope", + "key" : "write", + "roles" : "ROLE_WRITE", + "description" : "Allows users to write the catalogue" + } + } +} diff --git a/src/test/resources/checks/v31/apim/OAR005/with-scopes-as-map.yaml b/src/test/resources/checks/v31/apim/OAR005/with-scopes-as-map.yaml new file mode 100644 index 00000000..e9d0a792 --- /dev/null +++ b/src/test/resources/checks/v31/apim/OAR005/with-scopes-as-map.yaml @@ -0,0 +1,43 @@ +openapi: "3.1.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + get: + responses: + 200: + description: Ok + x-scope: read_scope + post: + responses: + 200: + description: Ok + x-scope: read # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + put: + responses: + 200: + description: Ok + x-scope: write_scope + delete: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + +x-wso2-security: + apim: + x-wso2-scopes: + read: + name: read_scope + key: read + roles: ROLE_READ + description: Allows users to read the catalogue + write: + $ref: "#/x-wso2-definitions/writeScope" +x-wso2-definitions: + writeScope: + name: write_scope + key: write + roles: ROLE_WRITE + description: Allows users to write the catalogue diff --git a/src/test/resources/checks/v31/apim/OAR005/with-webhook-operations.json b/src/test/resources/checks/v31/apim/OAR005/with-webhook-operations.json new file mode 100644 index 00000000..386fd1c4 --- /dev/null +++ b/src/test/resources/checks/v31/apim/OAR005/with-webhook-operations.json @@ -0,0 +1,60 @@ +{ + "openapi" : "3.1.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/pets" : { + "$ref" : "#/components/pathItems/PetsPath" + } + }, + "webhooks" : { + "newPet" : { + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + } + }, + "components" : { + "pathItems" : { + "PetsPath" : { + "x-scope" : "scope_one", + "get" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_six" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + } + }, + "webhooks" : { + "reusableWebhook" : { + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_seven" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + } + } + }, + "x-wso2-security" : { + "apim" : { + "x-wso2-scopes" : [ { + "name" : "scope_one", + "key" : "scope_one", + "roles" : "role_one" + } ] + } + } +} diff --git a/src/test/resources/checks/v31/apim/OAR005/with-webhook-operations.yaml b/src/test/resources/checks/v31/apim/OAR005/with-webhook-operations.yaml new file mode 100644 index 00000000..6b1fa4b7 --- /dev/null +++ b/src/test/resources/checks/v31/apim/OAR005/with-webhook-operations.yaml @@ -0,0 +1,38 @@ +openapi: "3.1.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + $ref: "#/components/pathItems/PetsPath" +webhooks: + newPet: + post: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + +components: + pathItems: + PetsPath: + x-scope: scope_one + get: + responses: + 200: + description: Ok + x-scope: scope_six # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + webhooks: + reusableWebhook: + post: + responses: + 200: + description: Ok + x-scope: scope_seven # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + +x-wso2-security: + apim: + x-wso2-scopes: + - name: scope_one + key: scope_one + roles: role_one diff --git a/src/test/resources/checks/v31/apim/OAR005/without-security.json b/src/test/resources/checks/v31/apim/OAR005/without-security.json new file mode 100644 index 00000000..eff68435 --- /dev/null +++ b/src/test/resources/checks/v31/apim/OAR005/without-security.json @@ -0,0 +1,26 @@ +{ + "openapi" : "3.1.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/pets" : { + "get" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_one" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v31/apim/OAR005/without-security.yaml b/src/test/resources/checks/v31/apim/OAR005/without-security.yaml new file mode 100644 index 00000000..e2b8f1aa --- /dev/null +++ b/src/test/resources/checks/v31/apim/OAR005/without-security.yaml @@ -0,0 +1,15 @@ +openapi: "3.1.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + get: + responses: + 200: + description: Ok + x-scope: scope_one # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + post: + responses: + 200: + description: Ok diff --git a/src/test/resources/checks/v31/examples/OAR031/allof-schema-missing-example.yaml b/src/test/resources/checks/v31/examples/OAR031/allof-schema-missing-example.yaml new file mode 100644 index 00000000..5705e186 --- /dev/null +++ b/src/test/resources/checks/v31/examples/OAR031/allof-schema-missing-example.yaml @@ -0,0 +1,32 @@ +openapi: "3.1.0" +info: + version: 1.0.0 + title: Swagger Petstore +components: + schemas: + BaseEntity: + type: object + properties: + id: # Noncompliant {{OAR031: Property 'id' is missing an example.}} + type: integer + 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/externalref.yaml b/src/test/resources/checks/v31/examples/OAR031/externalref.yaml index 4e6e96e7..4473d4db 100644 --- a/src/test/resources/checks/v31/examples/OAR031/externalref.yaml +++ b/src/test/resources/checks/v31/examples/OAR031/externalref.yaml @@ -14,7 +14,7 @@ paths: summary: Get all users description: Returns a list of users. responses: - '200': # Noncompliant {{OAR031: Responses must have one or more examples defined}} + '200': # Noncompliant {{OAR031: Response must have an example defined}} description: A JSON array of user objects content: application/json: @@ -23,7 +23,7 @@ paths: items: $ref: '#/components/schemas/User' '400': - $ref: >- # Noncompliant {{OAR031: Responses must have one or more examples defined}} + $ref: >- # Noncompliant {{OAR031: Response must have an example defined}} http://localhost:18089/OAR031.yaml#/components/responses/server_error_response /users/{userId}: get: @@ -40,14 +40,14 @@ paths: name: Puppy type: dog responses: - '200': # Noncompliant {{OAR031: Responses must have one or more examples defined}} + '200': # Noncompliant {{OAR031: Response must have an example defined}} description: A single user object content: application/json: schema: $ref: '#/components/schemas/User' '400': - $ref: >- # Noncompliant {{OAR031: Responses must have one or more examples defined}} + $ref: >- # Noncompliant {{OAR031: Response must have an example defined}} http://localhost:18089/OAR031.yaml#/components/responses/server_error_response components: schemas: diff --git a/src/test/resources/checks/v31/examples/OAR031/nested-properties-examples.yaml b/src/test/resources/checks/v31/examples/OAR031/nested-properties-examples.yaml index c48f0f18..86b9cc6b 100644 --- a/src/test/resources/checks/v31/examples/OAR031/nested-properties-examples.yaml +++ b/src/test/resources/checks/v31/examples/OAR031/nested-properties-examples.yaml @@ -6,7 +6,7 @@ paths: /profile: put: summary: Update user profile - requestBody: # Noncompliant {{OAR031: Request body must have one or more examples defined}} + requestBody: # Noncompliant {{OAR031: Request body must have an example defined}} required: true content: application/json: @@ -35,5 +35,5 @@ paths: type: string example: "28001" responses: - '200': # Noncompliant {{OAR031: Responses must have one or more examples defined}} + '200': # Noncompliant {{OAR031: Response must have an example defined}} description: OK \ No newline at end of file diff --git a/src/test/resources/checks/v31/examples/OAR031/orphan-schema.yaml b/src/test/resources/checks/v31/examples/OAR031/orphan-schema.yaml new file mode 100644 index 00000000..8e7784ca --- /dev/null +++ b/src/test/resources/checks/v31/examples/OAR031/orphan-schema.yaml @@ -0,0 +1,32 @@ +openapi: "3.1.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + get: + responses: + 200: + description: Ok + content: + application/json: + schema: + $ref: '#/components/schemas/pet' + example: + name: Fluffy + 204: + description: No content +components: + schemas: + pet: + type: object + properties: + name: + type: string + example: "Fluffy" + # Never referenced by any path - must not be flagged (orphan-schema exclusion). + UnusedSchema: + type: object + properties: + unused_field: + type: string diff --git a/src/test/resources/checks/v31/examples/OAR031/without-examples.yaml b/src/test/resources/checks/v31/examples/OAR031/without-examples.yaml index 5fa170e9..42f0f6f9 100644 --- a/src/test/resources/checks/v31/examples/OAR031/without-examples.yaml +++ b/src/test/resources/checks/v31/examples/OAR031/without-examples.yaml @@ -6,7 +6,7 @@ paths: /pets: get: responses: - 206: # Noncompliant {{OAR031: Responses must have one or more examples defined}} + 206: # Noncompliant {{OAR031: Response must have an example defined}} description: Pet list content: application/json: @@ -16,7 +16,7 @@ paths: $ref: "#/components/responses/server_error_response" /pets/{id}: parameters: - - in: query # Noncompliant {{OAR031: Parameters must have one or more examples defined}} + - in: query # Noncompliant {{OAR031: Parameter '$start' must have an example defined}} name: $start schema: type: integer @@ -24,7 +24,7 @@ paths: parameters: - $ref: "#/components/parameters/id" responses: - 200: # Noncompliant {{OAR031: Responses must have one or more examples defined}} + 200: # Noncompliant {{OAR031: Response must have an example defined}} description: One pet content: application/json: @@ -35,8 +35,8 @@ paths: components: parameters: - id: - in: path # Noncompliant {{OAR031: Parameters must have one or more examples defined}} + id: # Noncompliant {{OAR031: Parameter 'id' must have an example defined}} + in: path name: id schema: type: integer @@ -48,26 +48,26 @@ components: pet: type: object properties: - name: # Noncompliant {{OAR031: Properties must have an example defined}} + name: # Noncompliant {{OAR031: Property 'name' is missing an example.}} type: string - type: # Noncompliant {{OAR031: Properties must have an example defined}} + type: # Noncompliant {{OAR031: Property 'type' is missing an example.}} type: string pets: type: object properties: - size: # Noncompliant {{OAR031: Properties must have an example defined}} + size: # Noncompliant {{OAR031: Property 'size' is missing an example.}} type: integer pets: type: array items: $ref: '#/components/schemas/pet' responses: - server_error_response: # Noncompliant {{OAR031: Responses must have one or more examples defined}} + server_error_response: # Noncompliant {{OAR031: Response must have an example defined}} description: Default error response content: application/json: schema: type: object properties: - error: # Noncompliant {{OAR031: Properties must have an example defined}} + error: # Noncompliant {{OAR031: Property 'error' is missing an example.}} type: string \ No newline at end of file diff --git a/src/test/resources/checks/v31/format/OAR007/with-204-response.json b/src/test/resources/checks/v31/format/OAR007/with-204-response.json new file mode 100644 index 00000000..1ccf567f --- /dev/null +++ b/src/test/resources/checks/v31/format/OAR007/with-204-response.json @@ -0,0 +1,18 @@ +{ + "openapi": "3.1.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore" + }, + "paths": { + "/pets": { + "delete": { + "responses": { + "204": { + "description": "No Content" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v31/format/OAR007/with-204-response.yaml b/src/test/resources/checks/v31/format/OAR007/with-204-response.yaml new file mode 100644 index 00000000..bb080d5e --- /dev/null +++ b/src/test/resources/checks/v31/format/OAR007/with-204-response.yaml @@ -0,0 +1,10 @@ +openapi: "3.1.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + delete: + responses: + '204': + description: No Content diff --git a/src/test/resources/checks/v31/format/OAR007/with-chained-ref.json b/src/test/resources/checks/v31/format/OAR007/with-chained-ref.json new file mode 100644 index 00000000..3260aa1c --- /dev/null +++ b/src/test/resources/checks/v31/format/OAR007/with-chained-ref.json @@ -0,0 +1,28 @@ +{ + "openapi": "3.1.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore" + }, + "components": { + "responses": { + "A": { + "$ref": "#/components/responses/B" + }, + "B": { # Noncompliant {{OAR007: Section content is mandatory}} + "description": "No content defined" + } + } + }, + "paths": { + "/pets": { + "put": { + "responses": { + "200": { + "$ref": "#/components/responses/A" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v31/format/OAR007/with-chained-ref.yaml b/src/test/resources/checks/v31/format/OAR007/with-chained-ref.yaml new file mode 100644 index 00000000..0ea40fa0 --- /dev/null +++ b/src/test/resources/checks/v31/format/OAR007/with-chained-ref.yaml @@ -0,0 +1,16 @@ +openapi: "3.1.0" +info: + version: 1.0.0 + title: Swagger Petstore +components: + responses: + A: + $ref: '#/components/responses/B' + B: # Noncompliant {{OAR007: Section content is mandatory}} + description: No content defined +paths: + /pets: + put: + responses: + '200': + $ref: '#/components/responses/A' diff --git a/src/test/resources/checks/v31/format/OAR007/with-default-and-ref.json b/src/test/resources/checks/v31/format/OAR007/with-default-and-ref.json new file mode 100644 index 00000000..f3d84a94 --- /dev/null +++ b/src/test/resources/checks/v31/format/OAR007/with-default-and-ref.json @@ -0,0 +1,28 @@ +{ + "openapi": "3.1.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore" + }, + "components": { + "responses": { + "PetsResponse": { + "description": "OK", + "content": { + "application/json": {} + } + } + } + }, + "paths": { + "/pets": { + "put": { + "responses": { + "200": { + "$ref": "#/components/responses/PetsResponse" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v31/format/OAR007/with-default-and-ref.yaml b/src/test/resources/checks/v31/format/OAR007/with-default-and-ref.yaml new file mode 100644 index 00000000..a20959a4 --- /dev/null +++ b/src/test/resources/checks/v31/format/OAR007/with-default-and-ref.yaml @@ -0,0 +1,16 @@ +openapi: "3.1.0" +info: + version: 1.0.0 + title: Swagger Petstore +components: + responses: + PetsResponse: + description: OK + content: + application/json: {} +paths: + /pets: + put: + responses: + '200': + $ref: '#/components/responses/PetsResponse' diff --git a/src/test/resources/checks/v31/format/OAR007/with-default-response-key.json b/src/test/resources/checks/v31/format/OAR007/with-default-response-key.json new file mode 100644 index 00000000..ceaf057f --- /dev/null +++ b/src/test/resources/checks/v31/format/OAR007/with-default-response-key.json @@ -0,0 +1,19 @@ +{ + "openapi": "3.1.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore" + }, + "paths": { + "/pets": { + "post": { + "responses": { + "default": { # Noncompliant {{OAR007: Section content is mandatory}} + "description": "Unexpected error", + "content": {} + } + } + } + } + } +} diff --git a/src/test/resources/checks/v31/format/OAR007/with-default-response-key.yaml b/src/test/resources/checks/v31/format/OAR007/with-default-response-key.yaml new file mode 100644 index 00000000..9ad855e3 --- /dev/null +++ b/src/test/resources/checks/v31/format/OAR007/with-default-response-key.yaml @@ -0,0 +1,11 @@ +openapi: "3.1.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + post: + responses: + default: # Noncompliant {{OAR007: Section content is mandatory}} + description: Unexpected error + content: {} diff --git a/src/test/resources/checks/v31/format/OAR007/with-external-ref.json b/src/test/resources/checks/v31/format/OAR007/with-external-ref.json new file mode 100644 index 00000000..f6567e42 --- /dev/null +++ b/src/test/resources/checks/v31/format/OAR007/with-external-ref.json @@ -0,0 +1,18 @@ +{ + "openapi": "3.1.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore" + }, + "paths": { + "/pets": { + "put": { + "responses": { + "200": { + "$ref": "http://localhost:18089/OAR007.yaml#/components/responses/SuccessResponse" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v31/format/OAR007/with-external-ref.yaml b/src/test/resources/checks/v31/format/OAR007/with-external-ref.yaml new file mode 100644 index 00000000..3b7d240d --- /dev/null +++ b/src/test/resources/checks/v31/format/OAR007/with-external-ref.yaml @@ -0,0 +1,11 @@ +openapi: "3.1.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + put: + responses: + '200': + $ref: >- + http://localhost:18089/OAR007.yaml#/components/responses/SuccessResponse diff --git a/src/test/resources/checks/v31/format/OAR007/with-multiple-operations.json b/src/test/resources/checks/v31/format/OAR007/with-multiple-operations.json new file mode 100644 index 00000000..a9c4e4dc --- /dev/null +++ b/src/test/resources/checks/v31/format/OAR007/with-multiple-operations.json @@ -0,0 +1,53 @@ +{ + "openapi": "3.1.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore" + }, + "paths": { + "/pets": { + "get": { + "responses": { + "200": { + "description": "Ok", + "content": { + "application/json": {} + } + }, + "204": { + "description": "No Content" + } + } + }, + "post": { + "responses": { + "201": { # Noncompliant {{OAR007: Section content is mandatory}} + "description": "Created" + } + } + } + }, + "/owners": { + "put": { + "responses": { + "200": { + "description": "Ok", + "content": { + "application/xml": {} + } + }, + "400": { # Noncompliant {{OAR007: Section content is mandatory}} + "description": "Bad Request" + } + } + }, + "delete": { + "responses": { + "204": { + "description": "No Content" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v31/format/OAR007/with-multiple-operations.yaml b/src/test/resources/checks/v31/format/OAR007/with-multiple-operations.yaml new file mode 100644 index 00000000..bb48e6b3 --- /dev/null +++ b/src/test/resources/checks/v31/format/OAR007/with-multiple-operations.yaml @@ -0,0 +1,31 @@ +openapi: "3.1.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + get: + responses: + '200': + description: Ok + content: + application/json: {} + '204': + description: No Content + post: + responses: + '201': # Noncompliant {{OAR007: Section content is mandatory}} + description: Created + /owners: + put: + responses: + '200': + description: Ok + content: + application/xml: {} + '400': # Noncompliant {{OAR007: Section content is mandatory}} + description: Bad Request + delete: + responses: + '204': + description: No Content diff --git a/src/test/resources/checks/v31/format/OAR007/with-specific.json b/src/test/resources/checks/v31/format/OAR007/with-specific.json new file mode 100644 index 00000000..9afb31e4 --- /dev/null +++ b/src/test/resources/checks/v31/format/OAR007/with-specific.json @@ -0,0 +1,21 @@ +{ + "openapi": "3.1.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore" + }, + "paths": { + "/pets": { + "put": { + "responses": { + "200": { + "description": "Ok", + "content": { + "application/json": {} + } + } + } + } + } + } +} diff --git a/src/test/resources/checks/v31/format/OAR007/with-specific.yaml b/src/test/resources/checks/v31/format/OAR007/with-specific.yaml new file mode 100644 index 00000000..fa9f955c --- /dev/null +++ b/src/test/resources/checks/v31/format/OAR007/with-specific.yaml @@ -0,0 +1,12 @@ +openapi: "3.1.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + put: + responses: + '200': + description: Ok + content: + application/json: {} diff --git a/src/test/resources/checks/v31/format/OAR007/with-wrong-ref.json b/src/test/resources/checks/v31/format/OAR007/with-wrong-ref.json new file mode 100644 index 00000000..7a86ba86 --- /dev/null +++ b/src/test/resources/checks/v31/format/OAR007/with-wrong-ref.json @@ -0,0 +1,25 @@ +{ + "openapi": "3.1.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore" + }, + "components": { + "responses": { + "PetsResponse": { # Noncompliant {{OAR007: Section content is mandatory}} + "description": "No content defined" + } + } + }, + "paths": { + "/pets": { + "put": { + "responses": { + "200": { + "$ref": "#/components/responses/PetsResponse" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v31/format/OAR007/with-wrong-ref.yaml b/src/test/resources/checks/v31/format/OAR007/with-wrong-ref.yaml new file mode 100644 index 00000000..dfafb717 --- /dev/null +++ b/src/test/resources/checks/v31/format/OAR007/with-wrong-ref.yaml @@ -0,0 +1,14 @@ +openapi: "3.1.0" +info: + version: 1.0.0 + title: Swagger Petstore +components: + responses: + PetsResponse: # Noncompliant {{OAR007: Section content is mandatory}} + description: No content defined +paths: + /pets: + put: + responses: + '200': + $ref: '#/components/responses/PetsResponse' diff --git a/src/test/resources/checks/v31/format/OAR010/with-204-response.json b/src/test/resources/checks/v31/format/OAR010/with-204-response.json new file mode 100644 index 00000000..6f132667 --- /dev/null +++ b/src/test/resources/checks/v31/format/OAR010/with-204-response.json @@ -0,0 +1,27 @@ +{ + "openapi": "3.1.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore" + }, + "paths": { + "/pets": { + "post": { + "responses": { + "200": { + "description": "Ok", + "content": { + "application/json": {} + } + }, + "204": { + "description": "No Content", + "content": { + "application/xml": {} + } + } + } + } + } + } +} diff --git a/src/test/resources/checks/v31/format/OAR010/with-204-response.yaml b/src/test/resources/checks/v31/format/OAR010/with-204-response.yaml new file mode 100644 index 00000000..1b8999ec --- /dev/null +++ b/src/test/resources/checks/v31/format/OAR010/with-204-response.yaml @@ -0,0 +1,16 @@ +openapi: "3.1.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + post: + responses: + '200': + description: Ok + content: + application/json: {} + '204': + description: No Content + content: + application/xml: {} diff --git a/src/test/resources/checks/v31/format/OAR010/with-default-mixed-case.json b/src/test/resources/checks/v31/format/OAR010/with-default-mixed-case.json new file mode 100644 index 00000000..79e3af7a --- /dev/null +++ b/src/test/resources/checks/v31/format/OAR010/with-default-mixed-case.json @@ -0,0 +1,21 @@ +{ + "openapi": "3.1.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore" + }, + "paths": { + "/pets": { + "post": { + "responses": { + "200": { + "description": "Ok", + "content": { + "Application/JSON": {} + } + } + } + } + } + } +} diff --git a/src/test/resources/checks/v31/format/OAR010/with-default-mixed-case.yaml b/src/test/resources/checks/v31/format/OAR010/with-default-mixed-case.yaml new file mode 100644 index 00000000..cca3f65f --- /dev/null +++ b/src/test/resources/checks/v31/format/OAR010/with-default-mixed-case.yaml @@ -0,0 +1,12 @@ +openapi: "3.1.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + post: + responses: + '200': + description: Ok + content: + Application/JSON: {} diff --git a/src/test/resources/checks/v31/format/OAR010/with-wrong-default-and-ref.json b/src/test/resources/checks/v31/format/OAR010/with-wrong-default-and-ref.json new file mode 100644 index 00000000..005c8be1 --- /dev/null +++ b/src/test/resources/checks/v31/format/OAR010/with-wrong-default-and-ref.json @@ -0,0 +1,28 @@ +{ + "openapi": "3.1.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore" + }, + "components": { + "responses": { + "XmlOnlyResponse": { + "description": "OK", + "content": { # Noncompliant {{OAR010: Should indicate the default response media type}} + "application/xml": {} + } + } + } + }, + "paths": { + "/pets": { + "post": { + "responses": { + "200": { + "$ref": "#/components/responses/XmlOnlyResponse" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v31/format/OAR010/with-wrong-default-and-ref.yaml b/src/test/resources/checks/v31/format/OAR010/with-wrong-default-and-ref.yaml new file mode 100644 index 00000000..76fbf25d --- /dev/null +++ b/src/test/resources/checks/v31/format/OAR010/with-wrong-default-and-ref.yaml @@ -0,0 +1,16 @@ +openapi: "3.1.0" +info: + version: 1.0.0 + title: Swagger Petstore +components: + responses: + XmlOnlyResponse: + description: OK + content: # Noncompliant {{OAR010: Should indicate the default response media type}} + application/xml: {} +paths: + /pets: + post: + responses: + '200': + $ref: '#/components/responses/XmlOnlyResponse' diff --git a/src/test/resources/checks/v31/parameters/OAR026/header-with-$total-with-defval-true.json b/src/test/resources/checks/v31/parameters/OAR026/header-with-$total-with-defval-true.json new file mode 100644 index 00000000..940f0f1d --- /dev/null +++ b/src/test/resources/checks/v31/parameters/OAR026/header-with-$total-with-defval-true.json @@ -0,0 +1,26 @@ +{ + "openapi" : "3.1.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/pets" : { + "get" : { + "parameters" : [ { + "in" : "header", + "name" : "$total", + "schema" : { + "type" : "boolean", + "default" : true + } + } ], + "responses" : { + "206" : { + "description" : "Ok" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v31/parameters/OAR026/header-with-$total-with-defval-true.yaml b/src/test/resources/checks/v31/parameters/OAR026/header-with-$total-with-defval-true.yaml new file mode 100644 index 00000000..7936548a --- /dev/null +++ b/src/test/resources/checks/v31/parameters/OAR026/header-with-$total-with-defval-true.yaml @@ -0,0 +1,16 @@ +openapi: "3.1.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + get: + parameters: + - in: header + name: $total + schema: + type: boolean + default: true + responses: + 206: + description: Ok diff --git a/src/test/resources/checks/v31/parameters/OAR026/plain-with-$total-without-defval.json b/src/test/resources/checks/v31/parameters/OAR026/plain-with-$total-without-defval.json index fe56facb..9278595e 100644 --- a/src/test/resources/checks/v31/parameters/OAR026/plain-with-$total-without-defval.json +++ b/src/test/resources/checks/v31/parameters/OAR026/plain-with-$total-without-defval.json @@ -16,7 +16,7 @@ "type" : "string" } } - }, { # Noncompliant {{OAR026: The $total parameter default value should be false}} + }, { "in" : "query", "name" : "$total", "schema": { diff --git a/src/test/resources/checks/v31/parameters/OAR026/plain-with-$total-without-defval.yaml b/src/test/resources/checks/v31/parameters/OAR026/plain-with-$total-without-defval.yaml index 76791b5a..d18a1745 100644 --- a/src/test/resources/checks/v31/parameters/OAR026/plain-with-$total-without-defval.yaml +++ b/src/test/resources/checks/v31/parameters/OAR026/plain-with-$total-without-defval.yaml @@ -12,7 +12,7 @@ paths: type: array items: type: string - - in: query # Noncompliant {{OAR026: The $total parameter default value should be false}} + - in: query name: $total schema: type: boolean diff --git a/src/test/resources/checks/v31/parameters/OAR026/post-with-$total-with-defval-true.json b/src/test/resources/checks/v31/parameters/OAR026/post-with-$total-with-defval-true.json new file mode 100644 index 00000000..418764a4 --- /dev/null +++ b/src/test/resources/checks/v31/parameters/OAR026/post-with-$total-with-defval-true.json @@ -0,0 +1,26 @@ +{ + "openapi" : "3.1.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/pets" : { + "post" : { + "parameters" : [ { + "in" : "query", + "name" : "$total", + "schema" : { + "type" : "boolean", + "default" : true + } + } ], + "responses" : { + "201" : { + "description" : "Created" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v31/parameters/OAR026/post-with-$total-with-defval-true.yaml b/src/test/resources/checks/v31/parameters/OAR026/post-with-$total-with-defval-true.yaml new file mode 100644 index 00000000..9f7796c6 --- /dev/null +++ b/src/test/resources/checks/v31/parameters/OAR026/post-with-$total-with-defval-true.yaml @@ -0,0 +1,16 @@ +openapi: "3.1.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + post: + parameters: + - in: query + name: $total + schema: + type: boolean + default: true + responses: + 201: + description: Created diff --git a/src/test/resources/checks/v31/parameters/OAR026/with-$ref-unreferenced-with-$total-with-defval-true.json b/src/test/resources/checks/v31/parameters/OAR026/with-$ref-unreferenced-with-$total-with-defval-true.json new file mode 100644 index 00000000..8ba32f08 --- /dev/null +++ b/src/test/resources/checks/v31/parameters/OAR026/with-$ref-unreferenced-with-$total-with-defval-true.json @@ -0,0 +1,30 @@ +{ + "openapi" : "3.1.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "components" : { + "parameters" : { + "total" : { + "in" : "query", + "name" : "$total", + "schema" : { + "type" : "boolean", + "default" : true + } + } + } + }, + "paths" : { + "/pets" : { + "get" : { + "responses" : { + "206" : { + "description" : "Ok" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v31/parameters/OAR026/with-$ref-unreferenced-with-$total-with-defval-true.yaml b/src/test/resources/checks/v31/parameters/OAR026/with-$ref-unreferenced-with-$total-with-defval-true.yaml new file mode 100644 index 00000000..595b9232 --- /dev/null +++ b/src/test/resources/checks/v31/parameters/OAR026/with-$ref-unreferenced-with-$total-with-defval-true.yaml @@ -0,0 +1,18 @@ +openapi: "3.1.0" +info: + version: 1.0.0 + title: Swagger Petstore +components: + parameters: + total: + in: query + name: $total + schema: + type: boolean + default: true +paths: + /pets: + get: + responses: + 206: + description: Ok diff --git a/src/test/resources/checks/v31/parameters/OAR026/with-$ref-with-$total-without-defval.json b/src/test/resources/checks/v31/parameters/OAR026/with-$ref-with-$total-without-defval.json index a550035d..bd00551f 100644 --- a/src/test/resources/checks/v31/parameters/OAR026/with-$ref-with-$total-without-defval.json +++ b/src/test/resources/checks/v31/parameters/OAR026/with-$ref-with-$total-without-defval.json @@ -16,7 +16,7 @@ } } }, - "total" : { # Noncompliant {{OAR026: The $total parameter default value should be false}} + "total" : { "in" : "query", "name" : "$total", "schema": { diff --git a/src/test/resources/checks/v31/parameters/OAR026/with-$ref-with-$total-without-defval.yaml b/src/test/resources/checks/v31/parameters/OAR026/with-$ref-with-$total-without-defval.yaml index a7888290..985a84f6 100644 --- a/src/test/resources/checks/v31/parameters/OAR026/with-$ref-with-$total-without-defval.yaml +++ b/src/test/resources/checks/v31/parameters/OAR026/with-$ref-with-$total-without-defval.yaml @@ -11,7 +11,7 @@ components: type: array items: type: string - total: # Noncompliant {{OAR026: The $total parameter default value should be false}} + total: in: query name: $total schema: diff --git a/src/test/resources/checks/v32/apim/OAR005/extensive-api.json b/src/test/resources/checks/v32/apim/OAR005/extensive-api.json new file mode 100644 index 00000000..80e2569e --- /dev/null +++ b/src/test/resources/checks/v32/apim/OAR005/extensive-api.json @@ -0,0 +1,241 @@ +{ + "openapi" : "3.2.0", + "info" : { + "version" : "2.1.0", + "title" : "Retail Storefront API", + "description" : "Public-facing REST API for the retail storefront covering product catalog browsing, order placement, account management, and platform administration." + }, + "paths" : { + "/catalog/products" : { + "get" : { + "operationId" : "get_catalog_products", + "summary" : "List products", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "CATALOG_SC_READ" + }, + "post" : { + "operationId" : "post_catalog_products", + "summary" : "Create a product", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "CATALOG_SC_WRITE" + } + }, + "/catalog/products/{productId}" : { + "get" : { + "operationId" : "get_catalog_products_productId", + "summary" : "Get a product", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "CATALOG_SC_READ" + }, + "put" : { + "operationId" : "put_catalog_products_productId", + "summary" : "Replace a product", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "CATALOG_SC_WRITE" + }, + "delete" : { + "operationId" : "delete_catalog_products_productId", + "summary" : "Delete a product", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "CATALOG_SC_WRITE" + } + }, + "/orders" : { + "get" : { + "operationId" : "get_orders", + "summary" : "List orders", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "ORDERS_SC_READ" + }, + "post" : { + "operationId" : "post_orders", + "summary" : "Place an order", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "ORDERS_SC_WRITE" + } + }, + "/orders/{orderId}" : { + "get" : { + "operationId" : "get_orders_orderId", + "summary" : "Get an order", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "ORDERS_SC_READ" + }, + "delete" : { + "operationId" : "delete_orders_orderId", + "summary" : "Cancel an order", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "ORDERS_SC_WRITE" + } + }, + "/account/profile" : { + "get" : { + "operationId" : "get_account_profile", + "summary" : "Get the caller's profile", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "ACCOUNT_SC_READ" + }, + "put" : { + "operationId" : "put_account_profile", + "summary" : "Update the caller's profile - undeclared scope", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "ACCOUNT_SC_WRITE" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + }, + "/admin/users" : { + "get" : { + "operationId" : "get_admin_users", + "summary" : "List platform users - matches key not name", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "admin_all" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "post" : { + "operationId" : "post_admin_users", + "summary" : "Create a platform user", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "ADMIN_SC_ALL" + } + }, + "/admin/audit-log" : { + "get" : { + "operationId" : "get_admin_audit-log", + "summary" : "Read the audit log", + "responses" : { + "200" : { + "description" : "Ok" + }, + "400" : { + "description" : "Bad request" + } + }, + "x-scope" : "ADMIN_SC_ALL" + } + } + }, + "x-wso2-security" : { + "apim" : { + "x-wso2-scopes" : [ { + "name" : "CATALOG_SC_READ", + "key" : "catalog_read", + "roles" : "ROLE_CATALOG_READ", + "description" : "Allows users to browse the product catalog" + }, { + "name" : "CATALOG_SC_WRITE", + "key" : "catalog_write", + "roles" : "ROLE_CATALOG_WRITE", + "description" : "Allows users to create or update products" + }, { + "name" : "ORDERS_SC_READ", + "key" : "orders_read", + "roles" : "ROLE_ORDERS_READ", + "description" : "Allows users to view orders" + }, { + "name" : "ORDERS_SC_WRITE", + "key" : "orders_write", + "roles" : "ROLE_ORDERS_WRITE", + "description" : "Allows users to place or cancel orders" + }, { + "name" : "ACCOUNT_SC_READ", + "key" : "account_read", + "roles" : "ROLE_ACCOUNT_READ", + "description" : "Allows users to view their own account" + }, { + "name" : "ADMIN_SC_ALL", + "key" : "admin_all", + "roles" : "ROLE_ADMIN", + "description" : "Full administrative access" + } ] + } + } +} diff --git a/src/test/resources/checks/v32/apim/OAR005/extensive-api.yaml b/src/test/resources/checks/v32/apim/OAR005/extensive-api.yaml new file mode 100644 index 00000000..651b1ae9 --- /dev/null +++ b/src/test/resources/checks/v32/apim/OAR005/extensive-api.yaml @@ -0,0 +1,167 @@ +openapi: "3.2.0" +info: + version: 2.1.0 + title: Retail Storefront API + description: Public-facing REST API for the retail storefront covering product catalog browsing, order placement, account management, and platform administration. +paths: + /catalog/products: + get: + operationId: get_catalog_products + summary: List products + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: CATALOG_SC_READ + post: + operationId: post_catalog_products + summary: Create a product + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: CATALOG_SC_WRITE + /catalog/products/{productId}: + get: + operationId: get_catalog_products_productId + summary: Get a product + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: CATALOG_SC_READ + put: + operationId: put_catalog_products_productId + summary: Replace a product + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: CATALOG_SC_WRITE + delete: + operationId: delete_catalog_products_productId + summary: Delete a product + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: CATALOG_SC_WRITE + /orders: + get: + operationId: get_orders + summary: List orders + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: ORDERS_SC_READ + post: + operationId: post_orders + summary: Place an order + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: ORDERS_SC_WRITE + /orders/{orderId}: + get: + operationId: get_orders_orderId + summary: Get an order + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: ORDERS_SC_READ + delete: + operationId: delete_orders_orderId + summary: Cancel an order + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: ORDERS_SC_WRITE + /account/profile: + get: + operationId: get_account_profile + summary: Get the caller's profile + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: ACCOUNT_SC_READ + put: + operationId: put_account_profile + summary: Update the caller's profile - undeclared scope + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: ACCOUNT_SC_WRITE # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + /admin/users: + get: + operationId: get_admin_users + summary: List platform users - matches key not name + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: admin_all # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + post: + operationId: post_admin_users + summary: Create a platform user + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: ADMIN_SC_ALL + /admin/audit-log: + get: + operationId: get_admin_audit-log + summary: Read the audit log + responses: + 200: + description: Ok + 400: + description: Bad request + x-scope: ADMIN_SC_ALL + +x-wso2-security: + apim: + x-wso2-scopes: + - name: CATALOG_SC_READ + key: catalog_read + roles: ROLE_CATALOG_READ + description: Allows users to browse the product catalog + - name: CATALOG_SC_WRITE + key: catalog_write + roles: ROLE_CATALOG_WRITE + description: Allows users to create or update products + - name: ORDERS_SC_READ + key: orders_read + roles: ROLE_ORDERS_READ + description: Allows users to view orders + - name: ORDERS_SC_WRITE + key: orders_write + roles: ROLE_ORDERS_WRITE + description: Allows users to place or cancel orders + - name: ACCOUNT_SC_READ + key: account_read + roles: ROLE_ACCOUNT_READ + description: Allows users to view their own account + - name: ADMIN_SC_ALL + key: admin_all + roles: ROLE_ADMIN + description: Full administrative access diff --git a/src/test/resources/checks/v32/apim/OAR005/with-additional-operations.json b/src/test/resources/checks/v32/apim/OAR005/with-additional-operations.json new file mode 100644 index 00000000..8e4e8bb3 --- /dev/null +++ b/src/test/resources/checks/v32/apim/OAR005/with-additional-operations.json @@ -0,0 +1,60 @@ +{ + "openapi" : "3.2.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/a" : { + "query" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "additionalOperations" : { + "PURGE" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_six" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + } + } + }, + "webhooks" : { + "newPet" : { + "query" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_seven" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "additionalOperations" : { + "LINK" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_eight" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + } + } + }, + "x-wso2-security" : { + "apim" : { + "x-wso2-scopes" : [ { + "name" : "scope_one", + "key" : "scope_one", + "roles" : "role_one" + } ] + } + } +} diff --git a/src/test/resources/checks/v32/apim/OAR005/with-additional-operations.yaml b/src/test/resources/checks/v32/apim/OAR005/with-additional-operations.yaml new file mode 100644 index 00000000..d5ec9127 --- /dev/null +++ b/src/test/resources/checks/v32/apim/OAR005/with-additional-operations.yaml @@ -0,0 +1,37 @@ +openapi: "3.2.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /a: + query: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + additionalOperations: + PURGE: + responses: + 200: + description: Ok + x-scope: scope_six # Noncompliant {{OAR005: WSO2 scope definition does not exists}} +webhooks: + newPet: + query: + responses: + 200: + description: Ok + x-scope: scope_seven # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + additionalOperations: + LINK: + responses: + 200: + description: Ok + x-scope: scope_eight # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + +x-wso2-security: + apim: + x-wso2-scopes: + - name: scope_one + key: scope_one + roles: role_one diff --git a/src/test/resources/checks/v32/apim/OAR005/with-all-verbs.json b/src/test/resources/checks/v32/apim/OAR005/with-all-verbs.json new file mode 100644 index 00000000..87f4f4dc --- /dev/null +++ b/src/test/resources/checks/v32/apim/OAR005/with-all-verbs.json @@ -0,0 +1,93 @@ +{ + "openapi" : "3.2.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/a" : { + "x-scope" : "scope_one", + "get" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "put" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "delete" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "options" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "head" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "patch" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "trace" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "query" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + } + }, + "x-wso2-security" : { + "apim" : { + "x-wso2-scopes" : [ { + "name" : "scope_one", + "key" : "scope_one", + "roles" : "role_one" + } ] + } + } +} diff --git a/src/test/resources/checks/v32/apim/OAR005/with-all-verbs.yaml b/src/test/resources/checks/v32/apim/OAR005/with-all-verbs.yaml new file mode 100644 index 00000000..3a51a562 --- /dev/null +++ b/src/test/resources/checks/v32/apim/OAR005/with-all-verbs.yaml @@ -0,0 +1,59 @@ +openapi: "3.2.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /a: + x-scope: scope_one + get: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + put: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + post: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + delete: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + options: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + head: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + patch: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + trace: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + query: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + +x-wso2-security: + apim: + x-wso2-scopes: + - name: scope_one + key: scope_one + roles: role_one diff --git a/src/test/resources/checks/v32/apim/OAR005/with-callback-operations.json b/src/test/resources/checks/v32/apim/OAR005/with-callback-operations.json new file mode 100644 index 00000000..e967307f --- /dev/null +++ b/src/test/resources/checks/v32/apim/OAR005/with-callback-operations.json @@ -0,0 +1,72 @@ +{ + "openapi" : "3.2.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/a" : { + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_one", + "callbacks" : { + "onEvent" : { + "'{$request.body#/callbackUrl}'" : { + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five", # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + "callbacks" : { + "onNested" : { + "'{$request.body#/nestedUrl}'" : { + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_six" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + } + } + } + } + } + } + } + } + } + }, + "components" : { + "callbacks" : { + "sharedCallback" : { + "'{$request.body#/callbackUrl}'" : { + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_seven" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + } + } + } + }, + "x-wso2-security" : { + "apim" : { + "x-wso2-scopes" : [ { + "name" : "scope_one", + "key" : "scope_one", + "roles" : "role_one" + } ] + } + } +} diff --git a/src/test/resources/checks/v32/apim/OAR005/with-callback-operations.yaml b/src/test/resources/checks/v32/apim/OAR005/with-callback-operations.yaml new file mode 100644 index 00000000..ea61929f --- /dev/null +++ b/src/test/resources/checks/v32/apim/OAR005/with-callback-operations.yaml @@ -0,0 +1,43 @@ +openapi: "3.2.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /a: + post: + responses: + 200: + description: Ok + x-scope: scope_one + callbacks: + onEvent: + '{$request.body#/callbackUrl}': + post: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + callbacks: + onNested: + '{$request.body#/nestedUrl}': + post: + responses: + 200: + description: Ok + x-scope: scope_six # Noncompliant {{OAR005: WSO2 scope definition does not exists}} +components: + callbacks: + sharedCallback: + '{$request.body#/callbackUrl}': + post: + responses: + 200: + description: Ok + x-scope: scope_seven # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + +x-wso2-security: + apim: + x-wso2-scopes: + - name: scope_one + key: scope_one + roles: role_one diff --git a/src/test/resources/checks/v32/apim/OAR005/with-chained-ref-security.json b/src/test/resources/checks/v32/apim/OAR005/with-chained-ref-security.json new file mode 100644 index 00000000..8b8fe22d --- /dev/null +++ b/src/test/resources/checks/v32/apim/OAR005/with-chained-ref-security.json @@ -0,0 +1,50 @@ +{ + "openapi" : "3.2.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/pets" : { + "get" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_two" + }, + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + } + }, + "x-wso2-security" : { + "$ref" : "#/x-wso2-definitions/alias" + }, + "x-wso2-definitions" : { + "alias" : { + "$ref" : "#/x-wso2-definitions/security" + }, + "security" : { + "apim" : { + "x-wso2-scopes" : [ { + "name" : "scope_one", + "description" : "scope_one", + "key" : "scope_one", + "roles" : "role_one" + }, { + "name" : "scope_two", + "description" : "scope_two", + "key" : "scope_two", + "roles" : "role_two" + } ] + } + } + } +} diff --git a/src/test/resources/checks/v32/apim/OAR005/with-chained-ref-security.yaml b/src/test/resources/checks/v32/apim/OAR005/with-chained-ref-security.yaml new file mode 100644 index 00000000..ba388fec --- /dev/null +++ b/src/test/resources/checks/v32/apim/OAR005/with-chained-ref-security.yaml @@ -0,0 +1,33 @@ +openapi: "3.2.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + get: + responses: + 200: + description: Ok + x-scope: scope_two + post: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + +x-wso2-security: + $ref: "#/x-wso2-definitions/alias" +x-wso2-definitions: + alias: + $ref: "#/x-wso2-definitions/security" + security: + apim: + x-wso2-scopes: + - name: scope_one + description: scope_one + key: scope_one + roles: role_one + - name: scope_two + description: scope_two + key: scope_two + roles: role_two diff --git a/src/test/resources/checks/v32/apim/OAR005/with-ref-scope.json b/src/test/resources/checks/v32/apim/OAR005/with-ref-scope.json new file mode 100644 index 00000000..f061e098 --- /dev/null +++ b/src/test/resources/checks/v32/apim/OAR005/with-ref-scope.json @@ -0,0 +1,55 @@ +{ + "openapi" : "3.2.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/pets" : { + "get" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_one" + }, + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_two" + }, + "put" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + } + }, + "x-wso2-security" : { + "apim" : { + "x-wso2-scopes" : [ { + "name" : "scope_one", + "description" : "scope_one", + "key" : "scope_one", + "roles" : "role_one" + }, { + "$ref" : "#/x-wso2-definitions/scopeTwo" + } ] + } + }, + "x-wso2-definitions" : { + "scopeTwo" : { + "name" : "scope_two", + "description" : "scope_two", + "key" : "scope_two", + "roles" : "role_two" + } + } +} diff --git a/src/test/resources/checks/v32/apim/OAR005/with-ref-scope.yaml b/src/test/resources/checks/v32/apim/OAR005/with-ref-scope.yaml new file mode 100644 index 00000000..a4549e95 --- /dev/null +++ b/src/test/resources/checks/v32/apim/OAR005/with-ref-scope.yaml @@ -0,0 +1,36 @@ +openapi: "3.2.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + get: + responses: + 200: + description: Ok + x-scope: scope_one + post: + responses: + 200: + description: Ok + x-scope: scope_two + put: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + +x-wso2-security: + apim: + x-wso2-scopes: + - name: scope_one + description: scope_one + key: scope_one + roles: role_one + - $ref: "#/x-wso2-definitions/scopeTwo" +x-wso2-definitions: + scopeTwo: + name: scope_two + description: scope_two + key: scope_two + roles: role_two diff --git a/src/test/resources/checks/v32/apim/OAR005/with-ref-security.json b/src/test/resources/checks/v32/apim/OAR005/with-ref-security.json new file mode 100644 index 00000000..647837ec --- /dev/null +++ b/src/test/resources/checks/v32/apim/OAR005/with-ref-security.json @@ -0,0 +1,47 @@ +{ + "openapi" : "3.2.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/pets" : { + "get" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_two" + }, + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + } + }, + "x-wso2-security" : { + "$ref" : "#/x-wso2-definitions/security" + }, + "x-wso2-definitions" : { + "security" : { + "apim" : { + "x-wso2-scopes" : [ { + "name" : "scope_one", + "description" : "scope_one", + "key" : "scope_one", + "roles" : "role_one" + }, { + "name" : "scope_two", + "description" : "scope_two", + "key" : "scope_two", + "roles" : "role_two" + } ] + } + } + } +} diff --git a/src/test/resources/checks/v32/apim/OAR005/with-ref-security.yaml b/src/test/resources/checks/v32/apim/OAR005/with-ref-security.yaml new file mode 100644 index 00000000..1a88793d --- /dev/null +++ b/src/test/resources/checks/v32/apim/OAR005/with-ref-security.yaml @@ -0,0 +1,31 @@ +openapi: "3.2.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + get: + responses: + 200: + description: Ok + x-scope: scope_two + post: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + +x-wso2-security: + $ref: "#/x-wso2-definitions/security" +x-wso2-definitions: + security: + apim: + x-wso2-scopes: + - name: scope_one + description: scope_one + key: scope_one + roles: role_one + - name: scope_two + description: scope_two + key: scope_two + roles: role_two diff --git a/src/test/resources/checks/v32/apim/OAR005/with-scope-key-not-name.json b/src/test/resources/checks/v32/apim/OAR005/with-scope-key-not-name.json new file mode 100644 index 00000000..0022eb31 --- /dev/null +++ b/src/test/resources/checks/v32/apim/OAR005/with-scope-key-not-name.json @@ -0,0 +1,37 @@ +{ + "openapi" : "3.2.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/pets" : { + "get" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "catalogue_read" + }, + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "read" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + } + }, + "x-wso2-security" : { + "apim" : { + "x-wso2-scopes" : [ { + "name" : "catalogue_read", + "description" : "catalogue_read", + "key" : "read", + "roles" : "role_one" + } ] + } + } +} diff --git a/src/test/resources/checks/v32/apim/OAR005/with-scope-key-not-name.yaml b/src/test/resources/checks/v32/apim/OAR005/with-scope-key-not-name.yaml new file mode 100644 index 00000000..97955637 --- /dev/null +++ b/src/test/resources/checks/v32/apim/OAR005/with-scope-key-not-name.yaml @@ -0,0 +1,24 @@ +openapi: "3.2.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + get: + responses: + 200: + description: Ok + x-scope: catalogue_read + post: + responses: + 200: + description: Ok + x-scope: read # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + +x-wso2-security: + apim: + x-wso2-scopes: + - name: catalogue_read + description: catalogue_read + key: read + roles: role_one diff --git a/src/test/resources/checks/v32/apim/OAR005/with-scopes-as-map.json b/src/test/resources/checks/v32/apim/OAR005/with-scopes-as-map.json new file mode 100644 index 00000000..dde82ce2 --- /dev/null +++ b/src/test/resources/checks/v32/apim/OAR005/with-scopes-as-map.json @@ -0,0 +1,66 @@ +{ + "openapi" : "3.2.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/pets" : { + "get" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "read_scope" + }, + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "read" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "put" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "write_scope" + }, + "delete" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + } + }, + "x-wso2-security" : { + "apim" : { + "x-wso2-scopes" : { + "read" : { + "name" : "read_scope", + "key" : "read", + "roles" : "ROLE_READ", + "description" : "Allows users to read the catalogue" + }, + "write" : { + "$ref" : "#/x-wso2-definitions/writeScope" + } + } + } + }, + "x-wso2-definitions" : { + "writeScope" : { + "name" : "write_scope", + "key" : "write", + "roles" : "ROLE_WRITE", + "description" : "Allows users to write the catalogue" + } + } +} diff --git a/src/test/resources/checks/v32/apim/OAR005/with-scopes-as-map.yaml b/src/test/resources/checks/v32/apim/OAR005/with-scopes-as-map.yaml new file mode 100644 index 00000000..4c837278 --- /dev/null +++ b/src/test/resources/checks/v32/apim/OAR005/with-scopes-as-map.yaml @@ -0,0 +1,43 @@ +openapi: "3.2.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + get: + responses: + 200: + description: Ok + x-scope: read_scope + post: + responses: + 200: + description: Ok + x-scope: read # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + put: + responses: + 200: + description: Ok + x-scope: write_scope + delete: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + +x-wso2-security: + apim: + x-wso2-scopes: + read: + name: read_scope + key: read + roles: ROLE_READ + description: Allows users to read the catalogue + write: + $ref: "#/x-wso2-definitions/writeScope" +x-wso2-definitions: + writeScope: + name: write_scope + key: write + roles: ROLE_WRITE + description: Allows users to write the catalogue diff --git a/src/test/resources/checks/v32/apim/OAR005/with-webhook-operations.json b/src/test/resources/checks/v32/apim/OAR005/with-webhook-operations.json new file mode 100644 index 00000000..75423a0a --- /dev/null +++ b/src/test/resources/checks/v32/apim/OAR005/with-webhook-operations.json @@ -0,0 +1,60 @@ +{ + "openapi" : "3.2.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/pets" : { + "$ref" : "#/components/pathItems/PetsPath" + } + }, + "webhooks" : { + "newPet" : { + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_five" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + } + }, + "components" : { + "pathItems" : { + "PetsPath" : { + "x-scope" : "scope_one", + "get" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_six" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + } + }, + "webhooks" : { + "reusableWebhook" : { + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_seven" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + } + } + } + }, + "x-wso2-security" : { + "apim" : { + "x-wso2-scopes" : [ { + "name" : "scope_one", + "key" : "scope_one", + "roles" : "role_one" + } ] + } + } +} diff --git a/src/test/resources/checks/v32/apim/OAR005/with-webhook-operations.yaml b/src/test/resources/checks/v32/apim/OAR005/with-webhook-operations.yaml new file mode 100644 index 00000000..5524e9f4 --- /dev/null +++ b/src/test/resources/checks/v32/apim/OAR005/with-webhook-operations.yaml @@ -0,0 +1,38 @@ +openapi: "3.2.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + $ref: "#/components/pathItems/PetsPath" +webhooks: + newPet: + post: + responses: + 200: + description: Ok + x-scope: scope_five # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + +components: + pathItems: + PetsPath: + x-scope: scope_one + get: + responses: + 200: + description: Ok + x-scope: scope_six # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + webhooks: + reusableWebhook: + post: + responses: + 200: + description: Ok + x-scope: scope_seven # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + +x-wso2-security: + apim: + x-wso2-scopes: + - name: scope_one + key: scope_one + roles: role_one diff --git a/src/test/resources/checks/v32/apim/OAR005/without-security.json b/src/test/resources/checks/v32/apim/OAR005/without-security.json new file mode 100644 index 00000000..fd2319a3 --- /dev/null +++ b/src/test/resources/checks/v32/apim/OAR005/without-security.json @@ -0,0 +1,26 @@ +{ + "openapi" : "3.2.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/pets" : { + "get" : { + "responses" : { + "200" : { + "description" : "Ok" + } + }, + "x-scope" : "scope_one" # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + }, + "post" : { + "responses" : { + "200" : { + "description" : "Ok" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v32/apim/OAR005/without-security.yaml b/src/test/resources/checks/v32/apim/OAR005/without-security.yaml new file mode 100644 index 00000000..3339db32 --- /dev/null +++ b/src/test/resources/checks/v32/apim/OAR005/without-security.yaml @@ -0,0 +1,15 @@ +openapi: "3.2.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + get: + responses: + 200: + description: Ok + x-scope: scope_one # Noncompliant {{OAR005: WSO2 scope definition does not exists}} + post: + responses: + 200: + description: Ok diff --git a/src/test/resources/checks/v32/examples/OAR031/allof-schema-missing-example.yaml b/src/test/resources/checks/v32/examples/OAR031/allof-schema-missing-example.yaml new file mode 100644 index 00000000..7e9327df --- /dev/null +++ b/src/test/resources/checks/v32/examples/OAR031/allof-schema-missing-example.yaml @@ -0,0 +1,32 @@ +openapi: "3.2.0" +info: + version: 1.0.0 + title: Swagger Petstore +components: + schemas: + BaseEntity: + type: object + properties: + id: # Noncompliant {{OAR031: Property 'id' is missing an example.}} + type: integer + 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/externalref.yaml b/src/test/resources/checks/v32/examples/OAR031/externalref.yaml index 2c326a8b..e003f0f5 100644 --- a/src/test/resources/checks/v32/examples/OAR031/externalref.yaml +++ b/src/test/resources/checks/v32/examples/OAR031/externalref.yaml @@ -14,7 +14,7 @@ paths: summary: Get all users description: Returns a list of users. responses: - '200': # Noncompliant {{OAR031: Responses must have one or more examples defined}} + '200': # Noncompliant {{OAR031: Response must have an example defined}} description: A JSON array of user objects content: application/json: @@ -23,7 +23,7 @@ paths: items: $ref: '#/components/schemas/User' '400': - $ref: >- # Noncompliant {{OAR031: Responses must have one or more examples defined}} + $ref: >- # Noncompliant {{OAR031: Response must have an example defined}} http://localhost:18089/OAR031.yaml#/components/responses/server_error_response /users/{userId}: get: @@ -40,14 +40,14 @@ paths: name: Puppy type: dog responses: - '200': # Noncompliant {{OAR031: Responses must have one or more examples defined}} + '200': # Noncompliant {{OAR031: Response must have an example defined}} description: A single user object content: application/json: schema: $ref: '#/components/schemas/User' '400': - $ref: >- # Noncompliant {{OAR031: Responses must have one or more examples defined}} + $ref: >- # Noncompliant {{OAR031: Response must have an example defined}} http://localhost:18089/OAR031.yaml#/components/responses/server_error_response components: schemas: diff --git a/src/test/resources/checks/v32/examples/OAR031/nested-properties-examples.yaml b/src/test/resources/checks/v32/examples/OAR031/nested-properties-examples.yaml index e93c96a9..c9656aff 100644 --- a/src/test/resources/checks/v32/examples/OAR031/nested-properties-examples.yaml +++ b/src/test/resources/checks/v32/examples/OAR031/nested-properties-examples.yaml @@ -6,7 +6,7 @@ paths: /profile: put: summary: Update user profile - requestBody: # Noncompliant {{OAR031: Request body must have one or more examples defined}} + requestBody: # Noncompliant {{OAR031: Request body must have an example defined}} required: true content: application/json: @@ -35,5 +35,5 @@ paths: type: string example: "28001" responses: - '200': # Noncompliant {{OAR031: Responses must have one or more examples defined}} + '200': # Noncompliant {{OAR031: Response must have an example defined}} description: OK \ No newline at end of file diff --git a/src/test/resources/checks/v32/examples/OAR031/orphan-schema.yaml b/src/test/resources/checks/v32/examples/OAR031/orphan-schema.yaml new file mode 100644 index 00000000..391fd0fc --- /dev/null +++ b/src/test/resources/checks/v32/examples/OAR031/orphan-schema.yaml @@ -0,0 +1,32 @@ +openapi: "3.2.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + get: + responses: + 200: + description: Ok + content: + application/json: + schema: + $ref: '#/components/schemas/pet' + example: + name: Fluffy + 204: + description: No content +components: + schemas: + pet: + type: object + properties: + name: + type: string + example: "Fluffy" + # Never referenced by any path - must not be flagged (orphan-schema exclusion). + UnusedSchema: + type: object + properties: + unused_field: + type: string diff --git a/src/test/resources/checks/v32/examples/OAR031/without-examples.yaml b/src/test/resources/checks/v32/examples/OAR031/without-examples.yaml index 9f62c796..1f5c0ad6 100644 --- a/src/test/resources/checks/v32/examples/OAR031/without-examples.yaml +++ b/src/test/resources/checks/v32/examples/OAR031/without-examples.yaml @@ -6,7 +6,7 @@ paths: /pets: get: responses: - 206: # Noncompliant {{OAR031: Responses must have one or more examples defined}} + 206: # Noncompliant {{OAR031: Response must have an example defined}} description: Pet list content: application/json: @@ -16,7 +16,7 @@ paths: $ref: "#/components/responses/server_error_response" /pets/{id}: parameters: - - in: query # Noncompliant {{OAR031: Parameters must have one or more examples defined}} + - in: query # Noncompliant {{OAR031: Parameter '$start' must have an example defined}} name: $start schema: type: integer @@ -24,7 +24,7 @@ paths: parameters: - $ref: "#/components/parameters/id" responses: - 200: # Noncompliant {{OAR031: Responses must have one or more examples defined}} + 200: # Noncompliant {{OAR031: Response must have an example defined}} description: One pet content: application/json: @@ -35,8 +35,8 @@ paths: components: parameters: - id: - in: path # Noncompliant {{OAR031: Parameters must have one or more examples defined}} + id: # Noncompliant {{OAR031: Parameter 'id' must have an example defined}} + in: path name: id schema: type: integer @@ -48,26 +48,26 @@ components: pet: type: object properties: - name: # Noncompliant {{OAR031: Properties must have an example defined}} + name: # Noncompliant {{OAR031: Property 'name' is missing an example.}} type: string - type: # Noncompliant {{OAR031: Properties must have an example defined}} + type: # Noncompliant {{OAR031: Property 'type' is missing an example.}} type: string pets: type: object properties: - size: # Noncompliant {{OAR031: Properties must have an example defined}} + size: # Noncompliant {{OAR031: Property 'size' is missing an example.}} type: integer pets: type: array items: $ref: '#/components/schemas/pet' responses: - server_error_response: # Noncompliant {{OAR031: Responses must have one or more examples defined}} + server_error_response: # Noncompliant {{OAR031: Response must have an example defined}} description: Default error response content: application/json: schema: type: object properties: - error: # Noncompliant {{OAR031: Properties must have an example defined}} + error: # Noncompliant {{OAR031: Property 'error' is missing an example.}} type: string \ No newline at end of file diff --git a/src/test/resources/checks/v32/format/OAR007/with-204-response.json b/src/test/resources/checks/v32/format/OAR007/with-204-response.json new file mode 100644 index 00000000..bab1a2ca --- /dev/null +++ b/src/test/resources/checks/v32/format/OAR007/with-204-response.json @@ -0,0 +1,18 @@ +{ + "openapi": "3.2.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore" + }, + "paths": { + "/pets": { + "delete": { + "responses": { + "204": { + "description": "No Content" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v32/format/OAR007/with-204-response.yaml b/src/test/resources/checks/v32/format/OAR007/with-204-response.yaml new file mode 100644 index 00000000..92acae09 --- /dev/null +++ b/src/test/resources/checks/v32/format/OAR007/with-204-response.yaml @@ -0,0 +1,10 @@ +openapi: "3.2.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + delete: + responses: + '204': + description: No Content diff --git a/src/test/resources/checks/v32/format/OAR007/with-chained-ref.json b/src/test/resources/checks/v32/format/OAR007/with-chained-ref.json new file mode 100644 index 00000000..969d51ca --- /dev/null +++ b/src/test/resources/checks/v32/format/OAR007/with-chained-ref.json @@ -0,0 +1,28 @@ +{ + "openapi": "3.2.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore" + }, + "components": { + "responses": { + "A": { + "$ref": "#/components/responses/B" + }, + "B": { # Noncompliant {{OAR007: Section content is mandatory}} + "description": "No content defined" + } + } + }, + "paths": { + "/pets": { + "put": { + "responses": { + "200": { + "$ref": "#/components/responses/A" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v32/format/OAR007/with-chained-ref.yaml b/src/test/resources/checks/v32/format/OAR007/with-chained-ref.yaml new file mode 100644 index 00000000..7b7d9803 --- /dev/null +++ b/src/test/resources/checks/v32/format/OAR007/with-chained-ref.yaml @@ -0,0 +1,16 @@ +openapi: "3.2.0" +info: + version: 1.0.0 + title: Swagger Petstore +components: + responses: + A: + $ref: '#/components/responses/B' + B: # Noncompliant {{OAR007: Section content is mandatory}} + description: No content defined +paths: + /pets: + put: + responses: + '200': + $ref: '#/components/responses/A' diff --git a/src/test/resources/checks/v32/format/OAR007/with-default-and-ref.json b/src/test/resources/checks/v32/format/OAR007/with-default-and-ref.json new file mode 100644 index 00000000..ae69aeff --- /dev/null +++ b/src/test/resources/checks/v32/format/OAR007/with-default-and-ref.json @@ -0,0 +1,28 @@ +{ + "openapi": "3.2.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore" + }, + "components": { + "responses": { + "PetsResponse": { + "description": "OK", + "content": { + "application/json": {} + } + } + } + }, + "paths": { + "/pets": { + "put": { + "responses": { + "200": { + "$ref": "#/components/responses/PetsResponse" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v32/format/OAR007/with-default-and-ref.yaml b/src/test/resources/checks/v32/format/OAR007/with-default-and-ref.yaml new file mode 100644 index 00000000..36a3ed7d --- /dev/null +++ b/src/test/resources/checks/v32/format/OAR007/with-default-and-ref.yaml @@ -0,0 +1,16 @@ +openapi: "3.2.0" +info: + version: 1.0.0 + title: Swagger Petstore +components: + responses: + PetsResponse: + description: OK + content: + application/json: {} +paths: + /pets: + put: + responses: + '200': + $ref: '#/components/responses/PetsResponse' diff --git a/src/test/resources/checks/v32/format/OAR007/with-default-response-key.json b/src/test/resources/checks/v32/format/OAR007/with-default-response-key.json new file mode 100644 index 00000000..0ca74d2d --- /dev/null +++ b/src/test/resources/checks/v32/format/OAR007/with-default-response-key.json @@ -0,0 +1,19 @@ +{ + "openapi": "3.2.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore" + }, + "paths": { + "/pets": { + "post": { + "responses": { + "default": { # Noncompliant {{OAR007: Section content is mandatory}} + "description": "Unexpected error", + "content": {} + } + } + } + } + } +} diff --git a/src/test/resources/checks/v32/format/OAR007/with-default-response-key.yaml b/src/test/resources/checks/v32/format/OAR007/with-default-response-key.yaml new file mode 100644 index 00000000..1b5d2fae --- /dev/null +++ b/src/test/resources/checks/v32/format/OAR007/with-default-response-key.yaml @@ -0,0 +1,11 @@ +openapi: "3.2.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + post: + responses: + default: # Noncompliant {{OAR007: Section content is mandatory}} + description: Unexpected error + content: {} diff --git a/src/test/resources/checks/v32/format/OAR007/with-external-ref.json b/src/test/resources/checks/v32/format/OAR007/with-external-ref.json new file mode 100644 index 00000000..3efefeac --- /dev/null +++ b/src/test/resources/checks/v32/format/OAR007/with-external-ref.json @@ -0,0 +1,18 @@ +{ + "openapi": "3.2.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore" + }, + "paths": { + "/pets": { + "put": { + "responses": { + "200": { + "$ref": "http://localhost:18089/OAR007.yaml#/components/responses/SuccessResponse" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v32/format/OAR007/with-external-ref.yaml b/src/test/resources/checks/v32/format/OAR007/with-external-ref.yaml new file mode 100644 index 00000000..b5813931 --- /dev/null +++ b/src/test/resources/checks/v32/format/OAR007/with-external-ref.yaml @@ -0,0 +1,11 @@ +openapi: "3.2.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + put: + responses: + '200': + $ref: >- + http://localhost:18089/OAR007.yaml#/components/responses/SuccessResponse diff --git a/src/test/resources/checks/v32/format/OAR007/with-multiple-operations.json b/src/test/resources/checks/v32/format/OAR007/with-multiple-operations.json new file mode 100644 index 00000000..d94df219 --- /dev/null +++ b/src/test/resources/checks/v32/format/OAR007/with-multiple-operations.json @@ -0,0 +1,53 @@ +{ + "openapi": "3.2.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore" + }, + "paths": { + "/pets": { + "get": { + "responses": { + "200": { + "description": "Ok", + "content": { + "application/json": {} + } + }, + "204": { + "description": "No Content" + } + } + }, + "post": { + "responses": { + "201": { # Noncompliant {{OAR007: Section content is mandatory}} + "description": "Created" + } + } + } + }, + "/owners": { + "put": { + "responses": { + "200": { + "description": "Ok", + "content": { + "application/xml": {} + } + }, + "400": { # Noncompliant {{OAR007: Section content is mandatory}} + "description": "Bad Request" + } + } + }, + "delete": { + "responses": { + "204": { + "description": "No Content" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v32/format/OAR007/with-multiple-operations.yaml b/src/test/resources/checks/v32/format/OAR007/with-multiple-operations.yaml new file mode 100644 index 00000000..92260973 --- /dev/null +++ b/src/test/resources/checks/v32/format/OAR007/with-multiple-operations.yaml @@ -0,0 +1,31 @@ +openapi: "3.2.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + get: + responses: + '200': + description: Ok + content: + application/json: {} + '204': + description: No Content + post: + responses: + '201': # Noncompliant {{OAR007: Section content is mandatory}} + description: Created + /owners: + put: + responses: + '200': + description: Ok + content: + application/xml: {} + '400': # Noncompliant {{OAR007: Section content is mandatory}} + description: Bad Request + delete: + responses: + '204': + description: No Content diff --git a/src/test/resources/checks/v32/format/OAR007/with-specific.json b/src/test/resources/checks/v32/format/OAR007/with-specific.json new file mode 100644 index 00000000..f722e678 --- /dev/null +++ b/src/test/resources/checks/v32/format/OAR007/with-specific.json @@ -0,0 +1,21 @@ +{ + "openapi": "3.2.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore" + }, + "paths": { + "/pets": { + "put": { + "responses": { + "200": { + "description": "Ok", + "content": { + "application/json": {} + } + } + } + } + } + } +} diff --git a/src/test/resources/checks/v32/format/OAR007/with-specific.yaml b/src/test/resources/checks/v32/format/OAR007/with-specific.yaml new file mode 100644 index 00000000..f74596be --- /dev/null +++ b/src/test/resources/checks/v32/format/OAR007/with-specific.yaml @@ -0,0 +1,12 @@ +openapi: "3.2.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + put: + responses: + '200': + description: Ok + content: + application/json: {} diff --git a/src/test/resources/checks/v32/format/OAR007/with-wrong-ref.json b/src/test/resources/checks/v32/format/OAR007/with-wrong-ref.json new file mode 100644 index 00000000..47e7b3c7 --- /dev/null +++ b/src/test/resources/checks/v32/format/OAR007/with-wrong-ref.json @@ -0,0 +1,25 @@ +{ + "openapi": "3.2.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore" + }, + "components": { + "responses": { + "PetsResponse": { # Noncompliant {{OAR007: Section content is mandatory}} + "description": "No content defined" + } + } + }, + "paths": { + "/pets": { + "put": { + "responses": { + "200": { + "$ref": "#/components/responses/PetsResponse" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v32/format/OAR007/with-wrong-ref.yaml b/src/test/resources/checks/v32/format/OAR007/with-wrong-ref.yaml new file mode 100644 index 00000000..9a687bef --- /dev/null +++ b/src/test/resources/checks/v32/format/OAR007/with-wrong-ref.yaml @@ -0,0 +1,14 @@ +openapi: "3.2.0" +info: + version: 1.0.0 + title: Swagger Petstore +components: + responses: + PetsResponse: # Noncompliant {{OAR007: Section content is mandatory}} + description: No content defined +paths: + /pets: + put: + responses: + '200': + $ref: '#/components/responses/PetsResponse' diff --git a/src/test/resources/checks/v32/format/OAR010/with-204-response.json b/src/test/resources/checks/v32/format/OAR010/with-204-response.json new file mode 100644 index 00000000..4c4eaec2 --- /dev/null +++ b/src/test/resources/checks/v32/format/OAR010/with-204-response.json @@ -0,0 +1,27 @@ +{ + "openapi": "3.2.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore" + }, + "paths": { + "/pets": { + "post": { + "responses": { + "200": { + "description": "Ok", + "content": { + "application/json": {} + } + }, + "204": { + "description": "No Content", + "content": { + "application/xml": {} + } + } + } + } + } + } +} diff --git a/src/test/resources/checks/v32/format/OAR010/with-204-response.yaml b/src/test/resources/checks/v32/format/OAR010/with-204-response.yaml new file mode 100644 index 00000000..1882ff1f --- /dev/null +++ b/src/test/resources/checks/v32/format/OAR010/with-204-response.yaml @@ -0,0 +1,16 @@ +openapi: "3.2.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + post: + responses: + '200': + description: Ok + content: + application/json: {} + '204': + description: No Content + content: + application/xml: {} diff --git a/src/test/resources/checks/v32/format/OAR010/with-default-mixed-case.json b/src/test/resources/checks/v32/format/OAR010/with-default-mixed-case.json new file mode 100644 index 00000000..d73a6340 --- /dev/null +++ b/src/test/resources/checks/v32/format/OAR010/with-default-mixed-case.json @@ -0,0 +1,21 @@ +{ + "openapi": "3.2.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore" + }, + "paths": { + "/pets": { + "post": { + "responses": { + "200": { + "description": "Ok", + "content": { + "Application/JSON": {} + } + } + } + } + } + } +} diff --git a/src/test/resources/checks/v32/format/OAR010/with-default-mixed-case.yaml b/src/test/resources/checks/v32/format/OAR010/with-default-mixed-case.yaml new file mode 100644 index 00000000..10787780 --- /dev/null +++ b/src/test/resources/checks/v32/format/OAR010/with-default-mixed-case.yaml @@ -0,0 +1,12 @@ +openapi: "3.2.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + post: + responses: + '200': + description: Ok + content: + Application/JSON: {} diff --git a/src/test/resources/checks/v32/format/OAR010/with-wrong-default-and-ref.json b/src/test/resources/checks/v32/format/OAR010/with-wrong-default-and-ref.json new file mode 100644 index 00000000..7b069a9d --- /dev/null +++ b/src/test/resources/checks/v32/format/OAR010/with-wrong-default-and-ref.json @@ -0,0 +1,28 @@ +{ + "openapi": "3.2.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore" + }, + "components": { + "responses": { + "XmlOnlyResponse": { + "description": "OK", + "content": { # Noncompliant {{OAR010: Should indicate the default response media type}} + "application/xml": {} + } + } + } + }, + "paths": { + "/pets": { + "post": { + "responses": { + "200": { + "$ref": "#/components/responses/XmlOnlyResponse" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v32/format/OAR010/with-wrong-default-and-ref.yaml b/src/test/resources/checks/v32/format/OAR010/with-wrong-default-and-ref.yaml new file mode 100644 index 00000000..69695377 --- /dev/null +++ b/src/test/resources/checks/v32/format/OAR010/with-wrong-default-and-ref.yaml @@ -0,0 +1,16 @@ +openapi: "3.2.0" +info: + version: 1.0.0 + title: Swagger Petstore +components: + responses: + XmlOnlyResponse: + description: OK + content: # Noncompliant {{OAR010: Should indicate the default response media type}} + application/xml: {} +paths: + /pets: + post: + responses: + '200': + $ref: '#/components/responses/XmlOnlyResponse' diff --git a/src/test/resources/checks/v32/parameters/OAR026/header-with-$total-with-defval-true.json b/src/test/resources/checks/v32/parameters/OAR026/header-with-$total-with-defval-true.json new file mode 100644 index 00000000..9f80a425 --- /dev/null +++ b/src/test/resources/checks/v32/parameters/OAR026/header-with-$total-with-defval-true.json @@ -0,0 +1,26 @@ +{ + "openapi" : "3.2.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/pets" : { + "get" : { + "parameters" : [ { + "in" : "header", + "name" : "$total", + "schema" : { + "type" : "boolean", + "default" : true + } + } ], + "responses" : { + "206" : { + "description" : "Ok" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v32/parameters/OAR026/header-with-$total-with-defval-true.yaml b/src/test/resources/checks/v32/parameters/OAR026/header-with-$total-with-defval-true.yaml new file mode 100644 index 00000000..8ef384dd --- /dev/null +++ b/src/test/resources/checks/v32/parameters/OAR026/header-with-$total-with-defval-true.yaml @@ -0,0 +1,16 @@ +openapi: "3.2.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + get: + parameters: + - in: header + name: $total + schema: + type: boolean + default: true + responses: + 206: + description: Ok diff --git a/src/test/resources/checks/v32/parameters/OAR026/plain-with-$total-without-defval.json b/src/test/resources/checks/v32/parameters/OAR026/plain-with-$total-without-defval.json index 82d1bd2c..72777f11 100644 --- a/src/test/resources/checks/v32/parameters/OAR026/plain-with-$total-without-defval.json +++ b/src/test/resources/checks/v32/parameters/OAR026/plain-with-$total-without-defval.json @@ -16,7 +16,7 @@ "type" : "string" } } - }, { # Noncompliant {{OAR026: The $total parameter default value should be false}} + }, { "in" : "query", "name" : "$total", "schema": { diff --git a/src/test/resources/checks/v32/parameters/OAR026/plain-with-$total-without-defval.yaml b/src/test/resources/checks/v32/parameters/OAR026/plain-with-$total-without-defval.yaml index fc709154..24b90ca9 100644 --- a/src/test/resources/checks/v32/parameters/OAR026/plain-with-$total-without-defval.yaml +++ b/src/test/resources/checks/v32/parameters/OAR026/plain-with-$total-without-defval.yaml @@ -12,7 +12,7 @@ paths: type: array items: type: string - - in: query # Noncompliant {{OAR026: The $total parameter default value should be false}} + - in: query name: $total schema: type: boolean diff --git a/src/test/resources/checks/v32/parameters/OAR026/post-with-$total-with-defval-true.json b/src/test/resources/checks/v32/parameters/OAR026/post-with-$total-with-defval-true.json new file mode 100644 index 00000000..d2712597 --- /dev/null +++ b/src/test/resources/checks/v32/parameters/OAR026/post-with-$total-with-defval-true.json @@ -0,0 +1,26 @@ +{ + "openapi" : "3.2.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "paths" : { + "/pets" : { + "post" : { + "parameters" : [ { + "in" : "query", + "name" : "$total", + "schema" : { + "type" : "boolean", + "default" : true + } + } ], + "responses" : { + "201" : { + "description" : "Created" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v32/parameters/OAR026/post-with-$total-with-defval-true.yaml b/src/test/resources/checks/v32/parameters/OAR026/post-with-$total-with-defval-true.yaml new file mode 100644 index 00000000..81041fd2 --- /dev/null +++ b/src/test/resources/checks/v32/parameters/OAR026/post-with-$total-with-defval-true.yaml @@ -0,0 +1,16 @@ +openapi: "3.2.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + post: + parameters: + - in: query + name: $total + schema: + type: boolean + default: true + responses: + 201: + description: Created diff --git a/src/test/resources/checks/v32/parameters/OAR026/with-$ref-unreferenced-with-$total-with-defval-true.json b/src/test/resources/checks/v32/parameters/OAR026/with-$ref-unreferenced-with-$total-with-defval-true.json new file mode 100644 index 00000000..76c2f81a --- /dev/null +++ b/src/test/resources/checks/v32/parameters/OAR026/with-$ref-unreferenced-with-$total-with-defval-true.json @@ -0,0 +1,30 @@ +{ + "openapi" : "3.2.0", + "info" : { + "version" : "1.0.0", + "title" : "Swagger Petstore" + }, + "components" : { + "parameters" : { + "total" : { + "in" : "query", + "name" : "$total", + "schema" : { + "type" : "boolean", + "default" : true + } + } + } + }, + "paths" : { + "/pets" : { + "get" : { + "responses" : { + "206" : { + "description" : "Ok" + } + } + } + } + } +} diff --git a/src/test/resources/checks/v32/parameters/OAR026/with-$ref-unreferenced-with-$total-with-defval-true.yaml b/src/test/resources/checks/v32/parameters/OAR026/with-$ref-unreferenced-with-$total-with-defval-true.yaml new file mode 100644 index 00000000..aefbef29 --- /dev/null +++ b/src/test/resources/checks/v32/parameters/OAR026/with-$ref-unreferenced-with-$total-with-defval-true.yaml @@ -0,0 +1,18 @@ +openapi: "3.2.0" +info: + version: 1.0.0 + title: Swagger Petstore +components: + parameters: + total: + in: query + name: $total + schema: + type: boolean + default: true +paths: + /pets: + get: + responses: + 206: + description: Ok diff --git a/src/test/resources/checks/v32/parameters/OAR026/with-$ref-with-$total-without-defval.json b/src/test/resources/checks/v32/parameters/OAR026/with-$ref-with-$total-without-defval.json index 0c9c05b7..11e2235a 100644 --- a/src/test/resources/checks/v32/parameters/OAR026/with-$ref-with-$total-without-defval.json +++ b/src/test/resources/checks/v32/parameters/OAR026/with-$ref-with-$total-without-defval.json @@ -16,7 +16,7 @@ } } }, - "total" : { # Noncompliant {{OAR026: The $total parameter default value should be false}} + "total" : { "in" : "query", "name" : "$total", "schema": { diff --git a/src/test/resources/checks/v32/parameters/OAR026/with-$ref-with-$total-without-defval.yaml b/src/test/resources/checks/v32/parameters/OAR026/with-$ref-with-$total-without-defval.yaml index 3ac00495..57681126 100644 --- a/src/test/resources/checks/v32/parameters/OAR026/with-$ref-with-$total-without-defval.yaml +++ b/src/test/resources/checks/v32/parameters/OAR026/with-$ref-with-$total-without-defval.yaml @@ -11,7 +11,7 @@ components: type: array items: type: string - total: # Noncompliant {{OAR026: The $total parameter default value should be false}} + total: in: query name: $total schema: