mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 13:10:44 +00:00
configurable servers; paths in swagger from root
This commit is contained in:
@ -56,7 +56,6 @@ import com.kingsrook.qqq.api.model.openapi.RequestBody;
|
|||||||
import com.kingsrook.qqq.api.model.openapi.Response;
|
import com.kingsrook.qqq.api.model.openapi.Response;
|
||||||
import com.kingsrook.qqq.api.model.openapi.Schema;
|
import com.kingsrook.qqq.api.model.openapi.Schema;
|
||||||
import com.kingsrook.qqq.api.model.openapi.SecurityScheme;
|
import com.kingsrook.qqq.api.model.openapi.SecurityScheme;
|
||||||
import com.kingsrook.qqq.api.model.openapi.Server;
|
|
||||||
import com.kingsrook.qqq.api.model.openapi.Tag;
|
import com.kingsrook.qqq.api.model.openapi.Tag;
|
||||||
import com.kingsrook.qqq.backend.core.actions.AbstractQActionFunction;
|
import com.kingsrook.qqq.backend.core.actions.AbstractQActionFunction;
|
||||||
import com.kingsrook.qqq.backend.core.actions.permissions.PermissionsHelper;
|
import com.kingsrook.qqq.backend.core.actions.permissions.PermissionsHelper;
|
||||||
@ -188,7 +187,8 @@ public class GenerateOpenApiSpecAction extends AbstractQActionFunction<GenerateO
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
public GenerateOpenApiSpecOutput execute(GenerateOpenApiSpecInput input) throws QException
|
public GenerateOpenApiSpecOutput execute(GenerateOpenApiSpecInput input) throws QException
|
||||||
{
|
{
|
||||||
String version = input.getVersion();
|
String version = input.getVersion();
|
||||||
|
String basePath = "/api/" + version + "/";
|
||||||
|
|
||||||
QInstance qInstance = QContext.getQInstance();
|
QInstance qInstance = QContext.getQInstance();
|
||||||
|
|
||||||
@ -205,10 +205,9 @@ public class GenerateOpenApiSpecAction extends AbstractQActionFunction<GenerateO
|
|||||||
.withDescription(apiInstanceMetaData.getDescription())
|
.withDescription(apiInstanceMetaData.getDescription())
|
||||||
.withContact(new Contact()
|
.withContact(new Contact()
|
||||||
.withEmail(apiInstanceMetaData.getContactEmail()))
|
.withEmail(apiInstanceMetaData.getContactEmail()))
|
||||||
.withVersion(version))
|
.withVersion(version));
|
||||||
.withServers(ListBuilder.of(new Server()
|
|
||||||
.withDescription("This server")
|
openAPI.withServers(apiInstanceMetaData.getServers());
|
||||||
.withUrl("/api/" + version)));
|
|
||||||
|
|
||||||
openAPI.setTags(new ArrayList<>());
|
openAPI.setTags(new ArrayList<>());
|
||||||
openAPI.setPaths(new LinkedHashMap<>());
|
openAPI.setPaths(new LinkedHashMap<>());
|
||||||
@ -457,7 +456,7 @@ public class GenerateOpenApiSpecAction extends AbstractQActionFunction<GenerateO
|
|||||||
|
|
||||||
if(queryCapability)
|
if(queryCapability)
|
||||||
{
|
{
|
||||||
openAPI.getPaths().put("/" + tableApiName + "/query", new Path()
|
openAPI.getPaths().put(basePath + tableApiName + "/query", new Path()
|
||||||
// todo!! .withPost(queryPost)
|
// todo!! .withPost(queryPost)
|
||||||
.withGet(queryGet)
|
.withGet(queryGet)
|
||||||
);
|
);
|
||||||
@ -524,7 +523,7 @@ public class GenerateOpenApiSpecAction extends AbstractQActionFunction<GenerateO
|
|||||||
|
|
||||||
if(getCapability || updateCapability || deleteCapability)
|
if(getCapability || updateCapability || deleteCapability)
|
||||||
{
|
{
|
||||||
openAPI.getPaths().put("/" + tableApiName + "/{" + primaryKeyApiName + "}", new Path()
|
openAPI.getPaths().put(basePath + tableApiName + "/{" + primaryKeyApiName + "}", new Path()
|
||||||
.withGet(getCapability ? idGet : null)
|
.withGet(getCapability ? idGet : null)
|
||||||
.withPatch(updateCapability ? idPatch : null)
|
.withPatch(updateCapability ? idPatch : null)
|
||||||
.withDelete(deleteCapability ? idDelete : null)
|
.withDelete(deleteCapability ? idDelete : null)
|
||||||
@ -534,6 +533,7 @@ public class GenerateOpenApiSpecAction extends AbstractQActionFunction<GenerateO
|
|||||||
Method slashPost = new Method()
|
Method slashPost = new Method()
|
||||||
.withSummary("Create one " + tableLabel)
|
.withSummary("Create one " + tableLabel)
|
||||||
.withDescription(INSERT_DESCRIPTION)
|
.withDescription(INSERT_DESCRIPTION)
|
||||||
|
.withOperationId("create" + tableApiNameUcFirst)
|
||||||
.withRequestBody(new RequestBody()
|
.withRequestBody(new RequestBody()
|
||||||
.withRequired(true)
|
.withRequired(true)
|
||||||
.withDescription("Values for the " + tableLabel + " record to create.")
|
.withDescription("Values for the " + tableLabel + " record to create.")
|
||||||
@ -554,7 +554,7 @@ public class GenerateOpenApiSpecAction extends AbstractQActionFunction<GenerateO
|
|||||||
|
|
||||||
if(insertCapability)
|
if(insertCapability)
|
||||||
{
|
{
|
||||||
openAPI.getPaths().put("/" + tableApiName + "/", new Path()
|
openAPI.getPaths().put(basePath + tableApiName + "/", new Path()
|
||||||
.withPost(slashPost));
|
.withPost(slashPost));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -564,6 +564,7 @@ public class GenerateOpenApiSpecAction extends AbstractQActionFunction<GenerateO
|
|||||||
Method bulkPost = new Method()
|
Method bulkPost = new Method()
|
||||||
.withSummary("Create multiple " + tableLabel + " records")
|
.withSummary("Create multiple " + tableLabel + " records")
|
||||||
.withDescription(BULK_INSERT_DESCRIPTION)
|
.withDescription(BULK_INSERT_DESCRIPTION)
|
||||||
|
.withOperationId("create" + tableApiNameUcFirst + "Bulk")
|
||||||
.withRequestBody(new RequestBody()
|
.withRequestBody(new RequestBody()
|
||||||
.withRequired(true)
|
.withRequired(true)
|
||||||
.withDescription("Values for the " + tableLabel + " records to create.")
|
.withDescription("Values for the " + tableLabel + " records to create.")
|
||||||
@ -579,6 +580,7 @@ public class GenerateOpenApiSpecAction extends AbstractQActionFunction<GenerateO
|
|||||||
Method bulkPatch = new Method()
|
Method bulkPatch = new Method()
|
||||||
.withSummary("Update multiple " + tableLabel + " records")
|
.withSummary("Update multiple " + tableLabel + " records")
|
||||||
.withDescription(BULK_UPDATE_DESCRIPTION)
|
.withDescription(BULK_UPDATE_DESCRIPTION)
|
||||||
|
.withOperationId("update" + tableApiNameUcFirst + "Bulk")
|
||||||
.withRequestBody(new RequestBody()
|
.withRequestBody(new RequestBody()
|
||||||
.withRequired(true)
|
.withRequired(true)
|
||||||
.withDescription("Values for the " + tableLabel + " records to update.")
|
.withDescription("Values for the " + tableLabel + " records to update.")
|
||||||
@ -600,6 +602,7 @@ public class GenerateOpenApiSpecAction extends AbstractQActionFunction<GenerateO
|
|||||||
Method bulkDelete = new Method()
|
Method bulkDelete = new Method()
|
||||||
.withSummary("Delete multiple " + tableLabel + " records")
|
.withSummary("Delete multiple " + tableLabel + " records")
|
||||||
.withDescription(BULK_DELETE_DESCRIPTION)
|
.withDescription(BULK_DELETE_DESCRIPTION)
|
||||||
|
.withOperationId("delete" + tableApiNameUcFirst + "Bulk")
|
||||||
.withRequestBody(new RequestBody()
|
.withRequestBody(new RequestBody()
|
||||||
.withRequired(true)
|
.withRequired(true)
|
||||||
.withDescription(primaryKeyLabel + " values for the " + tableLabel + " records to delete.")
|
.withDescription(primaryKeyLabel + " values for the " + tableLabel + " records to delete.")
|
||||||
@ -615,7 +618,7 @@ public class GenerateOpenApiSpecAction extends AbstractQActionFunction<GenerateO
|
|||||||
|
|
||||||
if(insertCapability || updateCapability || deleteCapability)
|
if(insertCapability || updateCapability || deleteCapability)
|
||||||
{
|
{
|
||||||
openAPI.getPaths().put("/" + tableApiName + "/bulk", new Path()
|
openAPI.getPaths().put(basePath + tableApiName + "/bulk", new Path()
|
||||||
.withPost(insertCapability ? bulkPost : null)
|
.withPost(insertCapability ? bulkPost : null)
|
||||||
.withPatch(updateCapability ? bulkPatch : null)
|
.withPatch(updateCapability ? bulkPatch : null)
|
||||||
.withDelete(deleteCapability ? bulkDelete : null));
|
.withDelete(deleteCapability ? bulkDelete : null));
|
||||||
|
@ -28,12 +28,14 @@ import java.util.Set;
|
|||||||
import com.kingsrook.qqq.api.ApiMiddlewareType;
|
import com.kingsrook.qqq.api.ApiMiddlewareType;
|
||||||
import com.kingsrook.qqq.api.model.APIVersion;
|
import com.kingsrook.qqq.api.model.APIVersion;
|
||||||
import com.kingsrook.qqq.api.model.metadata.tables.ApiTableMetaData;
|
import com.kingsrook.qqq.api.model.metadata.tables.ApiTableMetaData;
|
||||||
|
import com.kingsrook.qqq.api.model.openapi.Server;
|
||||||
import com.kingsrook.qqq.backend.core.instances.QInstanceValidator;
|
import com.kingsrook.qqq.backend.core.instances.QInstanceValidator;
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.QMiddlewareInstanceMetaData;
|
import com.kingsrook.qqq.backend.core.model.metadata.QMiddlewareInstanceMetaData;
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
|
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
|
||||||
import com.kingsrook.qqq.backend.core.utils.CollectionUtils;
|
import com.kingsrook.qqq.backend.core.utils.CollectionUtils;
|
||||||
import com.kingsrook.qqq.backend.core.utils.StringUtils;
|
import com.kingsrook.qqq.backend.core.utils.StringUtils;
|
||||||
|
import org.apache.commons.lang.BooleanUtils;
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -50,6 +52,8 @@ public class ApiInstanceMetaData extends QMiddlewareInstanceMetaData
|
|||||||
private List<APIVersion> pastVersions;
|
private List<APIVersion> pastVersions;
|
||||||
private List<APIVersion> futureVersions;
|
private List<APIVersion> futureVersions;
|
||||||
|
|
||||||
|
private List<Server> servers;
|
||||||
|
|
||||||
private boolean includeErrorTooManyRequests = true;
|
private boolean includeErrorTooManyRequests = true;
|
||||||
|
|
||||||
|
|
||||||
@ -118,7 +122,10 @@ public class ApiInstanceMetaData extends QMiddlewareInstanceMetaData
|
|||||||
ApiTableMetaData apiTableMetaData = ApiTableMetaData.of(table);
|
ApiTableMetaData apiTableMetaData = ApiTableMetaData.of(table);
|
||||||
if(apiTableMetaData != null)
|
if(apiTableMetaData != null)
|
||||||
{
|
{
|
||||||
validator.assertCondition(allVersions.contains(new APIVersion(apiTableMetaData.getInitialVersion())), "Table " + table.getName() + "'s initial API version is not a recognized version.");
|
if(BooleanUtils.isNotTrue(apiTableMetaData.getIsExcluded()))
|
||||||
|
{
|
||||||
|
validator.assertCondition(allVersions.contains(new APIVersion(apiTableMetaData.getInitialVersion())), "Table " + table.getName() + "'s initial API version is not a recognized version.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -373,4 +380,35 @@ public class ApiInstanceMetaData extends QMiddlewareInstanceMetaData
|
|||||||
return (this);
|
return (this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Getter for servers
|
||||||
|
*******************************************************************************/
|
||||||
|
public List<Server> getServers()
|
||||||
|
{
|
||||||
|
return (this.servers);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Setter for servers
|
||||||
|
*******************************************************************************/
|
||||||
|
public void setServers(List<Server> servers)
|
||||||
|
{
|
||||||
|
this.servers = servers;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Fluent setter for servers
|
||||||
|
*******************************************************************************/
|
||||||
|
public ApiInstanceMetaData withServers(List<Server> servers)
|
||||||
|
{
|
||||||
|
this.servers = servers;
|
||||||
|
return (this);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,6 @@
|
|||||||
mono-font="Monaco, Menlo, Consolas, source-code-pro, monospace"
|
mono-font="Monaco, Menlo, Consolas, source-code-pro, monospace"
|
||||||
font-size="large"
|
font-size="large"
|
||||||
show-header="false"
|
show-header="false"
|
||||||
allow-server-selection="false"
|
|
||||||
allow-spec-file-download="true"
|
allow-spec-file-download="true"
|
||||||
primary-color="{primaryColor}"
|
primary-color="{primaryColor}"
|
||||||
sort-endpoints-by="method"
|
sort-endpoints-by="method"
|
||||||
|
Reference in New Issue
Block a user