From e1a5f1e5c4d198b864ffbee683937bb80a80a313 Mon Sep 17 00:00:00 2001 From: "Matteo Franci a.k.a. Fugerit" Date: Fri, 15 Nov 2024 09:26:48 +0100 Subject: [PATCH] Add enumeration and format to field attributes #97 Added attributes : 'openapiFormat' 'openapiEnumeration' To field attribute exampleData renamed to openapiExample And relevant implementation --- .../base/config/DaogenCatalogField.java | 136 ++++-------------- .../MicroProfileSchemaWrapperGenerator.java | 17 ++- .../resources/config/daogen-config-1-0.xsd | 18 ++- .../daogenruntest-sample-daogen-config.xml | 5 +- .../daogen/fugerit-sample-daogen-config.xml | 7 +- src/docs/config/daogen-config-xsd-ref.html | 26 +++- 6 files changed, 85 insertions(+), 124 deletions(-) diff --git a/fj-daogen-base/src/main/java/org/fugerit/java/daogen/base/config/DaogenCatalogField.java b/fj-daogen-base/src/main/java/org/fugerit/java/daogen/base/config/DaogenCatalogField.java index 7ad6c93..53e5f70 100644 --- a/fj-daogen-base/src/main/java/org/fugerit/java/daogen/base/config/DaogenCatalogField.java +++ b/fj-daogen-base/src/main/java/org/fugerit/java/daogen/base/config/DaogenCatalogField.java @@ -3,6 +3,8 @@ import java.util.ArrayList; import java.util.List; +import lombok.Getter; +import lombok.Setter; import org.fugerit.java.core.cfg.xml.BasicIdConfigType; import org.fugerit.java.core.lang.helpers.BooleanUtils; import org.fugerit.java.core.lang.helpers.StringUtils; @@ -18,140 +20,48 @@ public class DaogenCatalogField extends BasicIdConfigType { public static final String ATT_COMMENTS = "comments"; public static final String ATT_UDT = "udt"; public static final String ATT_STRUCT_TYPE = "structType"; - public static final String ATT_STRUCT_SQL_TYPE = "structSqlType="; public static final String ATT_VIRTUAL = "virtual"; - public static final String ATT_EXAMPLE_DATA = "exampleData"; + public static final String ATT_OPENAPI_EXAMPLE = "openapiExample"; + public static final String ATT_OPENAPI_ENUMERATION = "openapiEnumeration"; + public static final String ATT_OPENAPI_FORMAT = "openapiFormat"; /** * */ private static final long serialVersionUID = -7578925751213309863L; - - private String comments; - private String sqlType; - - private String sqlTypeName; - - private String javaType; - - private String size; - - private String nullable; - - private String unsafe; - - private String selectOnly; - - private String udt; - - private String structType; - - private String virtual; + @Getter @Setter private String comments; - private String exampleData; + @Getter @Setter private String sqlType; - public boolean isUserType() { - return BooleanUtils.isTrue( this.getUdt() ); - } - - public String getComments() { - return comments; - } + @Getter @Setter private String sqlTypeName; - public void setComments(String comments) { - this.comments = comments; - } + @Getter @Setter private String javaType; - public String getSqlType() { - return sqlType; - } + @Getter @Setter private String size; - public void setSqlType(String sqlType) { - this.sqlType = sqlType; - } + @Getter @Setter private String nullable; - public String getSqlTypeName() { - return sqlTypeName; - } + @Getter @Setter private String unsafe; - public void setSqlTypeName(String sqlTypeName) { - this.sqlTypeName = sqlTypeName; - } + @Getter @Setter private String selectOnly; - public String getJavaType() { - return javaType; - } + @Getter @Setter private String udt; - public void setJavaType(String javaType) { - this.javaType = javaType; - } + @Getter @Setter private String structType; - public String getSize() { - return size; - } + @Getter @Setter private String virtual; - public void setSize(String size) { - this.size = size; - } + @Getter @Setter private String openapiExample; - public String getNullable() { - return nullable; - } + @Getter @Setter private String openapiEnumeration; - public void setNullable(String nullable) { - this.nullable = nullable; - } + @Getter @Setter private String openapiFormat; - public String getUnsafe() { - return unsafe; - } - - public void setUnsafe(String unsafe) { - this.unsafe = unsafe; - } - - public String getSelectOnly() { - return selectOnly; - } - - public void setSelectOnly(String selectOnly) { - this.selectOnly = selectOnly; - } - - public String getUdt() { - return udt; - } - - public void setUdt(String udt) { - this.udt = udt; - } - - public String getStructType() { - return structType; - } - - public void setStructType(String structType) { - this.structType = structType; - } - - public String getVirtual() { - return virtual; - } - - public void setVirtual(String virtual) { - this.virtual = virtual; - } - - public String getExampleData() { - return exampleData; - } - - public void setExampleData(String exampleData) { - this.exampleData = exampleData; + public boolean isUserType() { + return BooleanUtils.isTrue( this.getUdt() ); } - public String describe() { List list = new ArrayList<>(); list.add( StringUtils.concat( ":" , ATT_SQL_TYPE, this.getSqlType() ) ); @@ -163,7 +73,9 @@ public String describe() { list.add( StringUtils.concat( ":" , ATT_UDT, this.getUdt() ) ); list.add( StringUtils.concat( ":" , ATT_STRUCT_TYPE, this.getStructType() ) ); list.add( StringUtils.concat( ":" , ATT_VIRTUAL, this.getVirtual() ) ); - list.add( StringUtils.concat( ":" , ATT_EXAMPLE_DATA, this.getExampleData() ) ); + list.add( StringUtils.concat( ":" , ATT_OPENAPI_EXAMPLE, this.getOpenapiExample() ) ); + list.add( StringUtils.concat( ":" , ATT_OPENAPI_ENUMERATION, this.getOpenapiEnumeration() ) ); + list.add( StringUtils.concat( ":" , ATT_OPENAPI_FORMAT, this.getOpenapiFormat() ) ); return StringUtils.concat( ",", list ); } diff --git a/fj-daogen-base/src/main/java/org/fugerit/java/daogen/base/gen/MicroProfileSchemaWrapperGenerator.java b/fj-daogen-base/src/main/java/org/fugerit/java/daogen/base/gen/MicroProfileSchemaWrapperGenerator.java index 22e1244..e99608d 100644 --- a/fj-daogen-base/src/main/java/org/fugerit/java/daogen/base/gen/MicroProfileSchemaWrapperGenerator.java +++ b/fj-daogen-base/src/main/java/org/fugerit/java/daogen/base/gen/MicroProfileSchemaWrapperGenerator.java @@ -39,14 +39,25 @@ public String getEntityWrapperName() { return DaogenCatalogConstants.mpSchemaName( this.getCurrentEntity() ); } + private static void addIfNotEmpty( StringBuilder extra, String value, String formatString ) { + if ( StringUtils.isNotEmpty( value ) ) { + extra.append( String.format( formatString, value ) ); + } + } + @Override public void generateDaogenBody() throws IOException { WrapperUtils.generateBody( this, f -> { if (StringUtils.isNotEmpty( f.getComments() ) ) { String base = "@Schema( description = \"%s\" %s)"; - String extra = ""; - if ( StringUtils.isNotEmpty( f.getExampleData() ) ) { - extra = String.format( ", example =\"%s\"", f.getExampleData() ); + StringBuilder extra = new StringBuilder(); + addIfNotEmpty( extra, f.getOpenapiExample(), ", example =\"%s\"" ); + addIfNotEmpty( extra, f.getOpenapiFormat(), ", format =\"%s\"" ); + if ( StringUtils.isNotEmpty( f.getOpenapiEnumeration() ) ) { + String[] split = f.getOpenapiEnumeration().split( "," ); + extra.append( ", enumeration = { \"" ); + extra.append( StringUtils.concat( "\" , \"", split ) ); + extra.append( "\" }" ); } return String.format( base , f.getComments(), extra ); } else { diff --git a/fj-daogen-base/src/main/resources/config/daogen-config-1-0.xsd b/fj-daogen-base/src/main/resources/config/daogen-config-1-0.xsd index 366828b..986f8f0 100644 --- a/fj-daogen-base/src/main/resources/config/daogen-config-1-0.xsd +++ b/fj-daogen-base/src/main/resources/config/daogen-config-1-0.xsd @@ -572,10 +572,24 @@ The entry point for daogen-config documentation is : https://marsdocs.fugerit.or Virtual ('true') field will be included in model, but not in persistente (i.e. CRUD) operations. - + Example data for the field. - (e.g. '123') + (e.g. '1') + It will be used by all relevant generators. (for instance MicroProfileSchemaWrapperGenerator) + + + + + Comma separated enumeration of values. (normal comma escaped as {,}) + (e.g. '0,1') + It will be used by all relevant generators. (for instance MicroProfileSchemaWrapperGenerator) + + + + + OpenAPI format to use. + (e.g. 'int32') It will be used by all relevant generators. (for instance MicroProfileSchemaWrapperGenerator) diff --git a/fj-daogen-base/src/test/resources/sample/daogenruntest-sample-daogen-config.xml b/fj-daogen-base/src/test/resources/sample/daogenruntest-sample-daogen-config.xml index 2d5ff93..ea7b149 100644 --- a/fj-daogen-base/src/test/resources/sample/daogenruntest-sample-daogen-config.xml +++ b/fj-daogen-base/src/test/resources/sample/daogenruntest-sample-daogen-config.xml @@ -46,13 +46,14 @@ - + - + diff --git a/fj-daogen-sample/src/main/daogen/fugerit-sample-daogen-config.xml b/fj-daogen-sample/src/main/daogen/fugerit-sample-daogen-config.xml index 01cca50..865c623 100644 --- a/fj-daogen-sample/src/main/daogen/fugerit-sample-daogen-config.xml +++ b/fj-daogen-sample/src/main/daogen/fugerit-sample-daogen-config.xml @@ -42,13 +42,14 @@ - - + + - + diff --git a/src/docs/config/daogen-config-xsd-ref.html b/src/docs/config/daogen-config-xsd-ref.html index 11a39a6..ab0a33c 100644 --- a/src/docs/config/daogen-config-xsd-ref.html +++ b/src/docs/config/daogen-config-xsd-ref.html @@ -1015,14 +1015,36 @@

Reference daogen-config.xsd documentation for Ma - exampleData + openapiExample - Example data for the field. (e.g. '123') It will be used by all relevant generators. (for instance MicroProfileSchemaWrapperGenerator) + Example data for the field. (e.g. '1') It will be used by all relevant generators. (for instance MicroProfileSchemaWrapperGenerator) string + + + + openapiEnumeration + + + Comma separated enumeration of values. (normal comma escaped as {,}) (e.g. '0,1') It will be used by all relevant generators. (for instance MicroProfileSchemaWrapperGenerator) + + + string + + + + + openapiFormat + + + OpenAPI format to use. (e.g. 'int32') It will be used by all relevant generators. (for instance MicroProfileSchemaWrapperGenerator) + + + string +