Skip to content

Commit

Permalink
Merge pull request #672 from SciCatProject/swap-3430
Browse files Browse the repository at this point in the history
Update fullquery swagger documentation
  • Loading branch information
nitrosx authored Aug 21, 2023
2 parents 0560089 + 203d12a commit b6e19da
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 25 deletions.
93 changes: 84 additions & 9 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -690,21 +690,96 @@ export const filterDescription =
}\n \
</pre>';

export const fullQueryExample =
'{ "fields": ["field1", "field2"], "limits": {"limit": 1, "skip": 1, "order": "asc"}}';
export const fullQueryExampleLimits =
'{"limit": 1, "skip": 1, "order": "creationTime:desc"}';

export const fullQueryDescription =
export const datasetsFullQueryExampleFields =
'{"mode":{},"ownerGroup":["group1"],"scientific":[{"lhs":"sample","relation":"EQUAL_TO_STRING","rhs":"my sample"},{"lhs":"temperature","relation":"GREATER_THAN","rhs":10,"unit":"celsius"}]}';

export const fullQueryDescriptionLimits =
'<pre>\n \
{\n \
"fields?": [ "field1", "field2", ...],\n \
"limits?": {\n \
"limit": number,\n \
"skip": number,\n \
"order": [ascending, descending]\n \
}\n \
"limit": number,\n \
"skip": number,\n \
"order": [ascending, descending]\n \
}\n \
</pre>';

export const datasetsFullQueryDescriptionFields =
'<pre>\n \
{\n \
"mode":{\n \
"key": "value",\n \
},\n \
"text": string, <optional>\n \
"creationTime": { <optional>\n \
"begin": string,\n \
"end": string,\n \
},\n \
"type": ["type1", ...], <optional>\n \
"creationLocation": ["creationLocation1", ...], <optional>\n \
"ownerGroup": ["group1", ...], <optional>\n \
"keywords": ["keyword1", ...], <optional>\n \
"isPublished: boolean, <optional>\n \
"scientific": [ <optional>\n \
{\n \
"lhs":<metadata_key>>,\n \
"relation":["EQUAL_TO_STRING","EQUAL_TO_NUMERIC","GREATER_THAN","LESS_THAN"],\n \
"rhs":<metadata_value>,\n \
"unit":<unit>,\n \
},\n \
...\n \
],\n \
"metadataKey": "metadata", <optional>\n \
"_id": "item id", <optional>\n \
"userGroups": ["group1", ...], <optional>\n \
"sharedWith": "email", <optional>\n \
}\n \
</pre>';

export const proposalsFullQueryExampleFields =
'{"text": "some text", "proposalId": "proposal_id"}';

export const proposalsFullQueryDescriptionFields =
'<pre>\n \
{\n \
"text": string, <optional>\n \
"startTime": { <optional>\n \
"begin": string,\n \
"end": string,\n \
},\n \
"proposalId": { "regex": string, "options": string }, <optional>\n \
"title": { "regex": string, "options": string }, <optional>\n \
"firstname": { "regex": string, "options": string }, <optional>\n \
"lastname": { "regex": string, "options": string }, <optional>\n \
"endTime": { <optional>\n \
"begin": string,\n \
"end": string,\n \
},\n \
"userGroups": ["group1", ...],\n \
}\n \
</pre>';

export const samplesFullQueryExampleFields =
'{"text": "some text", "metadataKey": "key", "characteristics": [{"lhs":"material","relation":"EQUAL_TO_STRING","rhs":"my material"}]}';

export const samplesFullQueryDescriptionFields =
'<pre>\n \
{\n \
"text": string, <optional>\n \
"metadataKey": string, <optional>\n \
"charactersitics": [ <optional>\n \
{\n \
"lhs":<property>>,\n \
"relation":["EQUAL_TO_STRING","EQUAL_TO_NUMERIC","GREATER_THAN","LESS_THAN"],\n \
"rhs":<value>,\n \
"unit":<unit>,\n \
},\n \
...\n \
],\n \
}\n \
</pre>';

export const parseBoolean = (v: unknown): boolean => {
switch (v) {
case true:
Expand Down
15 changes: 11 additions & 4 deletions src/datasets/datasets.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ import { CreateDatasetDatablockDto } from "src/datablocks/dto/create-dataset-dat
import {
filterDescription,
filterExample,
datasetsFullQueryDescriptionFields,
fullQueryDescriptionLimits,
datasetsFullQueryExampleFields,
fullQueryExampleLimits,
replaceLikeOperator,
} from "src/common/utils";
import { TechniqueClass } from "./schemas/technique.schema";
Expand Down Expand Up @@ -558,17 +562,20 @@ export class DatasetsController {
@ApiQuery({
name: "fields",
description:
"Define the query conditions using mongoDB syntax as JSON object. It also supports the `text` search, if you want to look for strings anywhere in the dataset. Please refer to mongo documentation for more information about the syntax",
"Database filters to apply when retrieving datasets\n" +
datasetsFullQueryDescriptionFields,
required: false,
type: String,
example: {},
example: datasetsFullQueryExampleFields,
})
@ApiQuery({
name: "limits",
description: "Define further query parameters like skip, limit, order",
description:
"Define further query parameters like skip, limit, order\n" +
fullQueryDescriptionLimits,
required: false,
type: String,
example: '{ "skip": 0, "limit": 25, "order": "creationTime:desc" }',
example: fullQueryExampleLimits,
})
@ApiResponse({
status: 200,
Expand Down
25 changes: 18 additions & 7 deletions src/proposals/proposals.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ import { validate, ValidatorOptions } from "class-validator";
import {
filterDescription,
filterExample,
fullQueryDescription,
fullQueryExample,
fullQueryDescriptionLimits,
fullQueryExampleLimits,
proposalsFullQueryDescriptionFields,
proposalsFullQueryExampleFields,
} from "src/common/utils";
import { JWTUser } from "src/auth/interfaces/jwt-user.interface";

Expand Down Expand Up @@ -222,13 +224,22 @@ export class ProposalsController {
"It returns a list of proposals matching the query provided.<br>This endpoint still needs some work on the query specification.",
})
@ApiQuery({
name: "filters",
name: "fields",
description:
"Full query filters to apply when retrieving proposals\n" +
fullQueryDescription,
proposalsFullQueryDescriptionFields,
required: false,
type: String,
example: proposalsFullQueryExampleFields,
})
@ApiQuery({
name: "limits",
description:
"Define further query parameters like skip, limit, order\n" +
fullQueryDescriptionLimits,
required: false,
type: String,
example: fullQueryExample,
example: fullQueryExampleLimits,
})
@ApiResponse({
status: 200,
Expand Down Expand Up @@ -278,10 +289,10 @@ export class ProposalsController {
name: "filters",
description:
"Full facet query filters to apply when retrieving proposals\n" +
fullQueryDescription,
proposalsFullQueryDescriptionFields,
required: false,
type: String,
example: fullQueryExample,
example: proposalsFullQueryExampleFields,
})
@ApiResponse({
status: 200,
Expand Down
21 changes: 16 additions & 5 deletions src/samples/samples.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ import { IFilters } from "src/common/interfaces/common.interface";
import {
filterDescription,
filterExample,
fullQueryDescription,
fullQueryExample,
fullQueryDescriptionLimits,
fullQueryExampleLimits,
samplesFullQueryDescriptionFields,
samplesFullQueryExampleFields,
} from "src/common/utils";

@ApiBearerAuth()
Expand Down Expand Up @@ -129,13 +131,22 @@ export class SamplesController {
"It returns a list of samples matching the query provided.<br>This endpoint still needs some work on the query specification.",
})
@ApiQuery({
name: "filters",
name: "fields",
description:
"Full query filters to apply when retrieve samples\n" +
fullQueryDescription,
samplesFullQueryDescriptionFields,
required: false,
type: String,
example: samplesFullQueryExampleFields,
})
@ApiQuery({
name: "limits",
description:
"Define further query parameters like skip, limit, order\n" +
fullQueryDescriptionLimits,
required: false,
type: String,
example: fullQueryExample,
example: fullQueryExampleLimits,
})
@ApiResponse({
status: HttpStatus.OK,
Expand Down

0 comments on commit b6e19da

Please sign in to comment.