Prerequisites
-
pantheon dashboard for on-cloud DevPortal instances
-
devportal site
-
pantheon administrator identity
-
devportal administrator identity
-
services and rest-server modules [are part of your devportal instance, but should be enabled]
As a DevPortal administrator,
-
Go to the Modules list.
-
Locate Services module and turn it on.
-
Locate REST Server module and turn it on.
-
Save Configuration.
-
Go to Structure/Services
-
Click on Add button.
Fill the attributes of the new endpoint
Machine-readable name of the endpoint: devportal
Server: REST
Path to endpoint: devportal
-
Save the endpoint definition.
-
Click on Edit Resources link.
-
Unfold node Resource (click on right arrow) and select retrieve operation.
-
Press Save.
-
In a browser, navigate to the http://dev-.devportal.apigee.com/devportal/node/1 address. Load the page.
You should see now the XML representation of the node 1 contents.
-
In the dev- Services page, select Edit tab of the devportal endpoint.
-
Check Session authentication check box.
Save.
-
In the Resource Tab of the devportal endpoint, check login, logout, and token actions of the user resource.
-
Save.
As a Pantheon Administrator,
-
Clone the DevPortal site git repository, using git command from the Code tab.
-
Clone https://github.com/yuriylesyuk/smartdocs-services project.
-
Copy src/smartdocs_service directory from smartdocs-services project to the project of your DevPortal site at /sites/all/modules.
NOTE: For On-Premises installations, the path to the location of the smartdocs-services module directory will be /var/www/html/sites/all/modules
-
Commit and push the module.
git add . git commit -m 'Adding SmartDocs Services module.' git push
As a DevPortal side administrator,
-
Go to Structure/Services.
-
Click on Edit Resource link of the devportal Service.
-
On the Resources tab, check the checkbox next to the smartdocs resources for import action.
-
Save the changes.
-
Go to People/Permissions
-
In the Smartdocs Service section make sure that authenticated user is allowed to perform the Import Swagger specification operation.
-
Save permissions.
-
Go to Content/SmartDocs
-
Click on New model link.
-
Enter name field value: Banking
-
Click on Create Model button.
The message Banking was created successfully will appear.
-
Using Postman, execute request to login into your DevPortal site and obtain CSRF token.
-
Run the request.
-
Note the token value similar to:
"token": "4zWJagz4YbYKfXXbfXnvnXlHH4v5Nh5GhL6Ce_eKeXw"
-
In the Postman, create a new request for importing swagger yaml file.
Use banking.yaml file from the docs folder of the smartdocs-service project.
Verb: POST URL: http://dev-<site>.devportal.apigee.com/devportal/smartdocs/import Body: form-data
Body parameters
model Type: Text Value: banking files[swagger] Type: File Value: banking.yaml type Type: Text Value: yaml
Header: X-CSRF-Token
Header Value: 4zWJagz4YbYKfXXbfXnvnXlHH4v5Nh5GhL6Ce_eKeXw
-
Execute the request.
The result should be Status: 200
-
Go to Content/SmartDocs.
The banking line will show 1 Rendered Node, 1 Published Node.
-
Open Banking model.
The API Revision #1 will be displayed.
-
Click on Home Menu item. The new API resource transactions of /fundtransfers endpoint will be displayed.
-
Click on the transaction link.
The rendered SmartDocs will be displayed.
-
Create model petstore.
-
In the Postman, create a new request for importing swagger json file.
Use petstore.json file from the docs folder of the smartdocs-service project.
Verb: POST URL: http://dev-<site>.devportal.apigee.com/devportal/smartdocs/import Body: form-data
Body parameters
model Type: Text Value: banking files[swagger] Type: File Value: petstore.json type Type: Text Value: json
Header: X-CSRF-Token
Header Value: 4zWJagz4YbYKfXXbfXnvnXlHH4v5Nh5GhL6Ce_eKeXw
-
Execute the request.
The result should be Status: 200
Three new nodes will be rendered and published on petstore model.
The #1st revision of the petstore now contains three method definitions.
CI/CD is an important use case to use this module while working with Apigee DevPortal.
Usually, you put your OpenAPI specifications [former swagger] under VCS control next to the proxies they describe. Then a Jenkins job will be triggered by a commit and your sh script would publish latest version of the spec as a new SmartDocs revision.
Here is a curl command you can use to implement this publishing step.
curl -X POST \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d "{ \
\"username\": \"<devportal-user-id>\", \
\"password\": \"<her-password>\" \
}" \
"http://<your-drupal-site>/devportal/user/login"
The response will begin with:
{"sessid":"Opw4RXkzY-Ni5oHZpZW3j5K_jnHzbT3CzessDmh_-I0","session_name":"SESSa50ebb77519f2a0f5cc535f9f549be74","token":"CZq25s_qxvXwI4i93ICNzZSTSuAz-0x3LeV31FgFsaU","user":{...
Take a note on sessionid and session_name values, as we need them to set up a Cookie header value, in addition to the X-CSRF-Token header:
curl -X POST \
-H "Cookie: **SESSa50ebb77519f2a0f5cc535f9f549be74**=**Opw4RXkzY-Ni5oHZpZW3j5K_jnHzbT3CzessDmh_-I0**" \
-H "X-CSRF-Token: C**Zq25s_qxvXwI4i93ICNzZSTSuAz-0x3LeV31FgFsaU**" \
-F "model=model8" \
-F "files[swagger]=@banking.yaml" \
-F "field_name=field" \
"[http://<your-drupal-site>/devportal/smartdocs/import](http://192.168.56.102/devportal/smartdocs/import)"
While investing problems, it is useful to know that in a defaut installaton, the file we've processed can be retrieved at http://dev-.devportal.apigee.com/sites/default/files/banking.yaml
Go to Reports/Recent log messages.
You will see diagnostic messages, logged by watchdog() statements.
-
Modules
switch off in this order
-
smartdocs services
-
rest server
-
services
-
-
code remove smartdocs modules; commit; push
-
Delete banking model Content/SmartDocs
-
Clear log messages