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

Commit 4973493

Browse files
committed
reverse before allOf.find etc; 0.18.11
1 parent 812a689 commit 4973493

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@learnwiz/openapi-typescript-code-generator",
3-
"version": "0.18.10",
3+
"version": "0.18.11",
44
"description": "OpenAPI Code Generator using TypeScript AST.",
55
"keywords": [
66
"openapi",

src/internal/OpenApiTools/components/ClientSchema.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,18 @@ function isReadOnlySchema(schema: JSONSchema7Definition, context: ToTypeNode.Con
2828
}
2929

3030
if (Guard.isAllOfSchema(schema)) {
31-
const directReadOnly = schema.allOf.find(s => typeof s.readOnly !== "undefined");
31+
const directReadOnly = [...schema.allOf].reverse().find(s => typeof s.readOnly === "boolean");
3232
if (directReadOnly) {
3333
return directReadOnly.readOnly;
3434
}
35-
return schema.allOf.map(s => isReadOnlySchema(s, context)).find((s): s is boolean => typeof s !== undefined);
35+
return schema.allOf
36+
.map(s => isReadOnlySchema(s, context))
37+
.reverse()
38+
.find((s): s is boolean => typeof s === "boolean");
3639
}
3740

3841
if (Guard.isOneOfSchema(schema)) {
39-
return [...schema.oneOf].some(s => isReadOnlySchema(s, context));
42+
return schema.oneOf.some(s => isReadOnlySchema(s, context));
4043
}
4144

4245
if (Guard.isPrimitiveSchema(schema) || Guard.isArraySchema(schema) || Guard.isObjectSchema(schema)) {
@@ -156,7 +159,7 @@ export const generateNotInferedTypeAlias = (
156159
name: string,
157160
schema: OpenApi.Schema,
158161
convertContext: ConvertContext.Types,
159-
) => {
162+
): ts.TypeAliasDeclaration => {
160163
const typeNode = createNullableTypeNodeOrAny(factory, schema);
161164
return factory.TypeAliasDeclaration.create({
162165
export: true,

0 commit comments

Comments
 (0)