From 43a5dafd8287bd20071a1fd5b253063ac10f632f Mon Sep 17 00:00:00 2001 From: Teriuihi Date: Thu, 10 Apr 2025 23:16:57 +0200 Subject: [PATCH] Refactor API structure and update schema references Moved API files from `sub_api` to `schemas` for better organization. Updated schema references to use `ApiError` instead of `Error`. Adjusted build configuration to include new schema folder in the API generation process. --- open_api/build.gradle.kts | 9 +++++++++ open_api/src/main/resources/api.yml | 8 ++++---- .../main/resources/{sub_api => schemas}/bans/bans.yml | 6 +++--- .../resources/{sub_api => schemas}/generic/errors.yml | 2 +- .../main/resources/{sub_api => schemas}/team/team.yml | 2 +- 5 files changed, 18 insertions(+), 9 deletions(-) rename open_api/src/main/resources/{sub_api => schemas}/bans/bans.yml (95%) rename open_api/src/main/resources/{sub_api => schemas}/generic/errors.yml (87%) rename open_api/src/main/resources/{sub_api => schemas}/team/team.yml (93%) diff --git a/open_api/build.gradle.kts b/open_api/build.gradle.kts index b39bed0..d02fd1e 100644 --- a/open_api/build.gradle.kts +++ b/open_api/build.gradle.kts @@ -44,11 +44,17 @@ dependencies { implementation("org.springframework.boot:spring-boot-starter-web") implementation("org.springframework.boot:spring-boot-starter-validation") implementation("io.swagger.core.v3:swagger-annotations:2.2.20") + implementation("io.swagger.core.v3:swagger-models:2.2.8") + implementation("io.swagger.core.v3:swagger-core:2.2.8") + implementation("org.openapitools:jackson-databind-nullable:0.2.6") implementation("org.springframework.hateoas:spring-hateoas:2.2.0") } tasks.register< GenerateTask>("generateJavaApi") { + inputs.file("${projectDir}/src/main/resources/api.yml") + inputs.file("${projectDir}/src/main/resources/config_backend.json") + inputs.dir("${projectDir}/src/main/resources/schemas") generatorName.set("spring") library.set("spring-boot") inputSpec.set("${projectDir}/src/main/resources/api.yml") @@ -67,6 +73,9 @@ tasks.register< GenerateTask>("generateJavaApi") { } tasks.register("generateFrontendApi") { + inputs.file("${projectDir}/src/main/resources/api.yml") + inputs.file("${projectDir}/src/main/resources/config_backend.json") + inputs.dir("${projectDir}/src/main/resources/schemas") generatorName.set("typescript-angular") inputSpec.set("$rootDir/open_api/src/main/resources/api.yml") outputDir.set("${projectDir}/../frontend/src/api") diff --git a/open_api/src/main/resources/api.yml b/open_api/src/main/resources/api.yml index 3df005f..cfbb434 100644 --- a/open_api/src/main/resources/api.yml +++ b/open_api/src/main/resources/api.yml @@ -13,10 +13,10 @@ tags: description: Retrieves information about the staff team paths: /team/{team}: - $ref: './sub_api/team/team.yml#/getTeam' + $ref: './schemas/team/team.yml#/getTeam' /history/{userType}/search/{type}: - $ref: './sub_api/bans/bans.yml#/getUserNames' + $ref: './schemas/bans/bans.yml#/getUserNames' /history/{userType}/{type}/{user}: - $ref: './sub_api/bans/bans.yml#/getHistoryForUsers' + $ref: './schemas/bans/bans.yml#/getHistoryForUsers' /history/{userType}/{type}/{uuid}: - $ref: './sub_api/bans/bans.yml#/getHistoryForUuid' + $ref: './schemas/bans/bans.yml#/getHistoryForUuid' diff --git a/open_api/src/main/resources/sub_api/bans/bans.yml b/open_api/src/main/resources/schemas/bans/bans.yml similarity index 95% rename from open_api/src/main/resources/sub_api/bans/bans.yml rename to open_api/src/main/resources/schemas/bans/bans.yml index f4e75db..888093b 100644 --- a/open_api/src/main/resources/sub_api/bans/bans.yml +++ b/open_api/src/main/resources/schemas/bans/bans.yml @@ -23,7 +23,7 @@ getUserNames: content: application/json: schema: - $ref: "../generic/errors.yml#/components/schemas/Error" + $ref: "../generic/errors.yml#/components/schemas/ApiError" getHistoryForUsers: post: tags: @@ -49,7 +49,7 @@ getHistoryForUsers: content: application/json: schema: - $ref: "../generic/errors.yml#/components/schemas/Error" + $ref: "../generic/errors.yml#/components/schemas/ApiError" getHistoryForUuid: post: tags: @@ -75,7 +75,7 @@ getHistoryForUuid: content: application/json: schema: - $ref: "../generic/errors.yml#/components/schemas/Error" + $ref: "../generic/errors.yml#/components/schemas/ApiError" components: parameters: HistoryType: diff --git a/open_api/src/main/resources/sub_api/generic/errors.yml b/open_api/src/main/resources/schemas/generic/errors.yml similarity index 87% rename from open_api/src/main/resources/sub_api/generic/errors.yml rename to open_api/src/main/resources/schemas/generic/errors.yml index 6a999af..d495e60 100644 --- a/open_api/src/main/resources/sub_api/generic/errors.yml +++ b/open_api/src/main/resources/schemas/generic/errors.yml @@ -1,6 +1,6 @@ components: schemas: - Error: + ApiError: type: object properties: reason: diff --git a/open_api/src/main/resources/sub_api/team/team.yml b/open_api/src/main/resources/schemas/team/team.yml similarity index 93% rename from open_api/src/main/resources/sub_api/team/team.yml rename to open_api/src/main/resources/schemas/team/team.yml index c975c6f..49db31e 100644 --- a/open_api/src/main/resources/sub_api/team/team.yml +++ b/open_api/src/main/resources/schemas/team/team.yml @@ -24,7 +24,7 @@ getTeam: content: application/json: schema: - $ref: "../generic/errors.yml#/components/schemas/Error" + $ref: "../generic/errors.yml#/components/schemas/ApiError" components: schemas: TeamMembers: