Skip to content

Instantly share code, notes, and snippets.

@SylvainMarty
Last active March 25, 2021 16:33
Show Gist options
  • Save SylvainMarty/2d9a5176b3d57a21f2a0f4725fbfb4c5 to your computer and use it in GitHub Desktop.
Save SylvainMarty/2d9a5176b3d57a21f2a0f4725fbfb4c5 to your computer and use it in GitHub Desktop.
Generate PHP SDK from OpenAPI with Docker

1) Create the home folder of the future SDK

2) Copy the config.yml file into the SDK folder

3) Update the value of invokerPackage to match the SDK namespace

3) Download the generate_openapi_php_sdk.sh script at the root of your project

3) Generate SDK for specific OpenAPI URL with this snippet

SDK_DIR=src/MyBundle/SdkFolder ; \
OPENAPI_URL="http://localhost:8080/api-doc.json" ; \
sh ./generate_openapi_php_sdk.sh
additionalProperties:
invokerPackage: MyBundle\SdkFolder
variableNamingConvention: camelCase
#!/bin/sh
docker run -it --rm -v "$(shell pwd)/${SDK_DIR}:/local" \
-u 1000 \
openapitools/openapi-generator-cli \
/bin/sh -c "java -Xmx1024M -DloggerPath=conf/log4j.properties -jar '/opt/openapi-generator/modules/openapi-generator-cli/target/openapi-generator-cli.jar' generate -i ${OPENAPI_URL} -g php -o /tmp -c /local/config.yml && cp -fR /tmp/lib/* /local"
## Generate SDK for specific OpenAPI URL. Expects SDK_DIR=<src/Component/Agenda> and OPENAPI_URL=<http://localhost:5000/api-json> (SDK directory must contains a config.yml file)
openapi-gen-sdk:
printf "Generating SDK in $(shell pwd)/${SDK_DIR}\n"
docker run -it --rm -v "$(shell pwd)/${SDK_DIR}:/local" \
-u 1000 \
openapitools/openapi-generator-cli \
/bin/sh -c "java -Xmx1024M -DloggerPath=conf/log4j.properties -jar '/opt/openapi-generator/modules/openapi-generator-cli/target/openapi-generator-cli.jar' generate -i ${OPENAPI_URL} -g php -o /tmp -c /local/config.yml && cp -fR /tmp/lib/* /local"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment