diff --git a/CHANGELOG.md b/CHANGELOG.md index a74bf217..bd0214d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # TopModel.Generator (`modgen`) +## 1.46.0 + +- [`354`](https://github.com/klee-contrib/topmodel/issues/354) [JS] Template pour les noms des fichiers contenant les api clientes + +**Breaking changes** : + - Pour les utilisateurs angular, les services d'api client sont déplacés dans un fichier `*.service.ts`. Pour retrouver le comportement initial, définir la propriété `apiClientFilePath` à `{module}/{fileName}` + ## 1.45.2 - [`dd31cf`](https://github.com/klee-contrib/topmodel/commit/dd31cf8282fdf0343e8337bbfe594da2309a9b76) - [JSAPIClient] Fix génération multipart + query param + fix spacing dans le code généré (Angular + Nuxt) diff --git a/TopModel.Generator.Javascript/GeneratorRegistration.cs b/TopModel.Generator.Javascript/GeneratorRegistration.cs index 13c8b9ca..85b5f0fe 100644 --- a/TopModel.Generator.Javascript/GeneratorRegistration.cs +++ b/TopModel.Generator.Javascript/GeneratorRegistration.cs @@ -10,7 +10,23 @@ public class GeneratorRegistration : IGeneratorRegistration /// public void Register(IServiceCollection services, JavascriptConfig config, int number) { - TrimSlashes(config, c => c.ApiClientFilePath); + if (config.ApiClientFilePath != null) + { + TrimSlashes(config, c => c.ApiClientFilePath); + if (!config.ApiClientFilePath.Contains("{fileName}")) + { + config.ApiClientFilePath = config.ApiClientFilePath + "/{fileName}"; + } + } + else if (config.ApiMode == TargetFramework.ANGULAR) + { + config.ApiClientFilePath = "{module}/{fileName}.service"; + } + else + { + config.ApiClientFilePath = "{module}/{fileName}"; + } + TrimSlashes(config, c => c.ApiClientRootPath); TrimSlashes(config, c => c.DomainPath); TrimSlashes(config, c => c.FetchPath); diff --git a/TopModel.Generator.Javascript/JavascriptConfig.cs b/TopModel.Generator.Javascript/JavascriptConfig.cs index 736062f2..a7e16824 100644 --- a/TopModel.Generator.Javascript/JavascriptConfig.cs +++ b/TopModel.Generator.Javascript/JavascriptConfig.cs @@ -28,7 +28,7 @@ public class JavascriptConfig : GeneratorConfigBase /// /// Chemin vers lequel sont créés les fichiers d'endpoints générés, relatif à la racine de l'API. /// - public string ApiClientFilePath { get; set; } = "{module}"; + public string? ApiClientFilePath { get; set; } /// /// Chemin (ou alias commençant par '@') vers un 'fetch' personnalisé, relatif au répertoire de génération. @@ -138,8 +138,8 @@ public string GetEndpointsFileName(ModelFile file, string tag) return Path.Combine( OutputDirectory, ResolveVariables(ApiClientRootPath!, tag), - ResolveVariables(ApiClientFilePath, module: file.Namespace.ModulePathKebab), - $"{file.Options.Endpoints.FileName.ToKebabCase()}.ts") + ResolveVariables(ApiClientFilePath!, module: file.Namespace.ModulePathKebab) + .Replace("{fileName}", file.Options.Endpoints.FileName.ToKebabCase())) + ".ts" .Replace("\\", "/"); } diff --git a/samples/generators/angular/src/appgenerated/api/securite/profil/profil.ts b/samples/generators/angular/src/appgenerated/api/securite/profil/profil.service.ts similarity index 100% rename from samples/generators/angular/src/appgenerated/api/securite/profil/profil.ts rename to samples/generators/angular/src/appgenerated/api/securite/profil/profil.service.ts diff --git a/samples/generators/angular/src/appgenerated/api/securite/utilisateur/utilisateur.ts b/samples/generators/angular/src/appgenerated/api/securite/utilisateur/utilisateur.service.ts similarity index 100% rename from samples/generators/angular/src/appgenerated/api/securite/utilisateur/utilisateur.ts rename to samples/generators/angular/src/appgenerated/api/securite/utilisateur/utilisateur.service.ts diff --git a/samples/model/angular.topmodel.lock b/samples/model/angular.topmodel.lock index 66d085f9..cae31bfe 100644 --- a/samples/model/angular.topmodel.lock +++ b/samples/model/angular.topmodel.lock @@ -4,8 +4,8 @@ version: 1.45.2 generatedFiles: - - ../generators/angular/src/appgenerated/api/securite/profil/profil.ts - - ../generators/angular/src/appgenerated/api/securite/utilisateur/utilisateur.ts + - ../generators/angular/src/appgenerated/api/securite/profil/profil.service.ts + - ../generators/angular/src/appgenerated/api/securite/utilisateur/utilisateur.service.ts - ../generators/angular/src/appgenerated/model/securite/profil/profil-item.ts - ../generators/angular/src/appgenerated/model/securite/profil/profil-read.ts - ../generators/angular/src/appgenerated/model/securite/profil/profil-write.ts