From a91a715279d2b01931308156e3edc7511283dc3e Mon Sep 17 00:00:00 2001 From: Nasser Anssari Date: Thu, 7 Nov 2024 16:39:04 +0300 Subject: [PATCH 1/4] chore: update cars specs --- specs/xap-car.specs.yaml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/specs/xap-car.specs.yaml b/specs/xap-car.specs.yaml index f947986..7a39d3a 100644 --- a/specs/xap-car.specs.yaml +++ b/specs/xap-car.specs.yaml @@ -69,8 +69,8 @@ paths: in: query description: 'Radius used in conjunction with a point to define the search area when searching by lat/ long, city or address.See '' unit'' parameter below to select miles or kilometers.If no value is specified a default value of 25 will be assumed.' schema: - type: string - example: '10' + type: integer + example: 10 - name: dropOff.airport in: query description: 'Three letter code for the airport at which the customer would like to drop off the car.Supported values: standard 3 letter IATA Airport Code.Please see a full list of Car Vendor Codes and Airport Codes in the Related Links Section below.Cannot coexist with other drop off parameters, only one drop off parameter is allowed per request.If no drop off location is specified, it is assumed that the customer will be dropping the car off at the same location at which they picked it up.' @@ -98,19 +98,23 @@ paths: in: query description: 'Radius used in conjunction with a point to define the search area when searching by lat/ long, city or address.See '' unit'' parameter below to select miles or kilometers.If no value is specified a default value of 25 will be assumed.Note: The pickup radius value will be used (instead of the the drop-off radius) when the requested pickup and drop-off city/address are exactly the same.' schema: - type: string - example: '10' + type: integer + example: 10 - name: pickupTime in: query description: 'Requested car pickup date and time.Date should be ISO8601 Date format.The default TIME is 10:30:00.The supported search window is today to 330 days in the future.(Note that each rental counter has different hours of operation. If you select a time in the middle of the night there may be no inventory available as all locations may be closed.)' + required: true schema: type: string + format: date-time example: '2021-06-05T10:00' - name: dropOffTime in: query description: 'Requested car drop off date and time. Date should be ISO8601 Date format.The supported search window is today to 330 days in the future.Note: The dropOffTime must be at least 2 hours later than the pickupTime for the request to be valid.' + required: true schema: type: string + format: date-time example: '2021-06-06T10:00' - name: sortType in: query @@ -1477,7 +1481,6 @@ components: description: Details of requested car. CarDetailsResponse: required: - - CarDetails - TransactionId type: object properties: From bc743b348eb6ae4ab81ad5ecfb57cb97a133406b Mon Sep 17 00:00:00 2001 From: Nasser Anssari Date: Sun, 10 Nov 2024 14:37:06 +0300 Subject: [PATCH 2/4] post-process GetCarsListingsOperationParams --- .../change-builder-method-params-type.yaml | 11 +++++++ .../change-class-params-type.yaml | 16 ++++++++++ .../get-cars-listings-operation-params.ts | 32 +++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 customizations/generator/openapi/src/main/resources/post-processor/assets/rules/get-cars-listings-operation-params/change-builder-method-params-type.yaml create mode 100644 customizations/generator/openapi/src/main/resources/post-processor/assets/rules/get-cars-listings-operation-params/change-class-params-type.yaml create mode 100644 customizations/generator/openapi/src/main/resources/post-processor/src/processors/get-cars-listings-operation-params.ts diff --git a/customizations/generator/openapi/src/main/resources/post-processor/assets/rules/get-cars-listings-operation-params/change-builder-method-params-type.yaml b/customizations/generator/openapi/src/main/resources/post-processor/assets/rules/get-cars-listings-operation-params/change-builder-method-params-type.yaml new file mode 100644 index 0000000..c273f8d --- /dev/null +++ b/customizations/generator/openapi/src/main/resources/post-processor/assets/rules/get-cars-listings-operation-params/change-builder-method-params-type.yaml @@ -0,0 +1,11 @@ +rule: + kind: user_type + inside: + any: + - kind: parameter + regex: pickupTime + - kind: parameter + regex: dropOffTime + stopBy: + kind: class_declaration + regex: Builder diff --git a/customizations/generator/openapi/src/main/resources/post-processor/assets/rules/get-cars-listings-operation-params/change-class-params-type.yaml b/customizations/generator/openapi/src/main/resources/post-processor/assets/rules/get-cars-listings-operation-params/change-class-params-type.yaml new file mode 100644 index 0000000..606ec0f --- /dev/null +++ b/customizations/generator/openapi/src/main/resources/post-processor/assets/rules/get-cars-listings-operation-params/change-class-params-type.yaml @@ -0,0 +1,16 @@ +rule: + kind: user_type + pattern: $TYPE + inside: + any: + - kind: class_parameter + regex: pickupTime + - kind: class_parameter + regex: dropOffTime + - kind: nullable_type + inside: + any: + - kind: class_parameter + regex: pickupTime + - kind: class_parameter + regex: dropOffTime diff --git a/customizations/generator/openapi/src/main/resources/post-processor/src/processors/get-cars-listings-operation-params.ts b/customizations/generator/openapi/src/main/resources/post-processor/src/processors/get-cars-listings-operation-params.ts new file mode 100644 index 0000000..3d457cf --- /dev/null +++ b/customizations/generator/openapi/src/main/resources/post-processor/src/processors/get-cars-listings-operation-params.ts @@ -0,0 +1,32 @@ +import {Edit, NapiConfig, SgNode} from '@ast-grep/napi'; +import {Processor} from './processor'; +import {RuleFunction} from './shared.types'; + +export class NonCancellableDateTimeRangeProcessor extends Processor { + rules: RuleFunction[]; + id: String = 'get-cars-listings-operation-params'; + + constructor() { + super(); + this.rules = [ + this.changeClassParamType, + this.changeBuilderMethodParamType, + ].map(rule => rule.bind(this)); + } + + changeClassParamType(root: SgNode): Edit[] { + const config = this.readRule('change-class-params-type'); + + return root.findAll(config).map(node => { + return node.replace('java.time.LocalDateTime'); + }); + } + + changeBuilderMethodParamType(root: SgNode): Edit[] { + const config = this.readRule('change-builder-method-params-type'); + + return root.findAll(config).map(node => { + return node.replace('java.time.LocalDateTime'); + }); + } +} From 7baea477c0c93b7b5c6b50ece3abd103478ad6b2 Mon Sep 17 00:00:00 2001 From: Nasser Anssari Date: Sun, 10 Nov 2024 14:56:36 +0300 Subject: [PATCH 3/4] fixup --- .../openapi/src/main/resources/post-processor/src/index.ts | 4 ++++ ...ams.ts => get-cars-listings-operation-params-processor.ts} | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) rename customizations/generator/openapi/src/main/resources/post-processor/src/processors/{get-cars-listings-operation-params.ts => get-cars-listings-operation-params-processor.ts} (92%) diff --git a/customizations/generator/openapi/src/main/resources/post-processor/src/index.ts b/customizations/generator/openapi/src/main/resources/post-processor/src/index.ts index 01d23d4..e8fa9d1 100644 --- a/customizations/generator/openapi/src/main/resources/post-processor/src/index.ts +++ b/customizations/generator/openapi/src/main/resources/post-processor/src/index.ts @@ -4,6 +4,7 @@ import {GetLodgingQuotesOperationParamsProcessor} from './processors/get-lodging import {NonCancellableDateTimeRangeProcessor} from './processors/non-cancellable-date-time-range-processor'; import {PenaltyRuleProcessor} from './processors/penalty-rule-processor'; import {VendorLocationDetailsProcessor} from './processors/vendor-location-details-processor'; +import {GetCarsListingsOperationParamsProcessor} from './processors/get-cars-listings-operation-params-processor'; import * as path from 'path'; @@ -30,4 +31,7 @@ switch (fileName) { case 'VendorLocationDetails': new VendorLocationDetailsProcessor().process(filePath); break; + case 'GetCarsListingsOperationParams': + new GetCarsListingsOperationParamsProcessor().process(filePath); + break; } diff --git a/customizations/generator/openapi/src/main/resources/post-processor/src/processors/get-cars-listings-operation-params.ts b/customizations/generator/openapi/src/main/resources/post-processor/src/processors/get-cars-listings-operation-params-processor.ts similarity index 92% rename from customizations/generator/openapi/src/main/resources/post-processor/src/processors/get-cars-listings-operation-params.ts rename to customizations/generator/openapi/src/main/resources/post-processor/src/processors/get-cars-listings-operation-params-processor.ts index 3d457cf..bf11850 100644 --- a/customizations/generator/openapi/src/main/resources/post-processor/src/processors/get-cars-listings-operation-params.ts +++ b/customizations/generator/openapi/src/main/resources/post-processor/src/processors/get-cars-listings-operation-params-processor.ts @@ -2,7 +2,7 @@ import {Edit, NapiConfig, SgNode} from '@ast-grep/napi'; import {Processor} from './processor'; import {RuleFunction} from './shared.types'; -export class NonCancellableDateTimeRangeProcessor extends Processor { +export class GetCarsListingsOperationParamsProcessor extends Processor { rules: RuleFunction[]; id: String = 'get-cars-listings-operation-params'; From e1708c6ba04b4772cbad89275af2d67c43e3ad1a Mon Sep 17 00:00:00 2001 From: Nasser Anssari Date: Sun, 10 Nov 2024 17:37:41 +0300 Subject: [PATCH 4/4] truncate dropoff and pickup times --- .../import-chrono-unit.yaml | 4 ++++ .../truncate-pickup-dropoff-times.yaml | 16 ++++++++++++++ ...ars-listings-operation-params-processor.ts | 22 +++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 customizations/generator/openapi/src/main/resources/post-processor/assets/rules/get-cars-listings-operation-params/import-chrono-unit.yaml create mode 100644 customizations/generator/openapi/src/main/resources/post-processor/assets/rules/get-cars-listings-operation-params/truncate-pickup-dropoff-times.yaml diff --git a/customizations/generator/openapi/src/main/resources/post-processor/assets/rules/get-cars-listings-operation-params/import-chrono-unit.yaml b/customizations/generator/openapi/src/main/resources/post-processor/assets/rules/get-cars-listings-operation-params/import-chrono-unit.yaml new file mode 100644 index 0000000..214190f --- /dev/null +++ b/customizations/generator/openapi/src/main/resources/post-processor/assets/rules/get-cars-listings-operation-params/import-chrono-unit.yaml @@ -0,0 +1,4 @@ +rule: + kind: "import_header" + regex: "OperationParams" + pattern: "$HEADER" diff --git a/customizations/generator/openapi/src/main/resources/post-processor/assets/rules/get-cars-listings-operation-params/truncate-pickup-dropoff-times.yaml b/customizations/generator/openapi/src/main/resources/post-processor/assets/rules/get-cars-listings-operation-params/truncate-pickup-dropoff-times.yaml new file mode 100644 index 0000000..eb09ba3 --- /dev/null +++ b/customizations/generator/openapi/src/main/resources/post-processor/assets/rules/get-cars-listings-operation-params/truncate-pickup-dropoff-times.yaml @@ -0,0 +1,16 @@ +rule: + kind: value_argument + nthChild: 2 + inside: + kind: call_suffix + stopBy: end + has: + any: + - kind: value_arguments + regex: pickupTime + - kind: value_arguments + regex: dropOffTime + inside: + kind: function_declaration + stopBy: end + regex: getQueryParams diff --git a/customizations/generator/openapi/src/main/resources/post-processor/src/processors/get-cars-listings-operation-params-processor.ts b/customizations/generator/openapi/src/main/resources/post-processor/src/processors/get-cars-listings-operation-params-processor.ts index bf11850..4b5b27e 100644 --- a/customizations/generator/openapi/src/main/resources/post-processor/src/processors/get-cars-listings-operation-params-processor.ts +++ b/customizations/generator/openapi/src/main/resources/post-processor/src/processors/get-cars-listings-operation-params-processor.ts @@ -11,6 +11,8 @@ export class GetCarsListingsOperationParamsProcessor extends Processor { this.rules = [ this.changeClassParamType, this.changeBuilderMethodParamType, + this.importChronoUnit, + this.truncatePickupDropoffTimes, ].map(rule => rule.bind(this)); } @@ -29,4 +31,24 @@ export class GetCarsListingsOperationParamsProcessor extends Processor { return node.replace('java.time.LocalDateTime'); }); } + + importChronoUnit(root: SgNode): Edit[] { + const config = this.readRule('import-chrono-unit'); + + return root.findAll(config).map(node => { + const room = 'import java.time.temporal.ChronoUnit'; + const header = node.getMatch('HEADER')?.text(); + + return node.replace(`${room}\n${header}`); + }); + + } + + truncatePickupDropoffTimes(root: SgNode): Edit[] { + const config = this.readRule('truncate-pickup-dropoff-times'); + + return root.findAll(config).map(node => { + return node.replace('it.truncatedTo(ChronoUnit.MINUTES).toString()'); + }); + } }