Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class OpenApiSdkGenerator {

supportingFiles.add("${namespace.replaceFirstChar(Char::titlecase)}Client.kt")
supportingFiles.add("Room.kt")
supportingFiles.add("GetFlightListingsOperationSegmentParam.kt")

addGlobalProperty(CodegenConstants.SUPPORTING_FILES, supportingFiles.joinToString(","))
// addGlobalProperty("debugSupportingFiles", "")
Expand Down Expand Up @@ -159,6 +160,14 @@ class OpenApiSdkGenerator {
"Room.kt"
)
)

add(
SupportingFile(
"xap/get_flight_listings_operation_segment_param.mustache",
"$packagePath/models/",
"GetFlightListingsOperationSegmentParam.kt"
)
)
}
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
rule:
kind: 'function_declaration'
regex: 'fun build'
pattern: '$FUNC'
inside:
kind: 'class_body'
inside:
pattern: 'class Builder'
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
rule:
kind: "import_header"
regex: "OperationParams"
pattern: "$HEADER"
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
utils:
segment-builder:
kind: 'function_declaration'
regex: 'fun segment*'
inside:
kind: 'class_body'
inside:
pattern: 'class Builder'
rule:
any:
- matches: segment-builder
- kind: 'multiline_comment'
precedes:
matches: segment-builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
fun segment1(segment: GetFlightListingsOperationSegmentParam) = apply {
this.segment1Origin = segment.origin
this.segment1Destination = segment.destination
this.segment1DepartureDate = segment.departureDate
this.segment1DepartureStartTime = segment.departureStartTime
this.segment1DepartureEndTime = segment.departureEndTime
}

fun segment2(segment: GetFlightListingsOperationSegmentParam) = apply {
this.segment2Origin = segment.origin
this.segment2Destination = segment.destination
this.segment2DepartureDate = segment.departureDate
this.segment2DepartureStartTime = segment.departureStartTime
this.segment2DepartureEndTime = segment.departureEndTime
}

fun segment3(segment: GetFlightListingsOperationSegmentParam) = apply {
this.segment3Origin = segment.origin
this.segment3Destination = segment.destination
this.segment3DepartureDate = segment.departureDate
this.segment3DepartureStartTime = segment.departureStartTime
this.segment3DepartureEndTime = segment.departureEndTime
}

fun segment4(segment: GetFlightListingsOperationSegmentParam) = apply {
this.segment4Origin = segment.origin
this.segment4Destination = segment.destination
this.segment4DepartureDate = segment.departureDate
this.segment4DepartureStartTime = segment.departureStartTime
this.segment4DepartureEndTime = segment.departureEndTime
}

fun segment5(segment: GetFlightListingsOperationSegmentParam) = apply {
this.segment5Origin = segment.origin
this.segment5Destination = segment.destination
this.segment5DepartureDate = segment.departureDate
this.segment5DepartureStartTime = segment.departureStartTime
this.segment5DepartureEndTime = segment.departureEndTime
}

fun segment6(segment: GetFlightListingsOperationSegmentParam) = apply {
this.segment6Origin = segment.origin
this.segment6Destination = segment.destination
this.segment6DepartureDate = segment.departureDate
this.segment6DepartureStartTime = segment.departureStartTime
this.segment6DepartureEndTime = segment.departureEndTime
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {VendorLocationDetailsProcessor} from './processors/vendor-location-detai
import {GetCarsListingsOperationParamsProcessor} from './processors/get-cars-listings-operation-params-processor';
import {ActivitiesCancellationPolicyProcessor} from './processors/activities-cancellation-policy-processor';
import {AvailableTimeSlotProcessor} from './processors/available-time-slot-processor';
import {GetFlightListingsOperationParamsProcessor} from "./processors/get-flight-listings-operation-params-processor";

import * as path from 'path';

Expand Down Expand Up @@ -42,4 +43,7 @@ switch (fileName) {
case 'AvailableTimeSlot':
new AvailableTimeSlotProcessor().process(filePath);
break;
case 'GetFlightListingsOperationParams':
new GetFlightListingsOperationParamsProcessor().process(filePath);
break;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import * as fs from 'node:fs';
import {Edit, NapiConfig, SgNode} from '@ast-grep/napi';
import {Processor} from './processor';
import {RuleFunction} from './shared.types';

export class GetFlightListingsOperationParamsProcessor extends Processor {
rules: RuleFunction[];
id: String = 'get-flight-listings-operation-params';

constructor() {
super();
this.rules = [
this.removeSegmentBuilderMethods,
this.importSegment,
this.addSegmentsBuilderMethods,
].map(rule => rule.bind(this));
}

removeSegmentBuilderMethods(root: SgNode): Edit[] {
const config = this.readRule('remove-segments-builder-methods');

return root.findAll(config).map(node => {
return node.replace('');
});
}

importSegment(root: SgNode): Edit[] {
const config = this.readRule('import-segment');

return root.findAll(config).map(node => {
const segment = 'import com.expediagroup.sdk.xap.models.GetFlightListingsOperationSegmentParam';
const header = node.getMatch('HEADER')?.text();

return node.replace(`${segment}\n${header}`);
});
}

addSegmentsBuilderMethods(root: SgNode): Edit[] {
const config = this.readRule('add-segments-builder-methods');

const source = fs.readFileSync(
'./assets/templates/get-flight-listings-operation-params/segments.kt',
'utf-8'
);

return root.findAll(config).map(node => {
const func = node.getMatch('FUNC')?.text();
return node.replace(`${source}\n${func}`);
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.expediagroup.sdk.xap.models

data class GetFlightListingsOperationSegmentParam(
val origin: String,
val destination: String,
val departureDate: java.time.LocalDate,
val departureStartTime: String?,
val departureEndTime: String?
) {
companion object {
@JvmStatic
fun builder() = Builder()
}

class Builder(
private var origin: String? = null,
private var destination: String? = null,
private var departureDate: java.time.LocalDate? = null,
private var departureStartTime: String? = null,
private var departureEndTime: String? = null
) {
fun origin(origin: String?) = apply { this.origin = origin }

fun destination(destination: String?) = apply { this.destination = destination }

fun departureDate(departureDate: java.time.LocalDate?) = apply { this.departureDate = departureDate }

fun departureStartTime(departureStartTime: String?) = apply { this.departureStartTime = departureStartTime }

fun departureEndTime(departureEndTime: String?) = apply { this.departureEndTime = departureEndTime }

fun build(): GetFlightListingsOperationSegmentParam =
GetFlightListingsOperationSegmentParam(
origin = this.origin!!,
destination = this.destination!!,
departureDate = this.departureDate!!,
departureStartTime = this.departureStartTime,
departureEndTime = this.departureEndTime
)
}
}