When documenting Application Programming Interfaces (APIs), particularly those involving classes, methods, and properties, a structured and consistent approach is paramount. The Darwin Information Typing Architecture (DITA) provides a powerful XML-based framework for creating modular, reusable, and easily navigable API reference documentation. This guide explores how to effectively structure such documents using DITA and points to relevant examples.
<reference>
topic type, specifically designed for factual, lookup-oriented content like API elements.<map>
).<refsyn>
(for syntax/signatures) and <properties>
to clearly define API components.DITA is an XML-based open standard for authoring and publishing topic-oriented information. Its inherent modularity, support for content reuse, and specialization capabilities make it exceptionally well-suited for the complexities of technical documentation, including detailed API references. For APIs, DITA promotes:
The primary DITA information type for API documentation is the <reference>
topic. Reference topics are intended for "just the facts" content, perfect for describing programming constructs such as classes, methods, properties, functions, and commands. Each reference topic typically includes a title, a short description, and a body containing detailed information structured with specific DITA elements.
A well-structured DITA API reference ensures developers can quickly find and understand the information they need. The general approach involves creating individual reference topics for each major API component and then organizing them using DITA maps.
DITA maps (<map>
files) are crucial for defining the hierarchy and navigation of your API documentation. A map file contains references (<topicref>
) to your DITA topics, arranging them into a logical structure, much like a table of contents. For API documentation, a map might group classes by namespace, and under each class, list its methods and properties.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE map PUBLIC "-//OASIS//DTD DITA Map//EN" "map.dtd">
<map title="My Product API Reference">
<topicref href="api_overview.dita" navtitle="API Overview"/>
<topicref href="classes/myclass.dita" navtitle="MyClass">
<topicref href="methods/myclass_mymethod.dita" navtitle="myMethod()"/>
<topicref href="properties/myclass_myproperty.dita" navtitle="myProperty"/>
</topicref>
<topicref href="classes/anotherclass.dita" navtitle="AnotherClass"/>
<!-- Additional classes and elements -->
</map>
A DITA map organizes topics into a navigable structure.
Each API class should typically be documented in its own <reference>
topic. This topic serves as the main container for all information related to that class.
<title>
: The name of the class (e.g., "UserAccount Class").<shortdesc>
: A brief summary of the class's purpose.<refbody>
: Contains the detailed content.
<section>
for Description: A paragraph (<p>
) providing a more detailed explanation of the class, its role, and usage.<refsyn>
for Syntax: (Optional at class level, more common for methods) Can be used to show the class declaration signature.<section>
for Properties: A dedicated section to list and describe class properties (see below).<section>
for Methods: A dedicated section to list and link to or embed method descriptions (see below).Methods can be documented either as sections within the parent class's reference topic or as separate, more granular <reference>
topics linked from the class topic. The latter approach enhances modularity and reusability, especially for complex methods or those shared across classes (though less common).
<title>
: The method name, often including parentheses (e.g., "getUserProfile() Method").<shortdesc>
: A concise summary of what the method does.<refbody>
:
<refsyn>
(Syntax/Signature): Crucial for methods. This element is used to formally define the method's signature, including its name, parameters (with data types), return type, and any exceptions it might throw. Example: public String getUserProfile(int userId) throws NotFoundException
.<section>
for Parameters: Detailed descriptions of each parameter. Often presented using a <simpletable>
or a definition list (<dl>
). Each parameter entry should specify its name, data type, whether it's required or optional, and a description of its purpose.<section>
for Return Value: Description of the value returned by the method, including its data type and what it represents.<section>
for Exceptions: (If applicable) Details about exceptions the method may throw, and under what conditions.<example>
: Code snippets (within <codeblock>
) demonstrating how to use the method.Properties (also known as fields or attributes) are typically documented within a dedicated section of their parent class's reference topic. The <properties>
element is specifically designed for this.
<properties>
: A container element for a list of properties. It often functions like a specialized table.
<prophead>
: (Optional) Defines headers for the property list (e.g., Property Name, Type, Description).
<propnamehd>
, <proptypehd>
, <propvaluehd>
, <propdeschd>
<property>
: Represents a single property.
<propname>
: The name of the property.<proptype>
: The data type of the property (e.g., "String", "Integer", "Boolean").<propvalue>
: (If applicable) The default or possible values for the property.<propdesc>
: A description of the property's purpose and usage.Alternatively, if a more straightforward list or table format is preferred outside the specialized <properties>
structure, a <simpletable>
can also be used within a general <section>
to list properties.
To better understand how these components fit together, consider the following conceptual visualizations. The mindmap illustrates the hierarchical organization, while the radar chart highlights DITA's strengths for this type of documentation.
This mindmap shows a typical structure for DITA-based API documentation, starting from the overall API, organized by a DITA map, down to individual classes, methods, and properties within reference topics.
Conceptual mindmap of DITA API documentation structure.
This radar chart illustrates key attributes where DITA excels in the context of API documentation. The scores (out of 10) are qualitative assessments reflecting DITA's capabilities.
Comparative strengths of DITA for API documentation.
The following table summarizes some of the most important DITA elements used in structuring API reference documentation:
Element | Purpose in API Documentation |
---|---|
<reference> |
The root element for a reference topic, typically used for a class, or a complex method/property if documented separately. |
<title> |
Provides the main heading for the topic (e.g., class name, method name). |
<shortdesc> |
A brief, one or two-sentence summary of the API element. |
<refbody> |
Contains the main content of the reference topic, including sections, syntax, properties, and examples. |
<section> |
Used to group related content within the <refbody> , such as "Description," "Parameters," "Return Value." |
<refsyn> |
(Reference Syntax) Specifically designed to present the syntax or signature of a programming element (e.g., method signature, class declaration). |
<properties> |
A container for documenting a list of properties or attributes, often rendered as a table. |
<property> |
Defines a single property within the <properties> element. Contains sub-elements like <propname> , <proptype> , <propvalue> , and <propdesc> . |
<simpletable> |
Used for creating simple tables, often for listing parameters with their types and descriptions if <properties> is not suitable. |
<example> |
Contains an example illustrating the use of the API element, typically including a <codeblock> . |
<codeblock> |
Presents pre-formatted code samples. |
<p> |
A paragraph, used for descriptive text. |
<ul> , <ol> , <li> |
Used for unordered or ordered lists, e.g., for listing features or steps. |
<dl> , <dt> , <dd> |
Definition lists, useful for parameter lists where each term (parameter name) is followed by its description. |
Common DITA elements and their roles in API documentation.
Below is a simplified XML example demonstrating how a DITA reference topic might be structured for an API class named BankAccount
, including its properties and methods.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE reference PUBLIC "-//OASIS//DTD DITA Reference//EN" "reference.dtd">
<reference id="class_BankAccount">
<title>BankAccount Class</title>
<shortdesc>Represents a customer's bank account, providing functionalities for managing balances and transactions.</shortdesc>
<prolog>
<author>API Documentation Team</author>
<metadata>
<keywords>
<keyword>bank</keyword>
<keyword>account</keyword>
<keyword>API</keyword>
</keywords>
</metadata>
</prolog>
<refbody>
<section id="description">
<title>Class Description</title>
<p>The BankAccount class is used to manage financial information for a specific bank account.
It allows for deposits, withdrawals, and balance inquiries. Each instance of this class
corresponds to a unique bank account.</p>
</section>
<section id="properties_summary">
<title>Properties</title>
<properties>
<prophead>
<propnamehd>Property Name</propnamehd>
<proptypehd>Data Type</proptypehd>
<propdeschd>Description</propdeschd>
</prophead>
<property>
<propname>accountNumber</propname>
<proptype>String</proptype>
<propdesc>The unique identifier for the bank account. Read-only.</propdesc>
</property>
<property>
<propname>balance</propname>
<proptype>Decimal</proptype>
<propdesc>The current balance of the account. Updated by deposit and withdraw methods.</propdesc>
</property>
<property>
<propname>ownerName</propname>
<proptype>String</proptype>
<propdesc>The name of the account holder.</propdesc>
</property>
</properties>
</section>
<section id="methods_summary">
<title>Methods</title>
<!-- Method 1: deposit -->
<section id="method_deposit">
<title>deposit() Method</title>
<shortdesc>Adds funds to the account balance.</shortdesc>
<refsyn>public void deposit(Decimal amount)</refsyn>
<section id="deposit_parameters">
<title>Parameters</title>
<simpletable>
<sthead>
<stentry>Name</stentry><stentry>Type</stentry><stentry>Description</stentry>
</sthead>
<strow>
<stentry>amount</stentry><stentry>Decimal</stentry><stentry>The amount to deposit. Must be positive.</stentry>
</strow>
</simpletable>
</section>
<section id="deposit_returns">
<title>Returns</title>
<p>This method does not return a value (void).</p>
</section>
<section id="deposit_exceptions">
<title>Exceptions</title>
<p><codeph>IllegalArgumentException</codeph> if the amount is zero or negative.</p>
</section>
</section>
<!-- Method 2: withdraw -->
<section id="method_withdraw">
<title>withdraw() Method</title>
<shortdesc>Withdraws funds from the account balance.</shortdesc>
<refsyn>public boolean withdraw(Decimal amount)</refsyn>
<section id="withdraw_parameters">
<title>Parameters</title>
<simpletable>
<sthead>
<stentry>Name</stentry><stentry>Type</stentry><stentry>Description</stentry>
</sthead>
<strow>
<stentry>amount</stentry><stentry>Decimal</stentry><stentry>The amount to withdraw. Must be positive.</stentry>
</strow>
</simpletable>
</section>
<section id="withdraw_returns">
<title>Returns</title>
<p><codeph>true</codeph> if the withdrawal was successful; <codeph>false</codeph> if insufficient funds.</p>
</section>
<section id="withdraw_exceptions">
<title>Exceptions</title>
<p><codeph>IllegalArgumentException</codeph> if the amount is zero or negative.</p>
</section>
</section>
</section>
<example id="usage_example">
<title>Usage Example</title>
<codeblock>
BankAccount myAccount = new BankAccount("ACC12345", "Jane Doe");
myAccount.deposit(500.00);
boolean success = myAccount.withdraw(100.00);
if (success) {
System.out.println("Withdrawal successful. New balance: " + myAccount.getBalance());
} else {
System.out.println("Withdrawal failed.");
}
</codeblock>
</example>
</refbody>
</reference>
Example DITA structure for documenting an API class.
Visual representation of how API resources and their descriptions are often structured, relevant to DITA's organizational approach.
Many modern API documentation workflows involve integrating content from specifications like OpenAPI (formerly Swagger) into DITA. Tools and techniques exist to facilitate this, allowing for a single source of truth for API designs that can then be incorporated into broader DITA-based documentation sets. The following video discusses such integration, which can be highly relevant for advanced DITA usage in API documentation.
This video demonstrates integrating REST API content (OpenAPI) into DITA documentation, highlighting practical approaches.
<refsyn>
in DITA API docs?
When documenting Application Programming Interfaces (APIs), particularly those involving classes, methods, and properties, a structured and consistent approach is paramount. The Darwin Information Typing Architecture (DITA) provides a powerful XML-based framework for creating modular, reusable, and easily navigable API reference documentation. This guide explores how to effectively structure such documents using DITA and points to relevant examples.
<reference>
topic type, specifically designed for factual, lookup-oriented content like API elements.<map>
).<refsyn>
(for syntax/signatures) and <properties>
to clearly define API components.DITA is an XML-based open standard for authoring and publishing topic-oriented information. Its inherent modularity, support for content reuse, and specialization capabilities make it exceptionally well-suited for the complexities of technical documentation, including detailed API references. For APIs, DITA promotes:
The primary DITA information type for API documentation is the <reference>
topic. Reference topics are intended for "just the facts" content, perfect for describing programming constructs such as classes, methods, properties, functions, and commands. Each reference topic typically includes a title, a short description, and a body containing detailed information structured with specific DITA elements.
A well-structured DITA API reference ensures developers can quickly find and understand the information they need. The general approach involves creating individual reference topics for each major API component and then organizing them using DITA maps.
DITA maps (<map>
files) are crucial for defining the hierarchy and navigation of your API documentation. A map file contains references (<topicref>
) to your DITA topics, arranging them into a logical structure, much like a table of contents. For API documentation, a map might group classes by namespace, and under each class, list its methods and properties.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE map PUBLIC "-//OASIS//DTD DITA Map//EN" "map.dtd">
<map title="My Product API Reference">
<topicref href="api_overview.dita" navtitle="API Overview"/>
<topicref href="classes/myclass.dita" navtitle="MyClass">
<topicref href="methods/myclass_mymethod.dita" navtitle="myMethod()"/>
<topicref href="properties/myclass_myproperty.dita" navtitle="myProperty"/>
</topicref>
<topicref href="classes/anotherclass.dita" navtitle="AnotherClass"/>
<!-- Additional classes and elements -->
</map>
A DITA map organizes topics into a navigable structure.
Each API class should typically be documented in its own <reference>
topic. This topic serves as the main container for all information related to that class.
<title>
: The name of the class (e.g., "UserAccount Class").<shortdesc>
: A brief summary of the class's purpose.<refbody>
: Contains the detailed content.
<section>
for Description: A paragraph (<p>
) providing a more detailed explanation of the class, its role, and usage.<refsyn>
for Syntax: (Optional at class level, more common for methods) Can be used to show the class declaration signature.<section>
for Properties: A dedicated section to list and describe class properties (see below).<section>
for Methods: A dedicated section to list and link to or embed method descriptions (see below).Methods can be documented either as sections within the parent class's reference topic or as separate, more granular <reference>
topics linked from the class topic. The latter approach enhances modularity and reusability, especially for complex methods or those shared across classes (though less common).
<title>
: The method name, often including parentheses (e.g., "getUserProfile() Method").<shortdesc>
: A concise summary of what the method does.<refbody>
:
<refsyn>
(Syntax/Signature): Crucial for methods. This element is used to formally define the method's signature, including its name, parameters (with data types), return type, and any exceptions it might throw. Example: public String getUserProfile(int userId) throws NotFoundException
.<section>
for Parameters: Detailed descriptions of each parameter. Often presented using a <simpletable>
or a definition list (<dl>
). Each parameter entry should specify its name, data type, whether it's required or optional, and a description of its purpose.<section>
for Return Value: Description of the value returned by the method, including its data type and what it represents.<section>
for Exceptions: (If applicable) Details about exceptions the method may throw, and under what conditions.<example>
: Code snippets (within <codeblock>
) demonstrating how to use the method.Properties (also known as fields or attributes) are typically documented within a dedicated section of their parent class's reference topic. The <properties>
element is specifically designed for this.
<properties>
: A container element for a list of properties. It often functions like a specialized table.
<prophead>
: (Optional) Defines headers for the property list (e.g., Property Name, Type, Description).
<propnamehd>
, <proptypehd>
, <propvaluehd>
, <propdeschd>
<property>
: Represents a single property.
<propname>
: The name of the property.<proptype>
: The data type of the property (e.g., "String", "Integer", "Boolean").<propvalue>
: (If applicable) The default or possible values for the property.<propdesc>
: A description of the property's purpose and usage.Alternatively, if a more straightforward list or table format is preferred outside the specialized <properties>
structure, a <simpletable>
can also be used within a general <section>
to list properties.
To better understand how these components fit together, consider the following conceptual visualizations. The mindmap illustrates the hierarchical organization, while the radar chart highlights DITA's strengths for this type of documentation.
This mindmap shows a typical structure for DITA-based API documentation, starting from the overall API, organized by a DITA map, down to individual classes, methods, and properties within reference topics.
Conceptual mindmap of DITA API documentation structure.
This radar chart illustrates key attributes where DITA excels in the context of API documentation. The scores (out of 10) are qualitative assessments reflecting DITA's capabilities.
Comparative strengths of DITA for API documentation.
The following table summarizes some of the most important DITA elements used in structuring API reference documentation:
Element | Purpose in API Documentation |
---|---|
<reference> |
The root element for a reference topic, typically used for a class, or a complex method/property if documented separately. |
<title> |
Provides the main heading for the topic (e.g., class name, method name). |
<shortdesc> |
A brief, one or two-sentence summary of the API element. |
<refbody> |
Contains the main content of the reference topic, including sections, syntax, properties, and examples. |
<section> |
Used to group related content within the <refbody> , such as "Description," "Parameters," "Return Value." |
<refsyn> |
(Reference Syntax) Specifically designed to present the syntax or signature of a programming element (e.g., method signature, class declaration). |
<properties> |
A container for documenting a list of properties or attributes, often rendered as a table. |
<property> |
Defines a single property within the <properties> element. Contains sub-elements like <propname> , <proptype> , <propvalue> , and <propdesc> . |
<simpletable> |
Used for creating simple tables, often for listing parameters with their types and descriptions if <properties> is not suitable. |
<example> |
Contains an example illustrating the use of the API element, typically including a <codeblock> . |
<codeblock> |
Presents pre-formatted code samples. |
<p> |
A paragraph, used for descriptive text. |
<ul> , <ol> , <li> |
Used for unordered or ordered lists, e.g., for listing features or steps. |
<dl> , <dt> , <dd> |
Definition lists, useful for parameter lists where each term (parameter name) is followed by its description. |
Common DITA elements and their roles in API documentation.
Below is a simplified XML example demonstrating how a DITA reference topic might be structured for an API class named BankAccount
, including its properties and methods.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE reference PUBLIC "-//OASIS//DTD DITA Reference//EN" "reference.dtd">
<reference id="class_BankAccount">
<title>BankAccount Class</title>
<shortdesc>Represents a customer's bank account, providing functionalities for managing balances and transactions.</shortdesc>
<prolog>
<author>API Documentation Team</author>
<metadata>
<keywords>
<keyword>bank</keyword>
<keyword>account</keyword>
<keyword>API</keyword>
</keywords>
</metadata>
</prolog>
<refbody>
<section id="description">
<title>Class Description</title>
<p>The BankAccount class is used to manage financial information for a specific bank account.
It allows for deposits, withdrawals, and balance inquiries. Each instance of this class
corresponds to a unique bank account.</p>
</section>
<section id="properties_summary">
<title>Properties</title>
<properties>
<prophead>
<propnamehd>Property Name</propnamehd>
<proptypehd>Data Type</proptypehd>
<propdeschd>Description</propdeschd>
</prophead>
<property>
<propname>accountNumber</propname>
<proptype>String</proptype>
<propdesc>The unique identifier for the bank account. Read-only.</propdesc>
</property>
<property>
<propname>balance</propname>
<proptype>Decimal</proptype>
<propdesc>The current balance of the account. Updated by deposit and withdraw methods.</propdesc>
</property>
<property>
<propname>ownerName</propname>
<proptype>String</proptype>
<propdesc>The name of the account holder.</propdesc>
</property>
</properties>
</section>
<section id="methods_summary">
<title>Methods</title>
<!-- Method 1: deposit -->
<section id="method_deposit">
<title>deposit() Method</title>
<shortdesc>Adds funds to the account balance.</shortdesc>
<refsyn>public void deposit(Decimal amount)</refsyn>
<section id="deposit_parameters">
<title>Parameters</title>
<simpletable>
<sthead>
<stentry>Name</stentry><stentry>Type</stentry><stentry>Description</stentry>
</sthead>
<strow>
<stentry>amount</stentry><stentry>Decimal</stentry><stentry>The amount to deposit. Must be positive.</stentry>
</strow>
</simpletable>
</section>
<section id="deposit_returns">
<title>Returns</title>
<p>This method does not return a value (void).</p>
</section>
<section id="deposit_exceptions">
<title>Exceptions</title>
<p><codeph>IllegalArgumentException</codeph> if the amount is zero or negative.</p>
</section>
</section>
<!-- Method 2: withdraw -->
<section id="method_withdraw">
<title>withdraw() Method</title>
<shortdesc>Withdraws funds from the account balance.</shortdesc>
<refsyn>public boolean withdraw(Decimal amount)</refsyn>
<section id="withdraw_parameters">
<title>Parameters</title>
<simpletable>
<sthead>
<stentry>Name</stentry><stentry>Type</stentry><stentry>Description</stentry>
</sthead>
<strow>
<stentry>amount</stentry><stentry>Decimal</stentry><stentry>The amount to withdraw. Must be positive.</stentry>
</strow>
</simpletable>
</section>
<section id="withdraw_returns">
<title>Returns</title>
<p><codeph>true</codeph> if the withdrawal was successful; <codeph>false</codeph> if insufficient funds.</p>
</section>
<section id="withdraw_exceptions">
<title>Exceptions</title>
<p><codeph>IllegalArgumentException</codeph> if the amount is zero or negative.</p>
</section>
</section>
</section>
<example id="usage_example">
<title>Usage Example</title>
<codeblock>
BankAccount myAccount = new BankAccount("ACC12345", "Jane Doe");
myAccount.deposit(500.00);
boolean success = myAccount.withdraw(100.00);
if (success) {
System.out.println("Withdrawal successful. New balance: " + myAccount.getBalance());
} else {
System.out.println("Withdrawal failed.");
}
</codeblock>
</example>
</refbody>
</reference>
Example DITA structure for documenting an API class.
Visual representation of how API resources and their descriptions are often structured, relevant to DITA's organizational approach.
Many modern API documentation workflows involve integrating content from specifications like OpenAPI (formerly Swagger) into DITA. Tools and techniques exist to facilitate this, allowing for a single source of truth for API designs that can then be incorporated into broader DITA-based documentation sets. The following video discusses such integration, which can be highly relevant for advanced DITA usage in API documentation.
This video demonstrates integrating REST API content (OpenAPI) into DITA documentation, highlighting practical approaches.
<refsyn>
in DITA API docs?