From a6e34aaf644bfec12421f6386d5d3dccc3e634fd Mon Sep 17 00:00:00 2001 From: Ivan Garcia Sainz-Aja Date: Fri, 6 Jan 2023 11:23:26 +0100 Subject: [PATCH] fix: parsing fields annotations --- .../github/zenwave360/zdl/antlr/ZdlListenerImpl.java | 10 +++++++--- src/test/resources/simple.zdl | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/github/zenwave360/zdl/antlr/ZdlListenerImpl.java b/src/main/java/io/github/zenwave360/zdl/antlr/ZdlListenerImpl.java index b6f6b44..164c85a 100644 --- a/src/main/java/io/github/zenwave360/zdl/antlr/ZdlListenerImpl.java +++ b/src/main/java/io/github/zenwave360/zdl/antlr/ZdlListenerImpl.java @@ -167,7 +167,7 @@ public void enterField(io.github.zenwave360.zdl.antlr.ZdlParser.FieldContext ctx var isEntity = false; // TODO var isArray = ctx.field_type().ARRAY() != null; var validations = processFieldValidations(ctx.field_validations()); - currentStack.peek().appendTo("fields", name, new FluentMap() + var field = new FluentMap() .with("name", name) .with("type", type) .with("javadoc", javadoc) @@ -176,7 +176,8 @@ public void enterField(io.github.zenwave360.zdl.antlr.ZdlParser.FieldContext ctx .with("isEntity", isEntity) .with("isArray", isArray) .with("options", new FluentMap()) - .with("validations", validations)); + .with("validations", validations); + currentStack.peek().appendTo("fields", name, field); var entityName = currentStack.peek().get("name"); var entityLocation = currentCollection + "." + entityName + ".fields." + name; @@ -184,6 +185,8 @@ public void enterField(io.github.zenwave360.zdl.antlr.ZdlParser.FieldContext ctx model.setLocation(entityLocation + ".name", getLocations(ctx.field_name())); model.setLocation(entityLocation + ".type", getLocations(ctx.field_type())); model.setLocation(entityLocation + ".javadoc", getLocations(first(ctx.javadoc(), ctx.suffix_javadoc()))); + + currentStack.push(field); } private Map processFieldValidations(List field_validations) { @@ -203,13 +206,14 @@ private Map processFieldValidations(List(parentEntityFields.values()).get(parentEntityFields.size() - 1); String entityName = parent.field_type().ID().getText(); diff --git a/src/test/resources/simple.zdl b/src/test/resources/simple.zdl index 1c2114c..d1ca808 100644 --- a/src/test/resources/simple.zdl +++ b/src/test/resources/simple.zdl @@ -31,7 +31,7 @@ apis { @array([1, 2, 3]) @array2(1, 2, 3) entity Customer { - username String required unique min(5) + @dbref username String required unique min(5) tags String[] email String required unique max(MAX_LENGTH) pattern(/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/) }