Apidoc Markdown



APIDOCDOCUMENTATIONPATH = 'my-api-documentation' The `APIDOCDOCUMENTATIONPATH` default value is `apidoc` APIDoc Mixins-The documenter classes are composed by 2 types of mixings, the content mixins and the process mixins. The content mixins obtain the documentation text, and the process mixing transform this text in another thing. Run apidoc-markdown -i myapp/ -o apidoc/. Apidoc -i myapp/ -o apidoc/ Creates an apiDoc of all files within dir myapp/, and put all output to dir apidoc/. Without any parameter, apiDoc generate a documentation from all.cs.dart.erl.go.java.js.php.py.rb.ts files in current dir (incl. Subdirs) and writes the output to./apidoc/.

  1. Apidoc Markdown Cheat
  2. Apidoc Markdown Problems
  3. Apidoc Markdown File
  4. Api Doc Markdown Download
  5. Apidoc Markdown Table

yiisoft/yii2-apidoc API Documentation generator for the Yii framework 2.0

API documentation generator for Yii 2


This extension provides an API documentation generator for the Yii framework 2.0.

For license information check the LICENSE-file.

Installation ¶

The preferred way to install this extension is through composer.

Either run

The above command may not work on an existing project due to version conflicts that need to be resolved, so it is preferred to add the package manually to the require section of your composer.json:

afterwards run composer update. You may also run composer update yiisoft/yii2-apidoc cebe/markdown if you want to avoid updating unrelated packages.

Usage ¶

This extension offers two commands:

  • api to generate class API documentation. phpDocumentor is used as a base frameworkso refer to its guide for the syntax.
  • guide to render nice HTML pages from markdown files such as the yii guide.

Simple usage for stand-alone class documentation:

Simple usage for stand-alone guide documentation:

You can combine them to generate class API and guide documentation in one place:

Software

By default, the bootstrap template will be used. You can choose a different template with the --template=name parameter.Currently, there is only the bootstrap template available.

You may also add the yiiapidoccommandsApiController and GuideController to your console application command mapand run them inside of your applications console app.

Generating docs from multiple sources ¶

The apidoc generator can use multiple directories, so you can generate docs for your application and include the yii frameworkdocs to enable links between your classes and framework classes. This also allows @inheritdoc to workfor your classes that extend from the framework.Use the following command to generate combined api docs:

This will read the source files from ./vendor/yiisoft/yii2 directory and . which is the current directory (you may replace this with the location of your code if it is not in the current working directory).

Advanced usage ¶

The following script can be used to generate API documentation and guide in different directories and also multiple guidesin different languages (like it is done on yiiframework.com):

Creating a PDF of the guide ¶
Apidoc markdown for bullet

You need pdflatex and GNU make for this.

If all runs without errors the PDF will be guide.pdf in the output dir.

Special Markdown Syntax ¶

We have a special Syntax for linking to classes in the API documentation.See the code style guide for details.

Creating your own templates ¶

TBD

Using the model layer ¶

TBD

Apidoc Markdown Cheat

The API Doctor documentation test tool makes it easy to validate that the Markdown-based APIdocumentation matches a REST service implementation.

Apidoc markdown cheat

The toolset includes a command line and GUI application that can be used toperform for the following validations:

Apidoc Markdown Problems

  • Check for broken links in the documentation.
  • Print resource and method definitions.
  • Verify that the documentation is internally consistent:
    • Check that defined resources and APIs that return these resources match.
    • Check that example API responses are consistent with the resources they should return.
  • Verify that a target REST service matches the API documentation:
    • Check that requests and responses in the documentation match the service.
    • Inject parameters into the API calls to the service.
  • Publish documentation to an output folder.

Building

To build the project, invoke dotnet build. The tool has been upgraded to use dotnet core.

Command Line Tool

apidoc.exe [command] [options]

Available commands are:

  • print - Print files, resources, and methods discovered in the documentation.
  • check-links - Verify that links in the documentation aren’t broken.
  • check-docs - Check for errors in the documentation’s resources, requests, and response examples.
  • check-service - Check for differences between the documentation and service responses to documented requests.
  • publish - Publish the documentation into one of the supported output formats.

All commands have the following options available:

OptionDescription
--path <path>Path to the root of the documentation set to scan. If missing, the current path is assumed.
--shortPrint concise output to the console.
--verbosePrint verbose output to the console, including full HTTP requests/responses.
--log <log_file>Log console output to a file.
--parameters <params>A URL-encoded string containing key/value pairs. Allows additional parameters to be passed to the task. Currently used by the tagging feature to specify content to include. For more information see Markdown customizations.

Print Command

Print information about the source files, resources, methods, and requeststhat were parsed by the tool.

OptionDescription
--filesOutput information about the files contained in the document set.
--resourcesOutput resource definitions read from the documentation.
--methodsOutput method definitions read from the documentation.

One of these three arguments is required to use the print command.

Check-links Command

Check for broken links in the documentation.

No specific options are required. Using --verbose will include warnings aboutlinks that were not verified.

Example: apidoc.exe check-links --path ~/github/api-docs --method search

Check-docs Command

The check-docs command ensures that the documentation is internally consistent.It verifies that:

  • The JSON examples are proper JSON
  • The API methods that accept or return a specific resource type have valid request/response examples
  • The metadata in the documentation is formatted properly
OptionDescription
--method <method_name>Optional. Specify the name of a request method to evaluate. If missing, all methods are evaluated.

Example: apidoc.exe check-docs --path ~/github/api-docs --method search

Check-service Command

Check the documented requests and responses against an actual REST service. Thisoption will load accounts from a configuration file (see below), environmentvariables or use the specified access-token and url parameters to determinehow to make API calls with the target service.

Apidoc Markdown File

Any scenario files that are contained within the documentation path willautomatically be loaded and used by the check-service method.

OptionDescription
--access-token 'token'OAuth access token to use when calling the service. You may need to escape the token value by enclosing it in double quotes.
--branch-name <branch>Optional. Specify the branch name that is the source of the documentation. Compares this name to the configuration file to see if the check-service command is allowed for this branch.
--headers <headers>Optional. Enables adding additional headers to every API call made by check-service. The format should be a quoted string with aseparating different header lines.
--ignore-scopesOptional. Disables using scopes to determine which methods are exercised on an account.
--method <method_name>Optional. Check a single request/response method instead of everything in the documentation.
--odata-metadata <value>Optional. Specify the value of the odata.metadata level that is provided in the Accept header.
--pausePause for a key press between API calls to the service to enable reading the responses.
--scopes <scopes>Provide a command separated list of scopes which are provided by the command line accessToken.
--url <url>Set the base URL for the service calls.

Example: The one note man.

Account configuration file

You can specify account information in a configuration file stored inside thedocumentation set. Apidoc will look for any .json file that includes anaccounts property include an array of account objects. These accounts willbe used by the check-service command.

See more details about account configuration files.

Api Doc Markdown Download

Account by environment variables

Instead of using an access token on the command line or an account configuration fileyou can use the following environment variables to provide a refresh token andtoken service to generate access tokens. This enables the tool to be used inautomation scripts and other scenarios where it may not be possible to providean access-token in any other way.

Variable nameDescription
oauth-token-serviceURL for the OAuth 2.0 token service to be used to retrieve an access token
oauth-client-idClient ID that is passed to the token service
oauth-client-secretClient Secret that is passed to the token service
oauth-redirect-uriRedirect URI used to generate the refresh token
oauth-refresh-tokenRefresh token that is used to generate an access token

If these environment variables are set, it is not necessary to pass an accesstoken using the --access-token command line parameter. The tool will call thetoken service to retrieve an access token when necessary.

Publish Command

The publish command uses the documentation to generate a new set of outputs.

See the documentation on publishing using API Doctor formore details.

Documentation format

See Markdown requirements for more details aboutrequirements on the markdown source for documentation.

Request parameters

The tool also supports defining parameters for requests in a separate file. Thisinformation is loaded and used to make one or more requests to the service bysubstituting values for placeholders in the initial request.

For example, in a request for an item with a particular ID, you might write therequest to look like this:

However, when the test tool makes the API call to the service, calling it verbatimwould result in an error. Request parameters allow you to define one or morescenarios that are used to call the method.

A scenario can have one or more statically defined properties. It can also includean HTTP request and substitute one or more placeholder values with data fromthe response to that request.

The scenario file contains a single JSON array, with each member of the arrayconforming to this schema:

PropertyTypeDescription
namestringThe name of the scenario described.
methodstringThe name of the method this scenario uses. Either defined in the documentation or a substitute name is auto-generated.
enabledboolEnable or disable the scenario.
test-setuparraySee below.
request-parameterskey-value pairsSpecify the key-value pairs for parameters for the request. The key is used as a placeholder name, and the value is subed into the placeholder.
expectationskey-value pairsSpecify the expected values in the final response. The keys are the same Capture Grammar defined for request-parameters.

Test setup

The test-setup property allows you to define an array of calls that are madebefore the actual test method is executed. This allows you to pull values fromother requests and store them to be used in the test method call. This alsoallows you to chain together multiple calls from the documentation to enabletesting complex scenarios, like fragment uploads.

Each object in the array of test-setup is a PlaceholderRequest instance.

PropertyTypeDescription
methodstringThe name of a method from the documentation that should be used as this test-setup call
http-requeststringInstead of specifying a method from the docs, you can input a raw HTTP request to be used.
request-parameterskey-value pairsSpecify the key-value pairs for parameters for the request. The key is used as a placeholder name, and the value is subed into the placeholder.
allowed-status-codesarray of intNormally the request is considered failed of the response is anything other than 2xx. Use this to allow error codes and other responses to be considered valid.
capturekey-value pairsSpecify the key-value pairs of values that are read from this response and stored for another request under this scenario. Allows you to store values and use them in other requests under the same scenario.
canned-requeststringThe name of the canned-request defined in the scenario file that is executed. This way common requests can be stored in one place instead of repeated throughtout the test files.

Canned Requests

Canned requests look just like a test setup method, but instead of being ascenario for a particular method are avaialble to be used from any scenariodefinition.

Placeholder grammar

When specifying a placeholder name or value, the following syntax is used:

SyntaxExampleDescription
Curly Braces{path-to-file}Find and update a value in the URL matching the full string.
Square Braces[source-file-id]Look for a previous stored value that was output from a previous request within the same scenario.
JPath$.idReplace a property value in the JSON body of the request. If the content-type of the request is not application/json an error will occur.
!body!bodyReplace the content stream of the request with the provided value
!body.base64!body.base64Replace the content stream of the request with a decoded byte stream of the base 64 value provided.
!url!urlReplace the URL for the request with the provided value.
Header:Content-Type:Replace the value of a header with the specified value. Note the header name must end with a colon to be valid.
Random Filename`!random-filename-png!Returns a randomly generated value with a particular file extension that can be used to ensure tests don’t interfere with each other.

Capture grammar

The key of anything in the capture node MUST be wrapped in squarebrackets [foobar]. Otherwise the parameters will not be considered value.

Markdown

Apidoc Markdown Table

The output-value grammar follows the same syntax as the placeholder grammar:

SyntaxExampleDescription
JPath$.idRead and store the value at the JPath
Header:Content-Type:Read and store the value of the specified HTTP header
!body!bodyRead and store the complete body of the response

Code block annotation properties

The HTML-comment enclosed JSON object inside the documentation has the followingproperties defined:

Property descriptions

NameValueAllowed blocksDescription
blockTypestringAllDescribes the type of the json block proceeding the annotation.
@odata.typestringAllDescribes the name of the resource (either being defined, in the case of a resource block, or as the body type on a request/response block)
optionalPropertiesarray of stringsresourceAn array of properties that are not required to be in the code block.
isCollectionbooleanresponse, example, simulatedResponseIndicates that the block contains a collection of items that match the @odata.type schema. This is expected as an object with a single property that is an array of objects.
collectionPropertystringresponse, example, simulatedResponseProvides the name of the variable that contains the collection. Default value: value.
isEmptybooleanresponse, example, simulatedResponseIndicates that the collection value is expected to be empty (or not).
truncatedbooleanresponse, example, simulatedResponseIndicates that the block will not include all properties of the resource and that’s not an error. Properties explicitly shown in the code block are always considered required when tested against the service.
namestringrequest, exampleProvides the name of the request method being defined.
expectErrorbooleanresponse, example, simulatedResponseUse this to indicate that instead of returning the normal response as defined, an error response will be returned.
nullablePropertiesarray of stringsresponse, example, simulatedResponseProvide a list of properties that are allowed to have null values. By default, null values for a property will generate a warning.

Block types

| Name | Description ||:——————–|:————————————————————————————————————————————-|| resource | The json block describes a system resource (complex type) in the API. || request | The json block describes an HTTP request that can be made by clients. || response | The json block describes the HTTP response that is sent from the service. || example | An example of the JSON data that would be generated by the client or returned by the service, without being wrapped in an HTTP call. || simulatedResponse | Used for unit testing to simulate responses from the service. || ignored | No processing is done on the code block that follows. |

Open Source

See OpenSourceNotes for more details about open source usage in API Doctor.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Apidoc Markdown
This site is open source. Improve this page.