Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(Schema): Add Schema-related utils #928

Merged
merged 1 commit into from
Mar 13, 2024

Conversation

lordrip
Copy link
Member

@lordrip lordrip commented Mar 12, 2024

Context

In order to support OneOf schemas, we need two functions:

  • resolveRefIfNeeded: Resolve the $ref keyword against the definition dictionary
  • weightSchemaProperties: Compare a model against a list of OneOf schemas to check what would be the applied schema.

relates: #560

@lordrip lordrip linked an issue Mar 12, 2024 that may be closed by this pull request
In order to support `OneOf` schemas, we need two functions:

* `resolveRefIfNeeded`: Resolve the `$ref` keyword against the
  definition dictionary
* `weightSchemaProperties`: Compare a `model` against a list of `OneOf`
  schemas to check what would be the applied schema.

fix: KaotoIO#560
import { isDefined } from './is-defined';
import { resolveRefIfNeeded } from './resolve-ref-if-needed';

export const weightSchemaProperties = (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lordrip Could you please explain what would the weightSchemaProperties points result used for? Having a bit difficulties to wrap my head around this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great question, I hoped for the function to be more clear, but seems it is not an easy task 😅

The motivation for the function is to compare a model against a schema to get points based on how many matches we get.

As an example:
Model

{
  refErrorHandler: {
    id: 'ref-error-handler-id',
    ref: 'reference',
  }
}

Schema

{
  type: 'object',
  properties: {
    refErrorHandler: {
      type: 'object'
      properties: {
        id: {
          type: 'string'
        },
        ref: {
          type: 'string'
        }
      }
    }
  }
}

This would match the root refErrorHandler property but also its children properties and the types, returning a high points count.

Compared to a different schema, it would return fewer points:
Schema

{
  type: 'object',
  properties: {
    refErrorHandler: {
      type: 'string'
    }
  }
}

This function will be used in an upcoming PR, but in order to reduce the diff, I'm delivering it in pieces.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation!

@lordrip lordrip merged commit 5d2c790 into KaotoIO:main Mar 13, 2024
9 checks passed
@lordrip lordrip deleted the chore/add-schema-utils branch March 13, 2024 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Camel Route errorHandler
2 participants