Skip to content

Commit 372aa90

Browse files
authored
feat: cars enhancements (#29)
1 parent 1ffc44b commit 372aa90

File tree

7 files changed

+113
-5
lines changed

7 files changed

+113
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
rule:
2+
kind: user_type
3+
inside:
4+
any:
5+
- kind: parameter
6+
regex: pickupTime
7+
- kind: parameter
8+
regex: dropOffTime
9+
stopBy:
10+
kind: class_declaration
11+
regex: Builder
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
rule:
2+
kind: user_type
3+
pattern: $TYPE
4+
inside:
5+
any:
6+
- kind: class_parameter
7+
regex: pickupTime
8+
- kind: class_parameter
9+
regex: dropOffTime
10+
- kind: nullable_type
11+
inside:
12+
any:
13+
- kind: class_parameter
14+
regex: pickupTime
15+
- kind: class_parameter
16+
regex: dropOffTime
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
rule:
2+
kind: "import_header"
3+
regex: "OperationParams"
4+
pattern: "$HEADER"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
rule:
2+
kind: value_argument
3+
nthChild: 2
4+
inside:
5+
kind: call_suffix
6+
stopBy: end
7+
has:
8+
any:
9+
- kind: value_arguments
10+
regex: pickupTime
11+
- kind: value_arguments
12+
regex: dropOffTime
13+
inside:
14+
kind: function_declaration
15+
stopBy: end
16+
regex: getQueryParams

customizations/generator/openapi/src/main/resources/post-processor/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {GetLodgingQuotesOperationParamsProcessor} from './processors/get-lodging
44
import {NonCancellableDateTimeRangeProcessor} from './processors/non-cancellable-date-time-range-processor';
55
import {PenaltyRuleProcessor} from './processors/penalty-rule-processor';
66
import {VendorLocationDetailsProcessor} from './processors/vendor-location-details-processor';
7+
import {GetCarsListingsOperationParamsProcessor} from './processors/get-cars-listings-operation-params-processor';
78

89
import * as path from 'path';
910

@@ -30,4 +31,7 @@ switch (fileName) {
3031
case 'VendorLocationDetails':
3132
new VendorLocationDetailsProcessor().process(filePath);
3233
break;
34+
case 'GetCarsListingsOperationParams':
35+
new GetCarsListingsOperationParamsProcessor().process(filePath);
36+
break;
3337
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import {Edit, NapiConfig, SgNode} from '@ast-grep/napi';
2+
import {Processor} from './processor';
3+
import {RuleFunction} from './shared.types';
4+
5+
export class GetCarsListingsOperationParamsProcessor extends Processor {
6+
rules: RuleFunction[];
7+
id: String = 'get-cars-listings-operation-params';
8+
9+
constructor() {
10+
super();
11+
this.rules = [
12+
this.changeClassParamType,
13+
this.changeBuilderMethodParamType,
14+
this.importChronoUnit,
15+
this.truncatePickupDropoffTimes,
16+
].map(rule => rule.bind(this));
17+
}
18+
19+
changeClassParamType(root: SgNode): Edit[] {
20+
const config = this.readRule('change-class-params-type');
21+
22+
return root.findAll(config).map(node => {
23+
return node.replace('java.time.LocalDateTime');
24+
});
25+
}
26+
27+
changeBuilderMethodParamType(root: SgNode): Edit[] {
28+
const config = this.readRule('change-builder-method-params-type');
29+
30+
return root.findAll(config).map(node => {
31+
return node.replace('java.time.LocalDateTime');
32+
});
33+
}
34+
35+
importChronoUnit(root: SgNode): Edit[] {
36+
const config = this.readRule('import-chrono-unit');
37+
38+
return root.findAll(config).map(node => {
39+
const room = 'import java.time.temporal.ChronoUnit';
40+
const header = node.getMatch('HEADER')?.text();
41+
42+
return node.replace(`${room}\n${header}`);
43+
});
44+
45+
}
46+
47+
truncatePickupDropoffTimes(root: SgNode): Edit[] {
48+
const config = this.readRule('truncate-pickup-dropoff-times');
49+
50+
return root.findAll(config).map(node => {
51+
return node.replace('it.truncatedTo(ChronoUnit.MINUTES).toString()');
52+
});
53+
}
54+
}

specs/xap-car.specs.yaml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ paths:
6969
in: query
7070
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.'
7171
schema:
72-
type: string
73-
example: '10'
72+
type: integer
73+
example: 10
7474
- name: dropOff.airport
7575
in: query
7676
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:
9898
in: query
9999
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.'
100100
schema:
101-
type: string
102-
example: '10'
101+
type: integer
102+
example: 10
103103
- name: pickupTime
104104
in: query
105105
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.)'
106+
required: true
106107
schema:
107108
type: string
109+
format: date-time
108110
example: '2021-06-05T10:00'
109111
- name: dropOffTime
110112
in: query
111113
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.'
114+
required: true
112115
schema:
113116
type: string
117+
format: date-time
114118
example: '2021-06-06T10:00'
115119
- name: sortType
116120
in: query
@@ -1477,7 +1481,6 @@ components:
14771481
description: Details of requested car.
14781482
CarDetailsResponse:
14791483
required:
1480-
- CarDetails
14811484
- TransactionId
14821485
type: object
14831486
properties:

0 commit comments

Comments
 (0)