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(generator): Add core as a dependency to generated SDKs, and remove constraints from namespace format. #18

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
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ class OpenApiSdkGenerator {
// Configure SDK Artifact Coordinates
setArtifactVersion(version)
setGroupId("openworld.sdk")
setArtifactId("openworld-sdk-python-$namespace")
setArtifactId("openworld-sdk-python-$packageName")
// Configure package details
setInvokerPackage("openworld.sdk")
addAdditionalProperty("normalizedNamespace", "$packageName")
addAdditionalProperty("projectName", "openworld.sdk.$packageName")
addAdditionalProperty("namespace", "$namespace")
setPackageName("openworld.sdk.$packageName")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class {{{classname}}}:
os = platform.platform().split('-')
os_name = os[0]
os_version = os[1]
sdk_metadata = f'open-world-sdk-python-{{namespace}}/{{version}}'
sdk_metadata = f'open-world-sdk-python-{{normalizedNamespace}}/{{version}}'

self.__api_client = ApiClient(client_config)
self.__user_agent = f'{sdk_metadata} (Python {python_version}; {os_name} {os_version})'
Expand All @@ -40,6 +40,6 @@ class {{{classname}}}:
response_model={{#if returnType}}{{{returnType}}}{{/if}}{{#unless returnType}}None{{/unless}},
url=request_url
)

{{/each}}
{{/with}}
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ uri~=2.0.1
requests~=2.28.1
dataclasses_json~=0.5.7
furl~=2.1.2
openworld-sdk-python-core~=0.1.0
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from setuptools import setup

setup(
name='openworld-python-sdk-{{artifactId}}',
name='{{artifactId}}',
version='{{version}}',
packages=['openworld.sdk.{{namespace}}', 'openworld.sdk.{{namespace}}.model', 'openworld.sdk.{{namespace}}.client'],
package_dir={'openworld-python-sdk-core': '.'},
packages=['{{packageName}}', '{{packageName}}.model', '{{packageName}}.client'],
package_dir={'{{artifactId}}': '.'},
license='Apache License, Version 2.0',
author='Expedia Group',
install_requires=['dataclasses_json', 'uri', 'requests', 'furl'],
description='The Open World SDK for Python allows Expedia Group partners to easily build Python applications that leverage the Open World (TM) platform.'
install_requires=['dataclasses_json', 'uri', 'requests', 'furl', 'openworld-sdk-python-core'],
description='The Open World {{namespace}} SDK for Python allows Expedia Group partners to easily build Python applications that leverage the Open World (TM) platform.',
long_description='The Open World {{namespace}} SDK for Python allows Expedia Group partners to easily build Python applications that leverage the Open World (TM) platform.'
)
17 changes: 10 additions & 7 deletions generator/scripts/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ while getopts ":n:v:i:" OPTION; do
esac
done; validate_arguments

wrong_import="from openworld/sdk/$sdk_namespace"
new_import="from openworld.sdk.$sdk_namespace"
normalized_namespace=$(echo "$sdk_namespace"|sed -e 's/\(.*\)/\L\1/')
normalized_namespace=$(echo "$normalized_namespace"|sed -e 's/[^a-z0-9]//g')

wrong_import="from openworld/sdk/$normalized_namespace"
new_import="from openworld.sdk.$normalized_namespace"

# Generates an SDK wheel
echo "Generating an SDK"\
Expand All @@ -64,17 +67,17 @@ echo "Generating an SDK"\
&& mvn exec:java "-Dnamespace=$sdk_namespace" -DsdkVersion=$sdk_version "-Dspec=$input_spec"\
&& cd ..\
&& rm -rf ./package\
&& mkdir -p package/openworld/sdk/$sdk_namespace/client\
&& mkdir package/openworld/sdk/$sdk_namespace/model\
&& mv ./openapi/target/sdk/openworld/sdk/$sdk_namespace/client/tags/*.py ./package/openworld/sdk/$sdk_namespace/client/\
&& mv ./openapi/target/sdk/openworld/sdk/$sdk_namespace/model/*.py ./package/openworld/sdk/$sdk_namespace/model/\
&& mkdir -p package/openworld/sdk/$normalized_namespace/client\
&& mkdir package/openworld/sdk/$normalized_namespace/model\
&& mv ./openapi/target/sdk/openworld/sdk/$normalized_namespace/client/tags/*.py ./package/openworld/sdk/$normalized_namespace/client/\
&& mv ./openapi/target/sdk/openworld/sdk/$normalized_namespace/model/*.py ./package/openworld/sdk/$normalized_namespace/model/\
&& mv ./openapi/target/sdk/requirements.txt ./package/requirements.txt\
&& mv ./openapi/target/sdk/setup.py ./package/setup.py\
\
\
&& echo "Adding Imports"\
&& cd ./scripts || exit \
&& cd ../package/openworld/sdk/"$sdk_namespace"/model\
&& cd ../package/openworld/sdk/"$normalized_namespace"/model\
&& python3 ./../../../../../scripts/add-imports.py . \
&& pip3 install autoflake\
&& autoflake --in-place --remove-all-unused-imports -r .\
Expand Down