Remove handler name, use the last path segment to name the payload class
This commit is contained in:
parent
92098b1a3b
commit
20aa2becfb
6 changed files with 24 additions and 22 deletions
|
@ -1,15 +1,14 @@
|
|||
ProjektProperties(
|
||||
id: String,
|
||||
title: String,
|
||||
description: String
|
||||
)
|
||||
|
||||
/projekt/create -> createProjekt(
|
||||
/createProject -> (
|
||||
id: ProjektId,
|
||||
properties: ProjektProperties
|
||||
)
|
||||
|
||||
/projekt/update -> updateProjekt(
|
||||
/updateProject -> (
|
||||
id: ProjektId,
|
||||
properties: ProjektProperties
|
||||
)
|
|
@ -114,9 +114,10 @@ public class NodeTransformer {
|
|||
SimpleNode handlerParseNode =
|
||||
assertSimpleNodeType(
|
||||
node.jjtGetChild(1),
|
||||
TapirParserTreeConstants.JJTCOMPOUNDDATATYPE
|
||||
TapirParserTreeConstants.JJTDATATYPEFIELDS
|
||||
);
|
||||
HandlerNode handlerNode = handleHandler(handlerParseNode);
|
||||
List<FieldNode> fields = handleFields(handlerParseNode);
|
||||
HandlerNode handlerNode = new HandlerNode(pathsNode.paths().getLast(), fields);
|
||||
return new EndpointNode(pathsNode, handlerNode);
|
||||
}
|
||||
|
||||
|
|
|
@ -56,25 +56,26 @@ public class TargetGenerator {
|
|||
cfg.setLogTemplateExceptions(false);
|
||||
cfg.setWrapUncheckedExceptions(true);
|
||||
cfg.setFallbackOnNullLoopVariable(false);
|
||||
Template temp = cfg.getTemplate(ENDPOINTS_TEMPLATE_NAME);
|
||||
List<Path> templates = Files
|
||||
.list(this.templatePath)
|
||||
.filter(Files::isRegularFile)
|
||||
.filter(f -> f.getFileName().toString().endsWith(".ftl"))
|
||||
.toList() ;
|
||||
for (Path template : templates) {
|
||||
for (Path templatePath : templates) {
|
||||
try (var outputFile = Files.newBufferedWriter(
|
||||
outputName(template),
|
||||
outputName(templatePath),
|
||||
StandardOpenOption.CREATE,
|
||||
StandardOpenOption.TRUNCATE_EXISTING
|
||||
)) {
|
||||
if (this.verbose) {
|
||||
System.out.println("Processing " + template);
|
||||
System.out.println("Processing " + templatePath);
|
||||
}
|
||||
HashMap<String, Object> templateData = new HashMap<>();
|
||||
templateData.put("endpoints", endpoints);
|
||||
templateData.put("datatypes", dataTypes);
|
||||
temp.process(templateData, outputFile);
|
||||
cfg.getTemplate(
|
||||
templatePath.getFileName().toString()
|
||||
).process(templateData, outputFile);
|
||||
}
|
||||
}
|
||||
} catch (TemplateException | IOException ex) {
|
||||
|
|
|
@ -90,7 +90,7 @@ void dataTypes() :
|
|||
void endpoint() :
|
||||
{}
|
||||
{
|
||||
path() <TRANSITION> compoundDataType()
|
||||
path() <TRANSITION> <OPENPARANTHESIS> dataTypeFields() <CLOSEPARANTHESIS>
|
||||
}
|
||||
|
||||
void endpoints() :
|
||||
|
|
8
tapir-templates/codec.ftl
Normal file
8
tapir-templates/codec.ftl
Normal file
|
@ -0,0 +1,8 @@
|
|||
object Codecs:
|
||||
|
||||
<#list datatypes as datatype>
|
||||
given Codec[${datatype.name?cap_first}] = deriveCodec
|
||||
</#list>
|
||||
<#list endpoints as endpoint>
|
||||
given Codec[${endpoint.handler.name?cap_first}Payload] = deriveCodec
|
||||
</#list>
|
|
@ -1,4 +1,4 @@
|
|||
package se.senashdev.projekt.api
|
||||
package se.senashdev.project.api
|
||||
|
||||
import se.rutdev.projekt.api.HttpProtocol.VersionedResponse
|
||||
import se.rutdev.framework.json.circe.RutUtilsCodec
|
||||
|
@ -19,22 +19,15 @@ class Endpoints(override val config: OAuthUtils.OAuthConfig) extends framework.s
|
|||
</#list>
|
||||
|
||||
<#list endpoints as endpoint>
|
||||
case class ${endpoint.handler.name?cap_first}(
|
||||
case class ${endpoint.handler.name?cap_first}Payload(
|
||||
<#list endpoint.handler.fields as field>
|
||||
${field.name} : ${field.type},
|
||||
</#list>
|
||||
)
|
||||
</#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] =
|
||||
val ${endpoint.handler.name}Endpoint = ApiEndpoint[${endpoint.handler.name?cap_first}Payload, VersionedResponse] =
|
||||
<#list endpoint.paths.paths>
|
||||
apiV1Endpoint
|
||||
.post
|
||||
|
@ -42,7 +35,7 @@ class Endpoints(override val config: OAuthUtils.OAuthConfig) extends framework.s
|
|||
.in("${segment}")
|
||||
</#items>
|
||||
.post
|
||||
.in(jsonBody[${endpoint.handler.name?cap_first}])
|
||||
.in(jsonBody[${endpoint.handler.name?cap_first}Payload])
|
||||
.out(jsonBody[VersionedResponse])
|
||||
</#list>
|
||||
</#list>
|
||||
|
|
Loading…
Add table
Reference in a new issue