mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 05:01:07 +00:00
add /apis.json and (re)add .../versions.json paths
This commit is contained in:
@ -29,9 +29,60 @@ import java.util.List;
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
** List.of is "great", but annoying because it makes unmodifiable lists...
|
** List.of is "great", but annoying because it makes unmodifiable lists...
|
||||||
** So, replace it with this, which returns ArrayLists, which "don't suck"
|
** So, replace it with this, which returns ArrayLists, which "don't suck"
|
||||||
|
**
|
||||||
|
** Can use it 3 ways:
|
||||||
|
** ListBuilder.of(value, value2, ...) => List (an ArrayList)
|
||||||
|
** ListBuilder.<ElementType>of(SomeList::new).with(value).with(value2)...build() => SomeList (the type you specify)
|
||||||
|
** new ListBuilder.<ElementType>.with(value).with(value2)...build() => List (an ArrayList - for when you have more than 10 values...)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
public class ListBuilder
|
public class ListBuilder<E>
|
||||||
{
|
{
|
||||||
|
private List<E> list;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Constructor
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
public ListBuilder()
|
||||||
|
{
|
||||||
|
this.list = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Constructor
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
public ListBuilder(List<E> list)
|
||||||
|
{
|
||||||
|
this.list = list;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
public ListBuilder<E> with(E value)
|
||||||
|
{
|
||||||
|
list.add(value);
|
||||||
|
return (this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
public List<E> build()
|
||||||
|
{
|
||||||
|
return (this.list);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
**
|
**
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
package com.kingsrook.qqq.backend.core.utils.collections;
|
package com.kingsrook.qqq.backend.core.utils.collections;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
@ -69,4 +71,22 @@ class ListBuilderTest
|
|||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
list.add(4);
|
list.add(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
@Test
|
||||||
|
void testBuilderMode()
|
||||||
|
{
|
||||||
|
List<String> builtList = new ListBuilder<String>().with("A").with("B").build();
|
||||||
|
assertEquals(List.of("A", "B"), builtList);
|
||||||
|
assertEquals(ArrayList.class, builtList.getClass());
|
||||||
|
|
||||||
|
List<String> builtLinkedList = new ListBuilder<String>(new LinkedList<>()).with("A").with("B").build();
|
||||||
|
assertEquals(List.of("A", "B"), builtLinkedList);
|
||||||
|
assertEquals(LinkedList.class, builtLinkedList.getClass());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -162,6 +162,8 @@ public class QJavalinApiHandler
|
|||||||
ApiBuilder.get("/api/docs/js/rapidoc.min.js", (context) -> QJavalinApiHandler.serveResource(context, "rapidoc/rapidoc-9.3.4.min.js", MapBuilder.of("Content-Type", ContentType.JAVASCRIPT)));
|
ApiBuilder.get("/api/docs/js/rapidoc.min.js", (context) -> QJavalinApiHandler.serveResource(context, "rapidoc/rapidoc-9.3.4.min.js", MapBuilder.of("Content-Type", ContentType.JAVASCRIPT)));
|
||||||
ApiBuilder.get("/api/docs/css/qqq-api-styles.css", (context) -> QJavalinApiHandler.serveResource(context, "rapidoc/rapidoc-overrides.css", MapBuilder.of("Content-Type", ContentType.CSS)));
|
ApiBuilder.get("/api/docs/css/qqq-api-styles.css", (context) -> QJavalinApiHandler.serveResource(context, "rapidoc/rapidoc-overrides.css", MapBuilder.of("Content-Type", ContentType.CSS)));
|
||||||
|
|
||||||
|
ApiBuilder.get("/apis.json", QJavalinApiHandler::doGetApisJson);
|
||||||
|
|
||||||
ApiInstanceMetaDataContainer apiInstanceMetaDataContainer = ApiInstanceMetaDataContainer.of(qInstance);
|
ApiInstanceMetaDataContainer apiInstanceMetaDataContainer = ApiInstanceMetaDataContainer.of(qInstance);
|
||||||
for(Map.Entry<String, ApiInstanceMetaData> entry : apiInstanceMetaDataContainer.getApis().entrySet())
|
for(Map.Entry<String, ApiInstanceMetaData> entry : apiInstanceMetaDataContainer.getApis().entrySet())
|
||||||
{
|
{
|
||||||
@ -172,6 +174,7 @@ public class QJavalinApiHandler
|
|||||||
// default page is the current version spec //
|
// default page is the current version spec //
|
||||||
//////////////////////////////////////////////
|
//////////////////////////////////////////////
|
||||||
ApiBuilder.get(rootPath, context -> doSpecHtml(context, apiInstanceMetaData));
|
ApiBuilder.get(rootPath, context -> doSpecHtml(context, apiInstanceMetaData));
|
||||||
|
ApiBuilder.get(rootPath + "versions.json", context -> doVersions(context, apiInstanceMetaData));
|
||||||
|
|
||||||
ApiBuilder.path(rootPath + "{version}", () ->
|
ApiBuilder.path(rootPath + "{version}", () ->
|
||||||
{
|
{
|
||||||
@ -248,7 +251,61 @@ public class QJavalinApiHandler
|
|||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
**
|
** list the apis supported in this instance
|
||||||
|
*******************************************************************************/
|
||||||
|
private static void doGetApisJson(Context context)
|
||||||
|
{
|
||||||
|
Map<String, Object> rs = new HashMap<>();
|
||||||
|
List<Map<String, Object>> apis = new ArrayList<>();
|
||||||
|
rs.put("apis", apis);
|
||||||
|
|
||||||
|
ApiInstanceMetaDataContainer apiInstanceMetaDataContainer = ApiInstanceMetaDataContainer.of(qInstance);
|
||||||
|
for(Map.Entry<String, ApiInstanceMetaData> entry : apiInstanceMetaDataContainer.getApis().entrySet())
|
||||||
|
{
|
||||||
|
Map<String, Object> thisApi = new HashMap<>();
|
||||||
|
|
||||||
|
ApiInstanceMetaData apiInstanceMetaData = entry.getValue();
|
||||||
|
thisApi.put("name", apiInstanceMetaData.getName());
|
||||||
|
thisApi.put("path", apiInstanceMetaData.getPath());
|
||||||
|
thisApi.put("label", apiInstanceMetaData.getLabel());
|
||||||
|
|
||||||
|
String tableName = context.queryParam("tableName");
|
||||||
|
if(tableName != null)
|
||||||
|
{
|
||||||
|
QTableMetaData table = qInstance.getTable(tableName);
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////
|
||||||
|
// look for reasons we might exclude this api for this table //
|
||||||
|
///////////////////////////////////////////////////////////////
|
||||||
|
ApiTableMetaDataContainer apiTableMetaDataContainer = ApiTableMetaDataContainer.of(table);
|
||||||
|
if(apiTableMetaDataContainer == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ApiTableMetaData apiTableMetaData = apiTableMetaDataContainer.getApiTableMetaData(apiInstanceMetaData.getName());
|
||||||
|
if(apiTableMetaData == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(BooleanUtils.isTrue(apiTableMetaData.getIsExcluded()))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
apis.add(thisApi);
|
||||||
|
}
|
||||||
|
|
||||||
|
context.contentType(ContentType.APPLICATION_JSON);
|
||||||
|
context.result(JsonUtils.toJson(rs));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** list the versions in this api
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
private static void doVersions(Context context, ApiInstanceMetaData apiInstanceMetaData)
|
private static void doVersions(Context context, ApiInstanceMetaData apiInstanceMetaData)
|
||||||
{
|
{
|
||||||
@ -527,6 +584,7 @@ public class QJavalinApiHandler
|
|||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
// do replacements in the html //
|
// do replacements in the html //
|
||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
|
html = html.replace("{spec-url}", apiInstanceMetaData.getPath() + version + "/openapi.json");
|
||||||
html = html.replace("{version}", version);
|
html = html.replace("{version}", version);
|
||||||
html = html.replace("{primaryColor}", branding == null ? "#FF791A" : branding.getAccentColor());
|
html = html.replace("{primaryColor}", branding == null ? "#FF791A" : branding.getAccentColor());
|
||||||
|
|
||||||
@ -539,7 +597,7 @@ public class QJavalinApiHandler
|
|||||||
html = html.replace("{navLogoImg}", "");
|
html = html.replace("{navLogoImg}", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
html = html.replace("{title}", apiInstanceMetaData.getName() + " - " + version);
|
html = html.replace("{title}", apiInstanceMetaData.getLabel() + " - " + version);
|
||||||
|
|
||||||
StringBuilder otherVersionOptions = new StringBuilder();
|
StringBuilder otherVersionOptions = new StringBuilder();
|
||||||
for(APIVersion supportedVersion : apiInstanceMetaData.getSupportedVersions())
|
for(APIVersion supportedVersion : apiInstanceMetaData.getSupportedVersions())
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
<body>
|
<body>
|
||||||
<rapi-doc
|
<rapi-doc
|
||||||
id="the-rapi-doc"
|
id="the-rapi-doc"
|
||||||
spec-url="/api/{version}/openapi.json"
|
spec-url="{spec-url}"
|
||||||
regular-font="Roboto,Helvetica,Arial,sans-serif"
|
regular-font="Roboto,Helvetica,Arial,sans-serif"
|
||||||
mono-font="Monaco, Menlo, Consolas, source-code-pro, monospace"
|
mono-font="Monaco, Menlo, Consolas, source-code-pro, monospace"
|
||||||
font-size="large"
|
font-size="large"
|
||||||
|
Reference in New Issue
Block a user