Skip to content

Commit 3be8a5d

Browse files
MicheleBellizziNTTMicheleBellizziNTT
andauthored
Aggiornamento Validatore 2.5.1 (#170)
* aggiornamento validator 2.5.1, allineato per bug degli stream * fix * fix2 * fix3 * fix4 --------- Co-authored-by: MicheleBellizziNTT <MicheleGiorgio.Bellizzi@nttdata.com>
1 parent 0749f50 commit 3be8a5d

23 files changed

+11281
-362
lines changed

openapi/bundled-api-external-b2b-pa-v2-5.yaml

Lines changed: 10672 additions & 0 deletions
Large diffs are not rendered by default.

openapi/how-to-generate-the-bundled-openapi-definition.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
```
1313
3. Run the command to generate the 'bundled-api-external-b2b-pa-v2-4.yaml'
1414
```
15-
java -jar swagger-codegen-cli-3.0.35.jar generate -l openapi-yaml -i https://raw.githubusercontent.com/pagopa/pn-delivery/develop/docs/openapi/api-external-b2b-pa-bundle.yaml -o . -DoutputFile=bundled-api-external-b2b-pa-v2-4.yaml
15+
java -jar swagger-codegen-cli-3.0.35.jar generate -l openapi-yaml -i https://raw.githubusercontent.com/pagopa/pn-delivery/develop/docs/openapi/api-external-b2b-pa-bundle.yaml -o . -DoutputFile=bundled-api-external-b2b-pa-v2-5.yaml
1616
```
1717
3. Then do the modification as below to the generated file.
1818
4. Add to the `Problem` and `ProblemError` the `type: object` property

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "pn-local-validator",
3-
"version": "2.5",
3+
"version": "2.5.1",
44
"description": "A system that emulates some features of Piattaforma Notifiche platform.",
55
"main": "dist/main.js",
66
"scripts": {
77
"generate": "npm run generate:api && npm run generate:pnapi",
8-
"generate:pnapi": "shx rm -rf ./src/generated/pnapi && shx mkdir -p ./src/generated/pnapi && gen-api-models --api-spec ./openapi/bundled-api-external-b2b-pa-v2-4.yaml --no-strict --out-dir ./src/generated/pnapi --request-types --response-decoders",
8+
"generate:pnapi": "shx rm -rf ./src/generated/pnapi && shx mkdir -p ./src/generated/pnapi && gen-api-models --api-spec ./openapi/bundled-api-external-b2b-pa-v2-5.yaml --no-strict --out-dir ./src/generated/pnapi --request-types --response-decoders",
99
"generate:api": "shx rm -rf ./src/generated/api && shx mkdir -p ./src/generated/api && gen-api-models --api-spec ./openapi/internal.yaml --no-strict --out-dir ./src/generated/api",
1010
"clean": "tsc --build --clean",
1111
"postcompile": "shx cp -R ./src/adapters/http/download/exampledocuments ./dist/adapters/http/download/exampledocuments",

src/adapters/http/updateEventStream/router.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as TE from 'fp-ts/TaskEither';
66
import { flow, pipe } from 'fp-ts/function';
77
import * as t from 'io-ts';
88
import { makeUpdateStreamRecord } from '../../../domain/UpdateStreamRecord';
9-
import { StreamCreationRequest } from '../../../generated/pnapi/StreamCreationRequest';
9+
import { StreamCreationRequestV28 } from '../../../generated/pnapi/StreamCreationRequestV28';
1010
import { updateStreamRecordReturningOnlyTheOneUpdatedStream } from '../../../useCases/PersistRecord';
1111
import { SystemEnv } from '../../../useCases/SystemEnv';
1212
import { Handler, toExpressHandler } from '../Handler';
@@ -18,13 +18,19 @@ const handler =
1818
pipe(
1919
Apply.sequenceS(E.Apply)({
2020
apiKey: t.string.decode(req.headers['x-api-key']),
21-
body: StreamCreationRequest.decode(req.body),
21+
body: StreamCreationRequestV28.decode(req.body),
2222
streamId: t.string.decode(req.params.streamId),
2323
}),
24-
E.map(flow(makeUpdateStreamRecord(env), updateStreamRecordReturningOnlyTheOneUpdatedStream(env))),
24+
// bridge tipizzato per evitare any
25+
E.map(
26+
flow(
27+
(input) => makeUpdateStreamRecord(env)(input), // (input: UpdateStreamRecord['input']) => CreateEventStreamRecord
28+
updateStreamRecordReturningOnlyTheOneUpdatedStream(env)
29+
)
30+
),
2531
E.map(
2632
TE.fold(
27-
(_) => T.of(res.status(404).send(Problem.fromNumber(404))),
33+
() => T.of(res.status(404).send(Problem.fromNumber(404))),
2834
({ output }) => T.of(res.status(output.statusCode).send(output.returned))
2935
)
3036
)

src/adapters/inMemory/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import { Record, RecordRepository } from '../../domain/Repository';
66
import { Logger } from '../../logger';
77
import { DeleteStreamRecord } from '../../domain/DeleteStreamRecord';
88
import { CreateEventStreamRecord, isCreateEventStreamRecord } from '../../domain/CreateEventStreamRecord';
9-
import { StreamMetadataResponse } from '../../generated/pnapi/StreamMetadataResponse';
9+
import { StreamMetadataResponseV28 } from '../../generated/pnapi/StreamMetadataResponseV28';
1010
import { GetNotificationDetailRecord } from '../../domain/GetNotificationDetailRecord';
11-
import { FullSentNotificationV21 } from '../../generated/pnapi/FullSentNotificationV21';
12-
import { NotificationStatusEnum } from '../../generated/pnapi/NotificationStatus';
11+
import { FullSentNotificationV27 } from '../../generated/pnapi/FullSentNotificationV27';
12+
import { NotificationStatusV26Enum } from '../../generated/pnapi/NotificationStatusV26';
1313

1414
const filterByStreamId = (streamId: string, record: Record): boolean =>
1515
O.fold(
1616
() => true,
17-
(csr: CreateEventStreamRecord) => (csr.output.returned as StreamMetadataResponse).streamId !== streamId
17+
(csr: CreateEventStreamRecord) => (csr.output.returned as StreamMetadataResponseV28).streamId !== streamId
1818
)(isCreateEventStreamRecord(record));
1919

2020
// TODO: Instead of mutable variable, try to use the State Monad (or STM)
@@ -51,7 +51,7 @@ export const makeRecordRepository =
5151
): TE.TaskEither<Error, ReadonlyArray<Record>> => {
5252
// Filter out CreateEventStreamRecord with matching streamId
5353
const filteredStore = store.filter((record) =>
54-
filterByStreamId((createEvenStreamRecord.output.returned as StreamMetadataResponse).streamId, record)
54+
filterByStreamId((createEvenStreamRecord.output.returned as StreamMetadataResponseV28).streamId, record)
5555
);
5656
store = [...filteredStore, createEvenStreamRecord];
5757
return TE.of(store);
@@ -61,7 +61,7 @@ export const makeRecordRepository =
6161
): TE.TaskEither<Error, CreateEventStreamRecord> => {
6262
// Filter out CreateEventStreamRecord with matching streamId
6363
const filteredStore = store.filter((record) =>
64-
filterByStreamId((createEvenStreamRecord.output.returned as StreamMetadataResponse).streamId, record)
64+
filterByStreamId((createEvenStreamRecord.output.returned as StreamMetadataResponseV28).streamId, record)
6565
);
6666
if (filteredStore.length === store.length) {
6767
const error = new Error('No records were updated.');
@@ -75,7 +75,7 @@ export const makeRecordRepository =
7575
store = [...store, element];
7676
const getNotificationDetailRecord: GetNotificationDetailRecord = (store.filter(singleRecord => singleRecord.type === 'GetNotificationDetailRecord')[0] as GetNotificationDetailRecord);
7777
if (getNotificationDetailRecord !== undefined) {
78-
(getNotificationDetailRecord.output.returned as FullSentNotificationV21).notificationStatus = NotificationStatusEnum.CANCELLED;
78+
(getNotificationDetailRecord.output.returned as FullSentNotificationV27).notificationStatus = NotificationStatusV26Enum.CANCELLED;
7979
}
8080
return TE.of(element);
8181
}

0 commit comments

Comments
 (0)