1
+ import DotProp from "dot-prop" ;
1
2
import type { JSONSchema7Definition } from "json-schema" ;
2
3
import ts from "typescript" ;
3
4
@@ -11,16 +12,10 @@ import type { AnySchema, ArraySchema, ObjectSchema, PrimitiveSchema } from "../t
11
12
import type * as Walker from "../Walker" ;
12
13
import * as ExternalDocumentation from "./ExternalDocumentation" ;
13
14
14
- function isReadOnlySchema ( schema : JSONSchema7Definition , context : ToTypeNode . Context ) : boolean | undefined {
15
- while ( Guard . isReference ( schema ) ) {
16
- const schemaName = schema . $ref . match ( / ^ # \/ c o m p o n e n t s \/ s c h e m a s \/ ( .+ ) $ / ) ?. [ 1 ] ;
17
- if ( ! schemaName ) return undefined ;
18
- const dereffed = context . rootSchema . components ?. schemas ?. [ schemaName ] ;
19
- if ( dereffed ) {
20
- schema = dereffed ;
21
- } else {
22
- return undefined ;
23
- }
15
+ function isReadOnlySchema ( currentPoint : string , schema : JSONSchema7Definition , context : ToTypeNode . Context ) : boolean | undefined {
16
+ if ( Guard . isReference ( schema ) ) {
17
+ const { pathArray } = context . resolveReferencePath ( currentPoint , schema . $ref ) ;
18
+ schema = DotProp . get ( context . rootSchema , pathArray . join ( "." ) ) as any ;
24
19
}
25
20
26
21
if ( typeof schema === "boolean" ) {
@@ -32,14 +27,15 @@ function isReadOnlySchema(schema: JSONSchema7Definition, context: ToTypeNode.Con
32
27
if ( directReadOnly ) {
33
28
return directReadOnly . readOnly ;
34
29
}
30
+
35
31
return schema . allOf
36
- . map ( s => isReadOnlySchema ( s , context ) )
32
+ . map ( s => isReadOnlySchema ( currentPoint , s , context ) )
37
33
. reverse ( )
38
34
. find ( ( s ) : s is boolean => typeof s === "boolean" ) ;
39
35
}
40
36
41
37
if ( Guard . isOneOfSchema ( schema ) ) {
42
- return schema . oneOf . some ( s => isReadOnlySchema ( s , context ) ) ;
38
+ return schema . oneOf . some ( s => isReadOnlySchema ( currentPoint , s , context ) ) ;
43
39
}
44
40
45
41
if ( Guard . isPrimitiveSchema ( schema ) || Guard . isArraySchema ( schema ) || Guard . isObjectSchema ( schema ) ) {
@@ -62,7 +58,7 @@ export const generatePropertySignatures = (
62
58
}
63
59
const required : string [ ] = schema . required || [ ] ;
64
60
return Object . entries ( schema . properties )
65
- . filter ( ( [ , schema ] ) => ! isReadOnlySchema ( schema , context ) )
61
+ . filter ( ( [ , schema ] ) => ! isReadOnlySchema ( currentPoint , schema , context ) )
66
62
. map ( ( [ propertyName , property ] ) => {
67
63
if ( ! property ) {
68
64
return factory . PropertySignature . create ( {
0 commit comments