Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: added a temporary fix to unblock python orgs release [DO-NOT-MERGE Before Release] #616

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
24 changes: 23 additions & 1 deletion scripts/build_twilio_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import shutil
from pathlib import Path
from typing import List, Tuple

from clean_unused_imports import remove_unused_imports, remove_duplicate_imports

'''
Expand All @@ -31,6 +30,10 @@ def build(openapi_spec_path: str, output_path: str, language: str) -> None:
spec_files = [domain]
else:
spec_folder = openapi_spec_path
# It will be removed once orgs team add the path(/Organizations/{OrganizationSid}) to twilio_iam_organizations spec
if language == 'python':
iam_orgs_spec_path = spec_folder + 'twilio_iam_organizations.json'
merge_orgs_schema('twilio_am_temporary.json', iam_orgs_spec_path)
spec_files = sorted(os.listdir(spec_folder))
generate(spec_folder, spec_files, output_path, language)

Expand Down Expand Up @@ -113,6 +116,25 @@ def get_domain_info(oai_spec_location: str, domain: str, is_file: bool = False)
api_version = domain_parts[2]
return full_path, domain_name, api_version

def merge_orgs_schema(from_spec, to_spec):

with open(to_spec, 'r') as f1:
spec1 = json.load(f1)


with open(from_spec, 'r') as f2:
spec2 = json.load(f2)

if 'paths' in spec1 and 'paths' in spec2:
spec1['paths'].update(spec2['paths'])
else:
print("One of the files doesn't contain 'paths'.")

with open(to_spec, 'w') as outfile:
json.dump(spec1, outfile, indent=2)

print(f"Files merged successfully into {to_spec}.")


if __name__ == '__main__':
example_text = '''example:
Expand Down
116 changes: 116 additions & 0 deletions twilio_am_temporary.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{
"openapi": "3.0.1",
"security": [
{
"oAuth2ClientCredentials": []
}
],
"info": {
"title": "Organization Public API",
"contact": {
"name": "Twilio Support",
"url": "https://support.twilio.com",
"email": "[email protected]"
},
"license": {
"name": "Apache 2.0",
"url": "https://www.apache.org/licenses/LICENSE-2.0.html"
},
"version": "1.0.0"
},
"paths": {
"/Organizations/{OrganizationSid}": {
"servers": [
{
"url": "https://preview-iam.twilio.com"
}
],
"get": {
"summary": "List SCIM Users",
AsabuHere marked this conversation as resolved.
Show resolved Hide resolved
"operationId": "FetchOrganization",
"parameters": [
{
"name": "OrganizationSid",
"in": "path",
"required": true,
"schema": {
"pattern": "OR[0-9a-f]{32}",
"type": "string",
"format": "OrganizationSid",
"example": "OR33f4f3aa6fffe840d000f8ef22e883db"
}
}
],
"responses": {
"403": {
"description": "Forbidden",
"content": {
"application/scim+json": {
"schema": {

}
}
},
"headers": {
"Access-Control-Allow-Origin": {
"description": "Specify the origin(s) allowed to access the resource",
"schema": {
"type": "string"
},
"example": "*"
},
"Access-Control-Allow-Methods": {
"description": "Specify the HTTP methods allowed when accessing the resource",
"schema": {
"type": "string"
},
"example": "POST, OPTIONS"
},
"Access-Control-Allow-Headers": {
"description": "Specify the headers allowed when accessing the resource",
"schema": {
"type": "string"
},
"example": "Content-Type, Authorization"
},
"Access-Control-Allow-Credentials": {
"description": "Indicates whether the browser should include credentials",
"schema": {
"type": "boolean"
}
},
"Access-Control-Expose-Headers": {
"description": "Headers exposed to the client",
"schema": {
"type": "string",
"example": "X-Custom-Header1, X-Custom-Header2"
}
}
}
}
}
}
}
},
"components": {
"securitySchemes": {
"oAuth2ClientCredentials": {
"type": "oauth2",
"flows": {
"clientCredentials": {
"tokenUrl": "https://preview-iam.twilio.com/v1/token",
"scopes": {}
}
}
}
},
"schemas": {

}
},
"servers": [
{
"url": "https://preview-iam.twilio.com"
}
]
}
Loading