{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://json.schemastore.org/sergen.json",
  "title": "Serenity Code Generator (sergen) Configuration",
  "type": "object",
  "additionalProperties": false,
  "description": "Serenity code generator (sergen) configuration",
  "definitions": {
    "Table": {
      "type": "object",
      "title": "Table",
      "additionalProperties": false,
      "required": ["Tablename", "Identifier", "Module", "PermissionKey"],
      "properties": {
        "Tablename": {
          "type": "string",
          "description": "Table name",
          "minLength": 1
        },
        "Identifier": {
          "type": "string",
          "description": "Row identifier without Row suffix",
          "minLength": 1
        },
        "Module": {
          "type": "string",
          "description": "Module name",
          "minLength": 1
        },
        "PermissionKey": {
          "type": "string",
          "description": "Permission key",
          "minLength": 1
        }
      }
    },
    "Connection": {
      "type": "object",
      "title": "Connection",
      "description": "Connection information",
      "additionalProperties": false,
      "required": ["Key"],
      "properties": {
        "Key": {
          "type": "string",
          "description": "Key of connection",
          "minLength": 1
        },
        "ConnectionString": {
          "type": "string",
          "description": "Connection string",
          "minLength": 1
        },
        "ProviderName": {
          "type": "string",
          "description": "Provider name",
          "minLength": 1
        },
        "Dialect": {
          "type": "string",
          "title": "Dialect",
          "minLength": 1,
          "description": "Dialect",
          "anyOf": [
            {
              "enum": [
                "SqlServer",
                "SqlServer2012",
                "SqlServer2008",
                "SqlServer2005",
                "SqlServer2000",
                "Sqlite",
                "Postgres",
                "Oracle",
                "Oracle12c",
                "MySql",
                "Firebird"
              ]
            },
            {
              "type": "string"
            }
          ]
        },
        "Tables": {
          "type": "array",
          "uniqueItems": true,
          "title": "Tables",
          "description": "Generated table information",
          "items": {
            "$ref": "#/definitions/Table"
          }
        }
      }
    },
    "BaseRowClass": {
      "type": "object",
      "title": "BaseRowClass",
      "additionalProperties": false,
      "required": ["ClassName", "Fields"],
      "properties": {
        "ClassName": {
          "type": "string",
          "description": "The class name",
          "minLength": 1
        },
        "Fields": {
          "type": "array",
          "uniqueItems": true,
          "description": "The base class fields that should exists in a table for this base class to be used",
          "items": {
            "type": "string",
            "minLength": 1
          }
        }
      }
    }
  },
  "properties": {
    "Extends": {
      "type": "string",
      "title": "Extends",
      "minLength": 1,
      "description": "If specified, the settings in this file extends settings in a base file similar to tsconfig.json\nYou can also use Sergen defaults by specifying this like \"defaults@9.0.0\"",
      "anyOf": [
        {
          "type": "string",
          "pattern": "\\.json$"
        },
        {
          "enum": ["defaults@9.0.0", "defaults@6.6.0"]
        }
      ]
    },
    "RootNamespace": {
      "type": "string",
      "description": "The root namespace for the target project. It is recommended to have this in sergen.json. If not there, it will be auto calculated from root namespace in CSPROJ file, or derived from project file name by removing .Web suffix. Generated code will be placed under this namespace and project's own types are assumed to be under this namespace as well",
      "minLength": 1
    },
    "DeclareJoinConstants": {
      "type": "boolean",
      "description": "If true, generated code will declare and use jFKTable type of constants for expressions in entities"
    },
    "EnableGenerateFields": {
      "type": "boolean",
      "description": "If true, it allows the use of [GenerateFields] attributes on rows, which automatically generates the fields using a source generator. This should only be used when Serenity.Pro.Coder is enabled in the project"
    },
    "EnableGenerateInterface": {
      "type": "boolean",
      "description": "If true, it allows the use of [GenerateInterface] attributes on handlers, which automatically generates the interface using a source generator. This should only be used when Serenity.Pro.Coder is enabled in the project"
    },
    "EnableRowTemplates": {
      "type": "boolean",
      "description": "If true, enables RowTemplate class generation. This should only be used when Serenity.Pro.Coder is enabled in the project. Has no effect when EnableGenerateFields is true. EnableGenerateFields should be preferred over this as RowTemplate might cause some issues"
    },
    "EndOfLine": {
      "type": "string",
      "title": "EndOfLine",
      "description": "End of line character to use in generated files. If not specified, it will be auto detected from the environment. It is recommended to have \"lf\" for multi platform projects",
      "enum": ["LF", "CRLF"]
    },
    "FileScopedNamespaces": {
      "type": "boolean",
      "description": "If true, generated code will use file scoped namespaces"
    },
    "ParseGlobalUsings": {
      "type": "boolean",
      "description": "If true, generated code will parse global usings from the current project. Default is true"
    },
    "IncludeGlobalUsings": {
      "type": "array",
      "uniqueItems": true,
      "description": "If specified, generated code will assume these usings are in global using scope",
      "items": {
        "type": "string",
        "minLength": 1
      }
    },
    "ExcludeGlobalUsings": {
      "type": "array",
      "uniqueItems": true,
      "description": "If specified, generated code will assume these usings are not in global using scope even if they are in global using scope",
      "items": {
        "type": "string",
        "minLength": 1
      }
    },
    "OmitDefaultSchema": {
      "type": "boolean",
      "description": "If true, the default schema name, e.g. \"dbo\" for SQL Server won't be emitted in generated field expressions in Row.cs files. This is true by default only for MySql as in MySql schema names are actually database names"
    },
    "UseOriginAttribute": {
      "type": "boolean",
      "description": "If true, instead of using [Expression] attributes for foreign view fields, it will use Origin(nameof(jFK), nameof(FKRow.ViewField)) if the FKRow is already generated in the project. It will also use ForeignKey(typeof(FKRow)) type of foreign keys instead of strings"
    },
    "SaveGeneratedTables": {
      "type": "boolean",
      "description": "If true, generated table options like Identity, Module etc. will be saved to the Connections array in sergen.json after code generation. Default is true"
    },
    "ClientTypes": {
      "type": "object",
      "title": "ClientTypes",
      "description": "Client types code generation related configuration",
      "additionalProperties": false,
      "properties": {
        "OutDir": {
          "type": "string",
          "description": "The output directory for generated client types .cs files",
          "minLength": 1
        },
        "SourceGenerator": {
          "type": "boolean",
          "description": "If false, the client types source generator in Serenity.Pro.Coder will be disabled"
        }
      }
    },
    "MVC": {
      "type": "object",
      "title": "MVC",
      "description": "MVC (e.g. view locations) related configuration",
      "additionalProperties": false,
      "properties": {
        "UseRootNamespace": {
          "type": "boolean",
          "description": "Deprecated, Sergen will always use the root namespace to avoid class name clashes",
          "deprecated": true
        },
        "AsNamespace": {
          "type": "boolean",
          "description": "If true, use namespace {RootNamespace}.MVC instead of a MVC class inside the RootNamespace.\nESM helpers will also be generated in this namespace. Default is false.\nThis is useful if to avoid class name clashes with referenced projects. \nE.g. when add Serenity.Extensions to global usings, its MVC class would\nclash with the MVC class generated for the current project, \nsometimes causing issues in Razor views without a @namespace directive.\nSo this is recommended for feature projects like Serenity.Extensions"
        },
        "InternalAccess": {
          "type": "boolean",
          "description": "If true, Use internal instead of public for generated top level class (MVC/ESM)"
        },
        "OutDir": {
          "type": "string",
          "description": "The output directory for MVC.cs",
          "minLength": 1
        },
        "SearchViewPaths": {
          "type": "array",
          "uniqueItems": true,
          "description": "View paths to search for, defaults to \"Modules\" and \"Views\". \"ProjectName\" is used instead of \"Modules\" if Razor SDK is used for the project, e.g. a Razor class library",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "StripViewPaths": {
          "type": "array",
          "uniqueItems": true,
          "description": "Strip view paths from generated files. Defaults to \"Modules\", \"Views\". E.g. a subclass for Modules and Views won't be generated",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "SourceGenerator": {
          "type": "boolean",
          "description": "If false, the view paths source generator in Serenity.Pro.Coder will be disabled"
        }
      }
    },
    "ServerTypings": {
      "type": "object",
      "title": "ServerTypings",
      "description": "Server typings code generation related configuration",
      "additionalProperties": false,
      "properties": {
        "Assemblies": {
          "type": "array",
          "uniqueItems": true,
          "description": "Assemblies for server typings generation. Specify only if Sergen can't auto determine your project output file",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "OutDir": {
          "type": "string",
          "description": "The output directory for generated server typings files. Not used for modules",
          "minLength": 1
        },
        "LocalTexts": {
          "type": "boolean",
          "description": "If true, local texts will be generated"
        },
        "ModuleReExports": {
          "type": "boolean",
          "description": "If true, module re-exports will be generated. Defaults to true"
        },
        "ModuleTypings": {
          "type": "boolean",
          "description": "Deprecated as only ES modules style code generation is supported now. If true, module typings will be generated. Defaults to true if you have \"module\" defined in tsconfig.json",
          "deprecated": true
        },
        "NamespaceTypings": {
          "type": "boolean",
          "description": "Deprecated as only ES modules style code generation is supported now. If true, namespace typings will be generated. Defaults to true if you don't have \"module\" defined in tsconfig.json",
          "deprecated": true
        },
        "PreferRelativePaths": {
          "type": "boolean",
          "description": "If true, generated typings will use relative paths instead of paths from tsconfig.json, e.g. \"../ServerTypes/\" instead of \"@/ServerTypes/\""
        },
        "SourceGenerator": {
          "type": "boolean",
          "description": "If false, the server typings source generator in Serenity.Pro.Coder will be disabled"
        }
      }
    },
    "Restore": {
      "type": "object",
      "title": "Restore",
      "description": "Deprecated as Sergen no longer supports restoring static content. Sergen restore command related configuration",
      "deprecated": true,
      "additionalProperties": false,
      "properties": {
        "Include": {
          "type": "array",
          "uniqueItems": true,
          "description": "List of files (git ignore like) to include while restoring",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "Exclude": {
          "type": "array",
          "uniqueItems": true,
          "description": "List of files (git ignore like) to exclude while restoring",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "Typings": {
          "type": "boolean",
          "description": "Set false to disable namespace typings restore to typings/ folder"
        }
      }
    },
    "TSBuild": {
      "type": "object",
      "title": "TSBuild",
      "additionalProperties": true,
      "properties": {
        "EntryPoints": {
          "type": "array",
          "uniqueItems": true,
          "description": "List of entry point globs, default is \"Modules/**/*Page.ts\", \"Modules/**/*Page.tsx\", \"Modules/**/ScriptInit.ts\", \"Modules/**/*.mts\"",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "SourceGenerator": {
          "type": "boolean",
          "description": "Should the list of entry points, e.g. ESM be generated, only available with Serenity.Pro.Coder"
        }
      }
    },
    "Connections": {
      "type": "array",
      "uniqueItems": true,
      "title": "Connections",
      "description": "List of connections. It is only needed when it is desired to work / generated code based on a connection string that is not in appsettings.json",
      "items": {
        "$ref": "#/definitions/Connection"
      }
    },
    "KDiff3Path": {
      "type": "string",
      "description": "Deprecated. Path to KDiff3 executable. If not specified, it will be auto detected from the environment",
      "minLength": 1,
      "deprecated": true
    },
    "TSCPath": {
      "type": "string",
      "description": "Deprecated. Full path to TypeScript compiler. It is assumed to be in path if not specified",
      "minLength": 1,
      "deprecated": true
    },
    "BaseRowClasses": {
      "type": "array",
      "uniqueItems": true,
      "title": "BaseRowClasses",
      "description": "List of base row classes to be used instead of Row. They are matched by list of base properties",
      "items": {
        "$ref": "#/definitions/BaseRowClass"
      }
    },
    "ForeignFieldSelection": {
      "type": "string",
      "title": "ForeignFieldSelection",
      "description": "The set of foreign fields to generate, default is NameOnly.\n\nNone: Don't generate any foreign view fields except the ones explicitly included via IncludeForeignFields\nAll: Generate all the foreign view fields, except ones excluded explicitly via RemoveForeignFields\nNameOnly: Don't generate any foreign view fields except the Name property of the target row and ones explicitly included via IncludeForeignFields",
      "enum": ["None", "All", "NameOnly"]
    },
    "IncludeForeignFields": {
      "type": "array",
      "uniqueItems": true,
      "description": "A list of foreign fields to include in generated code. This could be used to include some additional fields This could be used to include some additional fields. Not so useful if ForeignFieldSelection is All",
      "items": {
        "type": "string",
        "minLength": 1
      }
    },
    "RemoveForeignFields": {
      "type": "array",
      "uniqueItems": true,
      "description": "A list of foreign fields to omit from generated code. This could be used to disable generating code for join fields like CreatedBy, ModifiedBy etc, so properties like CustomerCreatedBy, CustomerModifiedBy etc. won't be generated in OrderRow. Not so useful if ForeignFieldSelection is None or NameOnly",
      "items": {
        "type": "string",
        "minLength": 1
      }
    },
    "CustomTemplates": {
      "type": "string",
      "description": "The location of custom templates folder. The files in this folder will override the default scriban templates in Sergen. You may also include additional files to be generated. Their names must match the names at \nhttps://github.com/serenity-is/Serenity/tree/master/src/codegenerator/Templates \nYou may also include additional files to be generated",
      "minLength": 1
    },
    "CustomGenerate": {
      "type": "object",
      "title": "CustomGenerate",
      "description": "The relative paths of custom generated files",
      "additionalProperties": {
        "type": "string",
        "minLength": 1
      }
    },
    "CustomSettings": {
      "type": "object",
      "title": "CustomSettings",
      "description": "Custom settings to be passed to and used in custom templates"
    },
    "AppSettingFiles": {
      "type": "array",
      "uniqueItems": true,
      "description": "The list of appsettings.json files in order. Default is appsettings.json, appsettings.machine.json",
      "items": {
        "type": "string",
        "minLength": 1
      }
    },
    "UpgradeInfo": {
      "type": "object",
      "title": "UpgradeInfo",
      "description": "The upgrade / migration related information used by stargen to determine the base version of template used, and already applied upgrades",
      "additionalProperties": false,
      "properties": {
        "InitialType": {
          "type": "string",
          "title": "InitialType",
          "description": "Initial type of project. Available options are \"Community\" e.g. Serene, \"Premium\" e.g. StartSharp",
          "enum": ["Community", "Premium"]
        },
        "InitialVersion": {
          "type": "string",
          "description": "Version this project is created from. Used to determine which migrations should be applied to project (starting from)",
          "title": "InitialVersion",
          "pattern": "^(\\d+.)?(\\d+.)?(\\d+.)?(\\d+)?$",
          "minLength": 1
        },
        "AppliedUpgrades": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "title": "AppliedUpgrades",
          "uniqueItems": true,
          "description": "List of already applied upgrades if any"
        }
      }
    }
  }
}
