Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
giteshk opened this issue May 24, 2021 · 8 comments
Open

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

giteshk opened this issue May 24, 2021 · 8 comments

Comments

@giteshk
Copy link
Member

giteshk commented May 24, 2021

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

@giteshk
Copy link
Member Author

giteshk commented May 27, 2021

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'
  1. 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**"
                }
            }
        }
    }
}'
  1. 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 added a commit that referenced this issue Jun 10, 2021
ssvaidyanathan added a commit that referenced this issue Jun 10, 2021
@ssvaidyanathan
Copy link
Collaborator

Fixed and released in v2.1.2

@roby71
Copy link

roby71 commented Jun 16, 2021

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
Copy link
Collaborator

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 added a commit that referenced this issue Jun 16, 2021
@ssvaidyanathan
Copy link
Collaborator

ssvaidyanathan commented Jun 16, 2021

@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
Copy link
Collaborator

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

@roby71
Copy link

roby71 commented Aug 12, 2021

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
Copy link
Collaborator

Thanks - I will check it out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants