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
55 changes: 33 additions & 22 deletions .github/actions/generate_types/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@

import os
import json
import yaml
import requests
from collections import OrderedDict

def write_json(filename: str, object: dict) -> None:
"""
Expand All @@ -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:
"""
Expand Down Expand Up @@ -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)
2 changes: 0 additions & 2 deletions .github/actions/generate_types/requirements.txt

This file was deleted.

5 changes: 0 additions & 5 deletions .github/workflows/release-typescript-models.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"