Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix anyOf, oneOf and allOf types parsing #83

Merged
merged 4 commits into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Open API Lambda Connector Changelog

## Unreleased

- Fix param parsing of `anyOf`, `allOf` and `oneOf` ([#83](https://github.com/hasura/ndc-open-api-lambda/pull/83))


## [[1.5.0](https://github.com/hasura/ndc-open-api-lambda/releases/tag/v1.5.0)] 2025-03-07

- Update NDC NodeJS Lambda to `v1.11.0` [#80](https://github.com/hasura/ndc-open-api-lambda/pull/80)
Expand Down
18 changes: 18 additions & 0 deletions src/app/generator/functions-ts-generator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,24 @@ const tests: {
goldenFile: "./golden-files/trello",
baseUrl: "",
},
{
name: "one-of-param-test",
openApiUri: "./open-api-docs/one-of-param-test.json",
goldenFile: "./golden-files/one-of-param-test",
baseUrl: "",
},
{
name: "any-of-param-test",
openApiUri: "./open-api-docs/one-of-param-test.json",
goldenFile: "./golden-files/one-of-param-test",
baseUrl: "",
},
{
name: "all-of-param-test",
openApiUri: "./open-api-docs/one-of-param-test.json",
goldenFile: "./golden-files/one-of-param-test",
baseUrl: "",
},
];

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

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion src/app/parser/open-api/param-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,12 @@ export function schemaIsTypeScalar(schema: any): schema is SchemaTypeScalar {
return (
schema.type &&
Object.values(ScalarTypeEnum).includes(schema.type) &&
schema.properties === undefined
!schemaIsTypeObject(schema) &&
!schemaIsTypeRef(schema) &&
!schemaIsTypeArray(schema) &&
!schemaIsTypeAnyOf(schema) &&
!schemaIsTypeOneOf(schema) &&
!schemaIsTypeAllOf(schema)
);
}

Expand Down
43 changes: 43 additions & 0 deletions tests/test-data/golden-files/all-of-param-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as hasuraSdk from "@hasura/ndc-lambda-sdk";
import { Api } from "./api";

const api = new Api({
baseUrl: `${process.env.NDC_OAS_BASE_URL}`,
});

/**
* Get total
* @request GET :/total
* @allowrelaxedtypes
* @readonly
*/
export async function getTotalTotalList(
query: {
content?: {
/** Depending of resurce, use different content params */
inner_content?: { fields?: { include?: string[] } } & {
expand?: { all?: hasuraSdk.JSONValue; false?: hasuraSdk.JSONValue };
} & {
structure?: {
/** Possible have empty object, or different parent or child combinations */
tree?: hasuraSdk.JSONValue;
};
};
};
},
headers?: hasuraSdk.JSONValue,
): Promise<{
total?: number;
}> {
const result = await api.total.totalList({
query: query,
params: {
headers: (headers?.value as Record<string, string>) ?? undefined,
},
});
if (result.data) {
return result.data;
} else {
throw result.error;
}
}
46 changes: 46 additions & 0 deletions tests/test-data/golden-files/any-of-param-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import * as hasuraSdk from "@hasura/ndc-lambda-sdk";
import { Api } from "./api";

const api = new Api({
baseUrl: `${process.env.NDC_OAS_BASE_URL}`,
});

/**
* Get total
* @request GET :/total
* @allowrelaxedtypes
* @readonly
*/
export async function getTotalTotalList(
query: {
content?: {
/** Depending of resurce, use different content params */
inner_content?:
| { fields?: { include?: string[] } }
| {
expand?: { all?: hasuraSdk.JSONValue; false?: hasuraSdk.JSONValue };
}
| {
structure?: {
/** Possible have empty object, or different parent or child combinations */
tree?: hasuraSdk.JSONValue;
};
};
};
},
headers?: hasuraSdk.JSONValue,
): Promise<{
total?: number;
}> {
const result = await api.total.totalList({
query: query,
params: {
headers: (headers?.value as Record<string, string>) ?? undefined,
},
});
if (result.data) {
return result.data;
} else {
throw result.error;
}
}
46 changes: 46 additions & 0 deletions tests/test-data/golden-files/one-of-param-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import * as hasuraSdk from "@hasura/ndc-lambda-sdk";
import { Api } from "./api";

const api = new Api({
baseUrl: `${process.env.NDC_OAS_BASE_URL}`,
});

/**
* Get total
* @request GET :/total
* @allowrelaxedtypes
* @readonly
*/
export async function getTotalTotalList(
query: {
content?: {
/** Depending of resurce, use different content params */
inner_content?:
| { fields?: { include?: string[] } }
| {
expand?: { all?: hasuraSdk.JSONValue; false?: hasuraSdk.JSONValue };
}
| {
structure?: {
/** Possible have empty object, or different parent or child combinations */
tree?: hasuraSdk.JSONValue;
};
};
};
},
headers?: hasuraSdk.JSONValue,
): Promise<{
total?: number;
}> {
const result = await api.total.totalList({
query: query,
params: {
headers: (headers?.value as Record<string, string>) ?? undefined,
},
});
if (result.data) {
return result.data;
} else {
throw result.error;
}
}
134 changes: 134 additions & 0 deletions tests/test-data/open-api-docs/all-of-param-test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
{
"openapi": "3.0.3",
"info": {},
"servers": [],
"security": [],
"paths": {
"/total": {
"get": {
"summary": "Get total",
"description": "Get total",
"parameters": [
{
"$ref": "#/components/parameters/content"
}
],
"responses": {
"200": {
"description": "Get Total",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"total": {
"type": "integer"
}
}
}
}
}
},
"400": {
"$ref": "#/components/responses/BadRequestError"
},
"401": {
"$ref": "#/components/responses/AuthorizationError"
},
"403": {
"$ref": "#/components/responses/ForbiddenError"
},
"500": {
"$ref": "#/components/responses/ServerError"
}
}
}
}
},
"components": {
"parameters": {
"content": {
"name": "content",
"in": "query",
"required": false,
"example": "",
"schema": {
"type": "object",
"properties": {
"inner_content": {
"type": "object",
"description": "Depending of resurce, use different content params",
"allOf": [
{
"type": "object",
"properties": {
"fields": {
"type": "object",
"properties": {
"include": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
}
},
{
"type": "object",
"properties": {
"expand": {
"type": "object",
"properties": {
"all": {
"type": "object"
},
"false": {
"type": "object"
}
}
}
}
},
{
"type": "object",
"properties": {
"structure": {
"type": "object",
"properties": {
"tree": {
"type": "object",
"description": "Possible have empty object, or different parent or child combinations"
}
}
}
}
}
]
}
}
}
}
},
"schemas": {},
"securitySchemes": {},
"responses": {
"BadRequestError": {
"description": "BadRequestError\n"
},
"AuthorizationError": {
"description": "AuthorizationError\n"
},
"ForbiddenError": {
"description": "ForbiddenError\n"
},
"NotFoundError": {
"description": "NotFoundError \n"
},
"ServerError": {
"description": "ServerError\n"
}
}
}
}
Loading