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(
|
ProjektProperties(
|
||||||
id: String,
|
|
||||||
title: String,
|
title: String,
|
||||||
description: String
|
description: String
|
||||||
)
|
)
|
||||||
|
|
||||||
/projekt/create -> createProjekt(
|
/createProject -> (
|
||||||
id: ProjektId,
|
id: ProjektId,
|
||||||
properties: ProjektProperties
|
properties: ProjektProperties
|
||||||
)
|
)
|
||||||
|
|
||||||
/projekt/update -> updateProjekt(
|
/updateProject -> (
|
||||||
id: ProjektId,
|
id: ProjektId,
|
||||||
properties: ProjektProperties
|
properties: ProjektProperties
|
||||||
)
|
)
|
|
@ -114,9 +114,10 @@ public class NodeTransformer {
|
||||||
SimpleNode handlerParseNode =
|
SimpleNode handlerParseNode =
|
||||||
assertSimpleNodeType(
|
assertSimpleNodeType(
|
||||||
node.jjtGetChild(1),
|
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);
|
return new EndpointNode(pathsNode, handlerNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,25 +56,26 @@ public class TargetGenerator {
|
||||||
cfg.setLogTemplateExceptions(false);
|
cfg.setLogTemplateExceptions(false);
|
||||||
cfg.setWrapUncheckedExceptions(true);
|
cfg.setWrapUncheckedExceptions(true);
|
||||||
cfg.setFallbackOnNullLoopVariable(false);
|
cfg.setFallbackOnNullLoopVariable(false);
|
||||||
Template temp = cfg.getTemplate(ENDPOINTS_TEMPLATE_NAME);
|
|
||||||
List<Path> templates = Files
|
List<Path> templates = Files
|
||||||
.list(this.templatePath)
|
.list(this.templatePath)
|
||||||
.filter(Files::isRegularFile)
|
.filter(Files::isRegularFile)
|
||||||
.filter(f -> f.getFileName().toString().endsWith(".ftl"))
|
.filter(f -> f.getFileName().toString().endsWith(".ftl"))
|
||||||
.toList() ;
|
.toList() ;
|
||||||
for (Path template : templates) {
|
for (Path templatePath : templates) {
|
||||||
try (var outputFile = Files.newBufferedWriter(
|
try (var outputFile = Files.newBufferedWriter(
|
||||||
outputName(template),
|
outputName(templatePath),
|
||||||
StandardOpenOption.CREATE,
|
StandardOpenOption.CREATE,
|
||||||
StandardOpenOption.TRUNCATE_EXISTING
|
StandardOpenOption.TRUNCATE_EXISTING
|
||||||
)) {
|
)) {
|
||||||
if (this.verbose) {
|
if (this.verbose) {
|
||||||
System.out.println("Processing " + template);
|
System.out.println("Processing " + templatePath);
|
||||||
}
|
}
|
||||||
HashMap<String, Object> templateData = new HashMap<>();
|
HashMap<String, Object> templateData = new HashMap<>();
|
||||||
templateData.put("endpoints", endpoints);
|
templateData.put("endpoints", endpoints);
|
||||||
templateData.put("datatypes", dataTypes);
|
templateData.put("datatypes", dataTypes);
|
||||||
temp.process(templateData, outputFile);
|
cfg.getTemplate(
|
||||||
|
templatePath.getFileName().toString()
|
||||||
|
).process(templateData, outputFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (TemplateException | IOException ex) {
|
} catch (TemplateException | IOException ex) {
|
||||||
|
|
|
@ -90,7 +90,7 @@ void dataTypes() :
|
||||||
void endpoint() :
|
void endpoint() :
|
||||||
{}
|
{}
|
||||||
{
|
{
|
||||||
path() <TRANSITION> compoundDataType()
|
path() <TRANSITION> <OPENPARANTHESIS> dataTypeFields() <CLOSEPARANTHESIS>
|
||||||
}
|
}
|
||||||
|
|
||||||
void endpoints() :
|
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.projekt.api.HttpProtocol.VersionedResponse
|
||||||
import se.rutdev.framework.json.circe.RutUtilsCodec
|
import se.rutdev.framework.json.circe.RutUtilsCodec
|
||||||
|
@ -19,22 +19,15 @@ class Endpoints(override val config: OAuthUtils.OAuthConfig) extends framework.s
|
||||||
</#list>
|
</#list>
|
||||||
|
|
||||||
<#list endpoints as endpoint>
|
<#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>
|
<#list endpoint.handler.fields as field>
|
||||||
${field.name} : ${field.type},
|
${field.name} : ${field.type},
|
||||||
</#list>
|
</#list>
|
||||||
)
|
)
|
||||||
</#list>
|
</#list>
|
||||||
|
|
||||||
<#list datatypes as datatype>
|
|
||||||
given Codec[${datatype.name?cap_first}] = deriveCodec
|
|
||||||
</#list>
|
|
||||||
<#list endpoints as endpoint>
|
<#list endpoints as endpoint>
|
||||||
given Codec[${endpoint.handler.name?cap_first}] = deriveCodec
|
val ${endpoint.handler.name}Endpoint = ApiEndpoint[${endpoint.handler.name?cap_first}Payload, VersionedResponse] =
|
||||||
</#list>
|
|
||||||
|
|
||||||
<#list endpoints as endpoint>
|
|
||||||
val ${endpoint.handler.name}Endpoint = ApiEndpoint[${endpoint.handler.name?cap_first}, VersionedResponse] =
|
|
||||||
<#list endpoint.paths.paths>
|
<#list endpoint.paths.paths>
|
||||||
apiV1Endpoint
|
apiV1Endpoint
|
||||||
.post
|
.post
|
||||||
|
@ -42,7 +35,7 @@ class Endpoints(override val config: OAuthUtils.OAuthConfig) extends framework.s
|
||||||
.in("${segment}")
|
.in("${segment}")
|
||||||
</#items>
|
</#items>
|
||||||
.post
|
.post
|
||||||
.in(jsonBody[${endpoint.handler.name?cap_first}])
|
.in(jsonBody[${endpoint.handler.name?cap_first}Payload])
|
||||||
.out(jsonBody[VersionedResponse])
|
.out(jsonBody[VersionedResponse])
|
||||||
</#list>
|
</#list>
|
||||||
</#list>
|
</#list>
|
||||||
|
|
Loading…
Add table
Reference in a new issue