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

asyncapi Article's
30 articles in total
Favicon
List of AsyncAPI servers in MuleSoft
Favicon
AsyncAPI — A standard specification for documenting Event-Driven Applications
Favicon
AsyncAPI: a practical look
Favicon
Arquitetura Event-Driven usando AsyncAPI na prática
Favicon
AsyncAPI Codegen, a code generator from AsyncAPI spec v2 and v3.
Favicon
Integration Digest: October 2023
Favicon
An AsyncAPI Example: Building Your First Event-driven API
Favicon
How to document SSE app
Favicon
Perfectly sizing images in your API documentation
Favicon
Using OpenAPI and AsyncAPI Tags to Better Organize API Endpoints
Favicon
API Contracts - an Extended Introduction
Favicon
Why AvioBook switched from Swagger UI to Bump.sh for all of their APIs
Favicon
How to use and document polymorphism in API
Favicon
What are the different API types?
Favicon
Event driven API documentation made simple (Client-Side Rendering).
Favicon
Could AsyncApi Make A Dent on Climate Change?
Favicon
API Diff - Compare in seconds two versions of your API
Favicon
An introduction to the AsyncAPI specification
Favicon
Getting Started with CloudEvents and AsyncAPI
Favicon
Bump diff, the missing piece for an API “design-first” approach
Favicon
Mule support for Async API
Favicon
API documentation in event driven applications
Favicon
AsyncAPI Code Generation: Microservices Using Spring Cloud Stream
Favicon
(Part 2) Full automation of release with GitHub Actions and Conventional Commits for non-JS projects
Favicon
Nunjucks templating explained on the basis of AsyncAPI specification
Favicon
AsyncAPI for documentation and validation of event-driven architecture
Favicon
A Modeling Editor and Code Generator for AsyncAPI
Favicon
Designing, Documenting and Testing Event APIs for IoT Platforms
Favicon
Status update (week 11, 2019)
Favicon
Why Developers Need an Event Portal; Creating Applications that Disseminate Real-Time COVID-19 Data

Featured ones: