Skip to content

Commit

Permalink
Merge pull request #355 from klee-contrib/gideruette/issue354
Browse files Browse the repository at this point in the history
[JS] Template pour les noms des fichiers contenant les api clientes
  • Loading branch information
gideruette authored May 7, 2024
2 parents 77f4698 + 5ed868a commit 0852ff8
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
18 changes: 17 additions & 1 deletion TopModel.Generator.Javascript/GeneratorRegistration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,23 @@ public class GeneratorRegistration : IGeneratorRegistration<JavascriptConfig>
/// <inheritdoc cref="IGeneratorRegistration{T}.Register" />
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);
Expand Down
6 changes: 3 additions & 3 deletions TopModel.Generator.Javascript/JavascriptConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class JavascriptConfig : GeneratorConfigBase
/// <summary>
/// Chemin vers lequel sont créés les fichiers d'endpoints générés, relatif à la racine de l'API.
/// </summary>
public string ApiClientFilePath { get; set; } = "{module}";
public string? ApiClientFilePath { get; set; }

/// <summary>
/// Chemin (ou alias commençant par '@') vers un 'fetch' personnalisé, relatif au répertoire de génération.
Expand Down Expand Up @@ -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("\\", "/");
}

Expand Down
4 changes: 2 additions & 2 deletions samples/model/angular.topmodel.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0852ff8

Please sign in to comment.