From d66d2b2d0af9b074b19df3b69fb6e6ecc7fe9c34 Mon Sep 17 00:00:00 2001 From: Konrad Markus Date: Wed, 20 Sep 2023 17:49:42 +0300 Subject: [PATCH] Tighten itineraries-create request schemas --- .../itinerary-create/request-v1.json | 4 +- .../itinerary-create/request-v2.json | 4 +- .../itineraries/itinerary-create/request.json | 4 +- .../itinerary-create/request-v1.ts | 120 +++++++++++------ .../itinerary-create/request-v2.ts | 120 +++++++++++------ .../itineraries/itinerary-create/request.ts | 124 ++++++++++++------ 6 files changed, 251 insertions(+), 125 deletions(-) diff --git a/maas-schemas/schemas/maas-backend/itineraries/itinerary-create/request-v1.json b/maas-schemas/schemas/maas-backend/itineraries/itinerary-create/request-v1.json index 40c3c6f48..0f43ed419 100644 --- a/maas-schemas/schemas/maas-backend/itineraries/itinerary-create/request-v1.json +++ b/maas-schemas/schemas/maas-backend/itineraries/itinerary-create/request-v1.json @@ -15,6 +15,7 @@ "$ref": "#/definitions/body" } }, + "required": ["headers", "requestContext", "body"], "definitions": { "body": { "type": "object", @@ -55,7 +56,8 @@ } } } - } + }, + "required": ["itinerary"] } } } diff --git a/maas-schemas/schemas/maas-backend/itineraries/itinerary-create/request-v2.json b/maas-schemas/schemas/maas-backend/itineraries/itinerary-create/request-v2.json index 3d67acf96..6a4e64b3c 100644 --- a/maas-schemas/schemas/maas-backend/itineraries/itinerary-create/request-v2.json +++ b/maas-schemas/schemas/maas-backend/itineraries/itinerary-create/request-v2.json @@ -15,6 +15,7 @@ "$ref": "#/definitions/body" } }, + "required": ["headers", "requestContext", "body"], "definitions": { "body": { "type": "object", @@ -55,7 +56,8 @@ } } } - } + }, + "required": ["itinerary"] } } } diff --git a/maas-schemas/schemas/maas-backend/itineraries/itinerary-create/request.json b/maas-schemas/schemas/maas-backend/itineraries/itinerary-create/request.json index 64c89b735..7d9ae48cc 100644 --- a/maas-schemas/schemas/maas-backend/itineraries/itinerary-create/request.json +++ b/maas-schemas/schemas/maas-backend/itineraries/itinerary-create/request.json @@ -15,6 +15,7 @@ "$ref": "#/definitions/body" } }, + "required": ["headers", "requestContext", "body"], "definitions": { "body": { "type": "object", @@ -58,7 +59,8 @@ } } } - } + }, + "required": ["itinerary"] } } } diff --git a/maas-schemas/src/io-ts/_types/maas-backend/itineraries/itinerary-create/request-v1.ts b/maas-schemas/src/io-ts/_types/maas-backend/itineraries/itinerary-create/request-v1.ts index 70f7fa34e..ab36ffebf 100644 --- a/maas-schemas/src/io-ts/_types/maas-backend/itineraries/itinerary-create/request-v1.ts +++ b/maas-schemas/src/io-ts/_types/maas-backend/itineraries/itinerary-create/request-v1.ts @@ -38,7 +38,7 @@ export const schemaId = // OutwardReturnWrapper // The purpose of this remains a mystery export type OutwardReturnWrapper = t.Branded< - { + ({ itinerary?: Itinerary_8303_.Itinerary; customerSelections?: Array< { @@ -46,51 +46,65 @@ export type OutwardReturnWrapper = t.Branded< customerSelection?: CustomerSelection_57c3_.CustomerSelection; } & Record >; - } & Record, + } & Record) & { + itinerary: Defined; + }, OutwardReturnWrapperBrand >; export type OutwardReturnWrapperC = t.BrandC< t.IntersectionC< [ - t.PartialC<{ - itinerary: typeof Itinerary_8303_.Itinerary; - customerSelections: t.ArrayC< - t.IntersectionC< - [ - t.PartialC<{ - ref: typeof ProductOptionV2_8170_.Ref; - customerSelection: typeof CustomerSelection_57c3_.CustomerSelection; - }>, - t.RecordC, - ] - > - >; + t.IntersectionC< + [ + t.PartialC<{ + itinerary: typeof Itinerary_8303_.Itinerary; + customerSelections: t.ArrayC< + t.IntersectionC< + [ + t.PartialC<{ + ref: typeof ProductOptionV2_8170_.Ref; + customerSelection: typeof CustomerSelection_57c3_.CustomerSelection; + }>, + t.RecordC, + ] + > + >; + }>, + t.RecordC, + ] + >, + t.TypeC<{ + itinerary: typeof Defined; }>, - t.RecordC, ] >, OutwardReturnWrapperBrand >; export const OutwardReturnWrapper: OutwardReturnWrapperC = t.brand( t.intersection([ - t.partial({ - itinerary: Itinerary_8303_.Itinerary, - customerSelections: t.array( - t.intersection([ - t.partial({ - ref: ProductOptionV2_8170_.Ref, - customerSelection: CustomerSelection_57c3_.CustomerSelection, - }), - t.record(t.string, t.unknown), - ]), - ), + t.intersection([ + t.partial({ + itinerary: Itinerary_8303_.Itinerary, + customerSelections: t.array( + t.intersection([ + t.partial({ + ref: ProductOptionV2_8170_.Ref, + customerSelection: CustomerSelection_57c3_.CustomerSelection, + }), + t.record(t.string, t.unknown), + ]), + ), + }), + t.record(t.string, t.unknown), + ]), + t.type({ + itinerary: Defined, }), - t.record(t.string, t.unknown), ]), ( x, ): x is t.Branded< - { + ({ itinerary?: Itinerary_8303_.Itinerary; customerSelections?: Array< { @@ -98,7 +112,9 @@ export const OutwardReturnWrapper: OutwardReturnWrapperC = t.brand( customerSelection?: CustomerSelection_57c3_.CustomerSelection; } & Record >; - } & Record, + } & Record) & { + itinerary: Defined; + }, OutwardReturnWrapperBrand > => true, 'OutwardReturnWrapper', @@ -178,23 +194,43 @@ export type RequestV1 = t.Branded< headers?: ApiCommon_16a4_.StandardApiEndpointHeaders; requestContext?: ApiCommon_16a4_.ApiGatewayAuthorizedRequestContext; body?: Body; + } & { + headers: Defined; + requestContext: Defined; + body: Defined; }, RequestV1Brand >; export type RequestV1C = t.BrandC< - t.PartialC<{ - headers: typeof ApiCommon_16a4_.StandardApiEndpointHeaders; - requestContext: typeof ApiCommon_16a4_.ApiGatewayAuthorizedRequestContext; - body: typeof Body; - }>, + t.IntersectionC< + [ + t.PartialC<{ + headers: typeof ApiCommon_16a4_.StandardApiEndpointHeaders; + requestContext: typeof ApiCommon_16a4_.ApiGatewayAuthorizedRequestContext; + body: typeof Body; + }>, + t.TypeC<{ + headers: typeof Defined; + requestContext: typeof Defined; + body: typeof Defined; + }>, + ] + >, RequestV1Brand >; export const RequestV1: RequestV1C = t.brand( - t.partial({ - headers: ApiCommon_16a4_.StandardApiEndpointHeaders, - requestContext: ApiCommon_16a4_.ApiGatewayAuthorizedRequestContext, - body: Body, - }), + t.intersection([ + t.partial({ + headers: ApiCommon_16a4_.StandardApiEndpointHeaders, + requestContext: ApiCommon_16a4_.ApiGatewayAuthorizedRequestContext, + body: Body, + }), + t.type({ + headers: Defined, + requestContext: Defined, + body: Defined, + }), + ]), ( x, ): x is t.Branded< @@ -202,6 +238,10 @@ export const RequestV1: RequestV1C = t.brand( headers?: ApiCommon_16a4_.StandardApiEndpointHeaders; requestContext?: ApiCommon_16a4_.ApiGatewayAuthorizedRequestContext; body?: Body; + } & { + headers: Defined; + requestContext: Defined; + body: Defined; }, RequestV1Brand > => true, diff --git a/maas-schemas/src/io-ts/_types/maas-backend/itineraries/itinerary-create/request-v2.ts b/maas-schemas/src/io-ts/_types/maas-backend/itineraries/itinerary-create/request-v2.ts index a60a5d7cd..8b8c01694 100644 --- a/maas-schemas/src/io-ts/_types/maas-backend/itineraries/itinerary-create/request-v2.ts +++ b/maas-schemas/src/io-ts/_types/maas-backend/itineraries/itinerary-create/request-v2.ts @@ -38,7 +38,7 @@ export const schemaId = // OutwardReturnWrapper // The purpose of this remains a mystery export type OutwardReturnWrapper = t.Branded< - { + ({ itinerary?: ItineraryV2_5f31_.ItineraryV2; customerSelections?: Array< { @@ -46,51 +46,65 @@ export type OutwardReturnWrapper = t.Branded< customerSelection?: CustomerSelection_57c3_.CustomerSelection; } & Record >; - } & Record, + } & Record) & { + itinerary: Defined; + }, OutwardReturnWrapperBrand >; export type OutwardReturnWrapperC = t.BrandC< t.IntersectionC< [ - t.PartialC<{ - itinerary: typeof ItineraryV2_5f31_.ItineraryV2; - customerSelections: t.ArrayC< - t.IntersectionC< - [ - t.PartialC<{ - ref: typeof ProductOptionV2_8170_.Ref; - customerSelection: typeof CustomerSelection_57c3_.CustomerSelection; - }>, - t.RecordC, - ] - > - >; + t.IntersectionC< + [ + t.PartialC<{ + itinerary: typeof ItineraryV2_5f31_.ItineraryV2; + customerSelections: t.ArrayC< + t.IntersectionC< + [ + t.PartialC<{ + ref: typeof ProductOptionV2_8170_.Ref; + customerSelection: typeof CustomerSelection_57c3_.CustomerSelection; + }>, + t.RecordC, + ] + > + >; + }>, + t.RecordC, + ] + >, + t.TypeC<{ + itinerary: typeof Defined; }>, - t.RecordC, ] >, OutwardReturnWrapperBrand >; export const OutwardReturnWrapper: OutwardReturnWrapperC = t.brand( t.intersection([ - t.partial({ - itinerary: ItineraryV2_5f31_.ItineraryV2, - customerSelections: t.array( - t.intersection([ - t.partial({ - ref: ProductOptionV2_8170_.Ref, - customerSelection: CustomerSelection_57c3_.CustomerSelection, - }), - t.record(t.string, t.unknown), - ]), - ), + t.intersection([ + t.partial({ + itinerary: ItineraryV2_5f31_.ItineraryV2, + customerSelections: t.array( + t.intersection([ + t.partial({ + ref: ProductOptionV2_8170_.Ref, + customerSelection: CustomerSelection_57c3_.CustomerSelection, + }), + t.record(t.string, t.unknown), + ]), + ), + }), + t.record(t.string, t.unknown), + ]), + t.type({ + itinerary: Defined, }), - t.record(t.string, t.unknown), ]), ( x, ): x is t.Branded< - { + ({ itinerary?: ItineraryV2_5f31_.ItineraryV2; customerSelections?: Array< { @@ -98,7 +112,9 @@ export const OutwardReturnWrapper: OutwardReturnWrapperC = t.brand( customerSelection?: CustomerSelection_57c3_.CustomerSelection; } & Record >; - } & Record, + } & Record) & { + itinerary: Defined; + }, OutwardReturnWrapperBrand > => true, 'OutwardReturnWrapper', @@ -178,23 +194,43 @@ export type RequestV2 = t.Branded< headers?: ApiCommon_16a4_.StandardApiEndpointHeaders; requestContext?: ApiCommon_16a4_.ApiGatewayAuthorizedRequestContext; body?: Body; + } & { + headers: Defined; + requestContext: Defined; + body: Defined; }, RequestV2Brand >; export type RequestV2C = t.BrandC< - t.PartialC<{ - headers: typeof ApiCommon_16a4_.StandardApiEndpointHeaders; - requestContext: typeof ApiCommon_16a4_.ApiGatewayAuthorizedRequestContext; - body: typeof Body; - }>, + t.IntersectionC< + [ + t.PartialC<{ + headers: typeof ApiCommon_16a4_.StandardApiEndpointHeaders; + requestContext: typeof ApiCommon_16a4_.ApiGatewayAuthorizedRequestContext; + body: typeof Body; + }>, + t.TypeC<{ + headers: typeof Defined; + requestContext: typeof Defined; + body: typeof Defined; + }>, + ] + >, RequestV2Brand >; export const RequestV2: RequestV2C = t.brand( - t.partial({ - headers: ApiCommon_16a4_.StandardApiEndpointHeaders, - requestContext: ApiCommon_16a4_.ApiGatewayAuthorizedRequestContext, - body: Body, - }), + t.intersection([ + t.partial({ + headers: ApiCommon_16a4_.StandardApiEndpointHeaders, + requestContext: ApiCommon_16a4_.ApiGatewayAuthorizedRequestContext, + body: Body, + }), + t.type({ + headers: Defined, + requestContext: Defined, + body: Defined, + }), + ]), ( x, ): x is t.Branded< @@ -202,6 +238,10 @@ export const RequestV2: RequestV2C = t.brand( headers?: ApiCommon_16a4_.StandardApiEndpointHeaders; requestContext?: ApiCommon_16a4_.ApiGatewayAuthorizedRequestContext; body?: Body; + } & { + headers: Defined; + requestContext: Defined; + body: Defined; }, RequestV2Brand > => true, diff --git a/maas-schemas/src/io-ts/_types/maas-backend/itineraries/itinerary-create/request.ts b/maas-schemas/src/io-ts/_types/maas-backend/itineraries/itinerary-create/request.ts index 1d4e46a37..91370ffe6 100644 --- a/maas-schemas/src/io-ts/_types/maas-backend/itineraries/itinerary-create/request.ts +++ b/maas-schemas/src/io-ts/_types/maas-backend/itineraries/itinerary-create/request.ts @@ -39,7 +39,7 @@ export const schemaId = // OutwardReturnWrapper // The purpose of this remains a mystery export type OutwardReturnWrapper = t.Branded< - { + ({ itinerary?: Itinerary_8303_.Itinerary | ItineraryV2_5f31_.ItineraryV2; customerSelections?: Array< { @@ -47,53 +47,67 @@ export type OutwardReturnWrapper = t.Branded< customerSelection?: CustomerSelection_57c3_.CustomerSelection; } & Record >; - } & Record, + } & Record) & { + itinerary: Defined; + }, OutwardReturnWrapperBrand >; export type OutwardReturnWrapperC = t.BrandC< t.IntersectionC< [ - t.PartialC<{ - itinerary: t.UnionC< - [typeof Itinerary_8303_.Itinerary, typeof ItineraryV2_5f31_.ItineraryV2] - >; - customerSelections: t.ArrayC< - t.IntersectionC< - [ - t.PartialC<{ - ref: typeof ProductOptionV2_8170_.Ref; - customerSelection: typeof CustomerSelection_57c3_.CustomerSelection; - }>, - t.RecordC, - ] - > - >; + t.IntersectionC< + [ + t.PartialC<{ + itinerary: t.UnionC< + [typeof Itinerary_8303_.Itinerary, typeof ItineraryV2_5f31_.ItineraryV2] + >; + customerSelections: t.ArrayC< + t.IntersectionC< + [ + t.PartialC<{ + ref: typeof ProductOptionV2_8170_.Ref; + customerSelection: typeof CustomerSelection_57c3_.CustomerSelection; + }>, + t.RecordC, + ] + > + >; + }>, + t.RecordC, + ] + >, + t.TypeC<{ + itinerary: typeof Defined; }>, - t.RecordC, ] >, OutwardReturnWrapperBrand >; export const OutwardReturnWrapper: OutwardReturnWrapperC = t.brand( t.intersection([ - t.partial({ - itinerary: t.union([Itinerary_8303_.Itinerary, ItineraryV2_5f31_.ItineraryV2]), - customerSelections: t.array( - t.intersection([ - t.partial({ - ref: ProductOptionV2_8170_.Ref, - customerSelection: CustomerSelection_57c3_.CustomerSelection, - }), - t.record(t.string, t.unknown), - ]), - ), + t.intersection([ + t.partial({ + itinerary: t.union([Itinerary_8303_.Itinerary, ItineraryV2_5f31_.ItineraryV2]), + customerSelections: t.array( + t.intersection([ + t.partial({ + ref: ProductOptionV2_8170_.Ref, + customerSelection: CustomerSelection_57c3_.CustomerSelection, + }), + t.record(t.string, t.unknown), + ]), + ), + }), + t.record(t.string, t.unknown), + ]), + t.type({ + itinerary: Defined, }), - t.record(t.string, t.unknown), ]), ( x, ): x is t.Branded< - { + ({ itinerary?: Itinerary_8303_.Itinerary | ItineraryV2_5f31_.ItineraryV2; customerSelections?: Array< { @@ -101,7 +115,9 @@ export const OutwardReturnWrapper: OutwardReturnWrapperC = t.brand( customerSelection?: CustomerSelection_57c3_.CustomerSelection; } & Record >; - } & Record, + } & Record) & { + itinerary: Defined; + }, OutwardReturnWrapperBrand > => true, 'OutwardReturnWrapper', @@ -181,23 +197,43 @@ export type Request = t.Branded< headers?: ApiCommon_16a4_.StandardApiEndpointHeaders; requestContext?: ApiCommon_16a4_.ApiGatewayAuthorizedRequestContext; body?: Body; + } & { + headers: Defined; + requestContext: Defined; + body: Defined; }, RequestBrand >; export type RequestC = t.BrandC< - t.PartialC<{ - headers: typeof ApiCommon_16a4_.StandardApiEndpointHeaders; - requestContext: typeof ApiCommon_16a4_.ApiGatewayAuthorizedRequestContext; - body: typeof Body; - }>, + t.IntersectionC< + [ + t.PartialC<{ + headers: typeof ApiCommon_16a4_.StandardApiEndpointHeaders; + requestContext: typeof ApiCommon_16a4_.ApiGatewayAuthorizedRequestContext; + body: typeof Body; + }>, + t.TypeC<{ + headers: typeof Defined; + requestContext: typeof Defined; + body: typeof Defined; + }>, + ] + >, RequestBrand >; export const Request: RequestC = t.brand( - t.partial({ - headers: ApiCommon_16a4_.StandardApiEndpointHeaders, - requestContext: ApiCommon_16a4_.ApiGatewayAuthorizedRequestContext, - body: Body, - }), + t.intersection([ + t.partial({ + headers: ApiCommon_16a4_.StandardApiEndpointHeaders, + requestContext: ApiCommon_16a4_.ApiGatewayAuthorizedRequestContext, + body: Body, + }), + t.type({ + headers: Defined, + requestContext: Defined, + body: Defined, + }), + ]), ( x, ): x is t.Branded< @@ -205,6 +241,10 @@ export const Request: RequestC = t.brand( headers?: ApiCommon_16a4_.StandardApiEndpointHeaders; requestContext?: ApiCommon_16a4_.ApiGatewayAuthorizedRequestContext; body?: Body; + } & { + headers: Defined; + requestContext: Defined; + body: Defined; }, RequestBrand > => true,