3030import org .springframework .web .servlet .mvc .method .annotation .StreamingResponseBody ;
3131
3232import java .util .ArrayList ;
33+ import java .util .List ;
3334
35+ import static org .eclipse .openvsx .adapter .ExtensionQueryParam .*;
3436import static org .eclipse .openvsx .adapter .ExtensionQueryResult .ExtensionFile .*;
3537import static org .eclipse .openvsx .util .TargetPlatform .*;
3638import static org .eclipse .openvsx .util .TargetPlatform .NAME_UNIVERSAL ;
@@ -304,4 +306,41 @@ public ResponseEntity<StreamingResponseBody> browse(
304306
305307 return ResponseEntity .notFound ().build ();
306308 }
309+
310+ @ GetMapping (
311+ path = "/vscode/gallery/{namespaceName}/{extensionName}/latest" ,
312+ produces = MediaType .APPLICATION_JSON_VALUE
313+ )
314+ @ CrossOrigin
315+ @ Operation (summary = "Provides metadata of the extension matching the given parameters" )
316+ @ ApiResponse (
317+ responseCode = "200" ,
318+ description = "Returns the extension metadata"
319+ )
320+ @ ApiResponse (
321+ responseCode = "404" ,
322+ description = "The specified extension could not be found" ,
323+ content = @ Content ()
324+ )
325+ public ExtensionQueryResult .Extension getLatest (
326+ @ PathVariable @ Parameter (description = "Extension namespace" , example = "malloydata" ) String namespaceName ,
327+ @ PathVariable @ Parameter (description = "Extension name" , example = "malloy-vscode" ) String extensionName
328+ ) {
329+ var extensionId = String .join ("." , namespaceName , extensionName );
330+ var criterion = new ExtensionQueryParam .Criterion (ExtensionQueryParam .Criterion .FILTER_EXTENSION_NAME , extensionId );
331+ var filter = new ExtensionQueryParam .Filter (List .of (criterion ), 0 , 0 , 0 , 0 );
332+ int flags = FLAG_INCLUDE_VERSIONS | FLAG_INCLUDE_ASSET_URI | FLAG_INCLUDE_VERSION_PROPERTIES | FLAG_INCLUDE_FILES | FLAG_INCLUDE_STATISTICS ;
333+ var param = new ExtensionQueryParam (List .of (filter ), flags );
334+ var result = extensionQueryRequestHandler .getResult (param , 1 , DEFAULT_PAGE_SIZE );
335+ if (result .results ().isEmpty ()) {
336+ throw new NotFoundException ();
337+ }
338+
339+ var extensions = result .results ().get (0 ).extensions ();
340+ if (extensions .isEmpty ()) {
341+ throw new NotFoundException ();
342+ }
343+
344+ return extensions .get (0 );
345+ }
307346}
0 commit comments