From aa39217cdfdd2ed92755811af718c00029add30a Mon Sep 17 00:00:00 2001 From: "Felix T.J. Dietrich" Date: Sat, 26 Oct 2024 17:37:38 +0200 Subject: [PATCH] remove clean openapi specs script --- package.json | 2 +- scripts/clean-openapi-specs.js | 25 ------------------- .../www1/hephaestus/OpenAPIConfiguration.java | 11 ++++++-- 3 files changed, 10 insertions(+), 28 deletions(-) delete mode 100644 scripts/clean-openapi-specs.js diff --git a/package.json b/package.json index 0239ce68..e147ff92 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ ], "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-specs": "cd server/application-server && mvn verify -DskipTests=true", "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": "npm run generate:api:application-server-specs && npm run generate:api:clean && npm run generate:api:application-server-client" }, diff --git a/scripts/clean-openapi-specs.js b/scripts/clean-openapi-specs.js deleted file mode 100644 index 381e3e80..00000000 --- a/scripts/clean-openapi-specs.js +++ /dev/null @@ -1,25 +0,0 @@ -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/src/main/java/de/tum/in/www1/hephaestus/OpenAPIConfiguration.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/OpenAPIConfiguration.java index ef7063e1..a225cbe5 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/OpenAPIConfiguration.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/OpenAPIConfiguration.java @@ -41,7 +41,7 @@ public class OpenAPIConfiguration { @Bean public OpenApiCustomizer schemaCustomizer() { - return openApi -> { + return openApi -> { var components = openApi.getComponents(); // Only include schemas with DTO suffix and remove the suffix @@ -69,11 +69,11 @@ public OpenApiCustomizer schemaCustomizer() { components.setSchemas(schemas); - // Remove DTO suffix from reponse schemas var paths = openApi.getPaths(); paths.forEach((path, pathItem) -> { logger.info(path); pathItem.readOperations().forEach(operation -> { + // Remove DTO suffix from reponse schemas var responses = operation.getResponses(); responses.forEach((responseCode, response) -> { var content = response.getContent(); @@ -82,8 +82,15 @@ public OpenApiCustomizer schemaCustomizer() { }); }); + + // Remove -controller suffix from tags + operation.setTags(operation.getTags() + .stream() + .map(tag -> tag.substring(0, tag.length() - 11)).toList()); }); }); + + }; }