diff --git a/server/application-server/.vscode/launch.json b/server/application-server/.vscode/launch.json new file mode 100644 index 00000000..634a1211 --- /dev/null +++ b/server/application-server/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "java", + "name": "Current File", + "request": "launch", + "mainClass": "${file}" + }, + { + "type": "java", + "name": "Application", + "request": "launch", + "mainClass": "de.tum.in.www1.hephaestus.Application", + "projectName": "hephaestus", + "env": { + "SPRING_PROFILES_ACTIVE": "local" + }, + } + ] +} \ No newline at end of file diff --git a/server/application-server/openapi.yaml b/server/application-server/openapi.yaml index 282ebee1..00b4ad50 100644 --- a/server/application-server/openapi.yaml +++ b/server/application-server/openapi.yaml @@ -30,47 +30,7 @@ paths: content: application/json: schema: - $ref: "#/components/schemas/UserProfileDTO" - /pullrequest/{id}: - get: - tags: - - pull-request - operationId: getPullRequest - parameters: - - name: id - in: path - required: true - schema: - type: integer - format: int64 - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/PullRequest" - /pullrequest/author/{login}: - get: - tags: - - pull-request - operationId: getPullRequestsByAuthor - parameters: - - name: login - in: path - required: true - schema: - type: string - responses: - "200": - description: OK - content: - application/json: - schema: - uniqueItems: true - type: array - items: - $ref: "#/components/schemas/PullRequest" + $ref: "#/components/schemas/UserProfile" /meta: get: tags: @@ -82,7 +42,7 @@ paths: content: application/json: schema: - $ref: "#/components/schemas/MetaDataDTO" + $ref: "#/components/schemas/MetaData" /leaderboard: get: tags: @@ -114,7 +74,7 @@ paths: schema: type: array items: - $ref: "#/components/schemas/LeaderboardEntryDTO" + $ref: "#/components/schemas/LeaderboardEntry" /admin: get: tags: @@ -138,50 +98,10 @@ paths: content: application/json: schema: - $ref: "#/components/schemas/AuthUserInfoDTO" + $ref: "#/components/schemas/AuthUserInfo" components: schemas: - LabelInfoDTO: - required: - - color - - id - - name - type: object - properties: - id: - type: integer - format: int64 - name: - type: string - color: - type: string - PullRequestBaseInfoDTO: - required: - - htmlUrl - - id - - number - - state - - title - type: object - properties: - id: - type: integer - format: int64 - number: - type: integer - format: int32 - title: - type: string - state: - type: string - enum: - - OPEN - - CLOSED - repository: - $ref: "#/components/schemas/RepositoryInfoDTO" - htmlUrl: - type: string - PullRequestInfoDTO: + PullRequestInfo: required: - additions - commentsCount @@ -210,17 +130,17 @@ components: type: integer format: int32 author: - $ref: "#/components/schemas/UserInfoDTO" + $ref: "#/components/schemas/UserInfo" labels: type: array items: - $ref: "#/components/schemas/LabelInfoDTO" + $ref: "#/components/schemas/LabelInfo" assignees: type: array items: - $ref: "#/components/schemas/UserInfoDTO" + $ref: "#/components/schemas/UserInfo" repository: - $ref: "#/components/schemas/RepositoryInfoDTO" + $ref: "#/components/schemas/RepositoryInfo" additions: type: integer format: int32 @@ -241,79 +161,21 @@ components: updatedAt: type: string format: date-time - PullRequestReviewInfoDTO: - required: - - codeComments - - htmlUrl - - id - - isDismissed - - state - type: object - properties: - id: - type: integer - format: int64 - isDismissed: - type: boolean - state: - type: string - enum: - - COMMENTED - - APPROVED - - CHANGES_REQUESTED - - UNKNOWN - codeComments: - type: integer - format: int32 - author: - $ref: "#/components/schemas/UserInfoDTO" - pullRequest: - $ref: "#/components/schemas/PullRequestBaseInfoDTO" - htmlUrl: - type: string - submittedAt: - type: string - format: date-time - RepositoryInfoDTO: - required: - - htmlUrl - - id - - name - - nameWithOwner - type: object - properties: - id: - type: integer - format: int64 - name: - type: string - nameWithOwner: - type: string - description: - type: string - htmlUrl: - type: string - UserInfoDTO: + LabelInfo: required: - - avatarUrl - - htmlUrl + - color - id - - login - name type: object properties: id: type: integer format: int64 - login: - type: string - avatarUrl: - type: string name: type: string - htmlUrl: + color: type: string - UserProfileDTO: + UserProfile: required: - contributedRepositories - firstContribution @@ -321,119 +183,61 @@ components: type: object properties: userInfo: - $ref: "#/components/schemas/UserInfoDTO" + $ref: "#/components/schemas/UserInfo" firstContribution: type: string format: date-time contributedRepositories: type: array items: - $ref: "#/components/schemas/RepositoryInfoDTO" + $ref: "#/components/schemas/RepositoryInfo" reviewActivity: type: array items: - $ref: "#/components/schemas/PullRequestReviewInfoDTO" + $ref: "#/components/schemas/PullRequestReviewInfo" openPullRequests: type: array items: - $ref: "#/components/schemas/PullRequestInfoDTO" - Issue: + $ref: "#/components/schemas/PullRequestInfo" + PullRequestReviewInfo: required: + - codeComments - htmlUrl + - id + - isDismissed - state - - title type: object properties: id: type: integer format: int64 - createdAt: - type: string - format: date-time - updatedAt: - type: string - format: date-time - number: - type: integer - format: int32 + isDismissed: + type: boolean state: type: string enum: - - OPEN - - CLOSED - title: - type: string - body: - type: string - htmlUrl: - type: string - closedAt: - type: string - format: date-time - commentsCount: + - COMMENTED + - APPROVED + - CHANGES_REQUESTED + - UNKNOWN + codeComments: type: integer format: int32 author: - $ref: "#/components/schemas/User" - labels: - uniqueItems: true - type: array - items: - $ref: "#/components/schemas/Label" - assignees: - uniqueItems: true - type: array - items: - $ref: "#/components/schemas/User" - milestone: - $ref: "#/components/schemas/Milestone" - repository: - $ref: "#/components/schemas/Repository" - comments: - uniqueItems: true - type: array - items: - $ref: "#/components/schemas/IssueComment" - locked: - type: boolean + $ref: "#/components/schemas/UserInfo" pullRequest: - type: boolean - IssueComment: - required: - - authorAssociation - - body - - htmlUrl - type: object - properties: - id: - type: integer - format: int64 - createdAt: - type: string - format: date-time - updatedAt: - type: string - format: date-time - body: - type: string + $ref: "#/components/schemas/PullRequestBaseInfo" htmlUrl: type: string - authorAssociation: + submittedAt: type: string - enum: - - COLLABORATOR - - CONTRIBUTOR - - FIRST_TIMER - - FIRST_TIME_CONTRIBUTOR - - MANNEQUIN - - MEMBER - - NONE - - OWNER - author: - $ref: "#/components/schemas/User" - issue: - $ref: "#/components/schemas/Issue" - Label: + format: date-time + RepositoryInfo: + required: + - htmlUrl + - id + - name + - nameWithOwner type: object properties: id: @@ -441,61 +245,24 @@ components: format: int64 name: type: string + nameWithOwner: + type: string description: type: string - color: + htmlUrl: type: string - issues: - uniqueItems: true - type: array - items: - $ref: "#/components/schemas/Issue" - repository: - $ref: "#/components/schemas/Repository" - Milestone: + MetaData: type: object properties: - id: - type: integer - format: int64 - createdAt: - type: string - format: date-time - updatedAt: - type: string - format: date-time - number: - type: integer - format: int32 - state: - type: string - enum: - - OPEN - - CLOSED - htmlUrl: - type: string - title: - type: string - description: - type: string - closedAt: - type: string - format: date-time - dueOn: - type: string - format: date-time - creator: - $ref: "#/components/schemas/User" - issues: - uniqueItems: true + repositoriesToMonitor: type: array items: - $ref: "#/components/schemas/Issue" - repository: - $ref: "#/components/schemas/Repository" - PullRequest: + type: string + PullRequestBaseInfo: required: - htmlUrl + - id + - number - state - title type: object @@ -503,383 +270,50 @@ components: id: type: integer format: int64 - createdAt: - type: string - format: date-time - updatedAt: - type: string - format: date-time number: type: integer format: int32 + title: + type: string state: type: string enum: - OPEN - CLOSED - title: - type: string - body: - type: string - htmlUrl: - type: string - closedAt: - type: string - format: date-time - commentsCount: - type: integer - format: int32 - author: - $ref: "#/components/schemas/User" - labels: - uniqueItems: true - type: array - items: - $ref: "#/components/schemas/Label" - assignees: - uniqueItems: true - type: array - items: - $ref: "#/components/schemas/User" - milestone: - $ref: "#/components/schemas/Milestone" repository: - $ref: "#/components/schemas/Repository" - comments: - uniqueItems: true - type: array - items: - $ref: "#/components/schemas/IssueComment" - mergedAt: - type: string - format: date-time - mergeCommitSha: - type: string - isMergeable: - type: boolean - mergeableState: - type: string - maintainerCanModify: - type: boolean - commits: - type: integer - format: int32 - additions: - type: integer - format: int32 - deletions: - type: integer - format: int32 - changedFiles: - type: integer - format: int32 - mergedBy: - $ref: "#/components/schemas/User" - requestedReviewers: - uniqueItems: true - type: array - items: - $ref: "#/components/schemas/User" - reviews: - uniqueItems: true - type: array - items: - $ref: "#/components/schemas/PullRequestReview" - reviewComments: - uniqueItems: true - type: array - items: - $ref: "#/components/schemas/PullRequestReviewComment" - merged: - type: boolean - pullRequest: - type: boolean - draft: - type: boolean - locked: - type: boolean - PullRequestReview: - required: - - htmlUrl - - state - - submittedAt - type: object - properties: - id: - type: integer - format: int64 - body: - type: string - state: - type: string - enum: - - COMMENTED - - APPROVED - - CHANGES_REQUESTED - - UNKNOWN + $ref: "#/components/schemas/RepositoryInfo" htmlUrl: type: string - submittedAt: - type: string - format: date-time - commitId: - type: string - author: - $ref: "#/components/schemas/User" - pullRequest: - $ref: "#/components/schemas/PullRequest" - comments: - uniqueItems: true - type: array - items: - $ref: "#/components/schemas/PullRequestReviewComment" - dismissed: - type: boolean - PullRequestReviewComment: - required: - - authorAssociation - - body - - commitId - - diffHunk - - htmlUrl - - originalCommitId - - path - - side + AuthUserInfo: type: object properties: - id: - type: integer - format: int64 - createdAt: - type: string - format: date-time - updatedAt: - type: string - format: date-time - diffHunk: - type: string - path: - type: string - commitId: - type: string - originalCommitId: - type: string - body: - type: string - htmlUrl: - type: string - authorAssociation: - type: string - enum: - - COLLABORATOR - - CONTRIBUTOR - - FIRST_TIMER - - FIRST_TIME_CONTRIBUTOR - - MANNEQUIN - - MEMBER - - NONE - - OWNER - startLine: - type: integer - format: int32 - originalStartLine: - type: integer - format: int32 - startSide: - type: string - enum: - - LEFT - - RIGHT - - UNKNOWN - line: - type: integer - format: int32 - originalLine: - type: integer - format: int32 - side: - type: string - enum: - - LEFT - - RIGHT - - UNKNOWN - position: - type: integer - format: int32 - originalPosition: - type: integer - format: int32 - author: - $ref: "#/components/schemas/User" - review: - $ref: "#/components/schemas/PullRequestReview" - pullRequest: - $ref: "#/components/schemas/PullRequest" - Repository: - required: - - defaultBranch - - htmlUrl - - name - - nameWithOwner - - pushedAt - - visibility - type: object - properties: - id: - type: integer - format: int64 - createdAt: - type: string - format: date-time - updatedAt: - type: string - format: date-time name: type: string - nameWithOwner: - type: string - htmlUrl: - type: string - description: - type: string - homepage: - type: string - pushedAt: - type: string - format: date-time - visibility: - type: string - enum: - - PUBLIC - - PRIVATE - - INTERNAL - - UNKNOWN - stargazersCount: - type: integer - format: int32 - watchersCount: - type: integer - format: int32 - defaultBranch: - type: string - hasIssues: - type: boolean - hasProjects: - type: boolean - hasWiki: - type: boolean - issues: - uniqueItems: true - type: array - items: - $ref: "#/components/schemas/Issue" - labels: - uniqueItems: true - type: array - items: - $ref: "#/components/schemas/Label" - milestones: - uniqueItems: true + roles: type: array items: - $ref: "#/components/schemas/Milestone" - disabled: - type: boolean - private: - type: boolean - archived: - type: boolean - User: + type: string + UserInfo: required: - avatarUrl - htmlUrl + - id - login - name - - type type: object properties: id: type: integer format: int64 - createdAt: - type: string - format: date-time - updatedAt: - type: string - format: date-time login: type: string avatarUrl: type: string - description: - type: string name: type: string - company: - type: string - blog: - type: string - location: - type: string - email: - type: string htmlUrl: type: string - type: - type: string - enum: - - USER - - ORGANIZATION - - BOT - followers: - type: integer - format: int32 - following: - type: integer - format: int32 - createdIssues: - uniqueItems: true - type: array - items: - $ref: "#/components/schemas/Issue" - assignedIssues: - uniqueItems: true - type: array - items: - $ref: "#/components/schemas/Issue" - issueComments: - uniqueItems: true - type: array - items: - $ref: "#/components/schemas/IssueComment" - mergedPullRequests: - uniqueItems: true - type: array - items: - $ref: "#/components/schemas/PullRequest" - requestedPullRequestReviews: - uniqueItems: true - type: array - items: - $ref: "#/components/schemas/PullRequest" - reviews: - uniqueItems: true - type: array - items: - $ref: "#/components/schemas/PullRequestReview" - reviewComments: - uniqueItems: true - type: array - items: - $ref: "#/components/schemas/PullRequestReviewComment" - MetaDataDTO: - type: object - properties: - repositoriesToMonitor: - type: array - items: - type: string - LeaderboardEntryDTO: + LeaderboardEntry: required: - numberOfApprovals - numberOfChangeRequests @@ -899,7 +333,7 @@ components: type: integer format: int32 user: - $ref: "#/components/schemas/UserInfoDTO" + $ref: "#/components/schemas/UserInfo" numberOfReviewedPRs: type: integer format: int32 @@ -918,12 +352,3 @@ components: numberOfCodeComments: type: integer format: int32 - AuthUserInfoDTO: - type: object - properties: - name: - type: string - roles: - type: array - items: - type: string 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 4462f020..ef7063e1 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 @@ -1,5 +1,12 @@ package de.tum.in.www1.hephaestus; +import java.util.Map; +import java.util.stream.Collectors; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springdoc.core.customizers.OpenApiCustomizer; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import io.swagger.v3.oas.annotations.OpenAPIDefinition; @@ -7,6 +14,7 @@ import io.swagger.v3.oas.annotations.info.Info; import io.swagger.v3.oas.annotations.info.License; import io.swagger.v3.oas.annotations.servers.Server; +import io.swagger.v3.oas.models.media.Schema; @Configuration @OpenAPIDefinition( @@ -28,4 +36,64 @@ } ) public class OpenAPIConfiguration { + + Logger logger = LoggerFactory.getLogger(OpenAPIConfiguration.class); + + @Bean + public OpenApiCustomizer schemaCustomizer() { + return openApi -> { + var components = openApi.getComponents(); + + // Only include schemas with DTO suffix and remove the suffix + var schemas = components + .getSchemas() + .entrySet() + .stream() + .filter(entry -> entry.getKey().endsWith("DTO")) + .collect(Collectors.toMap(entry -> entry.getKey().substring(0, entry.getKey().length() - 3), + entry -> { + var schema = entry.getValue(); + schema.setName(entry.getKey().substring(0, entry.getKey().length() - 3)); + return schema; + })); + + // Remove DTO suffix from attribute names + schemas.forEach((key, value) -> { + Map> properties = value.getProperties(); + if (properties != null) { + properties.forEach((propertyKey, propertyValue) -> { + removeDTOSuffixesFromSchemaRecursively(propertyValue); + }); + } + }); + + components.setSchemas(schemas); + + // Remove DTO suffix from reponse schemas + var paths = openApi.getPaths(); + paths.forEach((path, pathItem) -> { + logger.info(path); + pathItem.readOperations().forEach(operation -> { + var responses = operation.getResponses(); + responses.forEach((responseCode, response) -> { + var content = response.getContent(); + content.forEach((contentType, mediaType) -> { + removeDTOSuffixesFromSchemaRecursively(mediaType.getSchema()); + + }); + }); + }); + }); + }; + } + + private void removeDTOSuffixesFromSchemaRecursively(Schema schema) { + if (schema.get$ref() != null && schema.get$ref().endsWith("DTO")) { + schema.set$ref(schema.get$ref().substring(0, schema.get$ref().length() - 3)); + } + + if (schema.getItems() != null) { + removeDTOSuffixesFromSchemaRecursively(schema.getItems()); + } + } } \ No newline at end of file