Skip to content

Commit

Permalink
chore: fixing orgs api param names
Browse files Browse the repository at this point in the history
  • Loading branch information
tiwarishubham635 committed Nov 28, 2024
1 parent f56392e commit 1ed7426
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 31 deletions.
29 changes: 3 additions & 26 deletions scripts/build_twilio_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ def generate(spec_folder: str, spec_files: List[str], output_path: str, language
for spec_file in spec_files:
if spec_file in generateForLanguages:
if language in dynamic_languages:
input_path_versioned, input_path_versionless = preprocess_orgs_spec(spec_folder, spec_file, parent_dir)
generate_custom_specs(input_path_versioned, output_path, language)
generate_custom_specs(input_path_versionless, output_path, language)
input_path_versioned, input_path_versionless, spec_dir = preprocess_orgs_spec(spec_folder, spec_file, parent_dir)
generate_domain_for_language(input_path_versioned, config_path, spec_dir, output_path, language, parent_dir)
generate_domain_for_language(input_path_versionless, config_path, spec_dir, output_path, language, parent_dir)
if language in generateForLanguages.get(spec_file):
generate_domain_for_language(spec_file, config_path, spec_folder, output_path, language, parent_dir)
else: generate_domain_for_language(spec_file, config_path, spec_folder, output_path, language, parent_dir)
Expand All @@ -72,22 +72,6 @@ def generate(spec_folder: str, spec_files: List[str], output_path: str, language
if language in REMOVE_DUPLICATE_IMPORT_LANGUAGES:
remove_duplicate_imports(output_path, language)

def generate_custom_specs(input_path: str, output_path: str, language: str) -> None:
parent_dir = Path(__file__).parent.parent
config_path = os.path.join(parent_dir, CONFIG_FOLDER, language)
full_config_path = os.path.join(config_path, "twilio_iam_organizations.json")
config = {
'generatorName': 'terraform-provider-twilio' if language == 'terraform' else f'twilio-{language}',
'inputSpec': input_path,
'outputDir': output_path,
'inlineSchemaNameDefaults': {
'arrayItemSuffix': ''
},
}
# print(config)
with open(full_config_path, 'w') as f:
f.write(json.dumps(config))


def generate_domain_for_language(spec_file: str, config_path: str, spec_folder: str, output_path: str, language: str, parent_dir: str) -> None:
full_path = os.path.join(spec_folder, spec_file)
Expand All @@ -104,13 +88,6 @@ def generate_domain_for_language(spec_file: str, config_path: str, spec_folder:
with open(full_config_path, 'w') as f:
f.write(json.dumps(config))

# print(f'Generating {output_path} from {spec_folder}')
# run_openapi_generator(parent_dir, language)
# print(f'Code generation completed at {output_path}')
# if language in CLEANUP_IMPORT_LANGUAGES:
# remove_unused_imports(output_path, language)
# if language in REMOVE_DUPLICATE_IMPORT_LANGUAGES:
# remove_duplicate_imports(output_path, language)

def run_openapi_generator(parent_dir: Path, language: str) -> None:
properties = '-DapiTests=false'
Expand Down
20 changes: 15 additions & 5 deletions scripts/process_orgs_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,20 @@ def preprocess_orgs_spec(spec_folder:str, spec_file:str, parent_dir: str):
if not os.path.exists(temp_dir):
os.makedirs(temp_dir)
spec_file_name = spec_file.split(".")[0]
versioned_specs_path = os.path.join(temp_dir, spec_file_name + "_" + version + ".json")
non_versioned_specs_path = os.path.join(temp_dir, spec_file_name + "_versionless.json")
with open(versioned_specs_path, 'w') as f:
spec_file_name_versioned = spec_file_name + "_" + version + ".json"
spec_file_name_versionless = spec_file_name + "_versionless.json"
with open(os.path.join(temp_dir, spec_file_name_versioned), 'w') as f:
f.write(json.dumps(versioned_specs, indent=2))
with open(non_versioned_specs_path, 'w') as f:
with open(os.path.join(temp_dir, spec_file_name_versionless), 'w') as f:
f.write(json.dumps(non_versioned_specs, indent=2))
return versioned_specs_path, non_versioned_specs_path

with open(os.path.join(temp_dir, spec_file_name_versionless), 'r') as f:
content = f.read()

# fix param names
content = content.replace("UserSid", "Id")
content = content.replace("RoleAssignmentSid", "Sid")

with open(os.path.join(temp_dir, spec_file_name_versionless), 'w') as file:
file.write(content)
return spec_file_name_versioned, spec_file_name_versionless, temp_dir

0 comments on commit 1ed7426

Please sign in to comment.