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/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/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-processor.ts b/customizations/generator/openapi/src/main/resources/post-processor/src/processors/get-cars-listings-operation-params-processor.ts new file mode 100644 index 0000000..4b5b27e --- /dev/null +++ b/customizations/generator/openapi/src/main/resources/post-processor/src/processors/get-cars-listings-operation-params-processor.ts @@ -0,0 +1,54 @@ +import {Edit, NapiConfig, SgNode} from '@ast-grep/napi'; +import {Processor} from './processor'; +import {RuleFunction} from './shared.types'; + +export class GetCarsListingsOperationParamsProcessor extends Processor { + rules: RuleFunction[]; + id: String = 'get-cars-listings-operation-params'; + + constructor() { + super(); + this.rules = [ + this.changeClassParamType, + this.changeBuilderMethodParamType, + this.importChronoUnit, + this.truncatePickupDropoffTimes, + ].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'); + }); + } + + 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()'); + }); + } +} 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: