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

This commit is contained in:
Lucas zapico 2024-10-10 07:35:20 -07:00 committed by GitHub
parent c6a676e1d5
commit 8162786d7c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 8 deletions

View File

@ -1,5 +1,9 @@
import { OrderByDirection } from 'src/engine/api/graphql/workspace-query-builder/interfaces/record.interface'; 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 { import {
computeDepthParameters, computeDepthParameters,
computeEndingBeforeParameters, computeEndingBeforeParameters,
@ -9,10 +13,6 @@ import {
computeOrderByParameters, computeOrderByParameters,
computeStartingAfterParameters, computeStartingAfterParameters,
} from 'src/engine/core-modules/open-api/utils/parameters.utils'; } 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('computeParameters', () => {
describe('computeLimit', () => { describe('computeLimit', () => {
@ -83,7 +83,9 @@ describe('computeParameters', () => {
name: 'filter', name: 'filter',
in: 'query', in: 'query',
description: `Filters objects returned. 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( Available comparators are **${Object.values(FilterComparators).join(
'**, **', '**, **',
)}**. )}**.
@ -102,6 +104,10 @@ describe('computeParameters', () => {
value: 'createdAt[gte]:"2023-01-01"', value: 'createdAt[gte]:"2023-01-01"',
description: 'A simple filter param', description: 'A simple filter param',
}, },
simpleNested: {
value: 'emails.primaryEmail[eq]:foo99@example.com',
description: 'A simple nested filter param',
},
complex: { complex: {
value: value:
'or(createdAt[gte]:"2024-01-01",createdAt[lte]:"2023-01-01",not(id[is]:NULL))', 'or(createdAt[gte]:"2024-01-01",createdAt[lte]:"2023-01-01",not(id[is]:NULL))',

View File

@ -2,10 +2,10 @@ import { OpenAPIV3_1 } from 'openapi-types';
import { OrderByDirection } from 'src/engine/api/graphql/workspace-query-builder/interfaces/record.interface'; 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 { 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 { 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_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 = ( export const computeLimitParameters = (
fromMetadata = false, fromMetadata = false,
@ -73,7 +73,9 @@ export const computeFilterParameters = (): OpenAPIV3_1.ParameterObject => {
name: 'filter', name: 'filter',
in: 'query', in: 'query',
description: `Filters objects returned. 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( Available comparators are **${Object.values(FilterComparators).join(
'**, **', '**, **',
)}**. )}**.
@ -82,7 +84,9 @@ export const computeFilterParameters = (): OpenAPIV3_1.ParameterObject => {
).join('**, **')}**. ).join('**, **')}**.
Default root conjunction is **${DEFAULT_CONJUNCTION}**. Default root conjunction is **${DEFAULT_CONJUNCTION}**.
To filter **null** values use **field[is]:NULL** or **field[is]:NOT_NULL** 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, required: false,
schema: { schema: {
type: 'string', type: 'string',
@ -92,6 +96,10 @@ export const computeFilterParameters = (): OpenAPIV3_1.ParameterObject => {
value: 'createdAt[gte]:"2023-01-01"', value: 'createdAt[gte]:"2023-01-01"',
description: 'A simple filter param', description: 'A simple filter param',
}, },
simpleNested: {
value: 'emails.primaryEmail[eq]:foo99@example.com',
description: 'A simple nested filter param',
},
complex: { complex: {
value: value:
'or(createdAt[gte]:"2024-01-01",createdAt[lte]:"2023-01-01",not(id[is]:NULL))', 'or(createdAt[gte]:"2024-01-01",createdAt[lte]:"2023-01-01",not(id[is]:NULL))',