Skip to content
This repository was archived by the owner on Feb 10, 2023. It is now read-only.

Commit bdc070e

Browse files
committed
use DotProp
1 parent 1f863d8 commit bdc070e

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

src/internal/OpenApiTools/components/ClientSchema.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import DotProp from "dot-prop";
12
import type { JSONSchema7Definition } from "json-schema";
23
import ts from "typescript";
34

@@ -11,16 +12,10 @@ import type { AnySchema, ArraySchema, ObjectSchema, PrimitiveSchema } from "../t
1112
import type * as Walker from "../Walker";
1213
import * as ExternalDocumentation from "./ExternalDocumentation";
1314

14-
function isReadOnlySchema(schema: JSONSchema7Definition, context: ToTypeNode.Context): boolean | undefined {
15-
while (Guard.isReference(schema)) {
16-
const schemaName = schema.$ref.match(/^#\/components\/schemas\/(.+)$/)?.[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;
2419
}
2520

2621
if (typeof schema === "boolean") {
@@ -32,14 +27,15 @@ function isReadOnlySchema(schema: JSONSchema7Definition, context: ToTypeNode.Con
3227
if (directReadOnly) {
3328
return directReadOnly.readOnly;
3429
}
30+
3531
return schema.allOf
36-
.map(s => isReadOnlySchema(s, context))
32+
.map(s => isReadOnlySchema(currentPoint, s, context))
3733
.reverse()
3834
.find((s): s is boolean => typeof s === "boolean");
3935
}
4036

4137
if (Guard.isOneOfSchema(schema)) {
42-
return schema.oneOf.some(s => isReadOnlySchema(s, context));
38+
return schema.oneOf.some(s => isReadOnlySchema(currentPoint, s, context));
4339
}
4440

4541
if (Guard.isPrimitiveSchema(schema) || Guard.isArraySchema(schema) || Guard.isObjectSchema(schema)) {
@@ -62,7 +58,7 @@ export const generatePropertySignatures = (
6258
}
6359
const required: string[] = schema.required || [];
6460
return Object.entries(schema.properties)
65-
.filter(([, schema]) => !isReadOnlySchema(schema, context))
61+
.filter(([, schema]) => !isReadOnlySchema(currentPoint, schema, context))
6662
.map(([propertyName, property]) => {
6763
if (!property) {
6864
return factory.PropertySignature.create({

0 commit comments

Comments
 (0)