Skip to content
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
14 changes: 14 additions & 0 deletions lib/core/lib/api.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ namespace Opportunities {
op read is Router.read;

@tag("optional")
@returnTypeChangedFrom(
CommonGrants.Versions.v0_6,
Responses.WithVersionErrors<Responses.FilteredT<
Models.OpportunityBase,
Models.OppFilters
>>
)
op search is Router.search;
}

Expand All @@ -137,6 +144,13 @@ namespace Awards {

@added(Versions.v0_4)
@tag("optional")
@returnTypeChangedFrom(
CommonGrants.Versions.v0_6,
Responses.WithVersionErrors<Responses.FilteredT<
Models.AwardBase,
Models.AwdFilters
>>
)
op search is Router.search;
}

Expand Down
71 changes: 71 additions & 0 deletions lib/core/lib/core/responses/success.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,77 @@ model FilteredT<ItemsT, FilterT> extends Success {
...FilteredBase<ItemsT, FilterT>;
}

// ############################################################################
// 200 search results response
// ############################################################################

/** Details about the search term applied to the response items */
@Versioning.added(CommonGrants.Versions.v0_6)
model SearchResultsInfo {
/** The search term used to find the response items */
@example("Pre-school education")
query: string;
}

/** Body properties shared by `SearchResults` and `SearchResultsT<ItemsT, FilterT>`
*
* @template ItemsT The schema for the value of the `"items"` property in this response
* @template FilterT The schema for the value of the `"filter"` property in this response
*/
@Versioning.added(CommonGrants.Versions.v0_6)
model SearchResultsBase<ItemsT, FilterT> {
...FilteredBase<ItemsT, FilterT>;

/** The search term applied to the response items
*
* Omitted when the request had no search term. An empty or whitespace-only
* `search` value counts as no search term.
*/
searchInfo?: SearchResultsInfo;
}

/** A paginated list of items of an unspecified shape matching a search
*
* Routes use the typed `SearchResultsT<ItemsT, FilterT>` variant.
*/
@doc("A paginated list of items matching a search")
@Versioning.added(CommonGrants.Versions.v0_6)
model SearchResults extends Success {
...SearchResultsBase<unknown, unknown>;
}

/** Template for a paginated list of typed items matching a search, with a typed filter
*
* @template ItemsT The schema for the value of the `"items"` property in this response
* @template FilterT The schema for the value of the `"filter"` property in this response
* @example How to specify a custom search results response model
*
* ```typespec
* // Define a model for the items in the response
* model CustomModel {
* id: string;
* description: string;
* }
*
* // Define a model for the filter in the response
* model CustomFilter extends Record<Filters.DefaultFilter> {
* lastModifiedAt: Filters.DateComparisonFilter;
* }
*
* // Pass that model to the `SearchResultsT` template
* alias CustomModelSearchResponse = Responses.SearchResultsT<CustomModel, CustomFilter>;
* ```
*/
@doc("A paginated list of typed items matching a search, with a typed filter")
@Versioning.added(CommonGrants.Versions.v0_6)
model SearchResultsT<ItemsT, FilterT> extends Success {
// Inherit the 200 status code
...Http.OkResponse;

...Headers.VersionResponse;
...SearchResultsBase<ItemsT, FilterT>;
}

// ############################################################################
// 201 response
// ############################################################################
Expand Down
7 changes: 5 additions & 2 deletions lib/core/lib/core/routes/awards.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ interface Awards {
* Must be an extension of Models.AwardBase. Default is Models.AwardBase.
*/
@summary("Search awards")
@doc("Search for awards based on the provided filters.")
@doc("Search for awards based on the provided search term and filters.")
@post
@route("/search")
search<T extends Models.AwardBase = Models.AwardBase>(
Expand All @@ -106,5 +106,8 @@ interface Awards {
pagination?: Pagination.PaginatedBodyParams,

...Headers.VersionRequest,
): Responses.WithVersionErrors<Responses.FilteredT<T, Models.AwdFilters>>;
): Responses.WithVersionErrors<Responses.SearchResultsT<
T,
Models.AwdFilters
>>;
}
7 changes: 5 additions & 2 deletions lib/core/lib/core/routes/opportunities.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ interface Opportunities {
* Must be an extension of Schemas.OpportunityBase. Default is Schemas.OpportunityBase.
*/
@summary("Search opportunities")
@doc("Search for opportunities based on the provided filters.")
@doc("Search for opportunities based on the provided search term and filters.")
@post
@route("/search")
search<T extends Models.OpportunityBase = Models.OpportunityBase>(
Expand All @@ -111,5 +111,8 @@ interface Opportunities {
pagination?: Pagination.PaginatedBodyParams,

...Headers.VersionRequest,
): Responses.WithVersionErrors<Responses.FilteredT<T, Models.OppFilters>>;
): Responses.WithVersionErrors<Responses.SearchResultsT<
T,
Models.OppFilters
>>;
}
2 changes: 1 addition & 1 deletion website/public/openapi/openapi.0.1.0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ paths:
post:
operationId: Opportunities_search
summary: Search opportunities
description: Search for opportunities based on the provided filters.
description: Search for opportunities based on the provided search term and filters.
parameters: []
responses:
'200':
Expand Down
2 changes: 1 addition & 1 deletion website/public/openapi/openapi.0.2.0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ paths:
post:
operationId: Opportunities_search
summary: Search opportunities
description: Search for opportunities based on the provided filters.
description: Search for opportunities based on the provided search term and filters.
parameters: []
responses:
'200':
Expand Down
2 changes: 1 addition & 1 deletion website/public/openapi/openapi.0.3.0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ paths:
post:
operationId: Opportunities_search
summary: Search opportunities
description: Search for opportunities based on the provided filters.
description: Search for opportunities based on the provided search term and filters.
parameters: []
responses:
'200':
Expand Down
4 changes: 2 additions & 2 deletions website/public/openapi/openapi.0.4.0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ paths:
post:
operationId: Awards_search
summary: Search awards
description: Search for awards based on the provided filters.
description: Search for awards based on the provided search term and filters.
parameters: []
responses:
'200':
Expand Down Expand Up @@ -619,7 +619,7 @@ paths:
post:
operationId: Opportunities_search
summary: Search opportunities
description: Search for opportunities based on the provided filters.
description: Search for opportunities based on the provided search term and filters.
parameters: []
responses:
'200':
Expand Down
4 changes: 2 additions & 2 deletions website/public/openapi/openapi.0.5.0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ paths:
post:
operationId: Awards_search
summary: Search awards
description: Search for awards based on the provided filters.
description: Search for awards based on the provided search term and filters.
parameters: []
responses:
'200':
Expand Down Expand Up @@ -619,7 +619,7 @@ paths:
post:
operationId: Opportunities_search
summary: Search opportunities
description: Search for opportunities based on the provided filters.
description: Search for opportunities based on the provided search term and filters.
parameters: []
responses:
'200':
Expand Down
81 changes: 75 additions & 6 deletions website/public/openapi/openapi.0.6.0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1109,12 +1109,12 @@ paths:
post:
operationId: Awards_search
summary: Search awards
description: Search for awards based on the provided filters.
description: Search for awards based on the provided search term and filters.
parameters:
- $ref: '#/components/parameters/CommonGrants.Headers.VersionRequest'
responses:
'200':
description: A paginated list of typed items with a typed filter
description: A paginated list of typed items matching a search, with a typed filter
headers:
CG-Version-Served:
required: true
Expand Down Expand Up @@ -1182,9 +1182,17 @@ paths:
required:
- filters
description: The filters applied to the response items
searchInfo:
allOf:
- $ref: '#/components/schemas/CommonGrants.Responses.SearchResultsInfo'
description: |-
The search term applied to the response items

Omitted when the request had no search term. An empty or whitespace-only
`search` value counts as no search term.
allOf:
- $ref: '#/components/schemas/CommonGrants.Responses.Success'
description: A paginated list of typed items with a typed filter
description: A paginated list of typed items matching a search, with a typed filter
'400':
description: The request is invalid, or its `CG-Version` value is malformed or was sent more than once
headers:
Expand Down Expand Up @@ -1909,12 +1917,12 @@ paths:
post:
operationId: Opportunities_search
summary: Search opportunities
description: Search for opportunities based on the provided filters.
description: Search for opportunities based on the provided search term and filters.
parameters:
- $ref: '#/components/parameters/CommonGrants.Headers.VersionRequest'
responses:
'200':
description: A paginated list of typed items with a typed filter
description: A paginated list of typed items matching a search, with a typed filter
headers:
CG-Version-Served:
required: true
Expand Down Expand Up @@ -1982,9 +1990,17 @@ paths:
required:
- filters
description: The filters applied to the response items
searchInfo:
allOf:
- $ref: '#/components/schemas/CommonGrants.Responses.SearchResultsInfo'
description: |-
The search term applied to the response items

Omitted when the request had no search term. An empty or whitespace-only
`search` value counts as no search term.
allOf:
- $ref: '#/components/schemas/CommonGrants.Responses.Success'
description: A paginated list of typed items with a typed filter
description: A paginated list of typed items matching a search, with a typed filter
'400':
description: The request is invalid, or its `CG-Version` value is malformed or was sent more than once
headers:
Expand Down Expand Up @@ -8977,6 +8993,59 @@ components:
allOf:
- $ref: '#/components/schemas/CommonGrants.Responses.Success'
description: A 200 response with a paginated list of items
CommonGrants.Responses.SearchResults:
type: object
required:
- items
- paginationInfo
- sortInfo
- filterInfo
properties:
items:
type: array
items: {}
description: Items from the current page
paginationInfo:
allOf:
- $ref: '#/components/schemas/CommonGrants.Pagination.PaginatedResultsInfo'
description: Details about the paginated results
sortInfo:
allOf:
- $ref: '#/components/schemas/CommonGrants.Sorting.SortedResultsInfo'
description: The sort order of the items
filterInfo:
type: object
properties:
filters: {}
errors:
type: array
items:
type: string
description: Non-fatal errors that occurred during filtering
required:
- filters
description: The filters applied to the response items
searchInfo:
allOf:
- $ref: '#/components/schemas/CommonGrants.Responses.SearchResultsInfo'
description: |-
The search term applied to the response items

Omitted when the request had no search term. An empty or whitespace-only
`search` value counts as no search term.
allOf:
- $ref: '#/components/schemas/CommonGrants.Responses.Success'
description: A paginated list of items matching a search
CommonGrants.Responses.SearchResultsInfo:
type: object
required:
- query
properties:
query:
type: string
description: The search term used to find the response items
example: Pre-school education
description: Details about the search term applied to the response items
CommonGrants.Responses.Sorted:
type: object
required:
Expand Down
45 changes: 45 additions & 0 deletions website/public/schemas/yaml/SearchResults.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
$schema: https://json-schema.org/draft/2020-12/schema
$id: SearchResults.yaml
type: object
properties:
items:
type: array
items: {}
description: Items from the current page
paginationInfo:
$ref: PaginatedResultsInfo.yaml
description: Details about the paginated results
sortInfo:
$ref: SortedResultsInfo.yaml
description: The sort order of the items
filterInfo:
type: object
properties:
filters: {}
errors:
type: array
items:
type: string
description: Non-fatal errors that occurred during filtering
required:
- filters
unevaluatedProperties:
not: {}
description: The filters applied to the response items
searchInfo:
$ref: SearchResultsInfo.yaml
description: |-
The search term applied to the response items

Omitted when the request had no search term. An empty or whitespace-only
`search` value counts as no search term.
required:
- items
- paginationInfo
- sortInfo
- filterInfo
allOf:
- $ref: Success.yaml
unevaluatedProperties:
not: {}
description: A paginated list of items matching a search
14 changes: 14 additions & 0 deletions website/public/schemas/yaml/SearchResultsInfo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
$schema: https://json-schema.org/draft/2020-12/schema
$id: SearchResultsInfo.yaml
type: object
properties:
query:
type: string
examples:
- Pre-school education
description: The search term used to find the response items
required:
- query
unevaluatedProperties:
not: {}
description: Details about the search term applied to the response items
Loading
Loading