Comments (16)
@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.
@BOLT04 validateTags
is better idea than update existing :)
from parser-js.
@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.
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.
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.
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.
I am currently getting familiar with the codebase of parser-js
and would like to give this issue a try soon.
from parser-js.
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 still interested?
from parser-js.
@derberg Currently working on #265, would love if someone can follow up on this for now.
from parser-js.
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.
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.
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:
Line 178 in e8c72d7
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.
@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.
@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.
🎉 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)
- Any reason why API docs are not generated for the library? HOT 1
- Certain suggestions for the new API HOT 2
- Payload property named message breaks with null value HOT 7
- Reference resolves to more than one schema HOT 11
- cannot find module for type declaration, in v3-next-major-spec HOT 1
- Message ID doesn't exist on reply level HOT 16
- javascript map() function doesn't work on SecurityRequirements object. HOT 5
- Parser do not validate and throw error when `parameters` are provided but address is null HOT 4
- Parser do not validate if channel that is referenced in reply with location has `null` in address HOT 6
- Parser returns `undefined` when there's bindings in message HOT 1
- Parser fails to throw an error when i provide an invalid asyncapi file HOT 1
- Inconsistence Parser Methods HOT 2
- .id() doesn't work for `$ref`ed components HOT 1
- Parser fails to return Operation Channel HOT 1
- document.allSchemas() returns "duplicated" schemas HOT 8
- Parser fails to return Operation HOT 1
- Upgrade parser in `next-major-spec` to use latest `@asyncapi/[email protected]`
- Some Spectral Rules for spec v3 should run after resolving references HOT 1
- The automated release is failing 🚨
- Inconsistent `range` Values in Error Diagnostics for Different AsyncAPI File Formats HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from parser-js.