JSON docs not rendered with Smartdocs Maven plugin

I am facing this strange issue with apigee maven smartdocs plugin - when I use the spec format as json, the model does not get rendered. Plugin version used is 1.0.7. I am using the spec given with the samples mock.yaml. I converted the yaml to json and tried to publish the json spec

-Dapigee.smartdocs.config.options=update works fine for both yaml and json specs.

-Dapigee.smartdocs.config.options=render works for yaml only. For json the following error is shown:

Caused by: java.lang.RuntimeException: Render failure: 500 Internal Server Error : An error occurred (0): Cannot load a revision number less than 1.  at com.apigee.smartdocs.config.mavenplugin.APIModelMojo.doRender (APIModelMojo.java:211)  at com.apigee.smartdocs.config.mavenplugin.APIModelMojo.execute (APIModelMojo.java:164)  at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)

The same specs both yaml and json when manually uploaded on the drupal portal, it gets uploaded and rendered.

I also noticed on the devportal - the API revision is empty when a json spec is created or updated through the plugin. apirevision-for-json-spec.jpg

However, if a yaml spec is used, the revision# is visible in the smartdocs model page.apirevision-for-yaml.jpg

Below is the maven command I have used

mvn install -X -Pdev -Dportal.username=xxx -Dportal.password=xxx -Dportal.directory=specs -Dapigee.smartdocs.config.options=render -Dportal.url=https://xxxxx.com "-Dportal.cronkey=xxxx" -Dportal.format=json

@Sai Saran Vaidyanathan - is it due to some configuration that I may have missed or is it a known issue?

Solved Solved
0 15 255
1 ACCEPTED SOLUTION

Issue resolved. There was an issue with the spec 🙂

View solution in original post

15 REPLIES 15

Can you confirm you are passing portal.format as the sample have it hardcoded as yaml in the pom file (profile)

@Sai Saran Vaidyanathan Yes, I am passing the portal.format as json. Below is the mvn command that I used

mvn install -X -Pdev -Dportal.username=xxx -Dportal.password=xxx -Dportal.directory=specs -Dapigee.smartdocs.config.options=render -Dportal.url=https://xxxxx.com "-Dportal.cronkey=xxxx" -Dportal.format=json

In your pom file you have updated the portal.format into a variable right ?

Also can you share the Open API JSON file you have?

@Sai Saran Vaidyanathan, yes my POM is updated as below
<profile>
<id>dev</id>
<properties>
<portal.username>{portal.username}</portal.username><!-- Username for the developer portal. -->
<portal.password>{portal.password}</portal.password><!-- Password for the developer portal. -->
<portal.directory>{portal.directory}</portal.directory><!-- Directory where OpenAPI specs are accessible. Using ./specs for sample-->
<portal.url>{portal.url}</portal.url><!-- URL of the developer portal. -->
<portal.path>smartdocs/apis</portal.path><!-- Servies path defined in the developer portal. -->
<portal.cronkey>{portal.cronkey}</portal.cronkey> <!-- Developer Portal Cron Key, you can get it from Home -> Administration -> Configuration -> System -->
<portal.format>{portal.format}</portal.format><!-- Format of the OpenAPI specs. json|yaml -->
</properties>
</profile>

I used the json version of the mock.yaml in the samples. I have attached the same here.

mockjson.txt

Shouldn't the variables have a $ (dollar sign) in front ? like

<portal.format>${portal.format}</portal.format>

@Sai Saran Vaidyanathan - Agreed there should be a $. But I see the values being printed in the maven console log, even though there was no $, probably because the env variables passed in the command are the same as the tag names.

[DEBUG] (f) buildDirectory = C:\work\apigee-smartdocs-maven-plugin-master\samples\DevPortal\target
[DEBUG] (s) options = render
[DEBUG] (f) portalCronKey = xxxx
[DEBUG] (f) portalDirectory = specs
[DEBUG] (f) portalFormat = json
[DEBUG] (f) portalPassword = xxxxx
[DEBUG] (f) portalPath = smartdocs/apis
[DEBUG] (f) portalURL = https://xxxxxx.com
[DEBUG] (f) portalUserName = xxxxx
[DEBUG] (f) projectName = DeveloperPortal
[DEBUG] (f) projectVersion = 1.0
[DEBUG] (s) skip = false
[DEBUG] -- end configuration --
[INFO] ************************************************************************
[INFO] Smart Docs
[INFO] ************************************************************************
[DEBUG] Build option render
[DEBUG] Portal Path smartdocs/apis
[INFO] Get OpenAPI Specs from specs
[INFO] Rendering Mock Target API OpenAPI spec.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.729 s
[INFO] Finished at: 2019-02-11T15:35:38-08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.apigee.smartdocs.config:apigee-smartdocs-maven-plugin:1.0.7:apimodel (smartdocs-deploy) on project DeveloperPortal: Execution smartdocs-deploy of goal com.apigee.smartdocs.config:apigee-smartdocs-maven-plugin:1.0.7:apimodel failed: Render failure: 500 Internal Server Error : An error occurred (0): Cannot load a revision number less than 1. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.apigee.smartdocs.config:apigee-smartdocs-maven-plugin:1.0.7:apimodel (smartdocs-deploy) on project DeveloperPortal: Execution smartdocs-deploy of goal com.apigee.smartdocs.config:apigee-smartdocs-maven-plugin:1.0.7:apimodel failed: Render failure: 500 Internal Server Error : An error occurred (0): Cannot load a revision number less than 1.
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)

@Sai Saran Vaidyanathan - another finding. If the JSON spec is loaded for the first time, i.e. the model doesnt exist at all, this issue occurs.

If you load and render the YAML first (model is created with yaml), and then run the plugin again to load and render the JSON spec, it works.

Just option=render wont work. You first need to push the model and then render it. Hope you are running it twice everytime you want it to be published ?

@Sai Saran Vaidyanathan,

I did use the command twice, once with option=update and once with option=render. I mentioned that in my initial post itself.

-Dapigee.smartdocs.config.options=update works fine for both yaml and json specs.

-Dapigee.smartdocs.config.options=render works for yaml only. For json the following error is shown:

Causedby: java.lang.RuntimeException:Render failure:500InternalServerError:An error occurred (0):Cannot load a revision number less than 1.  at com.apigee.smartdocs.config.mavenplugin.APIModelMojo.doRender (APIModelMojo.java:211)  at com.apigee.smartdocs.config.mavenplugin.APIModelMojo.execute (APIModelMojo.java:164)  at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)

When I load the specs for the first time with options=update or create, and format as JSON, there is no revision number visible in the drupal portal. Pls refer to the image I attached (apirevision-for-json-spec.jpg) in my initial post.

I took your json file and was able to push and render the spec on my dev portal. I made sure I did not have any model with the same name in the first place. Ran

mvn install -Pdev -Dapigee.smartdocs.config.options=update and

mvn install -Pdev -Dapigee.smartdocs.config.options=render

Worked as expected ! Can you try deleting your model in dev portal and running the commands again

@Sai Saran Vaidyanathan I tried deleting the model and executing the update and render. I am still facing the issue when I upload it for the first time as JSON. The update works fine, build is successful. The drupal portal doesn't show a revision number for the model.

Next I try to render, I see the error Cannot load a revision number less than 1 on the console output for the maven execution.

Few more details: My installation is Apigee on-prem 4.18.01, dev portal with Drupal version 7.63

Probably should get on a call. My email id is ssvaidyanathan@google.com

@Sai Saran Vaidyanathan Sure. Sent you the bridge details if you can join now. Thanks

Issue resolved. There was an issue with the spec 🙂

@Sai Saran Vaidyanathan Thanks for helping out in resolving this issue.

For the benefit of others who view the post later - the npm that converted the yaml to json used tabs for indentation which caused the issue, although editor.swagger.io didn't show any errors for the converted json spec. Once I replaced the tabs with spaces in the json file, the issue was resolved and the smartdocs was loaded successfully.

It helped to look at the Drupal ->Recent Log Messages where it showed that the spec had an issue, although the smartdocs plugin returned HTTP 200 and printed the message that the create or update of the model was successful