Git Product home page Git Product logo

Comments (16)

magicmatatjahu avatar magicmatatjahu commented on August 16, 2024 1

@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 :)

from parser-js.

magicmatatjahu avatar magicmatatjahu commented on August 16, 2024 1

@BOLT04 validateTags is better idea than update existing :)

from parser-js.

magicmatatjahu avatar magicmatatjahu commented on August 16, 2024 1

@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 :)

from parser-js.

github-actions avatar github-actions commented on August 16, 2024

This issue has been automatically marked as stale because it has not had recent activity 😴
It will be closed in 30 days if no further activity occurs. To unstale this issue, add a comment with detailed explanation.
Thank you for your contributions ❤️

from parser-js.

github-actions avatar github-actions commented on August 16, 2024

This issue has been automatically marked as stale because it has not had recent activity 😴
It will be closed in 30 days if no further activity occurs. To unstale this issue, add a comment with detailed explanation.
Thank you for your contributions ❤️

from parser-js.

github-actions avatar github-actions commented on August 16, 2024

This issue has been automatically marked as stale because it has not had recent activity 😴
It will be closed in 60 days if no further activity occurs. To unstale this issue, add a comment with detailed explanation.
Thank you for your contributions ❤️

from parser-js.

arjungarg07 avatar arjungarg07 commented on August 16, 2024

I am currently getting familiar with the codebase of parser-js and would like to give this issue a try soon.

from parser-js.

github-actions avatar github-actions commented on August 16, 2024

This issue has been automatically marked as stale because it has not had recent activity 😴
It will be closed in 60 days if no further activity occurs. To unstale this issue, add a comment with detailed explanation.
Thank you for your contributions ❤️

from parser-js.

derberg avatar derberg commented on August 16, 2024

@arjungarg07 still interested?

from parser-js.

arjungarg07 avatar arjungarg07 commented on August 16, 2024

@derberg Currently working on #265, would love if someone can follow up on this for now.

from parser-js.

github-actions avatar github-actions commented on August 16, 2024

This issue has been automatically marked as stale because it has not had recent activity 😴
It will be closed in 60 days if no further activity occurs. To unstale this issue, add a comment with detailed explanation.
Thank you for your contributions ❤️

from parser-js.

github-actions avatar github-actions commented on August 16, 2024

This issue has been automatically marked as stale because it has not had recent activity 😴
It will be closed in 60 days if no further activity occurs. To unstale this issue, add a comment with detailed explanation.
Thank you for your contributions ❤️

from parser-js.

BOLT04 avatar BOLT04 commented on August 16, 2024

Hi everyone 👋, is anyone working on this issue? if no one is working on it I'd like to contribute and give it a try 🙂.

@derberg I'm new to this codebase so could you tell me some details on where this issue touches? I did some digging and found the lib/customValidators.js file, so I'm guessing to pass the requirement "we need to add a custom validation of tags wherever tags are possible" we'd need to modify this file. This is used in the parser.js in this function:

async function customDocumentOperations(parsedJSON, asyncapiYAMLorJSON, initialFormat, options) {

I was thinking if we could simply modify the validateChannels function, adding code to validate if there are duplicate tags, something like this:

chnlsMap.forEach((val, key) => {
    // ...
    Object.keys(val).forEach((channelOperation) => {
      const valueArr = val[channelOperation].tags.map(item => item.name);
      const hasDuplicateTags = valueArr.some((item, idx) => valueArr.indexOf(item) != idx);
      
      if (hasDuplicateTags) {
        throw new ParserError({
          type: validationError,
          title: `Invalid channel \"${channelOperation}\", there can't be any duplicate tags`,
          parsedJSON,
          validationErrors: groupValidationErrors(
            'channels',
            'channels contains duplicate tags',
            new Map(), // TODO: Not sure what would go here
          ),
        });
      }
    });
  });

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

Does this refer to the parsedJSON parameter of the validateChannels function, for example? If it does, can you explain further why we can't use it?

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?

Feel free to give me any feedback on what I suggested, I could be looking at this issue completely wrong 😅

from parser-js.

BOLT04 avatar BOLT04 commented on August 16, 2024

@magicmatatjahu would it be better to add a validateTags function with all those places tags can occur, like this:

async function customDocumentOperations(parsedJSON, asyncapiYAMLorJSON, initialFormat, options) {
  validateServerVariables(parsedJSON, asyncapiYAMLorJSON, initialFormat);
  validateServerSecurity(parsedJSON, asyncapiYAMLorJSON, initialFormat, SPECIAL_SECURITY_TYPES);

  if (!parsedJSON.channels) return;

+ validateTags(parsedJSON, asyncapiYAMLorJSON, initialFormat);
  validateChannels(parsedJSON, asyncapiYAMLorJSON, initialFormat);
  validateOperationId(parsedJSON, asyncapiYAMLorJSON, initialFormat, OPERATIONS);

  await customComponentsMsgOperations(parsedJSON, asyncapiYAMLorJSON, initialFormat, options);
  await customChannelsOperations(parsedJSON, asyncapiYAMLorJSON, initialFormat, options);
}

or modify the existing validate functions and create new ones if they don't exist (e.g. I didn't find validation for OperationTrait)?

from parser-js.

BOLT04 avatar BOLT04 commented on August 16, 2024

@magicmatatjahu can a message and operation object be present in another object other than channels? If not then I could leverage a loop iterating channels and validate message and operation tags there.

from parser-js.

asyncapi-bot avatar asyncapi-bot commented on August 16, 2024

🎉 This issue has been resolved in version 1.11.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

from parser-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.