Skip to content

Commit ed8c1ed

Browse files
authored
fix anyOf, oneOf and allOf types parsing (#83)
Changes are in this commit: 57ab162 Tests are in this commit 9ef96e2
1 parent ec0788d commit ed8c1ed

File tree

10 files changed

+581
-16
lines changed

10 files changed

+581
-16
lines changed

changelog.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Open API Lambda Connector Changelog
22

3+
## Unreleased
4+
5+
- Fix param parsing of `anyOf`, `allOf` and `oneOf` ([#83](https://github.com/hasura/ndc-open-api-lambda/pull/83))
6+
7+
38
## [[1.5.0](https://github.com/hasura/ndc-open-api-lambda/releases/tag/v1.5.0)] 2025-03-07
49

510
- Update NDC NodeJS Lambda to `v1.11.0` [#80](https://github.com/hasura/ndc-open-api-lambda/pull/80)

src/app/generator/functions-ts-generator.test.ts

+18
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,24 @@ const tests: {
164164
goldenFile: "./golden-files/trello",
165165
baseUrl: "",
166166
},
167+
{
168+
name: "one-of-param-test",
169+
openApiUri: "./open-api-docs/one-of-param-test.json",
170+
goldenFile: "./golden-files/one-of-param-test",
171+
baseUrl: "",
172+
},
173+
{
174+
name: "any-of-param-test",
175+
openApiUri: "./open-api-docs/one-of-param-test.json",
176+
goldenFile: "./golden-files/one-of-param-test",
177+
baseUrl: "",
178+
},
179+
{
180+
name: "all-of-param-test",
181+
openApiUri: "./open-api-docs/one-of-param-test.json",
182+
goldenFile: "./golden-files/one-of-param-test",
183+
baseUrl: "",
184+
},
167185
];
168186

169187
describe("functions-ts-generator", async () => {

src/app/generator/test-data/param-generator/golden-files/here-maps-tracking.json

+15-15
Large diffs are not rendered by default.

src/app/parser/open-api/param-types.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,12 @@ export function schemaIsTypeScalar(schema: any): schema is SchemaTypeScalar {
143143
return (
144144
schema.type &&
145145
Object.values(ScalarTypeEnum).includes(schema.type) &&
146-
schema.properties === undefined
146+
!schemaIsTypeObject(schema) &&
147+
!schemaIsTypeRef(schema) &&
148+
!schemaIsTypeArray(schema) &&
149+
!schemaIsTypeAnyOf(schema) &&
150+
!schemaIsTypeOneOf(schema) &&
151+
!schemaIsTypeAllOf(schema)
147152
);
148153
}
149154

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import * as hasuraSdk from "@hasura/ndc-lambda-sdk";
2+
import { Api } from "./api";
3+
4+
const api = new Api({
5+
baseUrl: `${process.env.NDC_OAS_BASE_URL}`,
6+
});
7+
8+
/**
9+
* Get total
10+
* @request GET :/total
11+
* @allowrelaxedtypes
12+
* @readonly
13+
*/
14+
export async function getTotalTotalList(
15+
query: {
16+
content?: {
17+
/** Depending of resurce, use different content params */
18+
inner_content?: { fields?: { include?: string[] } } & {
19+
expand?: { all?: hasuraSdk.JSONValue; false?: hasuraSdk.JSONValue };
20+
} & {
21+
structure?: {
22+
/** Possible have empty object, or different parent or child combinations */
23+
tree?: hasuraSdk.JSONValue;
24+
};
25+
};
26+
};
27+
},
28+
headers?: hasuraSdk.JSONValue,
29+
): Promise<{
30+
total?: number;
31+
}> {
32+
const result = await api.total.totalList({
33+
query: query,
34+
params: {
35+
headers: (headers?.value as Record<string, string>) ?? undefined,
36+
},
37+
});
38+
if (result.data) {
39+
return result.data;
40+
} else {
41+
throw result.error;
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import * as hasuraSdk from "@hasura/ndc-lambda-sdk";
2+
import { Api } from "./api";
3+
4+
const api = new Api({
5+
baseUrl: `${process.env.NDC_OAS_BASE_URL}`,
6+
});
7+
8+
/**
9+
* Get total
10+
* @request GET :/total
11+
* @allowrelaxedtypes
12+
* @readonly
13+
*/
14+
export async function getTotalTotalList(
15+
query: {
16+
content?: {
17+
/** Depending of resurce, use different content params */
18+
inner_content?:
19+
| { fields?: { include?: string[] } }
20+
| {
21+
expand?: { all?: hasuraSdk.JSONValue; false?: hasuraSdk.JSONValue };
22+
}
23+
| {
24+
structure?: {
25+
/** Possible have empty object, or different parent or child combinations */
26+
tree?: hasuraSdk.JSONValue;
27+
};
28+
};
29+
};
30+
},
31+
headers?: hasuraSdk.JSONValue,
32+
): Promise<{
33+
total?: number;
34+
}> {
35+
const result = await api.total.totalList({
36+
query: query,
37+
params: {
38+
headers: (headers?.value as Record<string, string>) ?? undefined,
39+
},
40+
});
41+
if (result.data) {
42+
return result.data;
43+
} else {
44+
throw result.error;
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import * as hasuraSdk from "@hasura/ndc-lambda-sdk";
2+
import { Api } from "./api";
3+
4+
const api = new Api({
5+
baseUrl: `${process.env.NDC_OAS_BASE_URL}`,
6+
});
7+
8+
/**
9+
* Get total
10+
* @request GET :/total
11+
* @allowrelaxedtypes
12+
* @readonly
13+
*/
14+
export async function getTotalTotalList(
15+
query: {
16+
content?: {
17+
/** Depending of resurce, use different content params */
18+
inner_content?:
19+
| { fields?: { include?: string[] } }
20+
| {
21+
expand?: { all?: hasuraSdk.JSONValue; false?: hasuraSdk.JSONValue };
22+
}
23+
| {
24+
structure?: {
25+
/** Possible have empty object, or different parent or child combinations */
26+
tree?: hasuraSdk.JSONValue;
27+
};
28+
};
29+
};
30+
},
31+
headers?: hasuraSdk.JSONValue,
32+
): Promise<{
33+
total?: number;
34+
}> {
35+
const result = await api.total.totalList({
36+
query: query,
37+
params: {
38+
headers: (headers?.value as Record<string, string>) ?? undefined,
39+
},
40+
});
41+
if (result.data) {
42+
return result.data;
43+
} else {
44+
throw result.error;
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
{
2+
"openapi": "3.0.3",
3+
"info": {},
4+
"servers": [],
5+
"security": [],
6+
"paths": {
7+
"/total": {
8+
"get": {
9+
"summary": "Get total",
10+
"description": "Get total",
11+
"parameters": [
12+
{
13+
"$ref": "#/components/parameters/content"
14+
}
15+
],
16+
"responses": {
17+
"200": {
18+
"description": "Get Total",
19+
"content": {
20+
"application/json": {
21+
"schema": {
22+
"type": "object",
23+
"properties": {
24+
"total": {
25+
"type": "integer"
26+
}
27+
}
28+
}
29+
}
30+
}
31+
},
32+
"400": {
33+
"$ref": "#/components/responses/BadRequestError"
34+
},
35+
"401": {
36+
"$ref": "#/components/responses/AuthorizationError"
37+
},
38+
"403": {
39+
"$ref": "#/components/responses/ForbiddenError"
40+
},
41+
"500": {
42+
"$ref": "#/components/responses/ServerError"
43+
}
44+
}
45+
}
46+
}
47+
},
48+
"components": {
49+
"parameters": {
50+
"content": {
51+
"name": "content",
52+
"in": "query",
53+
"required": false,
54+
"example": "",
55+
"schema": {
56+
"type": "object",
57+
"properties": {
58+
"inner_content": {
59+
"type": "object",
60+
"description": "Depending of resurce, use different content params",
61+
"allOf": [
62+
{
63+
"type": "object",
64+
"properties": {
65+
"fields": {
66+
"type": "object",
67+
"properties": {
68+
"include": {
69+
"type": "array",
70+
"items": {
71+
"type": "string"
72+
}
73+
}
74+
}
75+
}
76+
}
77+
},
78+
{
79+
"type": "object",
80+
"properties": {
81+
"expand": {
82+
"type": "object",
83+
"properties": {
84+
"all": {
85+
"type": "object"
86+
},
87+
"false": {
88+
"type": "object"
89+
}
90+
}
91+
}
92+
}
93+
},
94+
{
95+
"type": "object",
96+
"properties": {
97+
"structure": {
98+
"type": "object",
99+
"properties": {
100+
"tree": {
101+
"type": "object",
102+
"description": "Possible have empty object, or different parent or child combinations"
103+
}
104+
}
105+
}
106+
}
107+
}
108+
]
109+
}
110+
}
111+
}
112+
}
113+
},
114+
"schemas": {},
115+
"securitySchemes": {},
116+
"responses": {
117+
"BadRequestError": {
118+
"description": "BadRequestError\n"
119+
},
120+
"AuthorizationError": {
121+
"description": "AuthorizationError\n"
122+
},
123+
"ForbiddenError": {
124+
"description": "ForbiddenError\n"
125+
},
126+
"NotFoundError": {
127+
"description": "NotFoundError \n"
128+
},
129+
"ServerError": {
130+
"description": "ServerError\n"
131+
}
132+
}
133+
}
134+
}

0 commit comments

Comments
 (0)