Class KtormSchemaCodegen

    • Field Detail

      • IDENTIFIER_MAX_LENGTH

        public static final Integer IDENTIFIER_MAX_LENGTH
      • importModelPackageName

        protected String importModelPackageName
      • defaultDatabaseName

        protected String defaultDatabaseName
      • databaseNamePrefix

        protected String databaseNamePrefix
      • databaseNameSuffix

        protected String databaseNameSuffix
      • tableNamePrefix

        protected String tableNamePrefix
      • tableNameSuffix

        protected String tableNameSuffix
      • columnNamePrefix

        protected String columnNamePrefix
      • columnNameSuffix

        protected String columnNameSuffix
      • identifierNamingConvention

        protected String identifierNamingConvention
      • primaryKeyConvention

        protected String primaryKeyConvention
      • addSurrogateKey

        protected boolean addSurrogateKey
    • Constructor Detail

      • KtormSchemaCodegen

        public KtormSchemaCodegen()
    • Method Detail

      • processIntegerTypeProperty

        public void processIntegerTypeProperty​(CodegenModel model,
                                               CodegenProperty property,
                                               String description,
                                               org.openapitools.codegen.languages.KtormSchemaCodegen.KtormSchema ktormSchema)
        Processes each model's property mapped to integer type and adds related vendor extensions
        Parameters:
        model - codegen model
        property - model's property
        description - property custom description
        ktormSchema - schema
      • processRealTypeProperty

        public void processRealTypeProperty​(CodegenModel model,
                                            CodegenProperty property,
                                            String description,
                                            org.openapitools.codegen.languages.KtormSchemaCodegen.KtormSchema ktormSchema)
        Processes each model's property mapped to some real type and adds related vendor extensions
        Parameters:
        model - codegen model
        property - model's property
        description - property custom description
        ktormSchema - schema
      • processBooleanTypeProperty

        public void processBooleanTypeProperty​(CodegenModel model,
                                               CodegenProperty property,
                                               String description,
                                               org.openapitools.codegen.languages.KtormSchemaCodegen.KtormSchema ktormSchema)
        Processes each model's property mapped to boolean type and adds related vendor extensions
        Parameters:
        model - codegen model
        property - model's property
        description - property custom description
        ktormSchema - schema
      • processStringTypeProperty

        public void processStringTypeProperty​(CodegenModel model,
                                              CodegenProperty property,
                                              String description,
                                              org.openapitools.codegen.languages.KtormSchemaCodegen.KtormSchema ktormSchema)
        Processes each model's property mapped to string type and adds related vendor extensions
        Parameters:
        model - codegen model
        property - model's property
        description - property custom description
        ktormSchema - schema
      • processDateTypeProperty

        public void processDateTypeProperty​(CodegenModel model,
                                            CodegenProperty property,
                                            String description,
                                            org.openapitools.codegen.languages.KtormSchemaCodegen.KtormSchema ktormSchema)
        Processes each model's property mapped to date type and adds related vendor extensions
        Parameters:
        model - codegen model
        property - model's property
        description - property custom description
        ktormSchema - schema
      • processJsonTypeProperty

        public void processJsonTypeProperty​(CodegenModel model,
                                            CodegenProperty property,
                                            String description,
                                            org.openapitools.codegen.languages.KtormSchemaCodegen.KtormSchema ktormSchema)
        Processes each model's property mapped to JSON type and adds related vendor extensions
        Parameters:
        model - codegen model
        property - model's property
        description - property custom description
        ktormSchema - schema
      • processUnknownTypeProperty

        public void processUnknownTypeProperty​(CodegenModel model,
                                               CodegenProperty property,
                                               String description,
                                               org.openapitools.codegen.languages.KtormSchemaCodegen.KtormSchema ktormSchema)
        Processes each model's property not mapped to any type and adds related vendor extensions Most of time it's related to referenced properties eg. \Model\User
        Parameters:
        model - codegen model
        property - model's property
        description - property custom description
        ktormSchema - schema
      • processTypeArgs

        public void processTypeArgs​(String dataType,
                                    String dataFormat,
                                    Object min,
                                    Object max,
                                    Map<String,​Object> columnDefinition)
        Processes each model's property type arguments definitions
        Parameters:
        dataType - the chosen sql type
        dataFormat - the chosen sql format
        min - the minimum value, if specified, in the target type
        max - the maximum value, if specified, in the target type
        columnDefinition - resulting column definition dictionary
      • processNullAndDefault

        public void processNullAndDefault​(CodegenModel model,
                                          CodegenProperty property,
                                          String description,
                                          Map<String,​Object> columnDefinition)
        Processes each model's property null/default definitions
        Parameters:
        model - model's name
        property - model's property
        description - property's customized description
        columnDefinition - resulting column definition dictionary
      • processForeignKey

        public boolean processForeignKey​(CodegenModel model,
                                         CodegenProperty property,
                                         Map<String,​Object> relationDefinition)
        Processes each model's property that relates to another model
        Parameters:
        model - model's name
        property - model's property
        relationDefinition - resulting relation definition dictionary
        Returns:
        did we create the foreign key section.
      • toDatabaseName

        public String toDatabaseName​(String name)
        Converts name to valid database name Produced name must be used with backticks only, eg. `database_name`
        Parameters:
        name - source name
        Returns:
        database name
      • toTableName

        public String toTableName​(String name)
        Converts name to valid column name Produced name must be used with backticks only, eg. `table_name`
        Parameters:
        name - source name
        Returns:
        table name
      • toColumnName

        public String toColumnName​(String name)
        Converts name to valid column name Produced name must be used with backticks only, eg. `column_name`
        Parameters:
        name - source name
        Returns:
        column name
      • toIdentifier

        public String toIdentifier​(String name,
                                   String prefix,
                                   String suffix)
        Converts name to valid identifier which can be used as database, table, column name Produced name must be used quoted only, eg. "column_name"
        Parameters:
        name - source name
        prefix - when escaped name is digits only, prefix will be prepended
        suffix - when escaped name is digits only, suffix will be appended
        Returns:
        identifier name
      • escapeQuotedIdentifier

        public String escapeQuotedIdentifier​(String identifier)
        Escapes identifier to use it in SQL statements with backticks, eg. SELECT "identifier" FROM Ref: https://www.sqlite.org/draft/tokenreq.html H41130 Spec is similar to MySQL
        Parameters:
        identifier - source identifier
        Returns:
        escaped identifier
      • setDefaultDatabaseName

        public void setDefaultDatabaseName​(String databaseName)
        Sets default database name for all queries Provided value will be escaped when necessary
        Parameters:
        databaseName - source name
      • getDefaultDatabaseName

        public String getDefaultDatabaseName()
        Returns default database name for all queries This value must be used with backticks only, eg. `database_name`
        Returns:
        default database name
      • setImportModelPackageName

        public void setImportModelPackageName​(String name)
        Sets imported package name for the models
        Parameters:
        name - name
      • getImportModelPackageName

        public String getImportModelPackageName()
        Returns imported package name for the models
        Returns:
        name
      • setIdentifierNamingConvention

        public void setIdentifierNamingConvention​(String naming)
        Sets identifier naming convention for table names and column names. This is not related to database name which is defined by defaultDatabaseName option.
        Parameters:
        naming - identifier naming convention (original|snake_case)
      • getIdentifierNamingConvention

        public String getIdentifierNamingConvention()
        Returns identifier naming convention for table names and column names.
        Returns:
        identifier naming convention
      • setPrimaryKeyConvention

        public void setPrimaryKeyConvention​(String name)
        Sets primary key naming convention
        Parameters:
        name - name
      • getPrimaryKeyConvention

        public String getPrimaryKeyConvention()
        Returns primary key naming convention
        Returns:
        name
      • setAddSurrogateKey

        public void setAddSurrogateKey​(boolean enable)
        Sets primary key naming convention
        Parameters:
        enable - enable this option
      • getAddSurrogateKey

        public boolean getAddSurrogateKey()
        Returns primary key naming convention
        Returns:
        is enabled
      • toSrcPath

        public String toSrcPath​(String packageName)
        Slightly modified version of AbstractPhpCodegen.toSrcPath method.
        Parameters:
        packageName - package name
        Returns:
        path