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

docs: enhance REST API OpenAPI spec with nested filter example #7366

Merged
merged 1 commit into from
Oct 10, 2024
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { OrderByDirection } from 'src/engine/api/graphql/workspace-query-builder/interfaces/record.interface';

import { DEFAULT_CONJUNCTION } from 'src/engine/api/rest/core/query-builder/utils/filter-utils/add-default-conjunction.utils';
import { FilterComparators } from 'src/engine/api/rest/core/query-builder/utils/filter-utils/parse-base-filter.utils';
import { Conjunctions } from 'src/engine/api/rest/core/query-builder/utils/filter-utils/parse-filter.utils';
import { DEFAULT_ORDER_DIRECTION } from 'src/engine/api/rest/input-factories/order-by-input.factory';
import {
computeDepthParameters,
computeEndingBeforeParameters,
Expand All @@ -9,10 +13,6 @@ import {
computeOrderByParameters,
computeStartingAfterParameters,
} from 'src/engine/core-modules/open-api/utils/parameters.utils';
import { DEFAULT_ORDER_DIRECTION } from 'src/engine/api/rest/input-factories/order-by-input.factory';
import { FilterComparators } from 'src/engine/api/rest/core/query-builder/utils/filter-utils/parse-base-filter.utils';
import { Conjunctions } from 'src/engine/api/rest/core/query-builder/utils/filter-utils/parse-filter.utils';
import { DEFAULT_CONJUNCTION } from 'src/engine/api/rest/core/query-builder/utils/filter-utils/add-default-conjunction.utils';

describe('computeParameters', () => {
describe('computeLimit', () => {
Expand Down Expand Up @@ -83,7 +83,9 @@ describe('computeParameters', () => {
name: 'filter',
in: 'query',
description: `Filters objects returned.
Should have the following shape: **field_1[COMPARATOR]:value_1,field_2[COMPARATOR]:value_2,...**
Should have the following shape: **field_1[COMPARATOR]:value_1,field_2[COMPARATOR]:value_2...
To filter on nested objects use **field.nestedField[COMPARATOR]:value_1
**
Available comparators are **${Object.values(FilterComparators).join(
'**, **',
)}**.
Expand All @@ -102,6 +104,10 @@ describe('computeParameters', () => {
value: 'createdAt[gte]:"2023-01-01"',
description: 'A simple filter param',
},
simpleNested: {
value: 'emails.primaryEmail[eq]:[email protected]',
description: 'A simple nested filter param',
},
complex: {
value:
'or(createdAt[gte]:"2024-01-01",createdAt[lte]:"2023-01-01",not(id[is]:NULL))',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { OpenAPIV3_1 } from 'openapi-types';

import { OrderByDirection } from 'src/engine/api/graphql/workspace-query-builder/interfaces/record.interface';

import { DEFAULT_CONJUNCTION } from 'src/engine/api/rest/core/query-builder/utils/filter-utils/add-default-conjunction.utils';
import { FilterComparators } from 'src/engine/api/rest/core/query-builder/utils/filter-utils/parse-base-filter.utils';
import { Conjunctions } from 'src/engine/api/rest/core/query-builder/utils/filter-utils/parse-filter.utils';
import { DEFAULT_ORDER_DIRECTION } from 'src/engine/api/rest/input-factories/order-by-input.factory';
import { DEFAULT_CONJUNCTION } from 'src/engine/api/rest/core/query-builder/utils/filter-utils/add-default-conjunction.utils';

export const computeLimitParameters = (
fromMetadata = false,
Expand Down Expand Up @@ -73,7 +73,9 @@ export const computeFilterParameters = (): OpenAPIV3_1.ParameterObject => {
name: 'filter',
in: 'query',
description: `Filters objects returned.
Should have the following shape: **field_1[COMPARATOR]:value_1,field_2[COMPARATOR]:value_2,...**
Should have the following shape: **field_1[COMPARATOR]:value_1,field_2[COMPARATOR]:value_2...
To filter on nested objects use **field.nestedField[COMPARATOR]:value_1
**
Available comparators are **${Object.values(FilterComparators).join(
'**, **',
)}**.
Expand All @@ -82,7 +84,9 @@ export const computeFilterParameters = (): OpenAPIV3_1.ParameterObject => {
).join('**, **')}**.
Default root conjunction is **${DEFAULT_CONJUNCTION}**.
To filter **null** values use **field[is]:NULL** or **field[is]:NOT_NULL**
To filter using **boolean** values use **field[eq]:true** or **field[eq]:false**`,
To filter using **boolean** values use **field[eq]:true** or **field[eq]:false**
`,

required: false,
schema: {
type: 'string',
Expand All @@ -92,6 +96,10 @@ export const computeFilterParameters = (): OpenAPIV3_1.ParameterObject => {
value: 'createdAt[gte]:"2023-01-01"',
description: 'A simple filter param',
},
simpleNested: {
value: 'emails.primaryEmail[eq]:[email protected]',
description: 'A simple nested filter param',
},
complex: {
value:
'or(createdAt[gte]:"2024-01-01",createdAt[lte]:"2023-01-01",not(id[is]:NULL))',
Expand Down
Loading