Skip to content

Commit 041bfa0

Browse files
committed
support for array examples, include default values in UI and minor style changes
1 parent 4315f53 commit 041bfa0

File tree

14 files changed

+345
-303
lines changed

14 files changed

+345
-303
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Custom Eelement for Open-API spec viewing
3636
- Use it inside another framework (react, vue, angular, lit-element)
3737
- Use JavaScript to change its attributes, and it will react to those changes
3838
- Style the element with standard css (change padding, position, border, margin )
39-
- Lightweight and fast (under 125 KB gzipped)
39+
- Lightweight and fast
4040
- Load local json spec from the disk
4141
- Supported on Chrome, FireFox and Safari. (Not yet tested on Edge)
4242

@@ -49,7 +49,6 @@ Custom Eelement for Open-API spec viewing
4949

5050

5151
## Build Process
52-
We recommend `yarn` over `npm` as we use yarn [resolutions](https://yarnpkg.com/lang/en/docs/selective-version-resolutions/) to keep the bundle size smaller. As of this writing this feature is not supported in npm natively
5352
```bash
5453
# Clone / Download the project then
5554
yarn install
@@ -60,4 +59,6 @@ yarn build
6059

6160
# for developement use yarn serve (this will start an webserver at port 8080, then navigate to localhost:8080)
6261
yarn serve
63-
```
62+
```
63+
64+
## Contribution

dist/rapidoc-min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rapidoc-min.js.gz

360 Bytes
Binary file not shown.

dist/report.html

Lines changed: 6 additions & 4 deletions
Large diffs are not rendered by default.

docs/rapidoc-min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/specs/data-types.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,16 @@ components:
123123
description: Categories this pet belongs to
124124
allOf:
125125
- $ref: '#/components/schemas/Category'
126+
DependentIds:
127+
type: array
128+
description: IDs of Dependents .
129+
items:
130+
type: integer
131+
example:
132+
- 278
133+
- 279
134+
- 280
135+
- 281
126136
name:
127137
description: Name of the person
128138
type: string

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rapidoc",
3-
"version": "5.3.0",
3+
"version": "5.3.1",
44
"description": "RapiDoc - Open API spec viewer with built in console",
55
"author": "Mrinmoy Majumdar <[email protected]>",
66
"repository": {
@@ -25,8 +25,8 @@
2525
"openapi themes",
2626
"swagger themes"
2727
],
28-
"main": "rapidoc.js",
29-
"module": "rapidoc.js",
28+
"main": ".src/rapidoc.js",
29+
"module": ".src/rapidoc.js",
3030
"dependencies": {
3131
"json-refs": "^3.0.13",
3232
"lit-element": "2.2.1",
@@ -41,16 +41,16 @@
4141
"lint-fix" : "./node_modules/eslint/bin/eslint.js --fix ./src/**"
4242
},
4343
"devDependencies": {
44-
"@babel/core": "^7.6.0",
45-
"@babel/preset-env": "^7.6.0",
44+
"@babel/core": "^7.6.2",
45+
"@babel/preset-env": "^7.6.2",
4646
"babel-loader": "^8.0.6",
4747
"babel-plugin-template-html-minifier": "^3.1.0",
4848
"clean-webpack-plugin": "^3.0.0",
4949
"compression-webpack-plugin": "^3.0.0",
5050
"css-loader": "^3.2.0",
51-
"eslint": "^6.4.0",
51+
"eslint": "^6.5.1",
5252
"eslint-config-airbnb": "^18.0.1",
53-
"eslint-loader": "^3.0.0",
53+
"eslint-loader": "^3.0.2",
5454
"eslint-import-resolver-webpack":"^0.11.1",
5555
"eslint-plugin-import": "^2.18.2",
5656
"file-loader": "^4.2.0",
@@ -60,9 +60,9 @@
6060
"node-sass": "^4.12.0",
6161
"sass-loader": "^8.0.0",
6262
"style-loader": "^1.0.0",
63-
"webpack": "^4.40.2",
64-
"webpack-bundle-analyzer": "^3.5.0",
63+
"webpack": "^4.41.0",
64+
"webpack-bundle-analyzer": "^3.5.2",
6565
"webpack-cli": "^3.3.9",
66-
"webpack-dev-server": "^3.8.1"
66+
"webpack-dev-server": "^3.8.2"
6767
}
6868
}

src/components/api-request.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import InputStyles from '@/styles/input-styles';
77
import FontStyles from '@/styles/font-styles';
88
import CommonStyles from '@/styles/common-styles';
99
import {
10-
schemaToModel, getTypeInfo, generateExample,
10+
schemaInObjectNotation, getTypeInfo, generateExample,
1111
} from '@/utils/common-utils';
1212
import '@/components/json-tree';
1313
import '@/components/schema-tree';
@@ -224,6 +224,7 @@ export default class ApiRequest extends LitElement {
224224
</td>
225225
<td>
226226
<div class="param-constraint">
227+
${paramSchema.default ? html`<span style="font-weight:bold">Default: </span>${paramSchema.default}<br/>` : ''}
227228
${paramSchema.constrain ? html`${paramSchema.constrain}<br/>` : ''}
228229
${paramSchema.allowedValues ? html`${paramSchema.allowedValues}` : ''}
229230
</div>
@@ -300,9 +301,9 @@ export default class ApiRequest extends LitElement {
300301
return;
301302
}
302303
if (mimeReq.includes('json')) {
303-
reqSchemaTree.json = schemaToModel(mimeReqObj.schema, {});
304+
reqSchemaTree.json = schemaInObjectNotation(mimeReqObj.schema, {});
304305
} else if (mimeReq.includes('xml')) {
305-
reqSchemaTree.xml = schemaToModel(mimeReqObj.schema, {});
306+
reqSchemaTree.xml = schemaInObjectNotation(mimeReqObj.schema, {});
306307
}
307308
reqExample = generateExample(
308309
mimeReqObj.schema ? mimeReqObj.schema.examples : '',
@@ -318,8 +319,8 @@ export default class ApiRequest extends LitElement {
318319
spellcheck = "false"
319320
data-ptype = "${mimeReq}"
320321
style="resize:vertical;display:${shortMimeTypes[mimeReq] === 'json' ? 'block' : 'none'}; "
321-
>${reqExample[0].exampleValue}
322-
</textarea>`;
322+
>${reqExample[0].exampleValue}</textarea>
323+
`;
323324
} else if (mimeReq.includes('form') || mimeReq.includes('multipart-form')) {
324325
isFormDataPresent = true;
325326
for (const fieldName in mimeReqObj.schema.properties) {
@@ -486,9 +487,7 @@ export default class ApiRequest extends LitElement {
486487
<button class="m-btn" @click="${this.downloadResponseBlob}">DOWNLOAD</button>
487488
</div>`
488489
: html`
489-
<textarea class="mono" spellcheck="false" style="resize:vertical;min-height:180px; padding:16px;">
490-
${this.responseText}
491-
</textarea>
490+
<textarea class="mono" spellcheck="false" style="resize:vertical;min-height:180px; padding:16px;">${this.responseText}</textarea>
492491
`
493492
}
494493
</div>

src/components/api-response.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { LitElement, html } from 'lit-element';
22
import marked from 'marked';
33
import { unsafeHTML } from 'lit-html/directives/unsafe-html';
4-
import { schemaToModel, generateExample } from '@/utils/common-utils';
4+
import { schemaInObjectNotation, generateExample } from '@/utils/common-utils';
55
import FontStyles from '@/styles/font-styles';
66
import FlexStyles from '@/styles/flex-styles';
77
import TableStyles from '@/styles/table-styles';
@@ -107,7 +107,7 @@ export default class ApiResponse extends LitElement {
107107
const mimeRespObj = this.responses[statusCode].content[mimeResp];
108108

109109
// Generate Schema
110-
const schemaTree = schemaToModel(mimeRespObj.schema, {});
110+
const schemaTree = schemaInObjectNotation(mimeRespObj.schema, {});
111111

112112
// Generate Example
113113
const respExample = generateExample(

src/components/json-tree.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ export default class JsonTree extends LitElement {
5757
<div class="inside-bracket">
5858
${Object.keys(data).map((key) => html`<div class="item"> ${detailType === 'pure_object' ? html`${key}:` : ''}${this.generateTree(data[key])}</div>`)}
5959
</div>
60-
<div class="right-bracket">${detailType === 'array' ? ']' : '}'}</div>
60+
<div class="right-bracket">${detailType === 'array' ? '],' : '},'}</div>
6161
`;
6262
}
6363

64-
return typeof data === 'string' ? html`<span class="${typeof data}">"${data}"</span>` : html`<span class="${typeof data}">${data}</span>`;
64+
return typeof data === 'string' ? html`<span class="${typeof data}">"${data}"</span>,` : html`<span class="${typeof data}">${data}</span>,`;
6565
}
6666
/* eslint-enable indent */
6767

0 commit comments

Comments
 (0)