Skip to content

Commit

Permalink
Merge branch 'main' into dtayeh/PAA-499-update-dispatcher-config
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarAlJarrah authored Aug 8, 2024
2 parents c92b32f + dfccfaf commit 830abd1
Show file tree
Hide file tree
Showing 15 changed files with 772 additions and 111 deletions.
1 change: 1 addition & 0 deletions .github/workflows/core-upgrade.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ jobs:
with:
name: branch-name
path: branch_name.txt
overwrite: true

- name: Publish Updated Version PR
uses: peter-evans/create-pull-request@v6
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/generator-download-specs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ jobs:
with:
name: raw-specs
path: raw-specs.yaml
overwrite: true
9 changes: 9 additions & 0 deletions .github/workflows/generator-generate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,16 @@ jobs:
path: |
generator/openapi/target/sdk
!generator/openapi/target/sdk/target
overwrite: true
- uses: actions/upload-artifact@v4
with:
name: jar
path: |
generator/openapi/target/sdk/target/*.jar
generator/openapi/target/sdk/target/maven-archiver/pom.properties
overwrite: true
- uses: actions/upload-artifact@v4
with:
name: docs
path: generator/openapi/target/sdk/target/dokka
overwrite: true
69 changes: 69 additions & 0 deletions .github/workflows/generator-test-sdk.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Generate Test SDK
on:
workflow_call:
inputs:
version:
description: 'SDK version to generate test jar for'
required: true
type: string
namespace:
description: 'SDK to generate test jar for'
required: true
type: string
endpoint_prefix:
description: 'Endpoint to prepend specs paths with'
required: true
type: string
specs_url:
description: 'Run tests based on specs'
required: true
type: string
outputs:
artifactId:
value: ${{ jobs.sdk-metadata.outputs.artifactId }}
groupId:
value: ${{ jobs.sdk-metadata.outputs.groupId }}
version:
value: ${{ jobs.sdk-metadata.outputs.version }}

jobs:
download-specs:
uses: ./.github/workflows/generator-download-specs.yaml
with:
url: ${{ inputs.specs_url }}
transform-specs:
needs: [ download-specs ]
uses: ./.github/workflows/generator-transform-specs.yaml
with:
configurations: -th -te ${{ inputs.endpoint_prefix }} --operationIdsToTags
generate-sdk:
needs: [ transform-specs ]
uses: ./.github/workflows/generator-generate.yaml
with:
name: ${{ inputs.namespace }}
version: ${{ inputs.version }}
sdk-metadata:
runs-on: ubuntu-latest
needs: [ generate-sdk ]
outputs:
artifactId: ${{ steps.parse-metadata.outputs.artifactId }}
groupId: ${{ steps.parse-metadata.outputs.groupId }}
version: ${{ steps.parse-metadata.outputs.version }}
steps:
- uses: actions/download-artifact@v4
with:
name: jar
path: jar
- id: parse-metadata
working-directory: jar/maven-archiver
shell: python -u {0}
run: |
import os
metadata: dict = dict()
with open("pom.properties") as properties:
metadata = dict(line.strip().split('=') for line in filter(bool, properties.readlines()))
with open(os.getenv("GITHUB_OUTPUT"), "a") as GITHUB_OUTPUT:
for key, value in metadata.items():
print(f"{key}={value}", file=GITHUB_OUTPUT)
1 change: 1 addition & 0 deletions .github/workflows/generator-transform-specs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ jobs:
with:
name: specs
path: specs.yaml
overwrite: true
1 change: 1 addition & 0 deletions .github/workflows/generator-verify.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
with:
name: sdk
path: generator/openapi/target/sdk
overwrite: true
verify-generated-sdk:
runs-on: ubuntu-latest
needs: generate-sdk
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/pr-check-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: PR Check Tests Run
on: push

jobs:
run-rapid-tests:
strategy:
matrix:
jdk: [8, 11, 17, 21]
fail-fast: true
max-parallel: 1
uses: ./.github/workflows/run-tests.yaml
with:
source: 'specs'
specs_url: 'https://ewe-assets.s3.amazonaws.com/developer-tools/api/rapid/v3/specs.yaml'
sdk_version: 1.0.${{ github.run_id }}
sdk_namespace: 'rapid'
jdk: ${{ matrix.jdk }}
endpoint_prefix: '/v3'
secrets: inherit
107 changes: 107 additions & 0 deletions .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: Run Tests
on:
workflow_dispatch:
inputs:
source:
description: 'Source of tests'
required: true
type: choice
options:
- 'specs'
- 'sdk'
default: 'sdk'
specs_url:
description: 'Run tests based on specs'
required: false
type: string
default: ''
sdk_version:
description: 'Run tests based on SDK'
required: false
type: string
default: 'LATEST'
sdk_namespace:
description: 'SDK to test'
required: true
type: string
default: 'rapid'
endpoint_prefix:
description: 'Endpoint to prepend specs paths with'
required: true
type: string
jdk:
description: 'JDK version to use'
required: true
type: choice
options:
- '21'
- '17'
- '11'
- '8'
default: '21'
workflow_call:
inputs:
source:
description: 'Source of tests'
required: true
type: string
default: 'sdk'
specs_url:
description: 'Run tests based on specs'
required: false
type: string
default: ''
sdk_version:
description: 'Run tests based on SDK'
required: false
type: string
default: 'LATEST'
sdk_namespace:
description: 'SDK to test'
required: true
type: string
default: 'rapid'
jdk:
description: 'JDK version to use'
required: true
type: string
default: '21'
endpoint_prefix:
description: 'Endpoint to prepend specs paths with'
required: true
type: string

jobs:
inputs-validation:
runs-on: ubuntu-latest
steps:
- shell: python -u {0}
run: |
if 'specs' in '${{ inputs.source }}' and not('${{ inputs.specs_url }}'):
print('::error::Invalid specs URL: ${{ inputs.specs_url }}')
exit(1)
if 'sdk' in '${{ inputs.source }}' and not('${{ inputs.sdk_version }}'):
print('::error::Invalid SDK version: ${{ inputs.sdk_version }}')
exit(1)
generate-test-sdk:
if: inputs.source == 'specs'
needs: [ inputs-validation ]
uses: ./.github/workflows/generator-test-sdk.yaml
with:
version: ${{ inputs.sdk_version }}
namespace: ${{ inputs.sdk_namespace }}
endpoint_prefix: ${{ inputs.endpoint_prefix }}
specs_url: ${{ inputs.specs_url }}
secrets: inherit
run-rapid-examples:
if: always() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') && inputs.sdk_namespace == 'rapid'
needs: [ generate-test-sdk ]
uses: "ExpediaGroup/rapid-java-sdk/.github/workflows/run-examples.yaml@main"
with:
sdk_version: ${{ needs.generate-test-sdk.outputs.version }}
jdk: ${{ inputs.jdk }}
sdk_generation_workflow_run_id: ${{ github.run_id }}
secrets:
KEY: ${{ secrets.RAPID_KEY }}
SECRET: ${{ secrets.RAPID_SECRET }}
66 changes: 66 additions & 0 deletions .github/workflows/selfserve-generate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Generate SDK

on:
workflow_call:
inputs:
name:
description: 'SDK Name'
required: true
type: string
version:
description: 'SDK Version'
required: true
type: string
templates:
description: 'Path to the templates directory'
required: true
type: string
specs_key:
description: 'Key to the transformed and ready to use specs artifact and name (without extension, e.g. specs, the file is expected to have the extension .yaml)'
default: 'specs'
type: string
sdk_key:
description: 'Key to the generated SDK artifact'
default: 'sdk'
type: string

jobs:
generate:
runs-on: ubuntu-latest
steps:
- name: Checkout EG SDK Repository
uses: actions/checkout@v4
with:
repository: 'ExpediaGroup/expediagroup-java-sdk'
path: sdk-repo

- name: Download Specs
uses: actions/download-artifact@v4
with:
name: ${{ inputs.specs_key }}
path: sdk-repo/generator/openapi

- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'

- name: Generate Product SDK
working-directory: sdk-repo/generator/openapi
run: |
mvn clean install exec:java "-Dnamespace=${{ inputs.name }}" -DsdkVersion=${{ inputs.version }} "-Dspec=./${{ inputs.specs_key }}.yaml" -DtemplatesDir="${{ inputs.templates }}"
- name: Install SDK
working-directory: sdk-repo/generator/openapi/target/sdk
run: |
mvn clean install
- name: Persist SDK Artifact
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.sdk_key }}
path: |
sdk-repo/generator/openapi/target/sdk
!sdk-repo/generator/openapi/target/sdk/target
overwrite: true
6 changes: 6 additions & 0 deletions generator/openapi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
<namespace>example</namespace>
<sdkVersion>0.0.1-SNAPSHOT</sdkVersion>
<language>java</language>
<templatesDir>templates/expediagroup-sdk</templatesDir>
<repoName>test-sdk</repoName>

<!-- Versions -->
<kotlin.version>2.0.0</kotlin.version>
Expand Down Expand Up @@ -397,6 +399,10 @@
<argument>${sdkVersion}</argument>
<argument>--language</argument>
<argument>${language}</argument>
<argument>-t</argument>
<argument>${templatesDir}</argument>
<argument>-r</argument>
<argumnet>${repoName}</argumnet>
</arguments>
</configuration>
</execution>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (C) 2022 Expedia, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.expediagroup.sdk.generators.openapi

/**
* This extension function converts a string to PascalCase.
* PascalCase is a type of identifier that consists of compound words or phrases such that each word or abbreviation begins with a capital letter.
* Non-alphabetic characters are ignored, and the next alphabetic character after them is capitalized.
*
* @receiver String The string to be converted to PascalCase.
* @return String The string converted to PascalCase.
*/
fun String.pascalCase(): String {
var capitalizeNext = true
val builder = StringBuilder()
forEach { char ->
when {
char.isLetterOrDigit().and(capitalizeNext) -> builder.append(char.uppercaseChar())
char.isLetterOrDigit() -> builder.append(char)
}
capitalizeNext = char.isLetter().not().or(builder.isEmpty())
}
return builder.toString()
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,19 @@ class OpenApiSdkGenerator {
@Option(name = ["-l", "--language"])
lateinit var programmingLanguage: String

@Option(name = ["-t", "--templates-dir"])
lateinit var templateDir: String

@Option(name = ["-r", "--repo-name"])
lateinit var repoName: String

fun run() {
try {
val product = Product(namespace, programmingLanguage)
val product = Product(namespace, repoName, programmingLanguage)
val config =
CodegenConfigurator().apply {
setGeneratorName("kotlin")
setTemplateDir("templates/expediagroup-sdk")
setTemplateDir(templateDir)
setInputSpec(inputFile)
setOutputDir(outputDirectory)
setArtifactId(product.artifactId)
Expand All @@ -107,8 +113,9 @@ class OpenApiSdkGenerator {
// Template specific properties
addAdditionalProperty("shadePrefix", product.shadePrefix)
addAdditionalProperty("namespace", product.namespace)
addAdditionalProperty("clientClassname", namespace.replaceFirstChar { it.uppercaseChar() })
addAdditionalProperty("clientClassname", namespace.pascalCase())
addAdditionalProperty("language", product.programmingLanguage.id)
addAdditionalProperty("repoName", product.repoName)
addAdditionalProperty("isKotlin", ProgrammingLanguage.isKotlin(product.programmingLanguage))
addAdditionalProperty("isRapid", ProductFamily.isRapid(product.namespace))
addAdditionalProperty("isExpediaGroup", ProductFamily.isExpediaGroup(product.namespace))
Expand Down
Loading

0 comments on commit 830abd1

Please sign in to comment.