11import { extractPointerFromRef , extractSourceFromRef , pointerToPath } from '@stoplight/json' ;
22import { Tree , TreeListParentNode , TreeState } from '@stoplight/tree-list' ;
33import { JsonPath , Optional } from '@stoplight/types' ;
4- import { JSONSchema4 } from 'json-schema' ;
54import { get as _get , isEqual as _isEqual , isObject as _isObject } from 'lodash' ;
65import { ResolvingError } from '../errors' ;
7- import { IArrayNode , IObjectNode , SchemaKind , SchemaNode , ViewMode } from '../types' ;
6+ import { IArrayNode , IObjectNode , JSONSchema , SchemaKind , SchemaNode , ViewMode } from '../types' ;
87import { hasRefItems , isArrayNodeWithItems , isCombinerNode , isRefNode } from '../utils/guards' ;
98import { inferType } from '../utils/inferType' ;
109import { getSchemaNodeMetadata } from './metadata' ;
@@ -20,8 +19,8 @@ export type SchemaTreeRefInfo = {
2019export type SchemaTreeRefDereferenceFn = (
2120 ref : SchemaTreeRefInfo ,
2221 propertyPath : JsonPath | null ,
23- schema : JSONSchema4 ,
24- ) => Optional < JSONSchema4 > ;
22+ schema : JSONSchema ,
23+ ) => Optional < JSONSchema > ;
2524
2625export type SchemaTreePopulateHandler = ( tree : SchemaTree , node : TreeListParentNode ) => void ;
2726
@@ -39,7 +38,7 @@ export { TreeState as SchemaTreeState };
3938export class SchemaTree extends Tree {
4039 public treeOptions : SchemaTreeOptions ;
4140
42- constructor ( public schema : JSONSchema4 , public state : TreeState , opts : SchemaTreeOptions ) {
41+ constructor ( public schema : JSONSchema , public state : TreeState , opts : SchemaTreeOptions ) {
4342 super ( {
4443 expanded : node =>
4544 ( ! ( node . id in state . expanded ) && SchemaTree . getLevel ( node ) <= opts . expandedDepth ) ||
@@ -51,7 +50,11 @@ export class SchemaTree extends Tree {
5150
5251 protected readonly visited = new WeakSet ( ) ;
5352
54- protected isViewModeRespected = ( fragment : JSONSchema4 ) => {
53+ protected isViewModeRespected = ( fragment : JSONSchema ) => {
54+ if ( ! ( 'writeOnly' in fragment ) && ! ( 'readOnly' in fragment ) ) {
55+ return true ;
56+ }
57+
5558 return ! (
5659 ! ! fragment . writeOnly !== ! ! fragment . readOnly &&
5760 ( ( this . treeOptions . viewMode === 'read' && fragment . writeOnly ) ||
@@ -112,7 +115,7 @@ export class SchemaTree extends Tree {
112115 this . treeOptions . onPopulate ?.( this , this . root ) ;
113116 }
114117
115- public populateTreeFragment ( parent : TreeListParentNode , schema : JSONSchema4 , path : JsonPath , stepIn : boolean ) {
118+ public populateTreeFragment ( parent : TreeListParentNode , schema : JSONSchema , path : JsonPath , stepIn : boolean ) {
116119 const initialLevel = Tree . getLevel ( parent ) ;
117120 const artificialRoot = Tree . createArtificialRoot ( ) ;
118121 populateTree ( schema , artificialRoot , initialLevel , path , {
0 commit comments