Enterprise Framework

Software Solutions in the Enterprise

Swagger Codegen for PHP

First install Java 7 or 8

1 - Set environment variables for java

export JAVA_HOME=$(/usr/libexec/java_home)
or
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`

export PATH=${JAVA_HOME}/bin:$PATH

2 - Clone the REPO 

$ git clone https://github.com/swagger-api/swagger-codegen.git

3 - Switch into the directory 

$ cd swagger-codegen

3 - Build the project form code using maven.  Direction for maven on other post.

$ mvn clean package

4 - Generate the client for your endpoint

Replace the below item in < > with your custom values.

java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
   -i ../acumatica_client/swagger/swagger_customerschema_17.200.001.json \
   -l php \
   --invoker-package "<RootNamespace>\<CustomNamespace>" \
   --git-user-id "<yourgithubuserid>" \
   --git-repo-id "<yourgithubrepo>" \
   -o ~/Source/Repos/<my_output_folder>

5.  Switch to the output folder from above <my_output_folder>

cd ~/Source/Repos/<my_output_folder>

6.  Make git_push executable so we can push to source control.

chmod +x git_push.sh

7.  Push to source control.

./git_push.sh

7a - git pull origin master --allow-unrelated-histories


8 - Open the newly generated README.md file, copy the text from the Installation & Usage, Composer.json section 

~/Source/Repos/<my_output_folder>/SwaggerClient-php/README.md

9 - Open your PHP client project that you want to use the swagger generated code in and paste the previously copied text from README.md

{
  "repositories": [
    {
      "type": "git",
      "url": "https://github.com/<yourgithubuserid>/<yourgithubrepo>.git"
    }
  ],
  "require": {
    "<yourgithubuserid>/<yourgithubrepo>": "*@dev"
  }
}

11 - Run Composer Install from the PHP Client project to install references

$ composer install

Note you may need to run 

$ composer update --lock

Add a generic called runme.php file and add code from README.md

categorySchemaDeleteById($id);
} catch (Exception $e) {
    echo 'Exception when calling CategorySchemaApi->categorySchemaDeleteById: ', $e->getMessage(), PHP_EOL;
}

?>

and run it
   
$ php runme.php
Comments are closed