-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Stoplight Elements to render OpenAPI docs (#693)
Instead of compiling static html files from openapi.yaml using redoc the docs are now rendered in the browser using https://github.com/stoplightio/elements
- Loading branch information
1 parent
949b803
commit 418400e
Showing
43 changed files
with
63 additions
and
81 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
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 |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
/lib/ | ||
/bin/ | ||
/node_modules/ | ||
/static/docs/ | ||
/static/js/lib/ | ||
/tmp/ | ||
*.log | ||
|
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
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
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
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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
BINS := bin/lavinmq bin/lavinmqctl bin/lavinmqperf | ||
SOURCES := $(shell find src/lavinmq src/stdlib -name '*.cr' 2> /dev/null) | ||
JS := static/js/lib/chunks/helpers.segment.js static/js/lib/chart.js static/js/lib/amqp-websocket-client.mjs static/js/lib/amqp-websocket-client.mjs.map static/js/lib/luxon.js static/js/lib/chartjs-adapter-luxon.esm.js | ||
DOCS := static/docs/index.html | ||
JS := static/js/lib/chunks/helpers.segment.js static/js/lib/chart.js static/js/lib/amqp-websocket-client.mjs static/js/lib/amqp-websocket-client.mjs.map static/js/lib/luxon.js static/js/lib/chartjs-adapter-luxon.esm.js static/js/lib/elements-8.2.0.js static/js/lib/elements-8.2.0.css | ||
CRYSTAL_FLAGS := --release | ||
override CRYSTAL_FLAGS += --error-on-warnings --link-flags=-pie | ||
|
||
|
@@ -44,9 +43,11 @@ static/js/lib/chartjs-adapter-luxon.esm.js: | static/js/lib | |
curl --retry 5 -sLo $@ https://cdn.jsdelivr.net/npm/[email protected]/dist/chartjs-adapter-luxon.esm.js | ||
sed -i'' -e "s|\(import { _adapters } from\).*|\1 './chart.js'|; s|\(import { DateTime } from\).*|\1 './luxon.js'|" $@ | ||
|
||
static/docs/index.html: openapi/openapi.yaml openapi/.spectral.json $(wildcard openapi/paths/*.yaml) $(wildcard openapi/schemas/*.yaml) | ||
npx --package=@stoplight/spectral-cli spectral --ruleset openapi/.spectral.json lint $< | ||
npx @redocly/cli build-docs --output $@ $< | ||
static/js/lib/elements-8.2.0.js: | static/js/lib | ||
curl --retry 5 -sLo $@ https://unpkg.com/@stoplight/[email protected]/web-components.min.js | ||
|
||
static/js/lib/elements-8.2.0.css: | static/js/lib | ||
curl --retry 5 -sLo $@ https://unpkg.com/@stoplight/[email protected]/styles.min.css | ||
|
||
man1/lavinmq.1: bin/lavinmq | man1 | ||
help2man -Nn "fast and advanced message queue server" $< -o $@ | ||
|
@@ -62,19 +63,23 @@ MANPAGES := man1/lavinmq.1 man1/lavinmqctl.1 man1/lavinmqperf.1 | |
.PHONY: man | ||
man: $(MANPAGES) | ||
|
||
.PHONY: docs | ||
docs: $(DOCS) | ||
|
||
.PHONY: js | ||
js: $(JS) | ||
|
||
.PHONY: deps | ||
deps: js lib docs | ||
deps: js lib | ||
|
||
.PHONY: lint | ||
lint: lib | ||
lib/ameba/bin/ameba src/ | ||
standard static/js | ||
|
||
.PHONY: lint-js | ||
lint-js: | ||
npx standard static/js | ||
|
||
.PHONY: lint-openapi | ||
lint-openapi: | ||
npx --package=@stoplight/spectral-cli spectral --ruleset openapi/.spectral.json lint static/docs/openapi.yaml | ||
|
||
.PHONY: test | ||
test: lib | ||
|
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 |
---|---|---|
|
@@ -3,7 +3,7 @@ Standards-Version: 4.6.0 | |
Homepage: https://github.com/cloudamqp/lavinmq | ||
Section: net | ||
Priority: optional | ||
Build-Depends: debhelper (>= 12), crystal (>= 1.8.0), nodejs (>= 12), curl | ||
Build-Depends: debhelper (>= 12), crystal (>= 1.8.0), curl | ||
Maintainer: CloudAMQP <[email protected]> | ||
|
||
Package: lavinmq | ||
|
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
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 |
---|---|---|
@@ -1,32 +1,15 @@ | ||
# LavinMQ Management HTTP API OpenAPI spec | ||
# LavinMQ HTTP API OpenAPI spec | ||
|
||
Run `make docs` to build docs (calls `npx redoc-cli`). | ||
|
||
It outputs to `static/docs/index.html` so you can view the docs at [http://localhost:15672/docs/](http://localhost:15672/docs/) if you have LavinMQ running. | ||
|
||
The dependencies: | ||
|
||
* [Spectral] is used to lint the documentation. To run it manually: `docker run --rm -it -v $(pwd):/tmp stoplight/spectral:6 --ruleset /tmp/openapi/.spectral.json lint openapi/openapi.yaml` | ||
* [ReDoc] is to build the documentation. | ||
To run it manually: `npx redoc-cli bundle openapi.yaml -o static/docs/index.html` | ||
|
||
You can preview docs using: | ||
|
||
``` | ||
npx redoc-cli serve openapi.yaml | ||
``` | ||
OpenAPI docs rendered in browser using https://github.com/stoplightio/elements | ||
|
||
(Note the gotcha: the browser caches the YAML files even if they have changed, open dev console in the browser to mitigate.) | ||
|
||
## OpenAPI notes | ||
|
||
* `summary` is the short description (used in the redoc menu for instance) | ||
* `summary` is the short description | ||
* `description` is a longer description (supports Markdown) | ||
|
||
The following script was used to generate the OpenAPI Spec YAML structure | ||
|
||
ruby openapi.rb | ||
|
||
[Spectral]: https://github.com/stoplightio/spectral | ||
[ReDoc]: https://github.com/Redocly/redoc | ||
[ReDoc Docker image]: https://github.com/Redocly/redoc/tree/master/config/docker#official-redoc-docker-image |
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
This file was deleted.
Oops, something went wrong.
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
Empty file.
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,21 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | ||
<title>LavinMQ HTTP API</title> | ||
<script src="../js/lib/elements-8.2.0.js"></script> | ||
<link rel="stylesheet" href="../js/lib/elements-8.2.0.css"> | ||
</head> | ||
<body> | ||
<elements-api | ||
apiDescriptionUrl="openapi.yaml" | ||
router="hash" | ||
layout="sidebar" | ||
logo="../img/favicon.png" | ||
tryItCredentialsPolicy="same-origin" | ||
hideSchemas="true" | ||
/> | ||
</body> | ||
</html> | ||
|
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 |
---|---|---|
@@ -1,16 +1,15 @@ | ||
--- | ||
openapi: 3.0.3 | ||
info: | ||
version: | ||
"$ref": "../shard.yml#/version" | ||
title: LavinMQ Management HTTP API | ||
version: v1.2.12 | ||
title: LavinMQ HTTP API | ||
description: HTTP API to programmatically manage all aspects of LavinMQ. | ||
contact: | ||
name: LavinMQ Team | ||
url: https://www.lavinmq.com/ | ||
email: [email protected] | ||
servers: | ||
- url: http://localhost:15672/api | ||
- url: /api | ||
components: | ||
schemas: | ||
ErrorResponse: | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.