diff --git a/src/main/java/apiquality/sonar/asyncapi/checks/RulesLists.java b/src/main/java/apiquality/sonar/asyncapi/checks/RulesLists.java
index 968aedb..7f879cc 100644
--- a/src/main/java/apiquality/sonar/asyncapi/checks/RulesLists.java
+++ b/src/main/java/apiquality/sonar/asyncapi/checks/RulesLists.java
@@ -72,7 +72,8 @@ public static ListWhen a message payload (AsyncAPI 2) or a Multi-Format Schema Object (AsyncAPI 3, on message.payload or a components.schemas entry) declares an Avro schemaFormat — i.e. its value contains application/vnd.apache.avro — that value must be exactly application/vnd.apache.avro;version=1.9.0.
Version 1.9.0 is the standard Avro schema version and appears in every example throughout the Style Guide. Any other version string, or a missing version, is reported as an issue. schemaFormat values that are not Avro at all (e.g. a JSON Schema schemaFormat) are out of scope for this rule.
+asyncapi: '2.6.0' +info: + title: Carga API + version: '1.0.0' +channels: + carga: + subscribe: + message: + schemaFormat: 'application/vnd.apache.avro;version=1.8.0' + payload: + type: record + name: CargaValue + namespace: com.example.avro + fields: + - name: id + type: string ++
+asyncapi: '2.6.0' +info: + title: Carga API + version: '1.0.0' +channels: + carga: + subscribe: + message: + schemaFormat: 'application/vnd.apache.avro;version=1.9.0' + payload: + type: record + name: CargaValue + namespace: com.example.avro + fields: + - name: id + type: string ++
+asyncapi: 3.0.0 +info: + title: Carga API + version: 1.0.0 +channels: + carga: + address: carga + messages: + CargaMessage: + payload: + schemaFormat: 'application/vnd.apache.avro;version=1.8.0' + schema: + type: record + name: CargaValue + namespace: com.example.avro + fields: + - name: id + type: string ++
+asyncapi: 3.0.0 +info: + title: Carga API + version: 1.0.0 +channels: + carga: + address: carga + messages: + CargaMessage: + payload: + schemaFormat: 'application/vnd.apache.avro;version=1.9.0' + schema: + type: record + name: CargaValue + namespace: com.example.avro + fields: + - name: id + type: string +diff --git a/src/main/resources/org/sonar/l10n/asyncapi/rules/asyncapi/schemas/AAR056.json b/src/main/resources/org/sonar/l10n/asyncapi/rules/asyncapi/schemas/AAR056.json new file mode 100644 index 0000000..7d5c09a --- /dev/null +++ b/src/main/resources/org/sonar/l10n/asyncapi/rules/asyncapi/schemas/AAR056.json @@ -0,0 +1,13 @@ +{ + "title": "AAR056 - AvroSchemaFormat - The schemaFormat must be application/vnd.apache.avro;version=1.9.0", + "type": "BUG", + "status": "ready", + "remediation": { + "func": "Constant\/Issue", + "constantCost": "5mn" + }, + "tags": [ + "schemas" + ], + "defaultSeverity": "MAJOR" +} diff --git a/src/main/resources/org/sonar/l10n/es/asyncapi/rules/asyncapi/schemas/AAR056.html b/src/main/resources/org/sonar/l10n/es/asyncapi/rules/asyncapi/schemas/AAR056.html new file mode 100644 index 0000000..033e8ba --- /dev/null +++ b/src/main/resources/org/sonar/l10n/es/asyncapi/rules/asyncapi/schemas/AAR056.html @@ -0,0 +1,82 @@ +
Cuando el payload de un mensaje (AsyncAPI 2) o un Multi-Format Schema Object (AsyncAPI 3, en message.payload o en una entrada de components.schemas) declara un schemaFormat de Avro — es decir, su valor contiene application/vnd.apache.avro — ese valor debe ser exactamente application/vnd.apache.avro;version=1.9.0.
La versión 1.9.0 es la versión estándar de Avro y aparece en todos los ejemplos de la GuÃa de Estilo. Cualquier otra versión, o la ausencia de versión, se reporta como incidencia. Los valores de schemaFormat que no sean de Avro (por ejemplo, un schemaFormat de JSON Schema) quedan fuera del alcance de esta regla.
+asyncapi: '2.6.0' +info: + title: Carga API + version: '1.0.0' +channels: + carga: + subscribe: + message: + schemaFormat: 'application/vnd.apache.avro;version=1.8.0' + payload: + type: record + name: CargaValue + namespace: com.example.avro + fields: + - name: id + type: string ++
+asyncapi: '2.6.0' +info: + title: Carga API + version: '1.0.0' +channels: + carga: + subscribe: + message: + schemaFormat: 'application/vnd.apache.avro;version=1.9.0' + payload: + type: record + name: CargaValue + namespace: com.example.avro + fields: + - name: id + type: string ++
+asyncapi: 3.0.0 +info: + title: Carga API + version: 1.0.0 +channels: + carga: + address: carga + messages: + CargaMessage: + payload: + schemaFormat: 'application/vnd.apache.avro;version=1.8.0' + schema: + type: record + name: CargaValue + namespace: com.example.avro + fields: + - name: id + type: string ++
+asyncapi: 3.0.0 +info: + title: Carga API + version: 1.0.0 +channels: + carga: + address: carga + messages: + CargaMessage: + payload: + schemaFormat: 'application/vnd.apache.avro;version=1.9.0' + schema: + type: record + name: CargaValue + namespace: com.example.avro + fields: + - name: id + type: string +diff --git a/src/main/resources/org/sonar/l10n/es/asyncapi/rules/asyncapi/schemas/AAR056.json b/src/main/resources/org/sonar/l10n/es/asyncapi/rules/asyncapi/schemas/AAR056.json new file mode 100644 index 0000000..6d6927d --- /dev/null +++ b/src/main/resources/org/sonar/l10n/es/asyncapi/rules/asyncapi/schemas/AAR056.json @@ -0,0 +1,13 @@ +{ + "title": "AAR056 - AvroSchemaFormat - El schemaFormat debe ser application/vnd.apache.avro;version=1.9.0", + "type": "BUG", + "status": "ready", + "remediation": { + "func": "Constant\/Issue", + "constantCost": "5mn" + }, + "tags": [ + "schemas" + ], + "defaultSeverity": "MAJOR" +} diff --git a/src/test/java/org/sonar/samples/asyncapi/checks/schemas/AAR056AvroSchemaFormatCheckTest.java b/src/test/java/org/sonar/samples/asyncapi/checks/schemas/AAR056AvroSchemaFormatCheckTest.java new file mode 100644 index 0000000..4232340 --- /dev/null +++ b/src/test/java/org/sonar/samples/asyncapi/checks/schemas/AAR056AvroSchemaFormatCheckTest.java @@ -0,0 +1,66 @@ +package org.sonar.samples.asyncapi.checks.schemas; + +import org.junit.Before; +import org.junit.Test; +import org.sonar.api.rule.Severity; +import org.sonar.api.rules.RuleType; +import org.sonar.samples.asyncapi.BaseCheckTest; + +import apiquality.sonar.asyncapi.checks.schemas.AAR056AvroSchemaFormatCheck; + +public class AAR056AvroSchemaFormatCheckTest extends BaseCheckTest { + + @Before + public void init() { + ruleName = "AAR056"; + check = new AAR056AvroSchemaFormatCheck(); + v2Path = getV2Path("schemas"); + v3Path = getV3Path("schemas"); + v31Path = getV31Path("schemas"); + } + + @Test + public void verifyV2Valid() { + verifyV2("valid.yaml"); + } + + @Test + public void verifyV2WrongVersion() { + verifyV2("wrong-version.yaml"); + } + + @Test + public void verifyV2NonAvroSchemaFormat() { + verifyV2("non-avro-schema-format.yaml"); + } + + @Test + public void verifyV3Valid() { + verifyV3("valid.yaml"); + } + + @Test + public void verifyV3WrongVersion() { + verifyV3("wrong-version.yaml"); + } + + @Test + public void verifyV3NonAvroSchemaFormat() { + verifyV3("non-avro-schema-format.yaml"); + } + + @Test + public void verifyV31Valid() { + verifyV31("valid.yaml"); + } + + @Test + public void verifyV31WrongVersion() { + verifyV31("wrong-version.yaml"); + } + + @Override + public void verifyRule() { + assertRuleProperties("AAR056 - AvroSchemaFormat - The schemaFormat must be application/vnd.apache.avro;version=1.9.0", RuleType.BUG, Severity.MAJOR, tags("schemas")); + } +} diff --git a/src/test/resources/checks/v2/schemas/AAR056/non-avro-schema-format.yaml b/src/test/resources/checks/v2/schemas/AAR056/non-avro-schema-format.yaml new file mode 100644 index 0000000..cf3f96e --- /dev/null +++ b/src/test/resources/checks/v2/schemas/AAR056/non-avro-schema-format.yaml @@ -0,0 +1,15 @@ +asyncapi: '2.6.0' +info: + title: Avro Schema Format Non Avro V2 + version: '1.0.0' +channels: + carga: + subscribe: + operationId: receiveCarga + message: + schemaFormat: 'application/schema+json;version=draft-07' + payload: + type: object + properties: + id: + type: string diff --git a/src/test/resources/checks/v2/schemas/AAR056/valid.yaml b/src/test/resources/checks/v2/schemas/AAR056/valid.yaml new file mode 100644 index 0000000..422196e --- /dev/null +++ b/src/test/resources/checks/v2/schemas/AAR056/valid.yaml @@ -0,0 +1,27 @@ +asyncapi: '2.6.0' +info: + title: Avro Schema Format Valid V2 + version: '1.0.0' +channels: + carga: + subscribe: + operationId: receiveCarga + message: + schemaFormat: 'application/vnd.apache.avro;version=1.9.0' + payload: + type: record + name: CargaValue + namespace: com.example.avro + fields: + - name: id + type: string +components: + schemas: + CargaComponent: + schemaFormat: 'application/vnd.apache.avro;version=1.9.0' + type: record + name: CargaComponent + namespace: com.example.avro + fields: + - name: id + type: string diff --git a/src/test/resources/checks/v2/schemas/AAR056/wrong-version.yaml b/src/test/resources/checks/v2/schemas/AAR056/wrong-version.yaml new file mode 100644 index 0000000..26be003 --- /dev/null +++ b/src/test/resources/checks/v2/schemas/AAR056/wrong-version.yaml @@ -0,0 +1,27 @@ +asyncapi: '2.6.0' +info: + title: Avro Schema Format Wrong Version V2 + version: '1.0.0' +channels: + carga: + subscribe: + operationId: receiveCarga + message: + schemaFormat: 'application/vnd.apache.avro;version=1.8.0' # Noncompliant {{AAR056: The 'schemaFormat' value 'application/vnd.apache.avro;version=1.8.0' must be exactly 'application/vnd.apache.avro;version=1.9.0' when the payload uses Avro}} + payload: + type: record + name: CargaValue + namespace: com.example.avro + fields: + - name: id + type: string +components: + schemas: + CargaComponent: + schemaFormat: 'application/vnd.apache.avro' # Noncompliant {{AAR056: The 'schemaFormat' value 'application/vnd.apache.avro' must be exactly 'application/vnd.apache.avro;version=1.9.0' when the payload uses Avro}} + type: record + name: CargaComponent + namespace: com.example.avro + fields: + - name: id + type: string diff --git a/src/test/resources/checks/v3/schemas/AAR056/non-avro-schema-format.yaml b/src/test/resources/checks/v3/schemas/AAR056/non-avro-schema-format.yaml new file mode 100644 index 0000000..83b7102 --- /dev/null +++ b/src/test/resources/checks/v3/schemas/AAR056/non-avro-schema-format.yaml @@ -0,0 +1,16 @@ +asyncapi: 3.0.0 +info: + title: Avro Schema Format Non Avro V3 + version: 1.0.0 +channels: + carga: + address: carga + messages: + CargaMessage: + payload: + schemaFormat: 'application/schema+json;version=draft-07' + schema: + type: object + properties: + id: + type: string diff --git a/src/test/resources/checks/v3/schemas/AAR056/valid.yaml b/src/test/resources/checks/v3/schemas/AAR056/valid.yaml new file mode 100644 index 0000000..9ea6785 --- /dev/null +++ b/src/test/resources/checks/v3/schemas/AAR056/valid.yaml @@ -0,0 +1,29 @@ +asyncapi: 3.0.0 +info: + title: Avro Schema Format Valid V3 + version: 1.0.0 +channels: + carga: + address: carga + messages: + CargaMessage: + payload: + schemaFormat: 'application/vnd.apache.avro;version=1.9.0' + schema: + type: record + name: CargaValue + namespace: com.example.avro + fields: + - name: id + type: string +components: + schemas: + CargaComponent: + schemaFormat: 'application/vnd.apache.avro;version=1.9.0' + schema: + type: record + name: CargaComponent + namespace: com.example.avro + fields: + - name: id + type: string diff --git a/src/test/resources/checks/v3/schemas/AAR056/wrong-version.yaml b/src/test/resources/checks/v3/schemas/AAR056/wrong-version.yaml new file mode 100644 index 0000000..c164c91 --- /dev/null +++ b/src/test/resources/checks/v3/schemas/AAR056/wrong-version.yaml @@ -0,0 +1,29 @@ +asyncapi: 3.0.0 +info: + title: Avro Schema Format Wrong Version V3 + version: 1.0.0 +channels: + carga: + address: carga + messages: + CargaMessage: + payload: + schemaFormat: 'application/vnd.apache.avro;version=1.8.0' # Noncompliant {{AAR056: The 'schemaFormat' value 'application/vnd.apache.avro;version=1.8.0' must be exactly 'application/vnd.apache.avro;version=1.9.0' when the payload uses Avro}} + schema: + type: record + name: CargaValue + namespace: com.example.avro + fields: + - name: id + type: string +components: + schemas: + CargaComponent: + schemaFormat: 'application/vnd.apache.avro' # Noncompliant {{AAR056: The 'schemaFormat' value 'application/vnd.apache.avro' must be exactly 'application/vnd.apache.avro;version=1.9.0' when the payload uses Avro}} + schema: + type: record + name: CargaComponent + namespace: com.example.avro + fields: + - name: id + type: string diff --git a/src/test/resources/checks/v31/schemas/AAR056/valid.yaml b/src/test/resources/checks/v31/schemas/AAR056/valid.yaml new file mode 100644 index 0000000..06e3d39 --- /dev/null +++ b/src/test/resources/checks/v31/schemas/AAR056/valid.yaml @@ -0,0 +1,18 @@ +asyncapi: 3.1.0 +info: + title: Avro Schema Format Valid V31 + version: 1.0.0 +channels: + carga: + address: carga + messages: + CargaMessage: + payload: + schemaFormat: 'application/vnd.apache.avro;version=1.9.0' + schema: + type: record + name: CargaValue + namespace: com.example.avro + fields: + - name: id + type: string diff --git a/src/test/resources/checks/v31/schemas/AAR056/wrong-version.yaml b/src/test/resources/checks/v31/schemas/AAR056/wrong-version.yaml new file mode 100644 index 0000000..c3c8ce2 --- /dev/null +++ b/src/test/resources/checks/v31/schemas/AAR056/wrong-version.yaml @@ -0,0 +1,18 @@ +asyncapi: 3.1.0 +info: + title: Avro Schema Format Wrong Version V31 + version: 1.0.0 +channels: + carga: + address: carga + messages: + CargaMessage: + payload: + schemaFormat: 'application/vnd.apache.avro;version=1.8.0' # Noncompliant {{AAR056: The 'schemaFormat' value 'application/vnd.apache.avro;version=1.8.0' must be exactly 'application/vnd.apache.avro;version=1.9.0' when the payload uses Avro}} + schema: + type: record + name: CargaValue + namespace: com.example.avro + fields: + - name: id + type: string