diff --git a/.github/workflows/generate-api-client.yml b/.github/workflows/generate-api-client.yml index 583d5ede..a285796e 100644 --- a/.github/workflows/generate-api-client.yml +++ b/.github/workflows/generate-api-client.yml @@ -2,6 +2,7 @@ name: OpenAPI on: pull_request: + types: [opened, synchronize, labeled, reopened] paths: - 'server/application-server/**' - '.github/workflows/generate-api-client.yml' @@ -9,15 +10,12 @@ on: paths: - 'server/application-server/openapi.yaml' - 'webapp/src/app/core/modules/openapi/**' + branches: [develop] workflow_dispatch: -concurrency: - group: generate-api-client - cancel-in-progress: true - jobs: generate-api-client: - name: Verify API Specs and Client + name: Verify API Specs and Client (add autocommit-openapi label to PR to auto-commit changes) runs-on: ubuntu-latest steps: @@ -25,6 +23,7 @@ jobs: uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.head.ref }} + persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token. fetch-depth: 0 - name: Set up Node.js @@ -56,4 +55,26 @@ jobs: echo "Changes detected in the API client directory." echo "NO_CHANGES_DETECTED=false" >> $GITHUB_ENV exit 1 - fi \ No newline at end of file + fi + + - name: Commit files + if: ${{ always() && contains(github.event.pull_request.labels.*.name, 'autocommit-openapi') }} + run: | + echo "Committing and pushing changes..." + git config --local user.name "github-actions[bot]" + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git commit -a -m "chore: update API specs and client" + + - name: Push changes + if: ${{ always() && contains(github.event.pull_request.labels.*.name, 'autocommit-openapi') }} + uses: ad-m/github-push-action@master + with: + github_token: ${{ secrets.GH_PAT }} + branch: ${{ github.event.pull_request.head.ref }} + + - name: Remove autocommit-openapi label + if: ${{ always() && contains(github.event.pull_request.labels.*.name, 'autocommit-openapi') }} + run: | + echo "Removing the autocommit-openapi label..." + curl --silent --fail-with-body -X DELETE -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels/autocommit-openapi diff --git a/package.json b/package.json index bcf86b75..0239ce68 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "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": "npm run generate:api:clean && npm run generate:api:application-server-client && npm run generate:api:application-server-specs" + "generate:api": "npm run generate:api:application-server-specs && npm run generate:api:clean && npm run generate:api:application-server-client" }, "devDependencies": { "@openapitools/openapi-generator-cli": "2.13.5", diff --git a/server/application-server/openapi.yaml b/server/application-server/openapi.yaml index 22c86182..1bb5e9cb 100644 --- a/server/application-server/openapi.yaml +++ b/server/application-server/openapi.yaml @@ -22,10 +22,11 @@ paths: operationId: getAllHellos responses: "200": - description: A list of all Hello entities + description: A set of all Hello entities content: application/json: schema: + uniqueItems: true type: array items: $ref: "#/components/schemas/Hello" diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/hello/HelloController.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/hello/HelloController.java index 10032ef8..c2480c42 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/hello/HelloController.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/hello/HelloController.java @@ -1,6 +1,7 @@ package de.tum.in.www1.hephaestus.hello; import java.util.List; +import java.util.Set; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; @@ -20,10 +21,10 @@ public HelloController(HelloService helloService) { /** * Retrieves all {@link Hello} entities. * - * @return A list of all Hello entities + * @return A set of all Hello entities */ @GetMapping - public List getAllHellos() { + public Set getAllHellos() { return helloService.getAllHellos(); } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/hello/HelloService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/hello/HelloService.java index e3f6d072..2c76cab1 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/hello/HelloService.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/hello/HelloService.java @@ -2,6 +2,8 @@ import java.time.Instant; import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -21,12 +23,12 @@ public HelloService(HelloRepository helloRepository) { /** * Retrieves all {@link Hello} entities from the repository. * - * @return A list of all Hello entities + * @return A set of all Hello entities */ - public List getAllHellos() { + public Set getAllHellos() { var hellos = helloRepository.findAll(); logger.info("Getting Hellos: {}", hellos); - return helloRepository.findAll(); + return helloRepository.findAll().stream().collect(Collectors.toSet()); } /** diff --git a/webapp/src/app/core/modules/openapi/api/hello.service.ts b/webapp/src/app/core/modules/openapi/api/hello.service.ts index 66ccbac5..6c97cd45 100644 --- a/webapp/src/app/core/modules/openapi/api/hello.service.ts +++ b/webapp/src/app/core/modules/openapi/api/hello.service.ts @@ -162,9 +162,9 @@ export class HelloService implements HelloServiceInterface { * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. * @param reportProgress flag to report request and response progress. */ - public getAllHellos(observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; - public getAllHellos(observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>>; - public getAllHellos(observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>>; + public getAllHellos(observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; + public getAllHellos(observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>>; + public getAllHellos(observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>>; public getAllHellos(observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable { let localVarHeaders = this.defaultHeaders; @@ -204,7 +204,7 @@ export class HelloService implements HelloServiceInterface { } let localVarPath = `/hello`; - return this.httpClient.request>('get', `${this.configuration.basePath}${localVarPath}`, + return this.httpClient.request>('get', `${this.configuration.basePath}${localVarPath}`, { context: localVarHttpContext, responseType: responseType_, diff --git a/webapp/src/app/core/modules/openapi/api/hello.serviceInterface.ts b/webapp/src/app/core/modules/openapi/api/hello.serviceInterface.ts index d14de82c..6b46b5fc 100644 --- a/webapp/src/app/core/modules/openapi/api/hello.serviceInterface.ts +++ b/webapp/src/app/core/modules/openapi/api/hello.serviceInterface.ts @@ -34,6 +34,6 @@ export interface HelloServiceInterface { * Retrieves all {@link Hello Hello} entities. * Retrieves all {@link Hello Hello} entities. */ - getAllHellos(extraHttpRequestParams?: any): Observable>; + getAllHellos(extraHttpRequestParams?: any): Observable>; }