Skip to content

Commit e1cdca8

Browse files
committed
fixed some corner cases for rendering example
1 parent 1d5248f commit e1cdca8

9 files changed

+261
-21
lines changed

dist/rapidoc-min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rapidoc-min.js.gz

24 Bytes
Binary file not shown.

dist/report.html

+2-2
Large diffs are not rendered by default.

docs/rapidoc-min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/specs/provide-example-data.yaml

+220
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
openapi: 3.0.0
2+
info:
3+
title: NetDGatewaAPI
4+
version: 0.0.0
5+
contact:
6+
name: Jacob Miles
7+
paths:
8+
/search/name:
9+
get:
10+
operationId: Search By Name
11+
summary: Search by Name
12+
description: Search by Name
13+
security:
14+
- bearerAuth: []
15+
parameters:
16+
- $ref: '#/components/parameters/lastName'
17+
- $ref: '#/components/parameters/firstName'
18+
- $ref: '#/components/parameters/dob'
19+
- $ref: '#/components/parameters/fileDateStart'
20+
- $ref: '#/components/parameters/fileDateEnd'
21+
- $ref: '#/components/parameters/business'
22+
- $ref: '#/components/parameters/attorney'
23+
responses:
24+
'200':
25+
$ref: '#/components/responses/SearchCaseList'
26+
'401':
27+
$ref: '#/components/responses/UnAuthorized'
28+
'406':
29+
$ref: '#/components/responses/NotAcceptable'
30+
'500':
31+
$ref: '#/components/responses/InternalServerError'
32+
33+
components:
34+
responses:
35+
SearchCaseList:
36+
description: Search Case List
37+
content:
38+
application/json:
39+
schema:
40+
$ref: '#/components/schemas/SearchCaseList'
41+
examples:
42+
json:
43+
value: >
44+
{
45+
"caseID": 64238,
46+
"caseNum": "C012040",
47+
"caseType": "Civil Miscellaneous",
48+
"caseTypeID": 8,
49+
"courtName": "0101",
50+
"courtType": "J",
51+
"citationNumber": "TX002733J8783",
52+
"name": "Doe,John M",
53+
"dateFiled": "1900-01-01",
54+
"charges": "",
55+
"status": "Pending",
56+
"judgeName": "Smith, James",
57+
"oriNumber": "TX034033J"
58+
}
59+
application/xml:
60+
schema:
61+
$ref: '#/components/schemas/SearchCaseList'
62+
example: >
63+
<SearchCaseListItem>
64+
<CaseId>64238</CaseId>
65+
<CaseNum>C012040</CaseNum>
66+
<CaseType>Civil Miscellaneous</CaseType>
67+
<CaseTypeID>8</CaseTypeID>
68+
<CourtName>0101</CourtName>
69+
<CourtType>J</CourtType>
70+
<CitationNumber>TX002733J8783</CitationNumber>
71+
<Name>Doe,John M</Name>
72+
<DateFiled>1900-01-01</DateFiled>
73+
<Charges></Charges>
74+
<Status>Pending</Status>
75+
<JudgeName>Smith, James</JudgeName>
76+
<OriNumber>TX034033J</OriNumber>
77+
</SearchCaseListItem>
78+
NotAcceptable:
79+
description: Not Acceptable
80+
content:
81+
application/json:
82+
schema:
83+
$ref: '#/components/schemas/ERROR'
84+
application/xml:
85+
schema:
86+
$ref: '#/components/schemas/ERROR'
87+
InternalServerError:
88+
description: Internal Server Error
89+
content:
90+
application/json:
91+
schema:
92+
$ref: '#/components/schemas/ERROR'
93+
application/xml:
94+
schema:
95+
$ref: '#/components/schemas/ERROR'
96+
UnAuthorized:
97+
description: Unauthorized
98+
content:
99+
application/json:
100+
schema:
101+
$ref: '#/components/schemas/ERROR'
102+
application/xml:
103+
schema:
104+
$ref: '#/components/schemas/ERROR'
105+
parameters:
106+
lastName:
107+
name: lastName
108+
in: query
109+
required: true
110+
description: Last Name
111+
schema:
112+
type: string
113+
firstName:
114+
name: firstName
115+
in: query
116+
required: false
117+
description: First Name
118+
schema:
119+
type: string
120+
dob:
121+
name: dob
122+
in: query
123+
required: false
124+
description: Date of Birth
125+
schema:
126+
type: string
127+
fileDateStart:
128+
name: fileDateStart
129+
in: query
130+
required: false
131+
description: File Date Start
132+
schema:
133+
type: string
134+
fileDateEnd:
135+
name: fileDateEnd
136+
in: query
137+
required: false
138+
description: File Date End
139+
schema:
140+
type: string
141+
business:
142+
name: business
143+
in: query
144+
required: false
145+
description: Is this a Business Name
146+
schema:
147+
type: boolean
148+
attorney:
149+
name: attorney
150+
in: query
151+
required: false
152+
description: Is this an Attorney Name
153+
schema:
154+
type: boolean
155+
156+
schemas:
157+
ERROR:
158+
description: If an error occurred during process an error message will be returned with the following structure.
159+
properties:
160+
ERRORID:
161+
type: string
162+
ERRORORI:
163+
type: string
164+
ERRORSEV:
165+
type: string
166+
ERRORTEXT:
167+
type: string
168+
example: >
169+
ERRORID: 'DET106'
170+
ERRORORI: 'TX034033J'
171+
ERRORSEV: '100'
172+
ERRORTEXT: 'No Details'
173+
SearchCaseList:
174+
type: object
175+
properties:
176+
CaseListItem:
177+
type: array
178+
items:
179+
type: object
180+
properties:
181+
CaseID:
182+
type: integer
183+
CaseNum:
184+
type: string
185+
CaseType:
186+
type: string
187+
CaseTypeID:
188+
type: integer
189+
CourtName:
190+
type: string
191+
CourtType:
192+
type: string
193+
CitationNumber:
194+
type: string
195+
Name:
196+
type: string
197+
DateFiled:
198+
type: string
199+
Charges:
200+
type: string
201+
Status:
202+
type: string
203+
JudgeName:
204+
type: string
205+
OriNumber:
206+
type: string
207+
example:
208+
CaseID: 64238
209+
CaseNum: 'C012040'
210+
CaseType: 'Civil Miscellaneous'
211+
CaseTypeID: 8
212+
CourtName: '0101'
213+
CourtType: 'J'
214+
CitationNumber: 'TX002733J8783'
215+
Name: 'Doe,John M'
216+
DateFiled: '1900-01-01'
217+
Charges: ''
218+
Status: 'Pending'
219+
JudgeName: 'Smith, James'
220+
OriNumber: 'TX034033J'

jsconfig.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
// This file is required for VSCode to understand webpack aliases
3+
"compilerOptions": {
4+
// This must be specified if "paths" is set
5+
"baseUrl": ".",
6+
// Relative to "baseUrl"
7+
"paths": {
8+
"@/*": ["./src/*"],
9+
}
10+
}
11+
}

src/components/api-response.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,11 @@ export default class ApiResponse extends LitElement {
9999

100100
// Generate Schema
101101
const schemaTree = schemaInObjectNotation(mimeRespObj.schema, {});
102+
102103
// Generate Example
103104
const respExample = generateExample(
104105
mimeRespObj.examples ? mimeRespObj.examples : '',
105-
mimeRespObj.schema ? mimeRespObj.schema.example : '',
106+
mimeRespObj.example ? mimeRespObj.example : '',
106107
mimeRespObj.schema,
107108
mimeResp,
108109
true,
@@ -115,7 +116,6 @@ export default class ApiResponse extends LitElement {
115116
};
116117
selectedMimeValueForEachStatus[statusCode] = mimeResp;
117118
}
118-
119119
// Headers for each response status
120120
const tempHeaders = [];
121121
for (const key in this.responses[statusCode].headers) {

src/utils/common-utils.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,12 @@ export function getSampleValueByType(schemaObj) {
178178
}
179179

180180
/* For changing JSON-Schema to a Sample Object, as per the schema */
181-
export function schemaToSampleObj(schema, config = {}) {
181+
export function schemaToSampleObj(schema, config = { }) {
182182
let obj = {};
183183
if (schema === null) {
184184
return;
185185
}
186+
186187
if (schema.type === 'object' || schema.properties) {
187188
for (const key in schema.properties) {
188189
if (schema.properties[key].deprecated && !config.includeDeprecated) { continue; }
@@ -217,7 +218,6 @@ export function schemaToSampleObj(schema, config = {}) {
217218
const tempSchema = schema.allOf[0];
218219
return getSampleValueByType(tempSchema);
219220
}
220-
221221
return;
222222
}
223223

@@ -375,15 +375,23 @@ export function generateExample(examples, example, schema, mimeType, includeRead
375375
if (schema) {
376376
// TODO: in case the mimeType is XML then parse it as XML
377377
if (mimeType.toLowerCase().includes('json') || mimeType.toLowerCase().includes('*/*')) {
378-
const egJson = schemaToSampleObj(schema, { includeReadOnly, includeWriteOnly: true, deprecated: true });
378+
const egJson = schema.example || schemaToSampleObj(
379+
schema,
380+
{
381+
includeReadOnly,
382+
includeWriteOnly: true,
383+
deprecated: true,
384+
examplesInJson: true,
385+
},
386+
);
379387
finalExamples.push({
380388
exampleType: mimeType,
381389
exampleValue: outputType === 'text' ? JSON.stringify(egJson, undefined, 2) : egJson,
382390
});
383391
} else {
384392
finalExamples.push({
385393
exampleType: mimeType,
386-
exampleValue: '',
394+
exampleValue: schema.example ? JSON.stringify(schema.example, undefined, 2) : '',
387395
});
388396
}
389397
} else {

webpack.config.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,26 @@ const FileManagerPlugin = require('filemanager-webpack-plugin');
33
const webpack = require('webpack');
44
const CompressionPlugin = require('compression-webpack-plugin');
55
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
6-
const { DuplicatesPlugin } = require("inspectpack/plugin");
6+
const { DuplicatesPlugin } = require('inspectpack/plugin');
77
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
88

99
const path = require('path');
10+
1011
const commonPlugins = [
1112
new webpack.HotModuleReplacementPlugin(),
1213
new webpack.optimize.LimitChunkCountPlugin({
13-
maxChunks:1
14+
maxChunks: 1
1415
}),
1516
new CleanWebpackPlugin(),
1617
new HtmlWebpackPlugin({template: 'index.html'}),
1718
new CompressionPlugin(),
1819
new FileManagerPlugin({
1920
onEnd : {
2021
copy: [
21-
{source: 'dist/*.js', destination: 'docs' },
22-
{source: 'dist/*.woff2', destination: 'docs' }
23-
]
24-
}
22+
{ source: 'dist/*.js', destination: 'docs' },
23+
{ source: 'dist/*.woff2', destination: 'docs' },
24+
],
25+
},
2526
})
2627
]
2728

@@ -52,9 +53,9 @@ module.exports = {
5253
filename: 'rapidoc-min.js',
5354
},
5455
devServer: {
55-
contentBase: path.join(__dirname, 'docs'),
56-
port: 8080,
57-
hot: true
56+
contentBase: path.join(__dirname, 'docs'),
57+
port: 8080,
58+
hot: true
5859
},
5960
module: {
6061
rules: [

0 commit comments

Comments
 (0)