Skip to content

Commit 5df76d0

Browse files
authored
Feature/isolate openapi gen templates (#4168)
## Proposed change feat: isolate and extend the OpenApi TypescriptFetch template <!-- Please include a summary of the changes and the related issue. Please also include relevant motivation and context. --> ## Related issues <!-- Please make sure to follow the [contribution guidelines](https://github.com/amadeus-digital/Otter/blob/main/CONTRIBUTING.md) --> *- No issue associated -* <!-- * 🐛 Fix #issue --> <!-- * 🐛 Fix resolves #issue --> <!-- * 🚀 Feature #issue --> <!-- * 🚀 Feature resolves #issue --> * :octocat: Pull Request #4159
2 parents 53b3767 + d368a4f commit 5df76d0

56 files changed

Lines changed: 411 additions & 187 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/check-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
- uses: ./.github/actions/setup-java
5050
with:
5151
install-jdk: 'true'
52-
- run: yarn build:swagger-gen
52+
- run: yarn build:jar
5353
- run: yarn build
5454
- uses: ./tools/github-actions/upload-build-output
5555
with:

.github/workflows/code-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ jobs:
7878
${{ runner.os }}-jest
7979
${{ runner.os }}
8080
- name: Build swagger generator
81-
run: yarn nx run ama-sdk-schematics:build-swagger
81+
run: yarn build:jar
8282
- name: Test
8383
env:
8484
NX_BASE: ${{ format('remotes/origin/{0}', github.base_ref || github.ref_name) }}

nx.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -699,8 +699,15 @@
699699
],
700700
"cache": true
701701
},
702-
"build-swagger": {
703-
"cache": true
702+
"build-jar": {
703+
"inputs": [
704+
"source",
705+
"{projectRoot}/pom.xml"
706+
],
707+
"outputs": [
708+
"{projectRoot}/target/*.jar"
709+
],
710+
"cache": false
704711
},
705712
"i18n": {
706713
"cache": true
@@ -742,4 +749,4 @@
742749
"cacheDirectory": ".cache/nx",
743750
"nxCloudId": "63e6951e043da20dd8321aec",
744751
"analytics": false
745-
}
752+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"build:tools": "yarn nx run-many --tui=false --target=build --projects=tag:hook:postinstall",
1717
"build:lint": "yarn nx run-many --tui=false --target=build --projects=eslint-plugin",
1818
"build:ama-openapi": "yarn nx run-many --tui=false --target=build --projects=tag:scope:ama-openapi",
19-
"build:swagger-gen": "yarn nx run-many --target=build-swagger",
19+
"build:jar": "yarn nx run-many --target=build-jar",
2020
"publish": "yarn nx run-many --target=prepare-publish --exclude-task-dependencies && yarn nx run-many --target=publish --exclude=tag:access:private",
2121
"publish:extensions": "yarn nx run-many --target=prepare-publish --exclude-task-dependencies && yarn nx run-many --target=publish-extension",
2222
"publish:extensions:affected": "yarn nx affected --target=publish-extension",

packages/@ama-sdk/schematics/schematics/typescript/core/openapi-codegen-typescript/.gitignore renamed to packages/@ama-sdk/openapi-codegen-typescript/.gitignore

File renamed without changes.

packages/@ama-sdk/schematics/schematics/typescript/core/openapi-codegen-typescript/README.md renamed to packages/@ama-sdk/openapi-codegen-typescript/README.md

File renamed without changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "@ama-sdk/openapi-codegen-typescript",
3+
"version": "0.0.0-placeholder",
4+
"publishConfig": {
5+
"access": "public"
6+
},
7+
"scripts": {
8+
"build:jar": "mvn clean package -f ./pom.xml",
9+
"build:jar:optional": "yarn run build:jar || true"
10+
},
11+
"main": "./target/typescriptFetch-openapi-generator.jar",
12+
"exports": {
13+
".": "./target/typescriptFetch-openapi-generator.jar",
14+
"./package.json": "./package.json"
15+
},
16+
"files": [
17+
"./target/typescriptFetch-openapi-generator.jar"
18+
]
19+
}

packages/@ama-sdk/schematics/schematics/typescript/core/openapi-codegen-typescript/pom.xml renamed to packages/@ama-sdk/openapi-codegen-typescript/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,6 @@
8787
</plugins>
8888
</build>
8989
<dependencies>
90-
<dependency>
91-
<groupId>io.swagger.core.v3</groupId>
92-
<artifactId>swagger-core</artifactId>
93-
<version>2.2.49</version>
94-
</dependency>
9590
<dependency>
9691
<groupId>org.openapitools</groupId>
9792
<artifactId>openapi-generator</artifactId>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "ama-sdk-openapi-codegen-typescript",
3+
"$schema": "https://raw.githubusercontent.com/nrwl/nx/master/packages/nx/schemas/project-schema.json",
4+
"projectType": "library",
5+
"sourceRoot": "packages/@ama-sdk/openapi-codegen-typescript/src",
6+
"prefix": "o3r",
7+
"targets": {
8+
"build": {
9+
"executor": "nx:noop",
10+
"dependsOn": [
11+
"build-jar:optional"
12+
]
13+
},
14+
"build-jar": {
15+
"executor": "nx:run-script",
16+
"options": {
17+
"script": "build:jar"
18+
},
19+
"configurations": {
20+
"optional": {
21+
"script": "build:jar:optional"
22+
}
23+
}
24+
},
25+
"publish": {
26+
"inputs": [
27+
"{projectRoot}/target/typescriptFetch-openapi-generator.jar"
28+
]
29+
}
30+
},
31+
"tags": []
32+
}

packages/@ama-sdk/schematics/schematics/typescript/core/openapi-codegen-typescript/src/main/java/com/amadeus/codegen/ts/AbstractTypeScriptClientCodegen.java renamed to packages/@ama-sdk/openapi-codegen-typescript/src/main/java/com/amadeus/codegen/ts/AbstractTypeScriptClientCodegen.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ public abstract class AbstractTypeScriptClientCodegen extends org.openapitools.c
6767
/** Custom request body transformation logic (GlobalSettings: requestBodyTransform, default: empty) */
6868
private final String requestBodyTransform;
6969

70+
/**
71+
* Preprocesses the OpenAPI specification to extract operation adapter paths.
72+
* This generates the OPERATION_ADAPTER data structure used for runtime operation matching.
73+
*
74+
* @param openAPI the OpenAPI specification to preprocess
75+
*/
76+
protected abstract void preprocessOperationAdapter(OpenAPI openAPI);
77+
7078
/**
7179
* Constructor for Otter-specific TypeScript client code generator.
7280
*
@@ -559,6 +567,18 @@ public void postProcessParameter(CodegenParameter parameter) {
559567
}
560568
}
561569

570+
/**
571+
* Otter-specific override: Add any additional preprocessing logic for the OpenAPI specification:
572+
* - Extract operation adapter paths for runtime matching and add to additionalProperties for template access.
573+
*
574+
* @param openAPI the OpenAPI specification to preprocess
575+
*/
576+
@Override
577+
public void preprocessOpenAPI(OpenAPI openAPI) {
578+
super.preprocessOpenAPI(openAPI);
579+
this.preprocessOperationAdapter(openAPI);
580+
}
581+
562582
/**
563583
* Otter-specific: Returns the TypeScript type for date-time objects without timezone modification.
564584
*

0 commit comments

Comments
 (0)