Skip to content

Commit

Permalink
fix(impl): [#199] fix API doc
Browse files Browse the repository at this point in the history
  • Loading branch information
dsmf committed Apr 9, 2024
1 parent 7efea9d commit d8957ad
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.media.Schema;
Expand Down Expand Up @@ -141,10 +140,13 @@ public CreatePoliciesResponse registerAllowedPolicy(@Valid @RequestBody final Cr
summary = "Lists the registered policies that should be accepted in EDC negotiation.",
security = @SecurityRequirement(name = "api_key"), tags = { "Item Relationship Service" },
description = "Lists the registered policies that should be accepted in EDC negotiation.")
@ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Returns the policies.",
content = { @Content(mediaType = APPLICATION_JSON_VALUE, array = @ArraySchema(
schema = @Schema(implementation = Policy.class)))
// TODO #199 OpenApi does not describe returned map correctly
@ApiResponses(value = { @ApiResponse(responseCode = "200",
description = "Returns the policies as map of BPN to list of policies.",
content = { @Content(mediaType = APPLICATION_JSON_VALUE,
examples = @ExampleObject(
value = PolicyResponse.BPN_TO_POLICY_MAP_EXAMPLE),
schema = @Schema(
description = "Map of BPN to list of policies"))
}),
@ApiResponse(responseCode = "401", description = UNAUTHORIZED_DESC,
content = { @Content(mediaType = APPLICATION_JSON_VALUE,
Expand All @@ -165,7 +167,9 @@ public CreatePoliciesResponse registerAllowedPolicy(@Valid @RequestBody final Cr
public Map<String, List<PolicyResponse>> getPolicies(//
@RequestParam(required = false) //
@ValidListOfBusinessPartnerNumbers //
@Parameter(description = "List of business partner numbers.") final List<String> businessPartnerNumbers) {
@Parameter(description = "List of business partner numbers.") //
final List<String> businessPartnerNumbers //
) {

final Map<String, String[]> parameterMap = this.httpServletRequest.getParameterMap();
if (CollectionUtils.containsAny(parameterMap.keySet(), List.of("bpn", "bpns", "bpnls"))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,58 @@
import org.eclipse.tractusx.irs.edc.client.policy.Policy;

/**
* Policy representation for get all policies response
* Policy representation for policies response
*/
@Builder
@Schema(example = PolicyResponse.EXAMPLE_PAYLOAD)
public record PolicyResponse(OffsetDateTime validUntil, Payload payload) {

public static final String BPN_TO_POLICY_MAP_EXAMPLE = """
{
"BPNL1234567890AB": [
{
"validUntil": "2025-12-12T23:59:59.999Z",
"payload": {
"@context": {
"odrl": "http://www.w3.org/ns/odrl/2/"
},
"@id": "policy-id3",
"policy": {
"policyId": "p3",
"createdOn": "2024-03-28T03:34:42.9454448Z",
"validUntil": "2025-12-12T23:59:59.999Z",
"permissions": [
{
"action": "USE",
"constraint": {
"and": [
{
"leftOperand": "Membership",
"operator": {
"@id": "eq"
},
"odrl:rightOperand": "active"
},
{
"leftOperand": "PURPOSE",
"operator": {
"@id": "eq"
},
"odrl:rightOperand": "ID 3.1 Trace"
}
],
"or": null
}
}
]
}
}
}
],
"BPNA1234567890DF": []
}
""";

@SuppressWarnings({ "FileTabCharacter",
"java:S2479"
})
Expand All @@ -44,7 +90,7 @@ public record PolicyResponse(OffsetDateTime validUntil, Payload payload) {
"@context": {
"odrl": "http://www.w3.org/ns/odrl/2/"
},
"@id": "policy-id",
"@id": "policy-id1",
"policy": {
"odrl:permission": [
{
Expand All @@ -71,9 +117,21 @@ public record PolicyResponse(OffsetDateTime validUntil, Payload payload) {
]
}
}
},
{
"validUntil": "2025-12-31T23:59:59.999Z",
"payload": {
"@context": {
"odrl": "http://www.w3.org/ns/odrl/2/"
},
"@id": "policy-id2",
"policy": {
...
}
}
}
]
""";
""";

public static PolicyResponse fromPolicy(final Policy policy) {
return PolicyResponse.builder()
Expand Down

0 comments on commit d8957ad

Please sign in to comment.