1
1
import { LitElement , html } from 'lit-element' ;
2
+ import JsonSchemaRefParser from 'json-schema-ref-parser' ;
2
3
import JsonTree from '@/components/json-tree' ;
3
4
import SchemaTree from '@/components/schema-tree' ;
4
5
import TagInput from '@/components/tag-input' ;
@@ -11,7 +12,6 @@ import CommonStyles from '@/styles/common-styles';
11
12
import { schemaToModel , getTypeInfo , generateExample , removeCircularReferences } from '@/utils/common-utils' ;
12
13
import marked from 'marked' ;
13
14
import { unsafeHTML } from 'lit-html/directives/unsafe-html.js' ;
14
- import { repeat } from "lit-html/lib/repeat"
15
15
16
16
export default class ApiRequest extends LitElement {
17
17
@@ -140,6 +140,7 @@ export default class ApiRequest extends LitElement {
140
140
path : { type : String } ,
141
141
parameters : { type : Array } ,
142
142
request_body : { type : Object } ,
143
+ parser : { type : Object } ,
143
144
responseMessage : { type : String , attribute :false } ,
144
145
responseText : { type : String , attribute :false } ,
145
146
responseHeaders : { type : String , attribute :false } ,
@@ -165,6 +166,12 @@ export default class ApiRequest extends LitElement {
165
166
166
167
const tableRows = [ ] ;
167
168
for ( const param of filteredParams ) {
169
+ if ( ! param . schema ) {
170
+ continue ;
171
+ }
172
+ if ( param . schema . $ref ) {
173
+ param . schema = this . parser . $refs . get ( param . schema . $ref ) ;
174
+ }
168
175
let paramSchema = getTypeInfo ( param . schema ) ;
169
176
let inputVal = '' ;
170
177
if ( param . example == '0' ) {
@@ -234,6 +241,10 @@ export default class ApiRequest extends LitElement {
234
241
if ( ! this . request_body ) {
235
242
return '' ;
236
243
}
244
+ if ( this . request_body . $ref ) {
245
+ this . request_body = this . parser . $refs . get ( this . request_body . $ref ) ;
246
+ }
247
+
237
248
if ( Object . keys ( this . request_body ) . length == 0 ) {
238
249
return '' ;
239
250
}
@@ -248,6 +259,7 @@ export default class ApiRequest extends LitElement {
248
259
let reqSchemaTree = "" ;
249
260
250
261
let content = this . request_body . content ;
262
+
251
263
for ( let mimeReq in content ) {
252
264
// do not change shortMimeTypes values, they are referenced in other places
253
265
if ( mimeReq . includes ( 'json' ) ) { shortMimeTypes [ mimeReq ] = 'json' ; }
@@ -260,8 +272,12 @@ export default class ApiRequest extends LitElement {
260
272
let reqExample = "" ;
261
273
if ( mimeReq . includes ( 'json' ) || mimeReq . includes ( 'xml' ) || mimeReq . includes ( 'text/plain' ) ) {
262
274
//Remove Circular references from RequestBody json-schema
275
+
263
276
try {
264
- mimeReqObj . schema = JSON . parse ( JSON . stringify ( mimeReqObj . schema , removeCircularReferences ( ) ) ) ;
277
+ if ( mimeReqObj . schema . $ref ) {
278
+ mimeReqObj . schema = this . parser . $refs . get ( mimeReqObj . schema . $ref ) ;
279
+ }
280
+ //mimeReqObj.schema = JSON.parse(JSON.stringify(mimeReqObj.schema, removeCircularReferences()));
265
281
}
266
282
catch {
267
283
console . error ( "Unable to resolve circular refs in schema" , mimeReqObj . schema ) ;
0 commit comments