From b506e3460debb820b0a0b4425bd3843f0890fc34 Mon Sep 17 00:00:00 2001 From: Mustafa Date: Wed, 22 Nov 2023 15:08:01 +0100 Subject: [PATCH 1/2] fix:seperate half of the docs --- .../IssuersCredentialControllerApiDocs.java | 323 ++++++++++++++++++ .../IssuersCredentialController.java | 281 +-------------- 2 files changed, 328 insertions(+), 276 deletions(-) create mode 100644 src/main/java/org/eclipse/tractusx/managedidentitywallets/apidocs/IssuersCredentialControllerApiDocs.java diff --git a/src/main/java/org/eclipse/tractusx/managedidentitywallets/apidocs/IssuersCredentialControllerApiDocs.java b/src/main/java/org/eclipse/tractusx/managedidentitywallets/apidocs/IssuersCredentialControllerApiDocs.java new file mode 100644 index 000000000..3a3c29d04 --- /dev/null +++ b/src/main/java/org/eclipse/tractusx/managedidentitywallets/apidocs/IssuersCredentialControllerApiDocs.java @@ -0,0 +1,323 @@ +package org.eclipse.tractusx.managedidentitywallets.apidocs; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.ExampleObject; +import io.swagger.v3.oas.annotations.parameters.RequestBody; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; + + +public class IssuersCredentialControllerApiDocs { + /** + * The constant API_TAG_VERIFIABLE_CREDENTIAL_ISSUER. + */ + public static final String API_TAG_VERIFIABLE_CREDENTIAL_ISSUER = "Verifiable Credential - Issuer"; + /** + * The constant API_TAG_VERIFIABLE_CREDENTIAL_VALIDATION. + */ + public static final String API_TAG_VERIFIABLE_CREDENTIAL_VALIDATION = "Verifiable Credential - Validation"; + + @Target(ElementType.METHOD) + @Retention(RetentionPolicy.RUNTIME) + @Tag(name = API_TAG_VERIFIABLE_CREDENTIAL_ISSUER) + @ApiResponses(value = { + @ApiResponse(responseCode = "401", description = "The request could not be completed due to a failed authorization.", content = { + @Content(examples = {}) }), + @ApiResponse(responseCode = "403", description = "The request could not be completed due to a forbidden access", content = { + @Content(examples = {}) }), + @ApiResponse(responseCode = "500", description = "Any other internal server error", content = { + @Content(examples = { + @ExampleObject(name = "Internal server error", value = """ + { + "type": "about:blank", + "title": "Error Title", + "status": 500, + "detail": "Error Details", + "instance": "API endpoint", + "properties": { + "timestamp": 1689762476720 + } + } + """) + }) }), + @ApiResponse(responseCode = "400", description = "The input does not comply to the syntax requirements", content = { + @Content(examples = { + @ExampleObject(name = "Response in case of invalid data provided", value = """ + { + "type": "about:blank", + "title": "title", + "status": 400, + "detail": "details", + "instance": "API endpoint", + "properties": + { + "timestamp": 1689760833962, + "errors": + { + } + } + } + """) + }) + }), + @ApiResponse(responseCode = "200", description = "Issuer credential list", content = { + @Content(examples = { + @ExampleObject(name = "Issuer credential list", value = """ + { + "content": [ + { + "@context": [ + "https://www.w3.org/2018/credentials/v1", + "https://catenax-ng.github.io/product-core-schemas/businessPartnerData.json", + "https://w3id.org/security/suites/jws-2020/v1" + ], + "id": "did:web:localhost:BPNL000000000000#ae364f71-f054-4d91-b579-f001bcb3e59e", + "type": [ + "VerifiableCredential", + "BpnCredential" + ], + "issuer": "did:web:localhost:BPNL000000000000", + "issuanceDate": "2023-07-19T09:27:42Z", + "expirationDate": "2024-12-31T18:30:00Z", + "credentialSubject": [ + { + "bpn": "BPNL000000000000", + "id": "did:web:localhost:BPNL000000000000", + "type": "BpnCredential" + } + ], + "proof": { + "created": "2023-07-19T09:27:44Z", + "jws": "eyJhbGciOiJFZERTQSJ9..evDHQfW4EzJUt2HnS_WlmO8FFtywTGnwyywtCE7WP41my4Iscpqr4tbuVOqnZg85b4U8L3_ut8_pEONIhbExCQ", + "proofPurpose": "proofPurpose", + "type": "JsonWebSignature2020", + "verificationMethod": "did:web:localhost:BPNL000000000000#" + } + }, + { + "type": [ + "VerifiableCredential", + "SummaryCredential" + ], + "@context": [ + "https://www.w3.org/2018/credentials/v1", + "https://catenax-ng.github.io/product-core-schemas/SummaryVC.json", + "https://w3id.org/security/suites/jws-2020/v1" + ], + "issuer": "did:web:localhost:BPNL000000000000", + "issuanceDate": "2023-07-19T09:11:39Z", + "expirationDate": "2024-12-31T18:30:00Z", + "credentialSubject": [ + { + "contractTemplate": "https://public.catena-x.org/contracts/", + "holderIdentifier": "BPNL000000000000", + "id": "did:web:localhost:BPNL000000000000", + "items": [ + "BpnCredential" + ], + "type": "SummaryCredential" + } + ], + "proof": { + "created": "2023-07-19T09:11:41Z", + "jws": "eyJhbGciOiJFZERTQSJ9..YvoFhDip3TQAfZUIu0yc843oA4uGTg049dMFt_GoaMmPjiNB_B1EFOL-gDpwjIxTYNlGOO_CLp9qStbzlDTNBg", + "proofPurpose": "proofPurpose", + "type": "JsonWebSignature2020", + "verificationMethod": "did:web:localhost:BPNL000000000000#" + } + }, + { + "@context": [ + "https://www.w3.org/2018/credentials/v1", + "https://catenax-ng.github.io/product-core-schemas/businessPartnerData.json", + "https://w3id.org/security/suites/jws-2020/v1" + ], + "id": "did:web:localhost:BPNL000000000000#f73e3631-ba87-4a03-bea3-b28700056879", + "type": [ + "VerifiableCredential", + "BpnCredential" + ], + "issuer": "did:web:localhost:BPNL000000000000", + "issuanceDate": "2023-07-19T09:11:34Z", + "expirationDate": "2024-12-31T18:30:00Z", + "credentialSubject": [ + { + "bpn": "BPNL000000000000", + "id": "did:web:localhost:BPNL000000000000", + "type": "BpnCredential" + } + ], + "proof": { + "created": "2023-07-19T09:11:39Z", + "jws": "eyJhbGciOiJFZERTQSJ9..fdn2qU85auOltdHDLdHI7sJVV1ZPdftpiXd_ndXN0dFgSDWiIrScdD03wtvKLq_H-shQWfh2RYeMmrlEzAhfDw", + "proofPurpose": "proofPurpose", + "type": "JsonWebSignature2020", + "verificationMethod": "did:web:localhost:BPNL000000000000#" + } + } + ], + "pageable": { + "sort": { + "empty": false, + "unsorted": false, + "sorted": true + }, + "offset": 0, + "pageNumber": 0, + "pageSize": 2147483647, + "paged": true, + "unpaged": false + }, + "last": true, + "totalPages": 1, + "totalElements": 3, + "first": true, + "size": 2147483647, + "number": 0, + "sort": { + "empty": false, + "unsorted": false, + "sorted": true + }, + "numberOfElements": 3, + "empty": false + } + """) + }) + }), + }) + @Operation(description = "Permission: **view_wallets** (The BPN of holderIdentifier must equal BPN of caller)\n\n Search verifiable credentials with filter criteria", summary = "Query Verifiable Credentials") + public @interface GetCredentialsApiDocs { + } + + @Target(ElementType.METHOD) + @Retention(RetentionPolicy.RUNTIME) + @RequestBody(content = { + @Content(examples = @ExampleObject(""" + { + "bpn": "BPNL000000000000" + } + """)) + }) + @Tag(name = API_TAG_VERIFIABLE_CREDENTIAL_ISSUER) + @ApiResponses(value = { + @ApiResponse(responseCode = "401", description = "The request could not be completed due to a failed authorization.", content = { + @Content(examples = {}) }), + @ApiResponse(responseCode = "403", description = "The request could not be completed due to a forbidden access", content = { + @Content(examples = {}) }), + @ApiResponse(responseCode = "500", description = "Any other internal server error", content = { + @Content(examples = { + @ExampleObject(name = "Internal server error", value = """ + { + "type": "about:blank", + "title": "Error Title", + "status": 500, + "detail": "Error Details", + "instance": "API endpoint", + "properties": { + "timestamp": 1689762476720 + } + } + """) + }) }), + @ApiResponse(responseCode = "409", description = "The request could not be completed due to a conflict.", content = { + @Content(examples = { + @ExampleObject(name = "MembershipCredential already exist", value = """ + { + "type": "about:blank", + "title": "Credential of type MembershipCredential is already exists ", + "status": 409, + "detail": "Credential of type MembershipCredential is already exists ", + "instance": "/api/credentials/issuer/membership", + "properties": { + "timestamp": 1689772483831 + } + } + """) + }) }), + @ApiResponse(responseCode = "404", description = "Wallet not found with provided identifier", content = { + @Content(examples = { + @ExampleObject(name = "Wallet not found with provided identifier", value = """ + { + "type": "about:blank", + "title": "Error Title", + "status": 404, + "detail": "Error Details", + "instance": "API endpoint", + "properties": { + "timestamp": 1689762476720 + } + } + """) + }) }), + @ApiResponse(responseCode = "400", description = "The input does not comply to the syntax requirements", content = { + @Content(examples = { + @ExampleObject(name = "Response in case of invalid data provided", value = """ + { + "type": "about:blank", + "title": "Invalid data provided", + "status": 400, + "detail": "details", + "instance": "API endpoint", + "properties": + { + "timestamp": 1689760833962, + "errors": + { + "filed": "filed error message" + } + } + } + """) + }) + }), + @ApiResponse(responseCode = "201", description = "Issuer credential", content = { + @Content(examples = { + @ExampleObject(name = "Membership credential", value = """ + { + "@context": [ + "https://www.w3.org/2018/credentials/v1", + "https://catenax-ng.github.io/product-core-schemas/businessPartnerData.json", + "https://w3id.org/security/suites/jws-2020/v1" + ], + "id": "did:web:localhost:BPNL000000000000#0d6b6447-99de-4bc5-94f3-3ac0ae8ee188", + "type": [ + "VerifiableCredential", + "MembershipCredential" + ], + "issuer": "did:web:localhost:BPNL000000000000", + "issuanceDate": "2023-07-19T13:13:53Z", + "expirationDate": "2024-12-31T18:30:00Z", + "credentialSubject": [ + { + "holderIdentifier": "BPNL000000000000", + "startTime": "2023-07-19T13:13:53.581081Z", + "memberOf": "Catena-X", + "id": "did:web:localhost:BPNL000000000000", + "type": "MembershipCredential", + "status": "Active" + } + ], + "proof": { + "proofPurpose": "proofPurpose", + "verificationMethod": "did:web:localhost:BPNL000000000000#", + "type": "JsonWebSignature2020", + "created": "2023-07-19T13:13:57Z", + "jws": "eyJhbGciOiJFZERTQSJ9..zt7SyONY1shO7N6KrabQJr9uNrToM1Bc4eagTQc1LxAfZ1v-SSp9Y-2cpZNDV8AR08r4L8VbtWrR9t2dNoAfDw" + } + } + """) + }) + }) }) + @Operation(summary = "Issue a Membership Verifiable Credential with base wallet issuer", description = "Permission: **update_wallets** (The BPN of base wallet must equal BPN of caller)\n\n Issue a verifiable credential by base wallet") + public @interface IssueMembershipCredentialApiDoc { + } + +} diff --git a/src/main/java/org/eclipse/tractusx/managedidentitywallets/controller/IssuersCredentialController.java b/src/main/java/org/eclipse/tractusx/managedidentitywallets/controller/IssuersCredentialController.java index 5e8f7b677..1cefef75d 100644 --- a/src/main/java/org/eclipse/tractusx/managedidentitywallets/controller/IssuersCredentialController.java +++ b/src/main/java/org/eclipse/tractusx/managedidentitywallets/controller/IssuersCredentialController.java @@ -32,6 +32,9 @@ import jakarta.validation.constraints.Min; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; + +import org.eclipse.tractusx.managedidentitywallets.apidocs.IssuersCredentialControllerApiDocs.GetCredentialsApiDocs; +import org.eclipse.tractusx.managedidentitywallets.apidocs.IssuersCredentialControllerApiDocs.IssueMembershipCredentialApiDoc; import org.eclipse.tractusx.managedidentitywallets.constant.RestURI; import org.eclipse.tractusx.managedidentitywallets.dto.IssueDismantlerCredentialRequest; import org.eclipse.tractusx.managedidentitywallets.dto.IssueFrameworkCredentialRequest; @@ -81,169 +84,7 @@ public class IssuersCredentialController extends BaseController { * @param principal the principal * @return the credentials */ - @Tag(name = API_TAG_VERIFIABLE_CREDENTIAL_ISSUER) - @ApiResponse(responseCode = "401", description = "The request could not be completed due to a failed authorization.", content = {@Content(examples = {})}) - @ApiResponse(responseCode = "403", description = "The request could not be completed due to a forbidden access", content = {@Content(examples = {})}) - @ApiResponse(responseCode = "500", description = "Any other internal server error", content = {@Content(examples = { - @ExampleObject(name = "Internal server error", value = """ - { - "type": "about:blank", - "title": "Error Title", - "status": 500, - "detail": "Error Details", - "instance": "API endpoint", - "properties": { - "timestamp": 1689762476720 - } - } - """) - })}) - @ApiResponse(responseCode = "400", description = "The input does not comply to the syntax requirements", content = { - @Content(examples = { - @ExampleObject(name = "Response in case of invalid data provided", value = """ - { - "type": "about:blank", - "title": "title", - "status": 400, - "detail": "details", - "instance": "API endpoint", - "properties": - { - "timestamp": 1689760833962, - "errors": - { - } - } - } - """) - }) - }) - @ApiResponse(responseCode = "200", description = "Issuer credential list", content = { - @Content(examples = { - @ExampleObject(name = "Issuer credential list", value = """ - { - "content": [ - { - "@context": [ - "https://www.w3.org/2018/credentials/v1", - "https://catenax-ng.github.io/product-core-schemas/businessPartnerData.json", - "https://w3id.org/security/suites/jws-2020/v1" - ], - "id": "did:web:localhost:BPNL000000000000#ae364f71-f054-4d91-b579-f001bcb3e59e", - "type": [ - "VerifiableCredential", - "BpnCredential" - ], - "issuer": "did:web:localhost:BPNL000000000000", - "issuanceDate": "2023-07-19T09:27:42Z", - "expirationDate": "2024-12-31T18:30:00Z", - "credentialSubject": [ - { - "bpn": "BPNL000000000000", - "id": "did:web:localhost:BPNL000000000000", - "type": "BpnCredential" - } - ], - "proof": { - "created": "2023-07-19T09:27:44Z", - "jws": "eyJhbGciOiJFZERTQSJ9..evDHQfW4EzJUt2HnS_WlmO8FFtywTGnwyywtCE7WP41my4Iscpqr4tbuVOqnZg85b4U8L3_ut8_pEONIhbExCQ", - "proofPurpose": "proofPurpose", - "type": "JsonWebSignature2020", - "verificationMethod": "did:web:localhost:BPNL000000000000#" - } - }, - { - "type": [ - "VerifiableCredential", - "SummaryCredential" - ], - "@context": [ - "https://www.w3.org/2018/credentials/v1", - "https://catenax-ng.github.io/product-core-schemas/SummaryVC.json", - "https://w3id.org/security/suites/jws-2020/v1" - ], - "issuer": "did:web:localhost:BPNL000000000000", - "issuanceDate": "2023-07-19T09:11:39Z", - "expirationDate": "2024-12-31T18:30:00Z" - "credentialSubject": [ - { - "contractTemplate": "https://public.catena-x.org/contracts/", - "holderIdentifier": "BPNL000000000000", - "id": "did:web:localhost:BPNL000000000000", - "items": [ - "BpnCredential" - ], - "type": "SummaryCredential" - } - ], - "proof": { - "created": "2023-07-19T09:11:41Z", - "jws": "eyJhbGciOiJFZERTQSJ9..YvoFhDip3TQAfZUIu0yc843oA4uGTg049dMFt_GoaMmPjiNB_B1EFOL-gDpwjIxTYNlGOO_CLp9qStbzlDTNBg", - "proofPurpose": "proofPurpose", - "type": "JsonWebSignature2020", - "verificationMethod": "did:web:localhost:BPNL000000000000#" - } - }, - { - "@context": [ - "https://www.w3.org/2018/credentials/v1", - "https://catenax-ng.github.io/product-core-schemas/businessPartnerData.json", - "https://w3id.org/security/suites/jws-2020/v1" - ], - "id": "did:web:localhost:BPNL000000000000#f73e3631-ba87-4a03-bea3-b28700056879", - "type": [ - "VerifiableCredential", - "BpnCredential" - ], - "issuer": "did:web:localhost:BPNL000000000000", - "issuanceDate": "2023-07-19T09:11:34Z", - "expirationDate": "2024-12-31T18:30:00Z", - "credentialSubject": [ - { - "bpn": "BPNL000000000000", - "id": "did:web:localhost:BPNL000000000000", - "type": "BpnCredential" - } - ], - "proof": { - "created": "2023-07-19T09:11:39Z", - "jws": "eyJhbGciOiJFZERTQSJ9..fdn2qU85auOltdHDLdHI7sJVV1ZPdftpiXd_ndXN0dFgSDWiIrScdD03wtvKLq_H-shQWfh2RYeMmrlEzAhfDw", - "proofPurpose": "proofPurpose", - "type": "JsonWebSignature2020", - "verificationMethod": "did:web:localhost:BPNL000000000000#" - } - } - ], - "pageable": { - "sort": { - "empty": false, - "unsorted": false, - "sorted": true - }, - "offset": 0, - "pageNumber": 0, - "pageSize": 2147483647, - "paged": true, - "unpaged": false - }, - "last": true, - "totalPages": 1, - "totalElements": 3, - "first": true, - "size": 2147483647, - "number": 0, - "sort": { - "empty": false, - "unsorted": false, - "sorted": true - }, - "numberOfElements": 3, - "empty": false - } - """) - }) - }) - @Operation(description = "Permission: **view_wallets** (The BPN of holderIdentifier must equal BPN of caller)\n\n Search verifiable credentials with filter criteria", summary = "Query Verifiable Credentials") + @GetCredentialsApiDocs @GetMapping(path = RestURI.ISSUERS_CREDENTIALS, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity> getCredentials(@Parameter(name = "credentialId", description = "Credential Id", examples = {@ExampleObject(name = "Credential Id", value = "did:web:localhost:BPNL000000000000#12528899-160a-48bd-ba15-f396c3959ae9")}) @RequestParam(required = false) String credentialId, @Parameter(name = "holderIdentifier", description = "Holder identifier(did of BPN)", examples = {@ExampleObject(name = "bpn", value = "BPNL000000000001", description = "bpn"), @ExampleObject(description = "did", name = "did", value = "did:web:localhost:BPNL000000000001")}) @RequestParam(required = false) String holderIdentifier, @@ -270,124 +111,12 @@ public ResponseEntity> getCredentials(@Parameter( * @param principal the principal * @return the response entity */ - @io.swagger.v3.oas.annotations.parameters.RequestBody(content = { - @Content(examples = @ExampleObject(""" - { - "bpn": "BPNL000000000000" - } - """)) - }) - @Tag(name = API_TAG_VERIFIABLE_CREDENTIAL_ISSUER) - @ApiResponse(responseCode = "401", description = "The request could not be completed due to a failed authorization.", content = {@Content(examples = {})}) - @ApiResponse(responseCode = "403", description = "The request could not be completed due to a forbidden access", content = {@Content(examples = {})}) - @ApiResponse(responseCode = "500", description = "Any other internal server error", content = {@Content(examples = { - @ExampleObject(name = "Internal server error", value = """ - { - "type": "about:blank", - "title": "Error Title", - "status": 500, - "detail": "Error Details", - "instance": "API endpoint", - "properties": { - "timestamp": 1689762476720 - } - } - """) - })}) - @ApiResponse(responseCode = "409", description = "The request could not be completed due to a conflict.", content = {@Content(examples = { - @ExampleObject(name = "MembershipCredential already exist", value = """ - { - "type": "about:blank", - "title": "Credential of type MembershipCredential is already exists ", - "status": 409, - "detail": "Credential of type MembershipCredential is already exists ", - "instance": "/api/credentials/issuer/membership", - "properties": { - "timestamp": 1689772483831 - } - } - """) - })}) - @ApiResponse(responseCode = "404", description = "Wallet not found with provided identifier", content = {@Content(examples = { - @ExampleObject(name = "Wallet not found with provided identifier", value = """ - { - "type": "about:blank", - "title": "Error Title", - "status": 404, - "detail": "Error Details", - "instance": "API endpoint", - "properties": { - "timestamp": 1689762476720 - } - } - """) - })}) - @ApiResponse(responseCode = "400", description = "The input does not comply to the syntax requirements", content = { - @Content(examples = { - @ExampleObject(name = "Response in case of invalid data provided", value = """ - { - "type": "about:blank", - "title": "Invalid data provided", - "status": 400, - "detail": "details", - "instance": "API endpoint", - "properties": - { - "timestamp": 1689760833962, - "errors": - { - "filed": "filed error message" - } - } - } - """) - }) - }) - @ApiResponse(responseCode = "201", description = "Issuer credential", content = { - @Content(examples = { - @ExampleObject(name = "Membership credential", value = """ - { - "@context": [ - "https://www.w3.org/2018/credentials/v1", - "https://catenax-ng.github.io/product-core-schemas/businessPartnerData.json", - "https://w3id.org/security/suites/jws-2020/v1" - ], - "id": "did:web:localhost:BPNL000000000000#0d6b6447-99de-4bc5-94f3-3ac0ae8ee188", - "type": [ - "VerifiableCredential", - "MembershipCredential" - ], - "issuer": "did:web:localhost:BPNL000000000000", - "issuanceDate": "2023-07-19T13:13:53Z", - "expirationDate": "2024-12-31T18:30:00Z", - "credentialSubject": [ - { - "holderIdentifier": "BPNL000000000000", - "startTime": "2023-07-19T13:13:53.581081Z", - "memberOf": "Catena-X", - "id": "did:web:localhost:BPNL000000000000", - "type": "MembershipCredential", - "status": "Active" - } - ], - "proof": { - "proofPurpose": "proofPurpose", - "verificationMethod": "did:web:localhost:BPNL000000000000#", - "type": "JsonWebSignature2020", - "created": "2023-07-19T13:13:57Z", - "jws": "eyJhbGciOiJFZERTQSJ9..zt7SyONY1shO7N6KrabQJr9uNrToM1Bc4eagTQc1LxAfZ1v-SSp9Y-2cpZNDV8AR08r4L8VbtWrR9t2dNoAfDw" - } - } - """) - }) - }) - @Operation(summary = "Issue a Membership Verifiable Credential with base wallet issuer", description = "Permission: **update_wallets** (The BPN of base wallet must equal BPN of caller)\n\n Issue a verifiable credential by base wallet") + @IssueMembershipCredentialApiDoc @PostMapping(path = RestURI.CREDENTIALS_ISSUER_MEMBERSHIP, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity issueMembershipCredential(@Valid @RequestBody IssueMembershipCredentialRequest issueMembershipCredentialRequest, Principal principal) { log.debug("Received request to issue membership credential. BPN: {}", getBPNFromToken(principal)); return ResponseEntity.status(HttpStatus.CREATED).body(issuersCredentialService.issueMembershipCredential(issueMembershipCredentialRequest, getBPNFromToken(principal))); } - /** * Issue dismantler credential response entity. * From bb6d45d817f718f9b76bd1e18f0aa7f94da11de7 Mon Sep 17 00:00:00 2001 From: Mustafa Date: Wed, 22 Nov 2023 15:14:55 +0100 Subject: [PATCH 2/2] fix:add one more seperation --- .../IssuersCredentialControllerApiDocs.java | 134 ++++++++++++++++++ .../IssuersCredentialController.java | 123 +--------------- 2 files changed, 137 insertions(+), 120 deletions(-) diff --git a/src/main/java/org/eclipse/tractusx/managedidentitywallets/apidocs/IssuersCredentialControllerApiDocs.java b/src/main/java/org/eclipse/tractusx/managedidentitywallets/apidocs/IssuersCredentialControllerApiDocs.java index 3a3c29d04..1b4373808 100644 --- a/src/main/java/org/eclipse/tractusx/managedidentitywallets/apidocs/IssuersCredentialControllerApiDocs.java +++ b/src/main/java/org/eclipse/tractusx/managedidentitywallets/apidocs/IssuersCredentialControllerApiDocs.java @@ -320,4 +320,138 @@ public class IssuersCredentialControllerApiDocs { public @interface IssueMembershipCredentialApiDoc { } + + @Target(ElementType.METHOD) + @Retention(RetentionPolicy.RUNTIME) + @RequestBody(content = { + @Content(examples = @ExampleObject(""" + { + "bpn": "BPNL000000000000", + "activityType": "vehicleDismantle", + "allowedVehicleBrands": [ + "Audi", "Abarth", "Alfa Romeo", "Chrysler" + ] + } + """)) + }) + @Tag(name = API_TAG_VERIFIABLE_CREDENTIAL_ISSUER) + @ApiResponses(value = { + @ApiResponse(responseCode = "401", description = "The request could not be completed due to a failed authorization.", content = { + @Content(examples = {}) }), + @ApiResponse(responseCode = "403", description = "The request could not be completed due to a forbidden access", content = { + @Content(examples = {}) }), + @ApiResponse(responseCode = "500", description = "Any other internal server error", content = { + @Content(examples = { + @ExampleObject(name = "Internal server error", value = """ + { + "type": "about:blank", + "title": "Error Title", + "status": 500, + "detail": "Error Details", + "instance": "API endpoint", + "properties": { + "timestamp": 1689762476720 + } + } + """) + }) }), + @ApiResponse(responseCode = "409", description = "The request could not be completed due to a conflict.", content = { + @Content(examples = { + @ExampleObject(name = "DismantlerCredential already exist", value = """ + { + "type": "about:blank", + "title": "Credential of type DismantlerCredential is already exists ", + "status": 409, + "detail": "Credential of type DismantlerCredential is already exists ", + "instance": "/api/credentials/issuer/dismantler", + "properties": { + "timestamp": 1689773804746 + } + } + """) + }) }), + @ApiResponse(responseCode = "404", description = "Wallet not found with provided identifier", content = { + @Content(examples = { + @ExampleObject(name = "Wallet not found with provided identifier", value = """ + { + "type": "about:blank", + "title": "Error Title", + "status": 404, + "detail": "Error Details", + "instance": "API endpoint", + "properties": { + "timestamp": 1689762476720 + } + } + """) + }) }), + @ApiResponse(responseCode = "400", description = "The input does not comply to the syntax requirements", content = { + @Content(examples = { + @ExampleObject(name = "Response in case of invalid data provided", value = """ + { + "type": "about:blank", + "title": "Invalid data provided", + "status": 400, + "detail": "details", + "instance": "API endpoint", + "properties": + { + "timestamp": 1689760833962, + "errors": + { + "filed": "filed error message" + } + } + } + """) + }) + }), + @ApiResponse(responseCode = "201", description = "Dismantler Credential", content = { + @Content(examples = { + @ExampleObject(name = "Dismantler Credential", value = """ + { + "@context": [ + "https://www.w3.org/2018/credentials/v1", + "https://catenax-ng.github.io/product-core-schemas/businessPartnerData.json", + "https://w3id.org/security/suites/jws-2020/v1" + ], + "id": "did:web:localhost:BPNL000000000000#5caac86c-8ef8-4aab-9d2b-fb18c62560a9", + "type": [ + "VerifiableCredential", + "DismantlerCredential" + ], + "issuer": "did:web:localhost:BPNL000000000000", + "issuanceDate": "2023-07-19T13:35:33Z", + "expirationDate": "2024-12-31T18:30:00Z", + "credentialSubject": [ + { + "holderIdentifier": "BPNL000000000000", + "allowedVehicleBrands": [ + "Audi", + "Abarth", + "Alfa Romeo", + "Chrysler" + ], + "id": "did:web:localhost:BPNL000000000000", + "activityType": "vehicleDismantle", + "type": "DismantlerCredential" + } + ], + "proof": { + "proofPurpose": "proofPurpose", + "verificationMethod": "did:web:localhost:BPNL000000000000#", + "type": "JsonWebSignature2020", + "created": "2023-07-19T13:35:38Z", + "jws": "eyJhbGciOiJFZERTQSJ9..UI82uq6iyqoaKjZIhJiV24v_Bqnj_7EqWiqZ3VWjqkoHLnr7JDtW5KVywWPl27j_baLBxxnM5jqjQdSK4rfbBg" + } + } + """) + }) + }) + }) + @Operation(summary = "Issue a Dismantler Verifiable Credential with base wallet issuer", description = "Permission: **update_wallets** (The BPN of base wallet must equal BPN of caller)\n\n Issue a verifiable credential by base wallet") + public @interface IssueDismantlerCredentialApiDoc { + } + + } diff --git a/src/main/java/org/eclipse/tractusx/managedidentitywallets/controller/IssuersCredentialController.java b/src/main/java/org/eclipse/tractusx/managedidentitywallets/controller/IssuersCredentialController.java index 1cefef75d..9fb4e68ee 100644 --- a/src/main/java/org/eclipse/tractusx/managedidentitywallets/controller/IssuersCredentialController.java +++ b/src/main/java/org/eclipse/tractusx/managedidentitywallets/controller/IssuersCredentialController.java @@ -34,6 +34,7 @@ import lombok.extern.slf4j.Slf4j; import org.eclipse.tractusx.managedidentitywallets.apidocs.IssuersCredentialControllerApiDocs.GetCredentialsApiDocs; +import org.eclipse.tractusx.managedidentitywallets.apidocs.IssuersCredentialControllerApiDocs.IssueDismantlerCredentialApiDoc; import org.eclipse.tractusx.managedidentitywallets.apidocs.IssuersCredentialControllerApiDocs.IssueMembershipCredentialApiDoc; import org.eclipse.tractusx.managedidentitywallets.constant.RestURI; import org.eclipse.tractusx.managedidentitywallets.dto.IssueDismantlerCredentialRequest; @@ -117,6 +118,7 @@ public ResponseEntity issueMembershipCredential(@Valid @Re log.debug("Received request to issue membership credential. BPN: {}", getBPNFromToken(principal)); return ResponseEntity.status(HttpStatus.CREATED).body(issuersCredentialService.issueMembershipCredential(issueMembershipCredentialRequest, getBPNFromToken(principal))); } + /** * Issue dismantler credential response entity. * @@ -124,126 +126,7 @@ public ResponseEntity issueMembershipCredential(@Valid @Re * @param principal the principal * @return the response entity */ - @io.swagger.v3.oas.annotations.parameters.RequestBody(content = { - @Content(examples = @ExampleObject(""" - { - "bpn": "BPNL000000000000", - "activityType": "vehicleDismantle", - "allowedVehicleBrands": [ - "Audi", "Abarth", "Alfa Romeo", "Chrysler" - ] - } - """)) - }) - @Tag(name = API_TAG_VERIFIABLE_CREDENTIAL_ISSUER) - @ApiResponse(responseCode = "401", description = "The request could not be completed due to a failed authorization.", content = {@Content(examples = {})}) - @ApiResponse(responseCode = "403", description = "The request could not be completed due to a forbidden access", content = {@Content(examples = {})}) - @ApiResponse(responseCode = "500", description = "Any other internal server error", content = {@Content(examples = { - @ExampleObject(name = "Internal server error", value = """ - { - "type": "about:blank", - "title": "Error Title", - "status": 500, - "detail": "Error Details", - "instance": "API endpoint", - "properties": { - "timestamp": 1689762476720 - } - } - """) - })}) - @ApiResponse(responseCode = "409", description = "The request could not be completed due to a conflict.", content = {@Content(examples = { - @ExampleObject(name = "DismantlerCredential already exist", value = """ - { - "type": "about:blank", - "title": "Credential of type DismantlerCredential is already exists ", - "status": 409, - "detail": "Credential of type DismantlerCredential is already exists ", - "instance": "/api/credentials/issuer/dismantler", - "properties": { - "timestamp": 1689773804746 - } - } - """) - })}) - @ApiResponse(responseCode = "404", description = "Wallet not found with provided identifier", content = {@Content(examples = { - @ExampleObject(name = "Wallet not found with provided identifier", value = """ - { - "type": "about:blank", - "title": "Error Title", - "status": 404, - "detail": "Error Details", - "instance": "API endpoint", - "properties": { - "timestamp": 1689762476720 - } - } - """) - })}) - @ApiResponse(responseCode = "400", description = "The input does not comply to the syntax requirements", content = { - @Content(examples = { - @ExampleObject(name = "Response in case of invalid data provided", value = """ - { - "type": "about:blank", - "title": "Invalid data provided", - "status": 400, - "detail": "details", - "instance": "API endpoint", - "properties": - { - "timestamp": 1689760833962, - "errors": - { - "filed": "filed error message" - } - } - } - """) - }) - }) - @ApiResponse(responseCode = "201", description = "Dismantler Credential", content = { - @Content(examples = { - @ExampleObject(name = "Dismantler Credential", value = """ - { - "@context": [ - "https://www.w3.org/2018/credentials/v1", - "https://catenax-ng.github.io/product-core-schemas/businessPartnerData.json", - "https://w3id.org/security/suites/jws-2020/v1" - ], - "id": "did:web:localhost:BPNL000000000000#5caac86c-8ef8-4aab-9d2b-fb18c62560a9", - "type": [ - "VerifiableCredential", - "DismantlerCredential" - ], - "issuer": "did:web:localhost:BPNL000000000000", - "issuanceDate": "2023-07-19T13:35:33Z", - "expirationDate": "2024-12-31T18:30:00Z", - "credentialSubject": [ - { - "holderIdentifier": "BPNL000000000000", - "allowedVehicleBrands": [ - "Audi", - "Abarth", - "Alfa Romeo", - "Chrysler" - ], - "id": "did:web:localhost:BPNL000000000000", - "activityType": "vehicleDismantle", - "type": "DismantlerCredential" - } - ], - "proof": { - "proofPurpose": "proofPurpose", - "verificationMethod": "did:web:localhost:BPNL000000000000#", - "type": "JsonWebSignature2020", - "created": "2023-07-19T13:35:38Z", - "jws": "eyJhbGciOiJFZERTQSJ9..UI82uq6iyqoaKjZIhJiV24v_Bqnj_7EqWiqZ3VWjqkoHLnr7JDtW5KVywWPl27j_baLBxxnM5jqjQdSK4rfbBg" - } - } - """) - }) - }) - @Operation(summary = "Issue a Dismantler Verifiable Credential with base wallet issuer", description = "Permission: **update_wallets** (The BPN of base wallet must equal BPN of caller)\n\n Issue a verifiable credential by base wallet") + @IssueDismantlerCredentialApiDoc @PostMapping(path = RestURI.CREDENTIALS_ISSUER_DISMANTLER, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity issueDismantlerCredential(@Valid @RequestBody IssueDismantlerCredentialRequest request, Principal principal) { log.debug("Received request to issue dismantler credential. BPN: {}", getBPNFromToken(principal));