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

Change sample code script to add python beta sample code #53

Merged
merged 1 commit into from
Oct 10, 2023
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
82 changes: 20 additions & 62 deletions add_code_samples_to_oas.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
'install': ruamel.yaml.scalarstring.FoldedScalarString('<dependency><groupId>com.asana</groupId><artifactId>asana</artifactId><version>1.0.0</version></dependency>'),
},
'node': {
'install': 'npm install asana@2.0.6',
},
'node-old': {
'install': 'npm install asana',
},
'node-beta': {
'install': 'npm install asana@2.0.6',
},
'python': {
'install': 'pip install asana',
'install': 'pip install asana==3.2.2',
},
'python-old': {
'install': 'pip install asana==3.2.1',
'python-beta': {
'install': 'pip install asana==4.0.11',
},
'php': {
'install': 'composer require asana/asana',
Expand Down Expand Up @@ -53,45 +53,14 @@ def camel_case(s):
code_samples = {}
for language in LANGUAGES:
if language in {"node", "python"}:
if language == "python":
# Add sample code for new client libraries
for dirpath,_,filenames in os.walk(f'./build/{language}/docs'):
for filename in filenames:
if re.search("^.*Api.yaml$", filename):
with open(f'{dirpath}/{filename}') as fp:
data = yaml.load(fp)
for resource, operations in data.items():
# OpenAPI Generator adds "Api" suffix to end of resource names we need
# to remove it so we can find a matching resource in our OpenAPI Spec
resource_name = resource.replace("Api", '').lower()
# Set resource key in code_samples dict
code_samples.setdefault(resource_name, {})
# Loop through each operation
for operation, code_sample in operations.items():
# Convert operation name from snake case to camel case
# NOTE: the python generator snake cases all opertionIDs we need to
# change this to camel case so we can find a matching resource in our OpenAPI Spec
operation_name_camel_case = camel_case(operation)
# Set operation name
code_samples[resource_name].setdefault(operation_name_camel_case, [])
# Add sample code
code_samples[resource_name][operation_name_camel_case].append(
{
"language": language,
"install": readme_code_config[language]['install'],
"code": code_sample,
}
)
# Add sample code for old client libraries
for dirpath,_,filenames in os.walk(f'./build/{language}-old/samples'):
# Add sample code for client libraries
for dirpath,_,filenames in os.walk(f'./build/{language}/samples'):
for filename in filenames:
with open(f'{dirpath}/{filename}') as fp:
data = yaml.load(fp)
for resource, operations in data.items():
# Set resource key in code_samples dict
# NOTE: java resource name has a "base" suffix. We'll need to remove this so we
# can group the sample code together with the other languages
resource_name = resource.replace("base", '') if language == 'java' else resource
resource_name = resource
code_samples.setdefault(resource_name, {})
# Loop through each operation
for operation, code_sample in operations.items():
Expand All @@ -100,32 +69,21 @@ def camel_case(s):
# Set operation name
code_samples[resource_name].setdefault(operation_name_camel_case, [])
# Add sample code
if language == "python":
code_samples[resource_name][operation_name_camel_case].append(
{
"language": language,
"install": readme_code_config[f'{language}-old']['install'],
"code": code_sample,
"name": f'{language}-old'
}
)
elif language == "node":
code_samples[resource_name][operation_name_camel_case].append(
{
"language": language,
"install": readme_code_config[f'{language}-old']['install'],
"code": code_sample,
}
)
if language == "node":
# Add sample code for new client libraries
for dirpath,_,filenames in os.walk(f'./build/{language}/docs'):
code_samples[resource_name][operation_name_camel_case].append(
{
"language": language,
"install": readme_code_config[f'{language}']['install'],
"code": code_sample,
}
)
# Add sample code for beta client libraries
for dirpath,_,filenames in os.walk(f'./build/{language}-beta/docs'):
for filename in filenames:
if re.search("^.*Api.yaml$", filename):
with open(f'{dirpath}/{filename}') as fp:
data = yaml.load(fp)
for resource, operations in data.items():
# OpenAPI Generator adds "Api" suffix to end of resource names we need
# Swagger Codegen Generator adds "Api" suffix to end of resource names we need
# to remove it so we can find a matching resource in our OpenAPI Spec
resource_name = resource.replace("Api", '').lower()
# Set resource key in code_samples dict
Expand All @@ -142,7 +100,7 @@ def camel_case(s):
code_samples[resource_name][operation_name_camel_case].append(
{
"language": language,
"install": readme_code_config[language]['install'],
"install": readme_code_config[f'{language}-beta']['install'],
"code": code_sample,
"name": f'{language}-beta'
}
Expand Down
12 changes: 6 additions & 6 deletions bin/build_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ checkout_client_lib() (
git clone "$url" "$dest"
)

checkout_old_client_lib() (
checkout_version_client_lib() (
url="$1"
dest="$2"
tag="$3"
Expand All @@ -38,14 +38,14 @@ checkout_old_client_lib() (
)

checkout_client_lib "https://github.com/Asana/java-asana.git" build/java
checkout_client_lib "https://github.com/Asana/node-asana.git" build/node
checkout_client_lib "https://github.com/Asana/python-asana.git" build/python
checkout_version_client_lib "https://github.com/Asana/node-asana.git" build/node v1.0.2
checkout_version_client_lib "https://github.com/Asana/python-asana.git" build/python v3.2.2
checkout_client_lib "https://github.com/Asana/php-asana.git" build/php
checkout_client_lib "https://github.com/Asana/ruby-asana.git" build/ruby

# Old Client Libraries
checkout_old_client_lib "https://github.com/Asana/node-asana.git" build/node-old v1.0.2
checkout_old_client_lib "https://github.com/Asana/python-asana.git" build/python-old v3.2.1
# Beta Client Libraries
checkout_client_lib "https://github.com/Asana/node-asana.git" build/node-beta
checkout_version_client_lib "https://github.com/Asana/python-asana.git" build/python-beta v4.0.11

# Run script to add client library sample code to OpenAPI Spec file
python add_code_samples_to_oas.py
Loading