Added types declarations

This commit is contained in:
Johan Maasing 2025-03-19 21:19:56 +01:00
parent 857f9c63a6
commit 127e4013e0
Signed by: johan
GPG key ID: FFD31BABEE2DEED2
7 changed files with 42 additions and 41 deletions

23
.gitignore vendored
View file

@ -1,3 +1,4 @@
tapir-out/**
# ---> Scala
*.class
*.log
@ -39,25 +40,6 @@ replay_pid*
.idea/**
*.iml
# AWS User-specific
.idea/**/aws.xml
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
@ -74,9 +56,6 @@ replay_pid*
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws

View file

@ -1,9 +1,15 @@
projekt/create/ -> createProjekt(
ProjektProperties(
id: String,
title: String,
description: String
)
/projekt/create -> createProjekt(
id: ProjektId,
properties: ProjektProperties
)
projekt/update/ -> updateProjekt(
/projekt/update -> updateProjekt(
id: ProjektId,
properties: ProjektProperties
)

View file

@ -65,7 +65,8 @@ public class Generator implements Callable<Integer> {
this.verbose,
this.outputDir,
this.templateDir,
transformer.getEndpoints()
transformer.getEndpoints(),
transformer.getDataTypes()
);
targetGenerator.generate();
return 0;

View file

@ -146,7 +146,7 @@ public class NodeTransformer {
SimpleNode payloadFieldParseNode =
assertSimpleNodeType(
compoundDatatTypeFields.jjtGetChild(i),
TapirParserTreeConstants.JJTDATATYPEFIELDS
TapirParserTreeConstants.JJTDATATYPEFIELD
);
int numFieldNodes = payloadFieldParseNode.jjtGetNumChildren();
if (numFieldNodes != 2) {
@ -173,7 +173,7 @@ public class NodeTransformer {
int numPathSegments = pathsParseNode.jjtGetNumChildren();
ArrayList<String> segments = new ArrayList<>();
for (int i = 0; i < numPathSegments; i++) {
SimpleNode segmentParseNode = assertSimpleNodeType(pathsParseNode.jjtGetChild(i), TapirParserTreeConstants.JJTPATH);
SimpleNode segmentParseNode = assertSimpleNodeType(pathsParseNode.jjtGetChild(i), TapirParserTreeConstants.JJTPATHSEGMENT);
segments.add(getStringValue(segmentParseNode));
}
return new PathsNode(segments);

View file

@ -19,6 +19,7 @@ public class TargetGenerator {
private final boolean verbose;
public static String ENDPOINTS_TEMPLATE_NAME = "endpoints.ftl";
private final List<EndpointNode> endpoints;
private final List<DataTypeNode> dataTypes;
public static class TargetGeneratorException extends Exception {
public TargetGeneratorException(String message) {
@ -34,7 +35,8 @@ public class TargetGenerator {
final boolean verbose,
Path outputPath,
Path templatePath,
List<EndpointNode> endpoints
List<EndpointNode> endpoints,
List<DataTypeNode> dataTypes
) {
this.verbose = verbose;
this.outputPath = Objects.requireNonNull(
@ -46,6 +48,7 @@ public class TargetGenerator {
"Template path is required"
);
this.endpoints = Objects.requireNonNull(endpoints);
this.dataTypes = Objects.requireNonNull(dataTypes);
}
public void generate() throws TargetGeneratorException {
@ -63,8 +66,9 @@ public class TargetGenerator {
StandardOpenOption.CREATE,
StandardOpenOption.TRUNCATE_EXISTING
)) {
HashMap<String, List<EndpointNode>> templateData = new HashMap<>();
HashMap<String, Object> templateData = new HashMap<>();
templateData.put("endpoints", endpoints);
templateData.put("datatypes", dataTypes);
temp.process(templateData, outputFile);
}
} catch (TemplateException | IOException ex) {

View file

@ -36,7 +36,7 @@ TOKEN : {
void pathSegment() :
{Token t;}
{
t=<IDENTIFIER>{jjtThis.value = t.image;} <SLASH>
<SLASH> t=<IDENTIFIER>{jjtThis.value = t.image;}
}
void path() :

View file

@ -10,6 +10,14 @@ import sttp.tapir.Schema
class Endpoints(override val config: OAuthUtils.OAuthConfig) extends framework.service.api.Endpoints with RutTapir with RutUtilsCodec:
type ApiEndpoint[I, O] = OAuthEndpoint[RequestMeta.OAuthRequestMeta, I, ProblemDetail, O]
<#list datatypes as datatype>
case class ${datatype.name}(
<#list datatype.fields as field>
${field.name} : ${field.type},
</#list>
)
</#list>
<#list endpoints as endpoint>
case class ${endpoint.handler.name?cap_first}(
<#list endpoint.handler.fields as field>
@ -18,20 +26,23 @@ class Endpoints(override val config: OAuthUtils.OAuthConfig) extends framework.s
)
</#list>
<#list datatypes as datatype>
given Codec[${datatype.name?cap_first}] = deriveCodec
</#list>
<#list endpoints as endpoint>
given Codec[${endpoint.handler.name?cap_first}] = deriveCodec
</#list>
<#list endpoints as endpoint>
val ${endpoint.handler.name}Endpoint = ApiEndpoint[${endpoint.handler.name?cap_first}, VersionedResponse] =
<#list endpoint.paths.paths>
apiV1Endpoint
.post
<#items as segment>
.in("${segment}")
</#items>
.post
.in(jsonBody[${endpoint.handler.name?cap_first}])
.out(jsonBody[VersionedResponse])
</#list>
val ${endpoint.handler.name}Endpoint = ApiEndpoint[${endpoint.handler.name?cap_first}, VersionedResponse] =
<#list endpoint.paths.paths>
apiV1Endpoint
.post
<#items as segment>
.in("${segment}")
</#items>
.post
.in(jsonBody[${endpoint.handler.name?cap_first}])
.out(jsonBody[VersionedResponse])
</#list>
</#list>