Skip to content

Commit

Permalink
Add enumeration and format to field attributes #97
Browse files Browse the repository at this point in the history
Added attributes :
'openapiFormat'
'openapiEnumeration'
To field

attribute exampleData renamed to openapiExample

And relevant implementation
  • Loading branch information
fugerit79 committed Nov 15, 2024
1 parent e3fdb36 commit e1a5f1e
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String> list = new ArrayList<>();
list.add( StringUtils.concat( ":" , ATT_SQL_TYPE, this.getSqlType() ) );
Expand All @@ -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 );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 16 additions & 2 deletions fj-daogen-base/src/main/resources/config/daogen-config-1-0.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -572,10 +572,24 @@ The entry point for daogen-config documentation is : https://marsdocs.fugerit.or
<xsd:documentation>Virtual ('true') field will be included in model, but not in persistente (i.e. CRUD) operations.</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute type="xsd:string" name="exampleData" use="optional" >
<xsd:attribute type="xsd:string" name="openapiExample" use="optional" >
<xsd:annotation>
<xsd:documentation>Example data for the field.</xsd:documentation>
<xsd:documentation>(e.g. '123')</xsd:documentation>
<xsd:documentation>(e.g. '1')</xsd:documentation>
<xsd:documentation>It will be used by all relevant generators. (for instance MicroProfileSchemaWrapperGenerator)</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute type="xsd:string" name="openapiEnumeration" use="optional" >
<xsd:annotation>
<xsd:documentation>Comma separated enumeration of values. (normal comma escaped as {,})</xsd:documentation>
<xsd:documentation>(e.g. '0,1')</xsd:documentation>
<xsd:documentation>It will be used by all relevant generators. (for instance MicroProfileSchemaWrapperGenerator)</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute type="xsd:string" name="openapiFormat" use="optional" >
<xsd:annotation>
<xsd:documentation>OpenAPI format to use.</xsd:documentation>
<xsd:documentation>(e.g. 'int32')</xsd:documentation>
<xsd:documentation>It will be used by all relevant generators. (for instance MicroProfileSchemaWrapperGenerator)</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@

<entity catalog="PUBLIC" comments="Contains users data" id="PUBLIC.FUGERIT.USER" name="USER" primaryKey="ID" schema="FUGERIT"
sequenceName="SEQ_USER" facadeMode="COMPLETE" orderBy="ID ASC" queryView="SELECT * FROM USER" structSqlType="(USE_NAME)">
<field comments="User system id" id="ID" javaType="java.lang.Long" nullable="no" size="0" sqlType="-5" sqlTypeName="BIGINT" exampleData="134"/>
<field comments="User system id" id="ID" javaType="java.lang.Long" nullable="no" size="0" sqlType="-5" sqlTypeName="BIGINT" openapiExample="134"/>
<field comments="User chosen id" id="USERNAME" javaType="java.lang.String" nullable="no" size="128" sqlType="12" sqlTypeName="VARCHAR"/>
<field comments="Password hash" id="PASSWORD" javaType="java.lang.String" nullable="no" size="128" sqlType="12" sqlTypeName="VARCHAR"/>
<field comments="Time of last user login" id="LAST_LOGIN" javaType="java.sql.Timestamp" nullable="yes" size="0" sqlType="93" sqlTypeName="TIMESTAMP"/>
<field comments="" id="DATE_INSERT" javaType="java.sql.Timestamp" nullable="yes" size="0" sqlType="93" sqlTypeName="TIMESTAMP"/>
<field comments="" id="DATE_UPDATE" javaType="java.sql.Timestamp" nullable="yes" size="0" sqlType="93" sqlTypeName="TIMESTAMP"/>
<field comments="1 active, 0 not active" id="STATE" javaType="java.lang.Integer" nullable="no" size="0" sqlType="4" sqlTypeName="INTEGER"/>
<field comments="1 active, 0 not active" id="STATE" javaType="java.lang.Integer" nullable="no" size="0" sqlType="4" sqlTypeName="INTEGER"
openapiExample="1" openapiEnumeration="0,1" openapiFormat="int32"/>
<field comments="1 active, 0 not active" id="STATE_TEST" javaType="java.lang.Integer" nullable="no" size="0" sqlType="4" sqlTypeName="INTEGER"/>
<field virtual="true" comments="1 active, 0 not active" id="STATE_VIRTUAL" javaType="java.lang.Integer" nullable="no" size="0" sqlType="4" sqlTypeName="INTEGER"/>
</entity>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@
<relation id="addressToUser" name="USER" from="PUBLIC.FUGERIT.ADDRESS" to="PUBLIC.FUGERIT.USER" mode="one" key="ID_USER"/>

<entity catalog="PUBLIC" comments="Contains users data" id="PUBLIC.FUGERIT.USER" name="USER" primaryKey="ID" schema="FUGERIT">
<field comments="User system id" id="ID" javaType="java.lang.Long" nullable="no" size="0" sqlType="-5" sqlTypeName="BIGINT" exampleData="123"/>
<field comments="User chosen id" id="USERNAME" javaType="java.lang.String" nullable="no" size="128" sqlType="12" sqlTypeName="VARCHAR" exampleData="user1"/>
<field comments="User system id" id="ID" javaType="java.lang.Long" nullable="no" size="0" sqlType="-5" sqlTypeName="BIGINT" openapiExample="1"/>
<field comments="User chosen id" id="USERNAME" javaType="java.lang.String" nullable="no" size="128" sqlType="12" sqlTypeName="VARCHAR" openapiExample="user1"/>
<field comments="Password hash" id="PASSWORD" javaType="java.lang.String" nullable="no" size="128" sqlType="12" sqlTypeName="VARCHAR"/>
<field comments="Time of last user login" id="LAST_LOGIN" javaType="java.sql.Timestamp" nullable="yes" size="0" sqlType="93" sqlTypeName="TIMESTAMP"/>
<field comments="" id="DATE_INSERT" javaType="java.sql.Timestamp" nullable="yes" size="0" sqlType="93" sqlTypeName="TIMESTAMP"/>
<field comments="" id="DATE_UPDATE" javaType="java.sql.Timestamp" nullable="yes" size="0" sqlType="93" sqlTypeName="TIMESTAMP"/>
<field comments="1 active, 0 not active" id="STATE" javaType="java.lang.Integer" nullable="no" size="0" sqlType="4" sqlTypeName="INTEGER"/>
<field comments="1 active, 0 not active" id="STATE" javaType="java.lang.Integer" nullable="no" size="0" sqlType="4" sqlTypeName="INTEGER"
openapiExample="1" openapiEnumeration="0,1" openapiFormat="int32"/>
<field virtual="true" comments="1 active, 0 not active" id="STATE_VIRTUAL" javaType="java.lang.Integer" nullable="no" size="0" sqlType="4" sqlTypeName="INTEGER"/>
</entity>
<entity catalog="PUBLIC" comments="Contains addresses data" foreignKeys="PUBLIC.FUGERIT.USER" id="PUBLIC.FUGERIT.ADDRESS" name="ADDRESS" primaryKey="ID" schema="FUGERIT">
Expand Down
26 changes: 24 additions & 2 deletions src/docs/config/daogen-config-xsd-ref.html
Original file line number Diff line number Diff line change
Expand Up @@ -1015,14 +1015,36 @@ <h1 style="font-weight: bold;">Reference daogen-config.xsd documentation for Ma
</tr>
<tr>
<td id="cell_10_0" style=" width: 20%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
<span >exampleData</span>
<span >openapiExample</span>
</td>
<td id="cell_10_1" style=" width: 40%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
<span >Example data for the field. (e.g. '123') It will be used by all relevant generators. (for instance MicroProfileSchemaWrapperGenerator)</span>
<span >Example data for the field. (e.g. '1') It will be used by all relevant generators. (for instance MicroProfileSchemaWrapperGenerator)</span>
</td>
<td id="cell_10_2" style=" width: 40%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
<span >string</span>
</td>
</tr>
<tr>
<td id="cell_11_0" style=" width: 20%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
<span >openapiEnumeration</span>
</td>
<td id="cell_11_1" style=" width: 40%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
<span >Comma separated enumeration of values. (normal comma escaped as {,}) (e.g. '0,1') It will be used by all relevant generators. (for instance MicroProfileSchemaWrapperGenerator)</span>
</td>
<td id="cell_11_2" style=" width: 40%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
<span >string</span>
</td>
</tr>
<tr>
<td id="cell_12_0" style=" width: 20%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
<span >openapiFormat</span>
</td>
<td id="cell_12_1" style=" width: 40%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
<span >OpenAPI format to use. (e.g. 'int32') It will be used by all relevant generators. (for instance MicroProfileSchemaWrapperGenerator)</span>
</td>
<td id="cell_12_2" style=" width: 40%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
<span >string</span>
</td>
</tr>
</tbody>
</table>
Expand Down

0 comments on commit e1a5f1e

Please sign in to comment.