Skip to content

Commit

Permalink
updated openapi and generated frontend api
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusDunn committed Mar 2, 2022
1 parent 4a73ebc commit 0defae7
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 23 deletions.
50 changes: 28 additions & 22 deletions api/src/main/kotlin/ca/vikelabs/maps/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package ca.vikelabs.maps
import ca.vikelabs.maps.data.impl.DatabaseOpenStreetMapsMapData
import ca.vikelabs.maps.routes.Ping
import ca.vikelabs.maps.routes.Search
import ca.vikelabs.maps.routes.Suggest
import org.http4k.contract.ContractRoutingHttpHandler
import org.http4k.contract.contract
import org.http4k.contract.openapi.ApiInfo
import org.http4k.contract.openapi.ApiRenderer
Expand All @@ -12,31 +14,35 @@ import org.http4k.contract.openapi.v3.AutoJsonToJsonSchema
import org.http4k.contract.openapi.v3.OpenApi3
import org.http4k.core.Uri

fun application(config: Config) = contract {
renderer = OpenApi3(
apiInfo = ApiInfo(
title = "map uvic",
version = "0.0.1",
description = "An API for navigating around the University of Victoria.",
),
json = OpenAPIJackson,
apiRenderer = ApiRenderer.Auto(
fun application(config: Config): ContractRoutingHttpHandler {
val mapData = DatabaseOpenStreetMapsMapData(config.dataSource)
return contract {
renderer = OpenApi3(
apiInfo = ApiInfo(
title = "map uvic",
version = "0.0.1",
description = "An API for navigating around the University of Victoria.",
),
json = OpenAPIJackson,
schema = AutoJsonToJsonSchema(
OpenAPIJackson,
modelNamer = { appendEnclosingClass(it.javaClass) }
)
),
servers = listOf(
ApiServer(
url = Uri.of("http://localhost:${config.serverPort}"),
description = "The greatest server!"
apiRenderer = ApiRenderer.Auto(
json = OpenAPIJackson,
schema = AutoJsonToJsonSchema(
OpenAPIJackson,
modelNamer = { appendEnclosingClass(it.javaClass) }
)
),
servers = listOf(
ApiServer(
url = Uri.of("http://localhost:${config.serverPort}"),
description = "The greatest server!"
)
)
)
)
descriptionPath = "/openapi.json"
routes += Ping().contractRoute
routes += Search(DatabaseOpenStreetMapsMapData(config.dataSource)).contractRoute
descriptionPath = "/openapi.json"
routes += Ping().contractRoute
routes += Search(mapData).contractRoute
routes += Suggest(mapData).contractRoute
}
}


Expand Down
2 changes: 1 addition & 1 deletion api/src/main/kotlin/ca/vikelabs/maps/routes/Suggest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Suggest(private val mapData: MapData) : HttpHandler {
val max = Query.int().defaulted("max", 10, "The max number of results returned.")
val response = Body.auto<ResponseBody>().toLens()

val spec = "search" meta {
val spec = "suggest" meta {
summary = "lists possible completions for a given string"
description =
"""Similar to search but doesn't use levenshteinDistance, instead just scanning the start of buildings
Expand Down
75 changes: 75 additions & 0 deletions api/src/test/resources/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,57 @@
"operationId": "getSearch",
"deprecated": false
}
},
"/suggest": {
"get": {
"summary": "lists possible completions for a given string",
"description": "Similar to search but doesn't use levenshteinDistance, instead just scanning the start of buildings \nand their abbreviations, it is however ordered by levenshteinDistance, capitalization are ignored \nfor suggestions but included for sorting.",
"tags": [
""
],
"parameters": [
{
"schema": {
"type": "string"
},
"in": "query",
"name": "query",
"required": true,
"description": "The query string the user has started typing"
},
{
"schema": {
"type": "integer"
},
"in": "query",
"name": "max",
"required": false,
"description": "The max number of results returned."
}
],
"responses": {
"200": {
"description": "a list of suggested search terms",
"content": {
"application/json": {
"example": {
"suggestions": [
"ECS",
"Elliot Building"
]
},
"schema": {
"$ref": "#/components/schemas/SuggestResponseBody"
}
}
}
}
},
"security": [
],
"operationId": "getSuggest",
"deprecated": false
}
}
},
"components": {
Expand Down Expand Up @@ -184,6 +235,30 @@
"latitude",
"longitude"
]
},
"SuggestResponseBody": {
"properties": {
"suggestions": {
"items": {
"type": "string"
},
"example": [
"ECS",
"Elliot Building"
],
"type": "array"
}
},
"example": {
"suggestions": [
"ECS",
"Elliot Building"
]
},
"type": "object",
"required": [
"suggestions"
]
}
},
"securitySchemes": {
Expand Down
1 change: 1 addition & 0 deletions app/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ export type { Coordinate } from './models/Coordinate';
export type { PingResponseBody } from './models/PingResponseBody';
export type { SearchResponseBody } from './models/SearchResponseBody';
export type { SearchResponseBodyBuilding } from './models/SearchResponseBodyBuilding';
export type { SuggestResponseBody } from './models/SuggestResponseBody';

export { Service } from './services/Service';
25 changes: 25 additions & 0 deletions app/api/services/Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/* eslint-disable */
import type { PingResponseBody } from '../models/PingResponseBody';
import type { SearchResponseBody } from '../models/SearchResponseBody';
import type { SuggestResponseBody } from '../models/SuggestResponseBody';
import type { CancelablePromise } from '../core/CancelablePromise';
import { request as __request } from '../core/request';

Expand Down Expand Up @@ -40,4 +41,28 @@ export class Service {
});
}

/**
* lists possible completions for a given string
* Similar to search but doesn't use levenshteinDistance, instead just scanning the start of buildings
* and their abbreviations, it is however ordered by levenshteinDistance, capitalization are ignored
* for suggestions but included for sorting.
* @param query The query string the user has started typing
* @param max The max number of results returned.
* @returns SuggestResponseBody a list of suggested search terms
* @throws ApiError
*/
public static getSuggest(
query: string,
max?: number,
): CancelablePromise<SuggestResponseBody> {
return __request({
method: 'GET',
path: `/suggest`,
query: {
'query': query,
'max': max,
},
});
}

}

0 comments on commit 0defae7

Please sign in to comment.