-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Document the openapi3.Unmarshal function
- Loading branch information
Showing
2 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
--- | ||
title: openapi3.Unmarshal | ||
description: Unmarshals the given resource into an OpenAPI 3 document. | ||
categories: [] | ||
keywords: [] | ||
action: | ||
aliases: [] | ||
related: [] | ||
returnType: openapi3.OpenAPIDocument | ||
signatures: ['openapi3.Unmarshal RESOURCE'] | ||
--- | ||
|
||
Use the `openapi3.Unmarshal` function with [global], [page], or [remote] resources. | ||
|
||
[global]: /getting-started/glossary/#global-resource | ||
[page]: /getting-started/glossary/#page-resource | ||
[remote]: /getting-started/glossary/#remote-resource | ||
[OpenAPI]: https://www.openapis.org/ | ||
|
||
For example, to work with a remote [OpenAPI] defintion: | ||
|
||
```go-html-template | ||
{{ $url := "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/examples/v3.0/petstore.json" }} | ||
{{ $api := "" }} | ||
{{ with resources.GetRemote $url }} | ||
{{ with .Err }} | ||
{{ errorf "%s" . }} | ||
{{ else }} | ||
{{ $api = . | openapi3.Unmarshal }} | ||
{{ end }} | ||
{{ else }} | ||
{{ errorf "Unable to get remote resource %q" $url }} | ||
{{ end }} | ||
``` | ||
|
||
To inspect the data structure: | ||
|
||
```go-html-template | ||
<pre>{{ debug.Dump $api }}</pre> | ||
``` | ||
|
||
To list the GET and POST operations for each of the API paths: | ||
|
||
```go-html-template | ||
{{ range $path, $details := $api.Paths }} | ||
<p>{{ $path }}</p> | ||
<dl> | ||
{{ with $details.Get }} | ||
<dt>GET</dt> | ||
<dd>{{ .Summary }}</dd> | ||
{{ end }} | ||
{{ with $details.Post }} | ||
<dt>POST</dt> | ||
<dd>{{ .Summary }}</dd> | ||
{{ end }} | ||
</dl> | ||
{{ end }} | ||
``` | ||
|
||
Hugo renders this to: | ||
|
||
|
||
```html | ||
<p>/pets</p> | ||
<dl> | ||
<dt>GET</dt> | ||
<dd>List all pets</dd> | ||
<dt>POST</dt> | ||
<dd>Create a pet</dd> | ||
</dl> | ||
<p>/pets/{petId}</p> | ||
<dl> | ||
<dt>GET</dt> | ||
<dd>Info for a specific pet</dd> | ||
< 893F td class="blob-code blob-code-addition js-file-line"> </dl> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
title: OpenAPI functions | ||
linkTitle: openapi3 | ||
description: Template functions to work with OpenAPI 3 definitions. | ||
categories: [] | ||
keywords: [] | ||
menu: | ||
docs: | ||
parent: functions | ||
--- | ||
|
||
Use these functions to work with OpenAPI 3 definitions. |