DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Google Cloud Pub/Sub vs. AWS SNS and SQS: One Java API for Both With MultiCloudJ
  • Passwordless Image Pulls in Kubernetes With ServiceAccount Tokens and a Credential Provider
  • Zero Trust for Agents: A New Lens to Secure Agents
  • Reusable Operational Playbooks With Agent Skills

Trending

  • Spring Security JWT Validation Best Practices
  • Why Operators Ignore Model Scores
  • Detecting Duplicates With Machine Learning in 2026: From String Metrics to Embeddings and LLMs
  • Building a Self-Healing Docker CI Gatekeeper With BuildKit

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Data Engineering
  3. Databases
  4. Auto-Generating API Specifications as OpenAPI, WSDL, and Sphinx

Auto-Generating API Specifications as OpenAPI, WSDL, and Sphinx

This article presents a workflow for auto-generation of API specifications for your Zato services.

By 
Dariusz Suchojad
·
Dec. 13, 19 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
23.7K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

Sphinx statue

Auto-Generating API Specifications as OpenAPI, WSDL, and Sphinx


This article presents a workflow for auto-generation of API specifications for your Zato services. If you need to share your APIs with partners, external or internal, this is how it can be done.


Sample Services


Let's consider the services below — they represent a subset of a hypothetical API of a telecommunication company. In this case, they are to do with pre-paid cards. Deploy them on your servers in a module called api.py.

Note that their implementation is omitted, we only deal with their I/O, as it is expressed using SimpleIO.

What we would like to have, and what we will achieve here, is a website with static HTML describing the services in terms of a formal API specification.

Java
 




xxxxxxxxxx
1
32


 
1
# -*- coding: utf-8 -*-
2
 
          
3
# Zato
4
from zato.server.service import Int, Service
5
 
          
6
# #####################################################################
7
 
          
8
class RechargeCard(Service):
9
    """ Recharges a pre-paid card.
10
    Amount must not be less than 1 and it cannot be greater than 10000.
11
    """
12
    class SimpleIO:
13
        input_required = 'number', Int('amount')
14
        output_required = Int('status')
15
 
          
16
    def handle(self):
17
        pass
18
 
          
19
# #####################################################################
20
 
          
21
class GetCurrentBalance(Service):
22
    """ Returns current balance of a pre-paid card.
23
    """
24
    class SimpleIO:
25
        input_required = Int('number')
26
        output_required = Int('status')
27
        output_optional = 'balance'
28
 
          
29
    def handle(self):
30
        pass
31
 
          
32
# #####################################################################



Docstrings and SimpleIO


In the sample services, observe that:


  • Documentation is added as docstrings — this is something that services, being simply Python classes, will have anyway
  •    
  •  One of the services has a multi-line docstring, whereas the other one is single-line. This will be of significance later on
  •    
  • SimpleIO definitions use both string types and integers
You might also like:  Creating an API Specification in a Design Center

Command Line Usage


To generate API specifications, command zato apispec is used. This is part of the CLI that Zato ships with.

Typically, only well-chosen services should be documented publicly, and the main two options the command has are --include and --exclude.

Both accept a comma-separated list of shell-like glob patterns that indicate which services should or should not be documented.

For instance, if the code above is saved in api.py, the command to output their API specification is:

Java
 




xxxxxxxxxx
1


 
1
zato apispec /path/to/server        \
2
    --dir /path/to/output/directory \
3
    --include api.*



Next, we can navigate to the directory just created and type the command below to build HTML.

Java
 




xxxxxxxxxx
1


 
1
cd /path/to/output/directory
2
make html



OpenAPI, WSDL, and Sphinx


The result of the commands is as below — OpenAPI and WSDL files are in the menu column to the left.

Also, note that in the main index only the very first line of a docstring is used but upon opening a sub-page for each service its full docstring is used.


Branding and Customization


While the result is self-contained and it can be already used as-is, there is still room for more.

Given that the output is generated using Sphinx, it is possible to customize it as needed, for instance, by applying custom CSS or other branding information, such as the logo of a company exposing a given API.

All of the files used for generation of HTML are stored in config directories of each server — if the path to a server is /path/to/server, then the full path to Sphinx templates is in /path/to/server/config/repo/static/sphinxdoc/apispec.


Summary


That is everything — generating static documentation is a matter of just a single command. The output can be fully customized while the resulting OpenAPI and WSDL artifacts can be given to partners to let third-parties automatically generate API clients for your Zato services.

API

Opinions expressed by DZone contributors are their own.

Related

  • Google Cloud Pub/Sub vs. AWS SNS and SQS: One Java API for Both With MultiCloudJ
  • Passwordless Image Pulls in Kubernetes With ServiceAccount Tokens and a Credential Provider
  • Zero Trust for Agents: A New Lens to Secure Agents
  • Reusable Operational Playbooks With Agent Skills

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook