diff --git a/docs/src/api/irs-api.yaml b/docs/src/api/irs-api.yaml index 415bdf19a..b139cb36a 100644 --- a/docs/src/api/irs-api.yaml +++ b/docs/src/api/irs-api.yaml @@ -1001,7 +1001,7 @@ paths: content: application/json: examples: - error: + success: $ref: '#/components/examples/get-policies-paged-result' schema: $ref: '#/components/schemas/Page' @@ -1088,9 +1088,11 @@ paths: "200": content: application/json: + examples: + success: + $ref: '#/components/examples/get-policies-by-id' schema: type: string - description: List of policies description: Returns the policies as list of policies. "401": content: @@ -1558,6 +1560,46 @@ components: relationships: [] submodels: [] tombstones: [] + get-policies-by-id: + value: + - bpn: BPNL1234567890AB + policy: + createdOn: 2024-07-08T12:01:19.4677109+02:00 + permissions: + - action: use + constraint: + and: [] + or: + - leftOperand: Membership + operator: + '@id': eq + rightOperand: active + - leftOperand: FrameworkAgreement.traceability + operator: + '@id': eq + rightOperand: active + - leftOperand: PURPOSE + operator: + '@id': eq + rightOperand: ID 3.1 Trace + - action: access + constraint: + and: [] + or: + - leftOperand: Membership + operator: + '@id': eq + rightOperand: active + - leftOperand: FrameworkAgreement.traceability + operator: + '@id': eq + rightOperand: active + - leftOperand: PURPOSE + operator: + '@id': eq + rightOperand: ID 3.1 Trace + policyId: 13a8523f-c80a-40b8-9e43-faab47fbceaa + validUntil: 2025-07-08T12:01:19.4677109+02:00 get-policies-paged-result: value: content: diff --git a/irs-api/src/main/java/org/eclipse/tractusx/irs/configuration/OpenApiExamples.java b/irs-api/src/main/java/org/eclipse/tractusx/irs/configuration/OpenApiExamples.java index 9b2c8981c..e7bfa1c46 100644 --- a/irs-api/src/main/java/org/eclipse/tractusx/irs/configuration/OpenApiExamples.java +++ b/irs-api/src/main/java/org/eclipse/tractusx/irs/configuration/OpenApiExamples.java @@ -153,6 +153,7 @@ public void createExamples(final Components components) { components.addExamples("complete-job-list-processing-state", createJobListProcessingState()); components.addExamples("aspect-models-list", createAspectModelsResult()); components.addExamples("get-policies-paged-result", createPageOfPolicies()); + components.addExamples("get-policies-by-id", createListOfPolicies()); } private Example createPageOfPolicies() { @@ -166,6 +167,19 @@ private Example createPageOfPolicies() { return toExample(page); } + private Example createListOfPolicies() { + final List policyWithBpn = List.of( // + new PolicyWithBpn("BPNL1234567890AB", Policy.builder() + .policyId("13a8523f-c80a-40b8-9e43-faab47fbceaa") + .createdOn(OffsetDateTime.parse( + "2024-07-08T12:01:19.4677109+02:00")) + .validUntil(OffsetDateTime.parse( + "2025-07-08T12:01:19.4677109+02:00")) + .permissions(createPermissions()) + .build())); + return toExample(policyWithBpn); + } + private List createPermissions() { return List.of(new Permission(PolicyType.USE, createConstraints()), new Permission(PolicyType.ACCESS, createConstraints())); diff --git a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/controllers/PolicyStoreController.java b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/controllers/PolicyStoreController.java index c5d1bd553..3e520daea 100644 --- a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/controllers/PolicyStoreController.java +++ b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/controllers/PolicyStoreController.java @@ -168,8 +168,10 @@ public CreatePoliciesResponse registerAllowedPolicy(@Valid @RequestBody final Cr @ApiResponses( value = { @ApiResponse(responseCode = "200", description = "Returns the policies as list of policies.", content = { @Content(mediaType = APPLICATION_JSON_VALUE, - // TODO examples = @ExampleObject(PolicyResponse.BPN_TO_POLICY_MAP_EXAMPLE), - schema = @Schema(description = "List of policies")) + schema = @Schema(description = "List of policies", + implementation = List.class), + examples = @ExampleObject(name = "success", + ref = "#/components/examples/get-policies-by-id")), }), @ApiResponse(responseCode = "401", description = UNAUTHORIZED_DESC, content = { @Content(mediaType = APPLICATION_JSON_VALUE, @@ -280,7 +282,7 @@ public Map> getPolicies(// description = "Successfully retrieved the paged policies", content = @Content(mediaType = APPLICATION_JSON_VALUE, schema = @Schema(implementation = Page.class), - examples = @ExampleObject(name = "error", + examples = @ExampleObject(name = "success", ref = "#/components/examples/get-policies-paged-result"))), @ApiResponse(responseCode = "401", description = UNAUTHORIZED_DESC,