Repository: asyncapi/parser-js
Pull request #999 (2024-06-03 10:57:27)

fix: remove unexpected support for traits at Channel Object level
**Description**

Fixes https://github.com/asyncapi/parser-js/issues/996

The current AsyncAPI spec (v3.0.0) support traits only at:

- [Message Object level](https://www.asyncapi.com/docs/reference/specification/v3.0.0#messageTraitObject)
- [Operation Object level](https://www.asyncapi.com/docs/reference/specification/v3.0.0#operationTraitObject)

Channels traits are not supported, however for some reason we added such support in our Parser code. 
This was causing a bug (linked above).

**Related issue(s)**
https://github.com/asyncapi/parser-js/issues/996

sonarcloud[bot]: ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=asyncapi_parser-js&pullRequest=999) **Quality Gate passed**  
Issues  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=asyncapi_parser-js&pullRequest=999&resolved=false&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=asyncapi_parser-js&pullRequest=999&resolutions=WONTFIX)

Measures  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=asyncapi_parser-js&pullRequest=999&resolved=false&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/no-data-16px.png '') No data about Coverage  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [1.1% Duplication on New Code](https://sonarcloud.io/component_measures?id=asyncapi_parser-js&pullRequest=999&metric=new_duplicated_lines_density&view=list)  
  
[See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=asyncapi_parser-js&pullRequest=999)


smoya: We can't merge this PR until https://github.com/asyncapi/parser-js/issues/1001 gets solved. Working on it.
sonarcloud[bot]: ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=asyncapi_parser-js&pullRequest=999) **Quality Gate passed**  
Issues  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=asyncapi_parser-js&pullRequest=999&resolved=false&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=asyncapi_parser-js&pullRequest=999&resolutions=WONTFIX)

Measures  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=asyncapi_parser-js&pullRequest=999&resolved=false&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/no-data-16px.png '') No data about Coverage  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [1.1% Duplication on New Code](https://sonarcloud.io/component_measures?id=asyncapi_parser-js&pullRequest=999&metric=new_duplicated_lines_density&view=list)  
  
[See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=asyncapi_parser-js&pullRequest=999)


sonarcloud[bot]: ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=asyncapi_parser-js&pullRequest=999) **Quality Gate passed**  
Issues  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=asyncapi_parser-js&pullRequest=999&resolved=false&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=asyncapi_parser-js&pullRequest=999&resolutions=WONTFIX)

Measures  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=asyncapi_parser-js&pullRequest=999&resolved=false&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/no-data-16px.png '') No data about Coverage  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [1.1% Duplication on New Code](https://sonarcloud.io/component_measures?id=asyncapi_parser-js&pullRequest=999&metric=new_duplicated_lines_density&view=list)  
  
[See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=asyncapi_parser-js&pullRequest=999)


smoya: /rtm

Patch:
diff --git a/src/custom-operations/apply-traits.ts b/src/custom-operations/apply-traits.ts
index 6d99453..1c2ff7e 100644
--- a/src/custom-operations/apply-traits.ts
+++ b/src/custom-operations/apply-traits.ts
@@ -51,11 +51,9 @@ function applyTraitsToObjectV2(value: Record<string, unknown>) {
 const v3TraitPaths = [
   // operations
   '$.operations.*',
-  '$.operations.*.channel.*',
   '$.operations.*.channel.messages.*',
   '$.operations.*.messages.*',
   '$.components.operations.*',
-  '$.components.operations.*.channel.*',
   '$.components.operations.*.channel.messages.*',
   '$.components.operations.*.messages.*',
   // Channels


Test patch:
diff --git a/test/validate.spec.ts b/test/validate.spec.ts
index 6a34585..60b8573 100644
--- a/test/validate.spec.ts
+++ b/test/validate.spec.ts
@@ -51,4 +51,47 @@ describe('validate()', function() {
     expect(hasErrorDiagnostic(diagnostics)).toEqual(false);
     expect(hasWarningDiagnostic(diagnostics)).toEqual(true);
   });
+
+  // See https://github.com/asyncapi/parser-js/issues/996
+  it('user case - null channel address should not make operation traits appliance fail', async function() {
+    const documentRaw = {
+      asyncapi: '3.0.0',
+      info: {
+        title: 'Nexus Server API',
+        version: '1.0.0'
+      },
+      channels: {
+        Exchange: {
+          address: null,
+          messages: {
+            FooEvent: {
+              name: 'FooEvent',
+              title: 'Tenant Created',
+              contentType: 'application/json',
+              payload: {
+                type: 'string'
+              }
+            }
+          }
+        }
+      },
+      operations: {
+        sendTenantCreated: {
+          title: 'Send tenant created event to client',
+          action: 'send',
+          channel: {
+            $ref: '#/channels/Exchange'
+          },
+          messages: [
+            {
+              $ref: '#/channels/Exchange/messages/FooEvent'
+            }
+          ]
+        }
+      }
+    };
+    const { document, diagnostics } = await parser.parse(documentRaw, { validateOptions: { allowedSeverity: { warning: false } } });
+    console.log(diagnostics);
+    expect(diagnostics).toHaveLength(0);
+  });
 });