Add /openapi endpoint using javalin-openapi-plugin#1058
Add /openapi endpoint using javalin-openapi-plugin#1058EPNW-Eric wants to merge 3 commits intokomoot:masterfrom
/openapi endpoint using javalin-openapi-plugin#1058Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Reviewed by Cursor Bugbot for commit a0f4a94. Configure here.
| .description("Forward and reverse geocoder built on OpenStreetMap data.") | ||
| ) | ||
| ) | ||
| )); |
There was a problem hiding this comment.
OpenAPI spec lists endpoints missing in reverse-only mode
Low Severity
When dbProperties.getReverseOnly() is true, the /api and /structured routes are not registered, but the OpenApiPlugin serves a compile-time-generated spec that always includes them. Users of a reverse-only deployment would see these endpoints in the /openapi document, attempt to call them, and receive 404 errors not mentioned in the spec.
Additional Locations (2)
Reviewed by Cursor Bugbot for commit a0f4a94. Configure here.
|
Thanks for that. Unfortunately, I've somewhat changed my mind on how to approach the OpenAPI issue and forgot to update #550 accordingly. Right now I'd prefer to go with the approach from #1038, i.e. having a formal OpenAPI spec separate from the service itself. So I'm going to close this. Apologies for that. Your work is appreciated nonetheless. |
|
No worries! Just that I understand it correctly: Will there be a formal OpenAPI spec and the code used by photon to expose the service generated based on it? Or will code and spec be decoupled and they both have to be keept in sync manually? Imo having them decoupled is cumbersome, so in my projects I usually write the OpenAPI spec first and by hand and use it as "ground of truth" to later use something like https://openapi-generator.tech/docs/generators/ to generate servercode from it. |


As requested in #550, this PR adds an OpenAPI endpoint. It does so by exposing the Photon API capabilities as an OpenAPI 3.x document at
/openapi, using thejavalin-openapi-plugincommunity library.Changes
build.gradleio.javalin.community.openapi:javalin-openapi-plugin:7.1.0: registers the/openapiroute and generates the JSON spec at startup by reading compile-time metadata.io.javalin.community.openapi:openapi-annotation-processor:7.1.0as an annotation processor; this scans@OpenApi-annotated handlers duringcompileJavaand emits the metadata the plugin reads at runtime.App.javaOpenApiPluginin the Javalin config with title, version, and description.GenericSearchHandler<T>route registrations for the new documented wrappers (see below), so the annotatedhandle()methods are what Javalin sees at each path.New handler wrapper classes
Handler, delegates toGenericSearchHandler<T>, adds a@OpenApiannotation tohandle()ApiSearchHandler: documents/api(forward geocoding): all query parameters includingq,lang,limit,lat/lonbias,bbox,countrycode,osm_tag,layer,include/exclude,dedupe,geometry,suggest_addresses,debug.StructuredSearchHandler: documents/structured(structured forward geocoding): address component fields (city,street,postcode, etc.) plus the shared base parameters.ReverseSearchHandler: documents/reverse(reverse geocoding): requiredlat/lon, optionalradius,distance_sort,query_string_filter, plus the shared base parameters.StatusRequestHandler@OpenApiannotation tohandle()to document the/statusendpoint.Why wrapper classes instead of annotating
GenericSearchHandlerdirectlyGenericSearchHandler<T>is reused for three different routes with different parameter sets. A single@OpenApiannotation on a class can only describe one path; the annotation processor links it to exactly one route. Three thin wrapper classes is the idiomatic solution - each has its own@OpenApiand delegates to the underlying generic handler, keeping all search logic in one place.How to verify
The response should be a valid OpenAPI 3.x JSON document listing
/api,/structured,/reverse, and/statuswith their query parameters and response schemas.DISCLAIMER: All code in commit EPNW-Eric/photon@a0f4a94 as well as this PRs text were written by AI.