Skip to content

Commit

Permalink
swagger: polishing #226
Browse files Browse the repository at this point in the history
- print support
- use thems styles for swagger
- docs
  • Loading branch information
McShelby committed Mar 27, 2022
1 parent f510f03 commit ff8f958
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 9 deletions.
2 changes: 1 addition & 1 deletion exampleSite/content/basics/migration/_index.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This document shows you what's new in the latest release. For a detailed list of

- **New**: Introduction of new CSS variables to set the font. The theme distinguishs between `--MAIN-font` for all content text and `--CODE-font` for inline or block code. There are additional overrides for all headings. See the [theme variant generator]({{%relref "basics/generator" %}}) of the exampleSite for all available variables.

- **New**: The new shortcode `swagger` is available to include a UI for REST OpenAPI Specifications. See the [`documentation`]({{% relref "shortcodes/swagger" %}}) for available features.
- **New**: The new shortcode `swagger` is available to include a UI for REST OpenAPI Specifications. See the [`documentation`]({{% relref "shortcodes/swagger" %}}) for available features. This feature will not work with Internet Explorer 11.

---

Expand Down
6 changes: 5 additions & 1 deletion exampleSite/content/shortcodes/swagger.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ title: "Swagger"

This shortcode uses the [RapiDoc](https://mrin9.github.io/RapiDoc) library to display your OpenAPI Specifications.

{{% notice note %}}
This only works in modern browsers.
{{% /notice %}}

## Configuration

Swagger is configured with default settings. You can customize Swagger's default settings for all of your files thru a JSON object in your `config.toml` or override these settings per page thru your pages frontmatter.

The JSON object of your `config.toml` / frontmatter is forwarded into Swagger's initialization. At the moment, only the `theme` setting is supported.

The `theme` setting can also be set by your used color variant. This will be the sitewide default and can - again - be overridden by your settings in `config.toml`, or frontmatter.
The `theme` setting can also be set by your used color variant. This will be the sitewide default and can - again - be overridden by your settings in `config.toml` or frontmatter.

### Example

Expand Down
6 changes: 2 additions & 4 deletions layouts/shortcodes/swagger.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
{{- $original := .Get "src" }}
<rapi-doc
allow-spec-file-download="true"
d-bg-color=""
default-schema-tab="example"
font-size="largest"
layout="column"
d-primary-color=""
load-fonts="false"
render-style="view"
schema-description-expanded="true"
schema-style="table"
show-header="false"
spec-url = "{{ $original | relURL }}"
sort-tags="true"
d-text-color=""
theme="light"
></rapi-doc>
{{- .Page.Store.Set "hasSwagger" true }}
6 changes: 6 additions & 0 deletions static/css/print.css
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ div.box {
div.box > .box-content {
background-color: white;
}
rapi-doc{
/* adjust rapi-doc internals to fill out available space */
font-size: 4pt;
margin-left: -12px;
width: calc( 100% + 12px + 8px );
}
.btn-default,
#body .tab-nav-button {
color: black !important;
Expand Down
5 changes: 4 additions & 1 deletion static/css/theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -1452,7 +1452,10 @@ h6 a {
margin-top: 1rem;
}

.select-container {
rapi-doc {
/* adjust rapi-doc internals to fill out available space */
margin-left: calc( -8px - 24px );
width: calc( 100% + 8px + 24px + 8px );
}

.select-container i {
Expand Down
13 changes: 11 additions & 2 deletions static/js/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,18 @@ function initSwagger( update ){
if( typeof variants == 'undefined' ){
return;
}
var theme = variants.getColorValue( 'SWAGGER-theme' );
var attrs = [
[ 'bg-color', variants.getColorValue( 'MAIN-BG-color' ) ],
[ 'mono-font', variants.getColorValue( 'CODE-font' ) ],
[ 'primary-color', variants.getColorValue( 'TAG-BG-color' ) ],
[ 'regular-font', variants.getColorValue( 'MAIN-font' ) ],
[ 'text-color', variants.getColorValue( 'MAIN-TEXT-color' ) ],
[ 'theme', variants.getColorValue( 'SWAGGER-theme' ) ],
];
document.querySelectorAll( 'rapi-doc' ).forEach( function( e ){
e.setAttribute( 'theme', theme );
attrs.forEach( function( attr ){
e.setAttribute( attr[0], attr[1] );
});
});
}

Expand Down

0 comments on commit ff8f958

Please sign in to comment.