diff --git a/src/main/java/org/eclipse/tractusx/managedidentitywallets/apidocs/DidDocumentControllerApiDocs.java b/src/main/java/org/eclipse/tractusx/managedidentitywallets/apidocs/DidDocumentControllerApiDocs.java new file mode 100644 index 000000000..78e20cc91 --- /dev/null +++ b/src/main/java/org/eclipse/tractusx/managedidentitywallets/apidocs/DidDocumentControllerApiDocs.java @@ -0,0 +1,157 @@ +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.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.Parameter; + +public class DidDocumentControllerApiDocs { + + @Target(ElementType.METHOD) + @Retention(RetentionPolicy.RUNTIME) + @ApiResponses(value = { + @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 = "404", description = "Wallet not found with provided bpn", content = { + @Content(examples = { + @ExampleObject(name = "Wallet not found with provided bpn", value = """ + { + "type": "about:blank", + "title": "Wallet not found for BPN BPNL00000000000", + "status": 404, + "detail": "Wallet not found for BPN BPNL00000000000", + "instance": "/BPNL00000000000/did.json", + "properties": { + "timestamp": 1689767698010 + } + } + """) + }) }), + @ApiResponse(responseCode = "200", description = "DID document", content = { + @Content(examples = { + @ExampleObject(name = " DID document", value = """ + { + "@context": [ + "https://www.w3.org/ns/did/v1", + "https://w3c.github.io/vc-jws-2020/contexts/v1" + ], + "id": "did:web:localhost:BPNL000000000000", + "verificationMethod": [ + { + "controller": "did:web:localhost:BPNL000000000000", + "id": "did:web:localhost:BPNL000000000000", + "publicKeyJwk": { + "crv": "Ed25519", + "kty": "OKP", + "x": "wAOQvr92L1m7RwrpeOrgWByVYvWmhRr4fJbiMwHEIdY" + }, + "type": "JsonWebKey2020" + } + ] + } + """) + }) + }) }) + @Operation(description = "Resolve the DID document for a given DID or BPN", summary = "Resolve DID Document") + public @interface GetDidDocumentApiDocs { + } + + @Target(ElementType.METHOD) + @Retention(RetentionPolicy.RUNTIME) + @ApiResponses(value = { + @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 = "404", description = "Wallet not found with provided bpn", content = { + @Content(examples = { + @ExampleObject(name = "Wallet not found with provided bpn", value = """ + { + "type": "about:blank", + "title": "Wallet not found for BPN BPNL00000000000", + "status": 404, + "detail": "Wallet not found for BPN BPNL00000000000", + "instance": "/BPNL00000000000/did.json", + "properties": { + "timestamp": 1689767698010 + } + } + """) + }) }), + @ApiResponse(responseCode = "200", description = "DID document", content = { + @Content(examples = { + @ExampleObject(name = " DID document", value = """ + { + "@context": [ + "https://www.w3.org/ns/did/v1", + "https://w3c.github.io/vc-jws-2020/contexts/v1" + ], + "id": "did:web:localhost:BPNL000000000000", + "verificationMethod": [ + { + "controller": "did:web:localhost:BPNL000000000000", + "id": "did:web:localhost:BPNL000000000000", + "publicKeyJwk": { + "crv": "Ed25519", + "kty": "OKP", + "x": "wAOQvr92L1m7RwrpeOrgWByVYvWmhRr4fJbiMwHEIdY" + }, + "type": "JsonWebKey2020" + } + ] + } + """) + }) + }) + }) + @Operation(description = "Resolve the DID document for a given BPN", summary = "Resolve DID Document") + public @interface GetDidResolveApiDocs { + } + + @Parameter(description = "Did or BPN", examples = { + @ExampleObject(name = "bpn", value = "BPNL000000000000", description = "bpn"), + @ExampleObject(description = "did", name = "did", value = "did:web:localhost:BPNL000000000000") }) + @Target(ElementType.PARAMETER) + @Retention(RetentionPolicy.RUNTIME) + public @interface DidOrBpnParameterDoc { + } + + @Parameter(description = "BPN", examples = { + @ExampleObject(name = "bpn", value = "BPNL000000000000", description = "bpn") }) + @Target(ElementType.PARAMETER) + @Retention(RetentionPolicy.RUNTIME) + public @interface BpnParameterDoc { + } + +} diff --git a/src/main/java/org/eclipse/tractusx/managedidentitywallets/controller/DidDocumentController.java b/src/main/java/org/eclipse/tractusx/managedidentitywallets/controller/DidDocumentController.java index 496223b89..6869d4532 100644 --- a/src/main/java/org/eclipse/tractusx/managedidentitywallets/controller/DidDocumentController.java +++ b/src/main/java/org/eclipse/tractusx/managedidentitywallets/controller/DidDocumentController.java @@ -21,14 +21,12 @@ package org.eclipse.tractusx.managedidentitywallets.controller; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.ExampleObject; -import io.swagger.v3.oas.annotations.responses.ApiResponse; -import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.eclipse.tractusx.managedidentitywallets.apidocs.DidDocumentControllerApiDocs.BpnParameterDoc; +import org.eclipse.tractusx.managedidentitywallets.apidocs.DidDocumentControllerApiDocs.DidOrBpnParameterDoc; +import org.eclipse.tractusx.managedidentitywallets.apidocs.DidDocumentControllerApiDocs.GetDidDocumentApiDocs; +import org.eclipse.tractusx.managedidentitywallets.apidocs.DidDocumentControllerApiDocs.GetDidResolveApiDocs; import org.eclipse.tractusx.managedidentitywallets.constant.RestURI; import org.eclipse.tractusx.managedidentitywallets.service.DidDocumentService; import org.eclipse.tractusx.ssi.lib.model.did.DidDocument; @@ -38,6 +36,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; +import io.swagger.v3.oas.annotations.tags.Tag; /** * The type Did document controller. @@ -55,62 +54,11 @@ public class DidDocumentController extends BaseController { * @param identifier the identifier * @return the did document */ - @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 = "404", description = "Wallet not found with provided bpn", content = {@Content(examples = { - @ExampleObject(name = "Wallet not found with provided bpn", value = """ - { - "type": "about:blank", - "title": "Wallet not found for identifier BPNL00000000000", - "status": 404, - "detail": "Wallet not found for identifier BPNL00000000000", - "instance": "/BPNL00000000000/did.json", - "properties": { - "timestamp": 1689767698010 - } - } - """) - })}) - @ApiResponse(responseCode = "200", description = "DID document", content = { - @Content(examples = { - @ExampleObject(name = " DID document", value = """ - { - "@context": [ - "https://www.w3.org/ns/did/v1", - "https://w3c.github.io/vc-jws-2020/contexts/v1" - ], - "id": "did:web:localhost:BPNL000000000000", - "verificationMethod": [ - { - "controller": "did:web:localhost:BPNL000000000000", - "id": "did:web:localhost:BPNL000000000000", - "publicKeyJwk": { - "crv": "Ed25519", - "kty": "OKP", - "x": "wAOQvr92L1m7RwrpeOrgWByVYvWmhRr4fJbiMwHEIdY" - }, - "type": "JsonWebKey2020" - } - ] - } - """) - }) - }) - @Operation(description = "Resolve the DID document for a given DID or BPN", summary = "Resolve DID Document") + @GetDidDocumentApiDocs @GetMapping(path = RestURI.DID_DOCUMENTS, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity getDidDocument(@Parameter(description = "Did or BPN",examples = {@ExampleObject(name = "bpn", value = "BPNL000000000000", description = "bpn"), @ExampleObject(description = "did", name = "did", value = "did:web:localhost:BPNL000000000000")}) @PathVariable(name = "identifier") String identifier) { + public ResponseEntity getDidDocument( + @DidOrBpnParameterDoc @PathVariable(name = "identifier") String identifier + ) { log.debug("Received request to get DID document for identifier: {}", identifier); return ResponseEntity.status(HttpStatus.OK).body(service.getDidDocument(identifier)); } @@ -121,62 +69,11 @@ public ResponseEntity getDidDocument(@Parameter(description = "Did * @param bpn the bpn * @return the did resolve */ - @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 = "404", description = "Wallet not found with provided bpn", content = {@Content(examples = { - @ExampleObject(name = "Wallet not found with provided bpn", value = """ - { - "type": "about:blank", - "title": "Wallet not found for identifier BPNL00000000000", - "status": 404, - "detail": "Wallet not found for identifier BPNL00000000000", - "instance": "/BPNL00000000000/did.json", - "properties": { - "timestamp": 1689767698010 - } - } - """) - })}) - @ApiResponse(responseCode = "200", description = "DID document", content = { - @Content(examples = { - @ExampleObject(name = " DID document", value = """ - { - "@context": [ - "https://www.w3.org/ns/did/v1", - "https://w3c.github.io/vc-jws-2020/contexts/v1" - ], - "id": "did:web:localhost:BPNL000000000000", - "verificationMethod": [ - { - "controller": "did:web:localhost:BPNL000000000000", - "id": "did:web:localhost:BPNL000000000000", - "publicKeyJwk": { - "crv": "Ed25519", - "kty": "OKP", - "x": "wAOQvr92L1m7RwrpeOrgWByVYvWmhRr4fJbiMwHEIdY" - }, - "type": "JsonWebKey2020" - } - ] - } - """) - }) - }) - @Operation(description = "Resolve the DID document for a given BPN", summary = "Resolve DID Document") + @GetDidResolveApiDocs @GetMapping(path = RestURI.DID_RESOLVE, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity getDidResolve(@Parameter(description = "BPN",examples = {@ExampleObject(name = "bpn", value = "BPNL000000000000", description = "bpn")}) @PathVariable(name = "bpn") String bpn) { + public ResponseEntity getDidResolve( + @BpnParameterDoc @PathVariable(name = "bpn") String bpn + ) { log.debug("Received request to get DID document for identifier: {}", bpn); return ResponseEntity.status(HttpStatus.OK).body(service.getDidDocument(bpn)); }