Giter Site home page Giter Site logo

Comments (5)

nospam2000 avatar nospam2000 commented on May 27, 2024

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.

WaleedAshraf avatar WaleedAshraf commented on May 27, 2024

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.

nospam2000 avatar nospam2000 commented on May 27, 2024

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.

nospam2000 avatar nospam2000 commented on May 27, 2024

the solution is already contained in the answers above

from asyncapi-validator.

WaleedAshraf avatar WaleedAshraf commented on May 27, 2024

Glad you found the solution 👍 . Thanks for the feedback.

from asyncapi-validator.

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.