Skip to content

Commit 844f8c4

Browse files
fix: excel integration and validation response (#388)
* feat: update response with correct info WIP * fix: update responses and excel report generation * docs: update readme with api-mode instructions --------- Signed-off-by: Nicklas Silversved <nicklas.silversved@digg.se>
1 parent 1ff5f43 commit 844f8c4

File tree

3 files changed

+70
-26
lines changed

3 files changed

+70
-26
lines changed

openapi.yaml

Lines changed: 58 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ paths:
149149
tags:
150150
- validate
151151
summary: Generate status report
152-
description: Accepts report data as the request body and returns a generated status report as a downloadable excel file.
152+
description: Accepts result data as the request body and returns a generated status report as a downloadable excel file.
153153
operationId: generateReport
154154
requestBody:
155155
required: true
@@ -158,13 +158,13 @@ paths:
158158
schema:
159159
type: object
160160
required:
161-
- report
161+
- result
162162
properties:
163-
report:
163+
result:
164164
type: array
165165
items:
166-
type: object
167-
description: An array of objects representing the data for the report.
166+
$ref: '#/components/schemas/RapLPCustomSpectralDiagnosticItem'
167+
description: An array of result items used to generate the Excel report.
168168
responses:
169169
'200':
170170
description: Successful operation
@@ -231,7 +231,7 @@ paths:
231231
content:
232232
application/json:
233233
schema:
234-
$ref: "#/components/schemas/RapLPCustomSpectralDiagnostic"
234+
$ref: "#/components/schemas/ValidationResponseDto"
235235
example:
236236
- id: "AME.04"
237237
omrade: "API Message"
@@ -391,7 +391,7 @@ components:
391391
title:
392392
type: string
393393
status:
394-
type: "integer"
394+
type: integer
395395
detail:
396396
type: string
397397
instance:
@@ -483,17 +483,6 @@ components:
483483
type: array
484484
items:
485485
$ref: "#/components/schemas/RapLPCustomSpectralDiagnosticItem"
486-
ValidationResponseDto:
487-
type: object
488-
properties:
489-
result:
490-
type: array
491-
items:
492-
$ref: "#/components/schemas/RapLPCustomSpectralDiagnosticItem"
493-
report:
494-
type: array
495-
items:
496-
$ref: "#/components/schemas/DiagnosticReport"
497486
DiagnosticRuleInfo:
498487
type: object
499488
properties:
@@ -503,15 +492,21 @@ components:
503492
omrade:
504493
type: string
505494
example: "URL Format och namngivning"
495+
required:
496+
- id
497+
- omrade
498+
506499
PopulatedDiagnosticRuleInfo:
507-
type: object
508500
allOf:
509-
- $ref: "#/components/schemas/DiagnosticRuleInfo"
501+
- $ref: '#/components/schemas/DiagnosticRuleInfo'
510502
- type: object
511503
properties:
512504
status:
513505
type: string
514506
example: "OK"
507+
required:
508+
- status
509+
515510
DiagnosticReport:
516511
type: object
517512
properties:
@@ -521,4 +516,46 @@ components:
521516
regler:
522517
type: array
523518
items:
524-
$ref: "#/components/schemas/PopulatedDiagnosticRuleInfo"
519+
$ref: '#/components/schemas/PopulatedDiagnosticRuleInfo'
520+
required:
521+
- Notering
522+
- regler
523+
524+
DiagnosticRuleinfoSet:
525+
type: object
526+
# additionalProperties: false
527+
properties:
528+
notApplicableRules:
529+
type: array
530+
items:
531+
$ref: '#/components/schemas/DiagnosticRuleInfo'
532+
executedUniqueRules:
533+
type: array
534+
items:
535+
$ref: '#/components/schemas/DiagnosticRuleInfo'
536+
executedUniqueRulesWithError:
537+
type: array
538+
items:
539+
$ref: '#/components/schemas/DiagnosticRuleInfo'
540+
541+
RapLPDiagnostic:
542+
type: object
543+
properties:
544+
_ruleSets:
545+
$ref: '#/components/schemas/DiagnosticRuleinfoSet'
546+
547+
ValidationResponseDto:
548+
type: object
549+
properties:
550+
result:
551+
type: array
552+
items:
553+
$ref: "#/components/schemas/RapLPCustomSpectralDiagnosticItem"
554+
report:
555+
type: array
556+
items:
557+
$ref: "#/components/schemas/DiagnosticReport"
558+
required:
559+
- result
560+
- report
561+

src/routes/validate.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { importAndCreateRuleInstances } from "../util/ruleUtil.ts";
1111
import { ApiInfo } from "../model/ApiInfo.ts";
1212
import { validationRules } from "../model/validationRules.ts";
1313
import { ExcelReportProcessor } from "../util/excelReportProcessor.ts"
14-
import {DiagnosticReport } from "../util/RapLPDiagnostic.ts";
14+
import {DiagnosticReport, RapLPDiagnostic } from "../util/RapLPDiagnostic.ts";
1515

1616
export const registerValidationRoutes = (app: Express) => {
1717
// Route for raw content upload.
@@ -55,15 +55,23 @@ export const registerValidationRoutes = (app: Express) => {
5555
try {
5656
const data = req.body;
5757

58-
if (!data || !data.report || !Array.isArray(data.report)) {
59-
return res.status(400).json({ error: 'Invalid data format. Expected an object with a "report" array.' });
58+
if (!data || !data.result || !Array.isArray(data.result)) {
59+
return res.status(400).json({ error: 'Invalid data format. Expected an object with a "result" array.' });
6060
}
6161

6262
const reportHandler = new ExcelReportProcessor();
6363
let buffer: Buffer;
6464

65+
const ruleCategories = data.categories && data.categories.length > 0 ? data.categories: undefined;
66+
67+
68+
const enabledRulesAndCategorys = await importAndCreateRuleInstances(ruleCategories);
69+
const customDiagnostic = new RapLPDiagnostic();
70+
customDiagnostic.processRuleExecutionInformation(data.result,enabledRulesAndCategorys.instanceCategoryMap);
71+
const diagnosticReports: DiagnosticReport[] = customDiagnostic.processDiagnosticInformation();
72+
6573
try {
66-
buffer = reportHandler.generateReportDocumentBuffer(data.report);
74+
buffer = reportHandler.generateReportDocumentBuffer(customDiagnostic);
6775
} catch (error) {
6876
console.error("Error generating report buffer:", error);
6977
return res.status(500).json({ error: 'Failed to generate report.' });

src/util/apiUtil.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ export async function processApiSpec(
5252
);
5353
const diagnosticReports: DiagnosticReport[] =
5454
customDiagnostic.processDiagnosticInformation();
55-
5655
return { result, report: diagnosticReports };
5756
}
5857

0 commit comments

Comments
 (0)