CE-1887 Checkstyle!

This commit is contained in:
2024-10-18 10:44:43 -05:00
parent 533822973b
commit 428e188b4b
15 changed files with 52 additions and 544 deletions

View File

@ -65,6 +65,7 @@ public class SchemaBuilder
}
/***************************************************************************
**
***************************************************************************/
@ -73,6 +74,7 @@ public class SchemaBuilder
private Class<?> originalClass;
/*******************************************************************************
** Getter for originalClass
**
@ -95,6 +97,7 @@ public class SchemaBuilder
}
/*******************************************************************************
** Fluent setter for originalClass
**
@ -187,23 +190,13 @@ public class SchemaBuilder
}
else
{
OpenAPIOneOf openAPIOneOfAnnotation = element.getAnnotation(OpenAPIOneOf.class);
OpenAPIMapKnownEntries openAPIMapKnownEntriesAnnotation = element.getAnnotation(OpenAPIMapKnownEntries.class);
OpenAPIOneOf openAPIOneOfAnnotation = element.getAnnotation(OpenAPIOneOf.class);
if(openAPIOneOfAnnotation != null)
{
String description = "[" + element + "]";
List<Schema> oneOfList = processOneOfAnnotation(openAPIOneOfAnnotation, c, description);
schema.withOneOf(oneOfList);
}
// todo no, lot like this else if(openAPIMapKnownEntriesAnnotation != null)
// todo no, lot like this {
// todo no, lot like this schema.withRef("#/components/schemas/" + openAPIMapKnownEntriesAnnotation.value().getSimpleName());
// todo no, lot like this // if(openAPIMapKnownEntriesAnnotation.additionalProperties())
// todo no, lot like this // {
// todo no, lot like this // schema.withAdditionalProperties(true);
// todo no, lot like this // }
// todo no, lot like this }
else
{
/////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -35,5 +35,8 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
public @interface OpenAPIDescription
{
/***************************************************************************
**
***************************************************************************/
String value();
}

View File

@ -36,6 +36,9 @@ import java.util.EnumSet;
@Retention(RetentionPolicy.RUNTIME)
public @interface OpenAPIEnumSubSet
{
/***************************************************************************
**
***************************************************************************/
Class<? extends EnumSubSet<?>> value();

View File

@ -35,5 +35,8 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
public @interface OpenAPIIncludeProperties
{
/***************************************************************************
**
***************************************************************************/
Class<?>[] ancestorClasses() default { };
}

View File

@ -35,7 +35,13 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
public @interface OpenAPIListItems
{
/***************************************************************************
**
***************************************************************************/
Class<?> value();
/***************************************************************************
**
***************************************************************************/
boolean useRef() default false;
}

View File

@ -35,7 +35,13 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
public @interface OpenAPIMapKnownEntries
{
/***************************************************************************
**
***************************************************************************/
Class<?> value();
/***************************************************************************
**
***************************************************************************/
boolean useRef() default false;
}

View File

@ -35,7 +35,13 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
public @interface OpenAPIMapValueType
{
/***************************************************************************
**
***************************************************************************/
Class<?> value();
/***************************************************************************
**
***************************************************************************/
boolean useRef() default false;
}

View File

@ -35,8 +35,14 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
public @interface OpenAPIOneOf
{
/***************************************************************************
**
***************************************************************************/
Mode mode() default Mode.PERMITTED_SUBCLASSES;
/***************************************************************************
**
***************************************************************************/
Class<?>[] options() default { };

View File

@ -153,6 +153,7 @@ public abstract class AbstractEndpointSpec<
case PUT -> ApiBuilder.put(fullPath, handler);
case PATCH -> ApiBuilder.patch(fullPath, handler);
case DELETE -> ApiBuilder.delete(fullPath, handler);
default -> throw new IllegalStateException("Unexpected value: " + completeOperation.getHttpMethod());
}
}

View File

@ -167,6 +167,7 @@ public abstract class AbstractMiddlewareVersion
warnIfPathMethodAlreadyUsed(path.getDelete(), completeOperation, spec);
path.withDelete(method);
}
default -> throw new IllegalStateException("Unexpected value: " + completeOperation.getHttpMethod());
}
for(Map.Entry<String, Schema> entry : CollectionUtils.nonNullMap(spec.defineComponentSchemas()).entrySet())

View File

@ -27,7 +27,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import com.kingsrook.qqq.middleware.javalin.executors.io.QueryMiddlewareInput;
import com.kingsrook.qqq.backend.core.context.QContext;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QCriteriaOperator;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QFilterCriteria;
@ -36,6 +35,7 @@ import com.kingsrook.qqq.backend.core.model.actions.tables.query.QueryJoin;
import com.kingsrook.qqq.backend.core.utils.JsonUtils;
import com.kingsrook.qqq.backend.core.utils.StringUtils;
import com.kingsrook.qqq.backend.core.utils.collections.MapBuilder;
import com.kingsrook.qqq.middleware.javalin.executors.io.QueryMiddlewareInput;
import com.kingsrook.qqq.openapi.model.Schema;
import com.kingsrook.qqq.openapi.model.Type;
import org.json.JSONArray;

View File

@ -1,356 +0,0 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2024. Kingsrook, LLC
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
* contact@kingsrook.com
* https://github.com/Kingsrook/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.kingsrook.qqq.api.wip;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;
import java.util.stream.Stream;
import io.javalin.config.Key;
import io.javalin.http.Context;
import io.javalin.http.HandlerType;
import io.javalin.http.HttpStatus;
import io.javalin.json.JsonMapper;
import io.javalin.plugin.ContextPlugin;
import io.javalin.security.RouteRole;
import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
/*******************************************************************************
**
*******************************************************************************/
public class TestContext implements Context
{
private Map<String, String> queryParams = new LinkedHashMap<>();
private Map<String, String> pathParams = new LinkedHashMap<>();
private Map<String, String> formParams = new LinkedHashMap<>();
private InputStream result;
/*******************************************************************************
** Constructor
**
*******************************************************************************/
public TestContext()
{
}
/***************************************************************************
**
***************************************************************************/
public TestContext withQueryParam(String key, String value)
{
queryParams.put(key, value);
return (this);
}
/***************************************************************************
**
***************************************************************************/
public TestContext withPathParam(String key, String value)
{
pathParams.put(key, value);
return (this);
}
/***************************************************************************
**
***************************************************************************/
public TestContext withFormParam(String key, String value)
{
formParams.put(key, value);
return (this);
}
/***************************************************************************
**
***************************************************************************/
@Override
public String queryParam(String key)
{
return queryParams.get(key);
}
/***************************************************************************
**
***************************************************************************/
@Override
public String formParam(String key)
{
return formParams.get(key);
}
/***************************************************************************
**
***************************************************************************/
@Override
public boolean strictContentTypes()
{
return false;
}
/***************************************************************************
**
***************************************************************************/
@Override
public HttpServletRequest req()
{
return null;
}
/***************************************************************************
**
***************************************************************************/
@Override
public HttpServletResponse res()
{
return null;
}
/***************************************************************************
**
***************************************************************************/
@Override
public HandlerType handlerType()
{
return null;
}
/***************************************************************************
**
***************************************************************************/
@Override
public String matchedPath()
{
return "";
}
/***************************************************************************
**
***************************************************************************/
@Override
public String endpointHandlerPath()
{
return "";
}
/***************************************************************************
**
***************************************************************************/
@Override
public <T> T appData(Key<T> key)
{
return null;
}
/***************************************************************************
**
***************************************************************************/
@Override
public JsonMapper jsonMapper()
{
return null;
}
/***************************************************************************
**
***************************************************************************/
@Override
public <T> T with(Class<? extends ContextPlugin<?, T>> aClass)
{
return null;
}
/***************************************************************************
**
***************************************************************************/
@Override
public String pathParam(String key)
{
return pathParams.get(key);
}
/***************************************************************************
**
***************************************************************************/
@Override
public Map<String, String> pathParamMap()
{
return pathParams;
}
/***************************************************************************
**
***************************************************************************/
@Override
public ServletOutputStream outputStream()
{
return null;
}
/***************************************************************************
**
***************************************************************************/
@Override
public Context minSizeForCompression(int i)
{
return null;
}
/***************************************************************************
**
***************************************************************************/
@Override
public Context result(InputStream inputStream)
{
this.result = inputStream;
return (this);
}
/***************************************************************************
**
***************************************************************************/
@Override
public InputStream resultInputStream()
{
return null;
}
/***************************************************************************
**
***************************************************************************/
@Override
public void future(Supplier<? extends CompletableFuture<?>> supplier)
{
}
/***************************************************************************
**
***************************************************************************/
@Override
public void redirect(String s, HttpStatus httpStatus)
{
}
/***************************************************************************
**
***************************************************************************/
@Override
public void writeJsonStream(Stream<?> stream)
{
}
/***************************************************************************
**
***************************************************************************/
@Override
public Context skipRemainingHandlers()
{
return null;
}
/***************************************************************************
**
***************************************************************************/
@Override
public Set<RouteRole> routeRoles()
{
return Set.of();
}
/*******************************************************************************
** Getter for response
**
*******************************************************************************/
public String getResultAsString() throws IOException
{
byte[] bytes = IOUtils.readFully(result, result.available());
return new String(bytes, StandardCharsets.UTF_8);
}
}

View File

@ -1,92 +0,0 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2024. Kingsrook, LLC
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
* contact@kingsrook.com
* https://github.com/Kingsrook/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.kingsrook.qqq.api.wip;
import java.util.Map;
import com.kingsrook.qqq.openapi.model.Schema;
import com.kingsrook.qqq.openapi.model.Type;
import org.assertj.core.api.AbstractStringAssert;
import org.json.JSONArray;
import org.json.JSONObject;
import static org.assertj.core.api.Assertions.assertThat;
/*******************************************************************************
**
*******************************************************************************/
public class TestUtils
{
/***************************************************************************
**
***************************************************************************/
private static void assertStringVsSchema(String string, Schema schema, String path)
{
String description = "At path " + path;
final AbstractStringAssert<?> assertion = assertThat(string).describedAs(description);
Type type = Type.valueOf(schema.getType().toUpperCase());
switch(type)
{
case OBJECT ->
{
assertion.startsWith("{");
JSONObject object = new JSONObject(string);
for(Map.Entry<String, Schema> entry : schema.getProperties().entrySet())
{
// todo deal with optional
Object subObject = object.get(entry.getKey());
assertStringVsSchema(subObject.toString(), entry.getValue(), path + "/" + entry.getKey());
}
}
case ARRAY ->
{
assertion.startsWith("[");
JSONArray array = new JSONArray(string);
for(int i = 0; i < array.length(); i++)
{
Object subObject = array.get(i);
assertStringVsSchema(subObject.toString(), schema.getItems(), path + "[" + i + "]");
}
}
case BOOLEAN ->
{
assertion.matches("(true|false)");
}
case INTEGER ->
{
assertion.matches("-?\\d+");
}
case NUMBER ->
{
assertion.matches("-?\\d+(\\.\\d+)?");
}
case STRING ->
{
assertion.matches("\".*\"");
}
}
}
}

View File

@ -1,75 +0,0 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2024. Kingsrook, LLC
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
* contact@kingsrook.com
* https://github.com/Kingsrook/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.kingsrook.qqq.api.wip.v1;
import com.kingsrook.qqq.api.wip.TestContext;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QueryInput;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QueryOutput;
import com.kingsrook.qqq.backend.core.model.data.QRecord;
import org.junit.jupiter.api.Test;
/*******************************************************************************
** Unit test for QueryGetSpecV1
*******************************************************************************/
class QueryGetSpecV1Test
{
/***************************************************************************
**
***************************************************************************/
@Test
void testBuildInput() throws Exception
{
TestContext context = new TestContext()
.withPathParam("table", "person")
.withQueryParam("filter", "{}");
// QueryMiddlewareInput queryMiddlewareInput = new QueryGetSpecV1().buildInput(context);
// assertEquals("person", queryMiddlewareInput.getTable());
// assertNotNull(queryMiddlewareInput.getFilter());
// assertEquals(0, queryMiddlewareInput.getFilter().getCriteria().size());
// assertEquals(0, queryMiddlewareInput.getFilter().getOrderBys().size());
// assertNull(queryMiddlewareInput.getQueryJoins());
}
/***************************************************************************
**
***************************************************************************/
@Test
void testBuildOutput() throws Exception
{
TestContext context = new TestContext();
QueryOutput queryOutput = new QueryOutput(new QueryInput());
queryOutput.addRecord(new QRecord().withValue("firstName", "Darin").withDisplayValue("firstName", "Darin"));
// QueryGetSpecV1 queryGetSpecV1 = new QueryGetSpecV1();
// queryGetSpecV1.buildOutput(context, new QueryMiddlewareOutput(queryOutput));
// String resultJson = context.getResultAsString();
// TestUtils.assertResultJsonVsSpec(queryGetSpecV1.defineSimpleSuccessResponse(), resultJson);
}
}

View File

@ -200,6 +200,9 @@ public class TestUtils
/***************************************************************************
**
***************************************************************************/
private static void defineApps(QInstance qInstance)
{
QAppMetaData childApp = new QAppMetaData()
@ -440,7 +443,7 @@ public class TestUtils
return new QProcessMetaData()
.withName("greet")
.withTableName(TABLE_NAME_PERSON)
.addStep(new QBackendStepMetaData()
.withStep(new QBackendStepMetaData()
.withName("prepare")
.withCode(new QCodeReference()
.withName(MockBackendStep.class.getName())
@ -472,13 +475,13 @@ public class TestUtils
.withName(PROCESS_NAME_GREET_PEOPLE_INTERACTIVE)
.withTableName(TABLE_NAME_PERSON)
.addStep(new QFrontendStepMetaData()
.withStep(new QFrontendStepMetaData()
.withName("setup")
.withFormField(new QFieldMetaData("greetingPrefix", QFieldType.STRING))
.withFormField(new QFieldMetaData("greetingSuffix", QFieldType.STRING))
)
.addStep(new QBackendStepMetaData()
.withStep(new QBackendStepMetaData()
.withName("doWork")
.withCode(new QCodeReference()
.withName(MockBackendStep.class.getName())
@ -497,7 +500,7 @@ public class TestUtils
.withFieldList(List.of(new QFieldMetaData("outputMessage", QFieldType.STRING))))
)
.addStep(new QFrontendStepMetaData()
.withStep(new QFrontendStepMetaData()
.withName("results")
.withFormField(new QFieldMetaData("outputMessage", QFieldType.STRING))
);
@ -528,7 +531,7 @@ public class TestUtils
return new QProcessMetaData()
.withName(PROCESS_NAME_SIMPLE_SLEEP)
.withIsHidden(true)
.addStep(SleeperStep.getMetaData());
.withStep(SleeperStep.getMetaData());
}
@ -540,11 +543,11 @@ public class TestUtils
{
return new QProcessMetaData()
.withName(PROCESS_NAME_SLEEP_INTERACTIVE)
.addStep(new QFrontendStepMetaData()
.withStep(new QFrontendStepMetaData()
.withName(SCREEN_0)
.withFormField(new QFieldMetaData("outputMessage", QFieldType.STRING)))
.addStep(SleeperStep.getMetaData())
.addStep(new QFrontendStepMetaData()
.withStep(SleeperStep.getMetaData())
.withStep(new QFrontendStepMetaData()
.withName(SCREEN_1)
.withFormField(new QFieldMetaData("outputMessage", QFieldType.STRING)));
}
@ -558,7 +561,7 @@ public class TestUtils
{
return new QProcessMetaData()
.withName(PROCESS_NAME_SIMPLE_THROW)
.addStep(ThrowerStep.getMetaData());
.withStep(ThrowerStep.getMetaData());
}