Logo

dev-resources.site

for different kinds of informations.

Perfectly sizing images in your API documentation

Published at
8/2/2023
Categories
openapi
asyncapi
apidocumentation
documentation
Author
vvenance
Author
8 person written this
vvenance
open
Perfectly sizing images in your API documentation

Images are cool and they should be everywhere in your API doc. End of this blog post, thanks everyone!

Well, more seriously, many people, obviously including me, love a nice visual, especially when it comes to learning something new like, let’s say… how to use a new API. Bump.sh always supported the ability to add images in the markdown of your API documentation and has now extended it with the ability of sizing to your needs.

Whether you want to have your API documentation more lively to your users with gifs, share your API diagrams, illustrate complex API behaviors (like polymorphism) with a nice visual, and you have an API Contract based on OpenAPI or AsyncAPI, you can now make sure the images in your API documentation renders in the size you’d prefer them to.

How Bump.sh renders images by default

Usually, in markdown, you would use this syntax to add an image

![Alt text](/path/to/image.jpg "Image title")
Enter fullscreen mode Exit fullscreen mode

By default Bump.sh lets the browser decide how it will display the generated html <img src="image.url">. For instance if the image is in a table cell, it will be limited to the size of the table cell, if in a paragraph, it will use the default image size.

However, you can now decide on the image size yourself.

How to customize the image size in your API documentation

Now you can take it a step even further into the personalisation with a =dimension parameter that lets you manually decide how your image should be displayed in your documentation.

=dimension just extends the well known Markdown syntax by allowing you to give extra dimension information before the closing parenthesis

![Alt text](/path/to/image.jpg "Image title" =dimension)
Enter fullscreen mode Exit fullscreen mode

As an example, if you wanted to display an image of 100 pixels height and 50 pixels width you could write

![Alt text](/path/to/image.jpg "Image title" =100pxx50px)
Enter fullscreen mode Exit fullscreen mode

=dimension uses the following syntax =[width][unit]x[height][unit] and is itself completely optional as well as almost all its parameters: just width or x + height are mandatory. If you don't specify width or height, the other value will be a ratio calculated from the original size of the image so it doesn't shrink.

Telling this might be confusing so here are a few examples to better understand what you can do with this =dimension parameter:

Let’s take this SpongeBob plushie picture. See how it renders by default:

SpongeBob plushie image in a Bump.sh documentation

And now let’s play around with the =dimension parameter!

=100pxx50px   # with everything
=100x50     # without unit
Enter fullscreen mode Exit fullscreen mode

SpongeBob plushie image in a Bump.sh documentation with 150 x 50 px sizing

=100        # without height (x separator not needed) and unit
=100px      # without height
Enter fullscreen mode Exit fullscreen mode

SpongeBob plushie image in a Bump.sh documentation with 100px sizing

=x50        # without width and unit
=x50px      # without width
Enter fullscreen mode Exit fullscreen mode

SpongeBob plushie image in a Bump.sh documentation with 100px sizing

Note that not specifying an unit will fall back to pixel.

It also supports all CSS length units, so you can work with px for pixel, %, or any other absolute or relative unit you are used to.

Same image as above with =dimensionset to =200cm:
SpongeBob plushie image in a Bump.sh documentation with 200cm sizing

Always make sure how the property you use is handled by different browsers as it may differ.

You can find an extended description of the behavior of this new image sizing feature in the documentation.

Trying with your own API documentation

Bump.sh lets you preview how your documentation would look like.

You can preview how your images will render while editing your API contract or in your tests using the Bump.sh CLI with the command

npm install -g bump-cli   ## installs bump.sh cli

bump preview --live --open openapi-definition.json
Enter fullscreen mode Exit fullscreen mode

Option --open will open the preview in your default browser, and --live will automatically update the preview in your browser upon saving edits in the file.

And do you know what’s best? You don’t even need a Bump.sh account to use our preview, so enjoy playing around with images to see how your API documentation could render with perfectly sized images 🖼️!

Conclusion

Images are cool and they should be everywhere in your API doc.

Images Everywhere meme

Valériane Venance is Principal Developer Advocate at Bump.sh. She loves writing docs and articles. You can follow her on Twitter or connect on LinkedIn

apidocumentation Article's
30 articles in total
Favicon
EchoAPI's Five Hidden Gems: Did You Know?
Favicon
Discover the 9 Best Open-Source Alternatives to Postman
Favicon
API Debugging Tool Designed for Java Developers
Favicon
Top 5 Enterprise-Grade API Documentation Tools and Software for Seamless Integration
Favicon
EchoAPI's Five Hidden Gems: Did You Know?
Favicon
Mastering JSON to Tabular Conversion: A Comprehensive Guide
Favicon
How EchoAPI Enhances Team Collaboration Efficiency
Favicon
Understanding RESTful API Design Principles
Favicon
Integrate Swagger UI with Codeigniter4
Favicon
Common API Design Mistakes and How to Avoid Them
Favicon
How to Implement Search and Filtering in APIs🦉
Favicon
Postman Proxy: Essential Multi-Purpose Tool for Developers
Favicon
How to Make Requests to the Payoneer API?
Favicon
How to Handle API Versioning Gracefully?
Favicon
Best Practices for Writing API Documentation đź“š
Favicon
EchoAPI for IntelliJ IDEA: A Plugin that Boosts API Management for Java Developers
Favicon
Best Practices for API Documentation
Favicon
Have You Heard of Swagger Documents?
Favicon
Guidelines for Deprecating Old API Versions
Favicon
Perfectly sizing images in your API documentation
Favicon
Introduction to APIs
Favicon
Top 6 SwaggerHub Alternatives in 2023
Favicon
Internal vs. External APIs – Does it Matter?
Favicon
What is a FinTech API?
Favicon
Documenting parameters and request/response bodies. đź“š
Favicon
Documenting endpoints in API documentation. đź“š
Favicon
Practical guide to launching a new public API for your company
Favicon
Ultimate Guide To Create an API Documentation with Examples
Favicon
What is OpenAPI?
Favicon
Which is the Best API Documentation Tool?

Featured ones: