parser-js: Add validation of duplicated tags

Reason/Context

We need to validate if users did not provide 2 tags with the same name on the same level. Tags can be provided in many objects, we should avoid duplicates only in a given object not across the whole document.

Description

https://json-schema.org/understanding-json-schema/reference/combining.html Unfortunately, now the schema will reject everything. This is because the Properties refers to the entire schema. And that entire schema includes no properties, and knows nothing about the properties in the subschemas inside of the allOf array. This shortcoming is perhaps one of the biggest surprises of the combining operations in JSON schema: it does not behave like inheritance in an object-oriented language. There are some proposals to address this in the next version of the JSON schema specification.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (8 by maintainers)

Commits related to this issue

Most upvoted comments

@BOLT04 At the moment message and operation can be only present in channel object. You can extend the function for channels validation, but your current implementation with a separate function just for tags is a better idea in my opinion. If you look at current validator implementation, you will see that channels validation checks things which can only be defined for channel, hence one validation place - tags can be in different places so separate function is better 😃

@BOLT04 validateTags is better idea than update existing 😃

@BOLT04 Hi! Yes, you’re thinking right about place where new code for validation should be 😃

I don’t think we can do it with JSON Schema.

Refers to the plain JSON Schema (https://json-schema.org/), not to our Schema (in the meaning of AsyncAPI), so of course you can use parsedJSON, because it is exactly AsyncAPI document saved as JSON 😃

I was also thinking we should add some test cases in the parse_tests.js file and perhaps tags_test.js, what do you think? Would it be possible to use the examples from asyncapi/tck?

Yes, tests will be needed, if you want you can use the test cases from tck. We have issue to use all cases from tck, but not now so feel free to use them.

Also, please have in mind that tags don’t occur only in channels (to be precise in the publish | subscribe fields) but also in the other parts of AsyncAPI spec:

  • in root of doc
  • in Operation (subscribe | publish) object
  • in OperationTrait object
  • in Message Object
  • in MessageTrait Object

so probably running validation in the validateChannels won’t be enough.

Also, your example solution is good 👍🏼 Go ahead with implementation, of course, if you want 😃