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

Util classes for building and validating schema + leia-common #11

Merged
merged 13 commits into from
Dec 3, 2024

Conversation

abhigun
Copy link
Contributor

@abhigun abhigun commented Nov 28, 2024

  • Introduced leia-common module to host all the common utils classes. Moved the SchemaValidationUtils and SchemaException classes from leia-schema-validator to this module.
  • Replaced SchemaValidatable annotation with a more generalized SchemaDefinition annotation for marking schema classes.
  • Added annotation classes for the Qualifiers( PII, Encrypted, ShortLived) that can be added on the members of the Schema class.
  • Introduced two new classes SchemaBuilder and SchemaPayloadValidator
    - SchemaBuilder: For building the schema request against a class annotated with SchemaDefinition
    - SchemaPayloadValidator: For validating a schema json payload against a specified SchemaKey
  • Addressed issues in handling plain Object and Primitive Class types in SchemaValidationUtils
  • Updated dependencies in leia-core and leia-schema-validator to include leia-common
  • Upgraded versions across all POM files for the new release

Copy link
Member

@koushikr koushikr left a comment

Choose a reason for hiding this comment

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

Added a few comments. A couple of high level questions, should we change the SchemaValidatable annotation to look like the following?

`@Target({ElementType.TYPE})
@retention(RetentionPolicy.RUNTIME)
public @interface SchemaDefinition {

SchemaType type() default SchemaType.JSON;

SchemaValidationType validationType() default SchemaValidationType.MATCHING;

SchemaState state() default SchemaState.CREATED;

String schemaName();

String versionId();

String namespace();

String description() default "";

Class<?>[] transformationTargets();

}`

And use the above to build the CreateSchemaRequest itself?

Roughly I'm thinking,

`
@OverRide
public Optional getDetails(Class<?> klass) {
if (null == klass) {
log.debug("No klass definition provided. Can't convert");
return Optional.empty();
}
final var schemaDefinition = klass.getAnnotation(SchemaDefinition.class);
if (null == schemaDefinition) {
log.debug("The klass {} is not annotated with SchemaDefinition. Can't convert", klass.getSimpleName());
return Optional.empty();
}
return Optional.of(CreateSchemaRequest.builder()
.schemaType(schemaDefinition.type())
.validationType(schemaDefinition.validationType())
.description(schemaDefinition.description())
.schemaName(schemaDefinition.schemaName())
.namespace(schemaDefinition.namespace())
.attributes(
FieldUtils.getAllFields(klass)
.stream()
.map(SchemaAttributeUtils::getAttribute)
.collect(Collectors.toSet())
)
.transformationTargets(
SchemaAttributeUtils.getTransformationTargets(
klass,
schemaDefinition.transformationTargets()
)
)
.build());
}

`

Also should we do SchemaUtils (Or SchemaAttributeUtils) as part of the schema-validator itself - also the ValidationUtils must move here? leia-client can use the validator as a dependency then?

.findFirst();
}

public Set<QualifierInfo> getQualifierInfo(final Type type) {
Copy link
Member

Choose a reason for hiding this comment

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

Same, rename this to getQualifer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, changed it to getQualifiers

import java.util.Set;

@UtilityClass
public class TestUtils {
Copy link
Member

Choose a reason for hiding this comment

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

Rename this to LeiaTestUtils

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Member

@koushikr koushikr left a comment

Choose a reason for hiding this comment

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

Added a few comments

@abhigun abhigun changed the title Util classes for building and validating schema json Util classes for building and validating schema + leia-common Dec 2, 2024
@koushikr koushikr merged commit 5b7f8b9 into grookage:master Dec 3, 2024
1 check passed
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.

2 participants