From 7773374c729ea54d643dfa74d5c13cee5c5facaa Mon Sep 17 00:00:00 2001 From: Sergii Leshchenko Date: Wed, 21 Jul 2021 11:43:36 +0300 Subject: [PATCH 1/2] remove v1alpha1 from schemas path to avoid confusion that it's taken into account --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index c4e6fb91f..da5f79dbd 100755 --- a/build.sh +++ b/build.sh @@ -59,6 +59,6 @@ generator/build/generator "deepcopy" "paths=./pkg/apis/workspaces/v1alpha2;./pkg echo "Generating JsonSchemas" -generator/build/generator "schemas" "output:schemas:artifacts:config=schemas" "paths=./pkg/apis/workspaces/v1alpha2;./pkg/apis/workspaces/v1alpha1" +generator/build/generator "schemas" "output:schemas:artifacts:config=schemas" "paths=./pkg/apis/workspaces/v1alpha2" echo "Finished generation of required GO sources, K8S CRDs, and Json Schemas" From 9448ff16a81f95fff993a768a66cce59256dd32c Mon Sep 17 00:00:00 2001 From: Sergii Leshchenko Date: Wed, 21 Jul 2021 11:44:52 +0300 Subject: [PATCH 2/2] generate typescript types based on schema instead of CRD --- .github/actions/generate_types/generate.py | 55 +++++++++++-------- .../actions/generate_types/requirements.txt | 2 - .../workflows/release-typescript-models.yaml | 5 -- 3 files changed, 33 insertions(+), 29 deletions(-) delete mode 100644 .github/actions/generate_types/requirements.txt diff --git a/.github/actions/generate_types/generate.py b/.github/actions/generate_types/generate.py index d468ddeda..76fd710de 100644 --- a/.github/actions/generate_types/generate.py +++ b/.github/actions/generate_types/generate.py @@ -12,9 +12,6 @@ import os import json -import yaml -import requests -from collections import OrderedDict def write_json(filename: str, object: dict) -> None: """ @@ -29,28 +26,41 @@ def create_ref(path): """ return '#/definitions/' + path -def consolidate_crds() -> object: +def consolidate_schemas() -> object: """ - Consolidate all crds in /crds into one json object + Consolidate all schemas into one json object """ - crds_dir = os.path.join('crds') - crds = os.listdir(crds_dir) - consolidated_crds_json = { + schemas_dir = os.path.join('schemas/latest') + consolidated_schemas_json = { 'definitions': {}, } - for file in crds: - crd_file_path = os.path.join(crds_dir, file) - with open(crd_file_path) as file: - yamlData = yaml.load(file, Loader=yaml.FullLoader) - crd_name = yamlData['spec']['names']['kind'] - - # Add all the available schema versions - for version in yamlData['spec']['versions']: - new_json_name = version['name'] + '.' + crd_name - new_schema = version['schema']['openAPIV3Schema'] - consolidated_crds_json['definitions'][new_json_name] = new_schema - - return consolidated_crds_json + + with open(os.path.join(schemas_dir, 'k8sApiVersion.txt')) as f: + k8sApiVersion = f.readline() + + with open(os.path.join(schemas_dir, 'jsonSchemaVersion.txt')) as f: + devfileVersion = f.readline() + devfileVersion = devfileVersion.replace('-alpha', '') + + definitionName = devfileVersion + '.Devfile' + devfile_json_schema_path = os.path.join(schemas_dir, 'devfile.json') + with open(devfile_json_schema_path, 'r') as devfileFile: + jsonData = json.load(devfileFile) + consolidated_schemas_json['definitions'][definitionName] = jsonData + + definitionName = k8sApiVersion + '.DevWorkspace' + dw_json_schema_path = os.path.join(schemas_dir, 'dev-workspace.json') + with open(dw_json_schema_path, 'r') as devfileFile: + jsonData = json.load(devfileFile) + consolidated_schemas_json['definitions'][definitionName] = jsonData + + definitionName = k8sApiVersion + '.DevWorkspaceTemplate' + dwt_json_schema_path = os.path.join(schemas_dir, 'dev-workspace-template.json') + with open(dwt_json_schema_path, 'r') as devfileFile: + jsonData = json.load(devfileFile) + consolidated_schemas_json['definitions'][definitionName] = jsonData + + return consolidated_schemas_json def add_property_definition(root_definitions_object: dict, current_path: str, curr_object: dict, queue: list) -> None: """ @@ -251,5 +261,6 @@ def flatten(consolidated_crds_object: dict) -> None: write_json('swagger.json', flattened_swagger_object) if __name__ == "__main__": - swagger_crds_json = consolidate_crds() + # Get the schema and flatten them + swagger_crds_json = consolidate_schemas() flatten(swagger_crds_json) diff --git a/.github/actions/generate_types/requirements.txt b/.github/actions/generate_types/requirements.txt deleted file mode 100644 index 756d3982b..000000000 --- a/.github/actions/generate_types/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -requests==2.24.0 -PyYAML==5.4.1 diff --git a/.github/workflows/release-typescript-models.yaml b/.github/workflows/release-typescript-models.yaml index b1bfefa9f..7bc5c2c9f 100644 --- a/.github/workflows/release-typescript-models.yaml +++ b/.github/workflows/release-typescript-models.yaml @@ -27,11 +27,6 @@ jobs: with: python-version: '3.9.2' - - name: Install Python dependencies - uses: py-actions/py-dependency-install@v2 - with: - path: "api/.github/actions/generate_types/requirements.txt" - - name: Generate openapi-generator compatible swagger.json run: | python .github/actions/generate_types/generate.py