Skip to content

Commit

Permalink
Merge pull request #157 from Cofinity-X/fix/DidDocumentController_Api
Browse files Browse the repository at this point in the history
Fix/did document controller api
  • Loading branch information
borisrizov-zf authored Dec 1, 2023
2 parents 0d6aee6 + 51a8b81 commit 7f66c42
Show file tree
Hide file tree
Showing 2 changed files with 170 additions and 116 deletions.
Original file line number Diff line number Diff line change
@@ -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 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")
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 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")
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 {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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<DidDocument> 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<DidDocument> 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));
}
Expand All @@ -121,62 +69,11 @@ public ResponseEntity<DidDocument> 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<DidDocument> getDidResolve(@Parameter(description = "BPN",examples = {@ExampleObject(name = "bpn", value = "BPNL000000000000", description = "bpn")}) @PathVariable(name = "bpn") String bpn) {
public ResponseEntity<DidDocument> 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));
}
Expand Down

0 comments on commit 7f66c42

Please sign in to comment.