Comments (5)
I think I found a solution by calling validator._ajv.compile() myself:
let dt = dpMeta.dataType;
let schemaDt = validator.schema.components.schemas.dpDataTypeV1.oneOf.find(element => element.const == dt);
const vali = validator._ajv.compile(schemaDt["x-dpDataType"]);
const result = vali(val.val);
if (!result) {
console.log(`Error: value "${val.val}" doesn't match type ${dt}`);
}
from asyncapi-validator.
If I understood your problem correctly, the dpDataType_Bool
is a message, then you should have it defined in your schema as a message.
It should have a topic (channel) and operation.
Something like this:
channels:
data-types:
description: data-types messages
publish:
message:
name: dpDataType_Bool
payload:
oneOf:
- type: boolean
- type: integer
minimum: 0
maximum: 1
- type: string
oneOf:
- const: 'true'
- const: 'false'
- const: '0'
- const: '1'
va.validate('dpDataType_Bool', message, 'data-types', 'publish')
from asyncapi-validator.
the part
anyOf:
- type: integer
- type: number
- type: string
-...
is a variant value and only one little part of the value message. The value message can contain thousands of that variant value.
Another metadata message contains the definition which of the variant values of the value message has which concrete type. e.g. the anyof value 'Bool' in the metadata message uses x-dpDataType to reference dpDataType_Bool which means dpDataType_Bool needs to be used to validate the variant of the value message.
The point is just that I need to be able to verify one single schema part against a value and not a whole message, because the rest of the message is already validated. For a whole validation of the value message additional external information from the metadata message is needed which contains the datatype definition.
This seems to work with the lines I posted above.
When I'm back at work next year I can post a more exhaustive example, but the schema file alone without the validation script is around 900 lines long.
Thanks a lot for your validator, it is a big benefit for me!
from asyncapi-validator.
the solution is already contained in the answers above
from asyncapi-validator.
Glad you found the solution 👍 . Thanks for the feedback.
from asyncapi-validator.
Related Issues (20)
- Parser expects there to be a components/messages property in the main schema HOT 3
- unknown format "int32" is used in schema HOT 6
- Feature: Support for operationId HOT 3
- What's the preferred way to handle invalid messages? HOT 2
- Question - CLI wrapper HOT 3
- Package asyncapi is deprecated HOT 1
- JSON references to external files are not resolved correctly HOT 1
- How to use validate() with channel with parameter? HOT 4
- Expose TypeScript types HOT 1
- Bug: Validation fails with exclusiveMinimum / exclusiveMaximum in schema HOT 1
- Can find msgIdentifier for fallowing schema HOT 8
- [QA] how to get property from Error object? HOT 7
- Feature: Use ajv-formats to validate data formats
- Invalid message gets marked valid? HOT 3
- Question: Circular References in the scheme HOT 5
- How to determine message from topic, with variables? HOT 1
- Does not support avro in AsynApi HOT 1
- Question: How to validate messages with Headers HOT 1
- Does not support version 3.0.0 HOT 5
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 asyncapi-validator.