From e7eb5810a558a9a32efb63e84ad432d4e819af49 Mon Sep 17 00:00:00 2001 From: "Felix T.J. Dietrich" Date: Thu, 1 Aug 2024 00:47:58 +0200 Subject: [PATCH] improve naming --- package.json | 2 +- scripts/clean-openapi-specs.js | 25 +++++++++++++++++++ server/application-server/openapi.yaml | 6 ++--- .../modules/openapi/.openapi-generator/FILES | 8 +++--- ...controller.service.ts => admin.service.ts} | 6 ++--- ...Interface.ts => admin.serviceInterface.ts} | 2 +- .../src/app/core/modules/openapi/api/api.ts | 14 +++++------ ...controller.service.ts => hello.service.ts} | 6 ++--- ...Interface.ts => hello.serviceInterface.ts} | 2 +- .../src/app/example/hello/hello.component.ts | 8 +++--- 10 files changed, 52 insertions(+), 27 deletions(-) create mode 100644 scripts/clean-openapi-specs.js rename webapp/src/app/core/modules/openapi/api/{admin-controller.service.ts => admin.service.ts} (97%) rename webapp/src/app/core/modules/openapi/api/{admin-controller.serviceInterface.ts => admin.serviceInterface.ts} (93%) rename webapp/src/app/core/modules/openapi/api/{hello-controller.service.ts => hello.service.ts} (98%) rename webapp/src/app/core/modules/openapi/api/{hello-controller.serviceInterface.ts => hello.serviceInterface.ts} (94%) diff --git a/package.json b/package.json index 03d0f9cd..fffb31ae 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,8 @@ ], "scripts": { "generate:api:clean": "rimraf webapp/src/app/core/modules/openapi", + "generate:api:application-server-specs": "cd server/application-server && mvn verify -DskipTests=true && node ../../scripts/clean-openapi-specs.js", "generate:api:application-server-client": "npx openapi-generator-cli generate -i server/application-server/openapi.yaml -g typescript-angular -o webapp/src/app/core/modules/openapi --additional-properties fileNaming=kebab-case,withInterfaces=true --generate-alias-as-model", - "generate:api:application-server-specs": "cd server/application-server && mvn verify -DskipTests=true", "generate:api": "npm run generate:api:clean && npm run generate:api:application-server-client && npm run generate:api:application-server-specs" }, "devDependencies": { diff --git a/scripts/clean-openapi-specs.js b/scripts/clean-openapi-specs.js new file mode 100644 index 00000000..381e3e80 --- /dev/null +++ b/scripts/clean-openapi-specs.js @@ -0,0 +1,25 @@ +const fs = require("fs"); +const path = require("path"); + +const filePath = path.join(__dirname, "../server/application-server/openapi.yaml"); + +fs.readFile(filePath, "utf8", (err, data) => { + if (err) { + console.error("Error reading the file:", err); + return; + } + + const pattern = /tags:\n\s*-\s*.*?-controller\b/g; + + // Function to remove '-controller' from the tag + const updatedContent = data.replace(pattern, (match) => { + return match.replace("-controller", ""); + }); + + fs.writeFile(filePath, updatedContent, "utf8", (err) => { + if (err) { + console.error("Error writing the file:", err); + return; + } + }); +}); diff --git a/server/application-server/openapi.yaml b/server/application-server/openapi.yaml index 83eb53fa..4d6608a9 100644 --- a/server/application-server/openapi.yaml +++ b/server/application-server/openapi.yaml @@ -16,7 +16,7 @@ paths: /hello: get: tags: - - hello-controller + - hello operationId: getAllHellos responses: "200": @@ -29,7 +29,7 @@ paths: $ref: "#/components/schemas/Hello" post: tags: - - hello-controller + - hello operationId: addHello responses: "200": @@ -41,7 +41,7 @@ paths: /admin: get: tags: - - admin-controller + - admin operationId: admin responses: "200": diff --git a/webapp/src/app/core/modules/openapi/.openapi-generator/FILES b/webapp/src/app/core/modules/openapi/.openapi-generator/FILES index c8e71851..a74bc16f 100644 --- a/webapp/src/app/core/modules/openapi/.openapi-generator/FILES +++ b/webapp/src/app/core/modules/openapi/.openapi-generator/FILES @@ -2,11 +2,11 @@ .openapi-generator-ignore README.md api.module.ts -api/admin-controller.service.ts -api/admin-controller.serviceInterface.ts +api/admin.service.ts +api/admin.serviceInterface.ts api/api.ts -api/hello-controller.service.ts -api/hello-controller.serviceInterface.ts +api/hello.service.ts +api/hello.serviceInterface.ts configuration.ts encoder.ts git_push.sh diff --git a/webapp/src/app/core/modules/openapi/api/admin-controller.service.ts b/webapp/src/app/core/modules/openapi/api/admin.service.ts similarity index 97% rename from webapp/src/app/core/modules/openapi/api/admin-controller.service.ts rename to webapp/src/app/core/modules/openapi/api/admin.service.ts index 80e13c91..6ba0eceb 100644 --- a/webapp/src/app/core/modules/openapi/api/admin-controller.service.ts +++ b/webapp/src/app/core/modules/openapi/api/admin.service.ts @@ -23,15 +23,15 @@ import { Observable } from 'rxjs'; import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; import { Configuration } from '../configuration'; import { - AdminControllerServiceInterface -} from './admin-controller.serviceInterface'; + AdminServiceInterface +} from './admin.serviceInterface'; @Injectable({ providedIn: 'root' }) -export class AdminControllerService implements AdminControllerServiceInterface { +export class AdminService implements AdminServiceInterface { protected basePath = 'http://localhost'; public defaultHeaders = new HttpHeaders(); diff --git a/webapp/src/app/core/modules/openapi/api/admin-controller.serviceInterface.ts b/webapp/src/app/core/modules/openapi/api/admin.serviceInterface.ts similarity index 93% rename from webapp/src/app/core/modules/openapi/api/admin-controller.serviceInterface.ts rename to webapp/src/app/core/modules/openapi/api/admin.serviceInterface.ts index 0039f41b..1dcc07cd 100644 --- a/webapp/src/app/core/modules/openapi/api/admin-controller.serviceInterface.ts +++ b/webapp/src/app/core/modules/openapi/api/admin.serviceInterface.ts @@ -19,7 +19,7 @@ import { Configuration } from '../configurat -export interface AdminControllerServiceInterface { +export interface AdminServiceInterface { defaultHeaders: HttpHeaders; configuration: Configuration; diff --git a/webapp/src/app/core/modules/openapi/api/api.ts b/webapp/src/app/core/modules/openapi/api/api.ts index f96d912e..496ee4fc 100644 --- a/webapp/src/app/core/modules/openapi/api/api.ts +++ b/webapp/src/app/core/modules/openapi/api/api.ts @@ -1,7 +1,7 @@ -export * from './admin-controller.service'; -import { AdminControllerService } from './admin-controller.service'; -export * from './admin-controller.serviceInterface'; -export * from './hello-controller.service'; -import { HelloControllerService } from './hello-controller.service'; -export * from './hello-controller.serviceInterface'; -export const APIS = [AdminControllerService, HelloControllerService]; +export * from './admin.service'; +import { AdminService } from './admin.service'; +export * from './admin.serviceInterface'; +export * from './hello.service'; +import { HelloService } from './hello.service'; +export * from './hello.serviceInterface'; +export const APIS = [AdminService, HelloService]; diff --git a/webapp/src/app/core/modules/openapi/api/hello-controller.service.ts b/webapp/src/app/core/modules/openapi/api/hello.service.ts similarity index 98% rename from webapp/src/app/core/modules/openapi/api/hello-controller.service.ts rename to webapp/src/app/core/modules/openapi/api/hello.service.ts index fb54a8dd..1f1eac8d 100644 --- a/webapp/src/app/core/modules/openapi/api/hello-controller.service.ts +++ b/webapp/src/app/core/modules/openapi/api/hello.service.ts @@ -25,15 +25,15 @@ import { Hello } from '../model/hello'; import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; import { Configuration } from '../configuration'; import { - HelloControllerServiceInterface -} from './hello-controller.serviceInterface'; + HelloServiceInterface +} from './hello.serviceInterface'; @Injectable({ providedIn: 'root' }) -export class HelloControllerService implements HelloControllerServiceInterface { +export class HelloService implements HelloServiceInterface { protected basePath = 'http://localhost'; public defaultHeaders = new HttpHeaders(); diff --git a/webapp/src/app/core/modules/openapi/api/hello-controller.serviceInterface.ts b/webapp/src/app/core/modules/openapi/api/hello.serviceInterface.ts similarity index 94% rename from webapp/src/app/core/modules/openapi/api/hello-controller.serviceInterface.ts rename to webapp/src/app/core/modules/openapi/api/hello.serviceInterface.ts index 3fe15862..db41b0f6 100644 --- a/webapp/src/app/core/modules/openapi/api/hello-controller.serviceInterface.ts +++ b/webapp/src/app/core/modules/openapi/api/hello.serviceInterface.ts @@ -20,7 +20,7 @@ import { Configuration } from '../configurat -export interface HelloControllerServiceInterface { +export interface HelloServiceInterface { defaultHeaders: HttpHeaders; configuration: Configuration; diff --git a/webapp/src/app/example/hello/hello.component.ts b/webapp/src/app/example/hello/hello.component.ts index 685ca777..c2d00c71 100644 --- a/webapp/src/app/example/hello/hello.component.ts +++ b/webapp/src/app/example/hello/hello.component.ts @@ -2,7 +2,7 @@ import { Component, inject } from '@angular/core'; import { injectMutation, injectQuery, injectQueryClient } from '@tanstack/angular-query-experimental'; import { AngularQueryDevtools } from '@tanstack/angular-query-devtools-experimental' import { lastValueFrom } from 'rxjs'; -import { HelloControllerService } from 'app/core/modules/openapi'; +import { HelloService } from 'app/core/modules/openapi'; import { AppButtonComponent } from 'app/ui/button/button/button.component'; @Component({ @@ -12,17 +12,17 @@ import { AppButtonComponent } from 'app/ui/button/button/button.component'; templateUrl: './hello.component.html' }) export class PokemonComponent { - helloControllerService = inject(HelloControllerService) + helloService = inject(HelloService) queryClient = injectQueryClient() query = injectQuery(() => ({ queryKey: ['hellos'], - queryFn: async () => lastValueFrom(this.helloControllerService.getAllHellos()), + queryFn: async () => lastValueFrom(this.helloService.getAllHellos()), }) ); mutation = injectMutation(() => ({ - mutationFn: () => lastValueFrom(this.helloControllerService.addHello()), + mutationFn: () => lastValueFrom(this.helloService.addHello()), onSuccess: () => this.queryClient.invalidateQueries({ queryKey: ['hellos'],