apigee / apigee-smartdocs-maven-plugin

Apache License 2.0
11 stars 10 forks source link

Add the ability to upload images from for the API Catalog #27

Open giteshk opened 3 years ago

giteshk commented 3 years ago

Original request was reported here: https://community.apigee.com/questions/91841/apigee-smartdocs-maven-plugin-publish-the-image-to.html

giteshk commented 3 years ago

The below steps have to be performed

  1. Upload the image file

    curl --location --request POST 'http://kickstart.local/jsonapi/media/image/field_media_image' \
    --header 'Content-Type: application/octet-stream' \
    --header 'Content-Disposition: file; filename="screenshot.png"' \
    --header 'Authorization: Basic base64_user_password' \
    --data-binary '@/path/to/image.png'
  2. Create the media entity

    curl --location --request POST 'http://kickstart.local/jsonapi/media/image' \
    --header 'Content-Type: application/vnd.api+json' \
    --header 'Authorization: Basic base64_user_password' \
    --data-raw '{
      "data": {
          "type": "media--image",
          "attributes": {
              "name": "Screenshot"
          },
          "relationships": {
              "field_media_image": {
                  "data": {
                      "type": "file--file",
                      "id": "**ID from step1 response**"
                  }
              }
          }
      }
    }'
  3. Create the API doc with the uploaded image

    curl --location --request POST 'http://kickstart.local/jsonapi/node/apidoc' \
    --header 'Content-Type: application/vnd.api+json' \
    --header 'Authorization: Basic base64_user_password' \
    --data-raw '{
      "data": {
          "type": "node--apidoc",
          "attributes": {
              "status": true,
              "title": "New API Doc",
              "body": {
                  "value": "<p>Lorem ipsum...</p>",
                  "format": "basic_html"
              },
              "field_apidoc_spec_file_source": "url",
              "field_apidoc_file_link": {
                  "uri": "https://petstore.swagger.io/v2/swagger.json"
              }
          },
      "relationships": {
              "field_image": {
                  "data": {
                      "type": "media--image",
                      "id": "**ID from step 2 response**"
                  }
              }
          }
      }
    }'
ssvaidyanathan commented 3 years ago

Fixed and released in v2.1.2

roby71 commented 3 years ago

Thank you for the new feature.

I provide you with feedback on the tests I have done:

  1. Add a new API along with the image. Result: OK
  2. Change the image using -Dapigee.smartdocs.config.options=update. Result: No effect, the old one remains.
  3. Update an API (with or without an image) that did not previously have an associated image. Result: Build failure with the error "Failed to execute goal com.apigee.smartdocs.config:apigee-smartdocs-maven-plugin:2.1.2:apidoc (smartdocs-deploy) on project DeveloperPortal: Execution smartdocs-deploy of goal com.apigee.smartdocs.config:apigee-smartdocs-maven-plugin:2.1.2:apidoc failed.: NullPointerException"
  4. Delete the image (I tried with a blank in the field_image of the JSON config file). Result: Build failure with the same error as above.

As a workaround I used the plugin option "sync".

ssvaidyanathan commented 3 years ago

Thanks for trying various scenarios. Please see my response below

Thank you for the new feature.

I provide you with feedback on the tests I have done:

  1. Add a new API along with the image. Result: OK
  2. Change the image using -Dapigee.smartdocs.config.options=update. Result: No effect, the old one remains.

Thats what we decided as its really complicated to update the image. The best option is to use "sync". I will update that in the README

  1. Update an API (with or without an image) that did not previously have an associated image. Result: Build failure with the error "Failed to execute goal com.apigee.smartdocs.config:apigee-smartdocs-maven-plugin:2.1.2:apidoc (smartdocs-deploy) on project DeveloperPortal: Execution smartdocs-deploy of goal com.apigee.smartdocs.config:apigee-smartdocs-maven-plugin:2.1.2:apidoc failed.: NullPointerException"

Will take a look

  1. Delete the image (I tried with a blank in the field_image of the JSON config file). Result: Build failure with the same error as above.

The plugin does not delete the image alone. If you want that, you will need to delete the API and then upload the spec again.

As a workaround I used the plugin option "sync".

ssvaidyanathan commented 3 years ago

@roby71 - I was not able to reproduce a few issues you reported (probably because you expected the update to update the image as well). The NullPointer is the main issue I was not able to reproduce.

Now that you understand what the plugin offers, I have added a check to the code. I would really appreciate if you can run few tests for me before I release this version. For this you will need to do the following in your local machine.

  1. Clone this repo
  2. Checkout the "Issue27" branch (git checkout Issue27)
  3. Execute the main pom.xml (mvn install on the main directory). This should create a 2.1.3-SNAPSHOT in your local .m2 repo (in your $HOME/.m2 directory)
  4. Update the samples/Drupal8/DevPortal/shared-pom.xml to use 2.1.3-SNAPSHOT
  5. Run the different tests pointing to your portal instance (please update the apicatalog-config.json or have the pom point to your config file)

Again - Thanks a lot for your feedback. I did miss a few scenarios I should have checked. Dont want to repeat that again :) Once you confirm, I will release a new version

ssvaidyanathan commented 3 years ago

@roby71 - please let me know if you can check this for me? Waiting for your response

roby71 commented 3 years ago

Sorry @ssvaidyanathan for the late reply.

I rerun the test set and the behavior does not seem to have changed: create, delete and sync options do what is expected, while the update throws the same error if the API does not already have an image configured. Here the debug log: smartdocs-update.log

I hope with this to have been helpful.

ssvaidyanathan commented 3 years ago

Thanks - I will check it out