Skip to content

Commit

Permalink
docs: enhance REST API OpenAPI spec with nested filter example (#7366)
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasZapico authored Oct 10, 2024
1 parent c6a676e commit 8162786
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
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

0 comments on commit 8162786

Please sign in to comment.