{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "additionalProperties": false,
  "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",
      "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"
          }
        }
      }
    }
  },
  "description": "Serenity code generator (sergen) configuration",
  "id": "https://json.schemastore.org/sergen.json",
  "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@x.y.z\"",
      "anyOf": [
        {
          "type": "string",
          "pattern": "\\.json$"
        },
        {
          "enum": ["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 this is 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"
    },
    "EnableRowTemplates": {
      "type": "boolean",
      "description": "If true, enables RowTemplate class generation. This should only be used when Serenity.Pro.Coder is enabled in the project"
    },
    "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",
      "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"
    },
    "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": "If true, generated MVC views will be placed under the root namespace of the project"
        },
        "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",
          "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": "If true, module typings will be generated. Defaults to true if you have \"module\" defined in tsconfig.json"
        },
        "NamespaceTypings": {
          "type": "boolean",
          "description": "If true, namespace typings will be generated. Defaults to true if you don't have \"module\" defined in tsconfig.json"
        },
        "SourceGenerator": {
          "type": "boolean",
          "description": "If false, the server typings source generator in Serenity.Pro.Coder will be disabled"
        }
      }
    },
    "Restore": {
      "type": "object",
      "title": "Restore",
      "description": "Sergen restore command related configuration",
      "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 \"**/Page.ts\", \"**/ScriptInit.ts\"",
          "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": "Path to KDiff3 executable. If not specified, it will be auto detected from the environment. (deprecated)",
      "minLength": 1
    },
    "TSCPath": {
      "type": "string",
      "description": "Full path to TypeScript compiler. It is assumed to be in path if not specified",
      "minLength": 1
    },
    "BaseRowClasses": {
      "type": "object",
      "title": "BaseRowClasses",
      "additionalProperties": false,
      "properties": {
        "ClassName": {
          "type": "string",
          "description": "The base 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
          }
        }
      }
    },
    "ForeignFieldSelection": {
      "type": "string",
      "title": "ForeignFieldSelection",
      "description": "The set of foreign fields to generate, default is NameOnly",
      "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/Serenity.Net.CodeGenerator/Templates",
      "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"
        }
      }
    }
  },
  "title": "Serenity Code Generator (sergen) Configuration",
  "type": "object"
}
