diff --git a/endpoints-templates/Codecs.ftl b/endpoints-templates/Codecs.ftl
new file mode 100644
index 0000000..91a06d3
--- /dev/null
+++ b/endpoints-templates/Codecs.ftl
@@ -0,0 +1,6 @@
+package se.senashdev.projekt.api
+
+object Codecs:
+<#list typeDefinitions as type>
+ given Codec[${type.name?cap_first}] = deriveCodec
+#list>
diff --git a/endpoints-templates/Endpoints.ftl b/endpoints-templates/Endpoints.ftl
new file mode 100644
index 0000000..fc1749a
--- /dev/null
+++ b/endpoints-templates/Endpoints.ftl
@@ -0,0 +1,27 @@
+package se.senashdev.projekt.api
+
+import se.rutdev.projekt.api.HttpProtocol.VersionedResponse
+import se.rutdev.framework.json.circe.RutUtilsCodec
+import se.rutdev.framework
+import se.rutdev.framework.service.api.{OAuthUtils, RequestMeta, RutTapir}
+import se.rutdev.pd.ProblemDetailProtocol.ProblemDetail
+import sttp.tapir.Schema
+import se.senashdev.projekt.api.Protocol.*
+import se.senashdev.projekt.api.Codecs._
+
+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 endpoints as endpoint>
+ val ${endpoint.inputType}Endpoint = ApiEndpoint[${endpoint.inputType?cap_first}, VersionedResponse] =
+ <#list endpoint.paths.paths>
+ apiV1Endpoint
+ .post
+ <#items as segment>
+ .in("${segment}")
+ #items>
+ .in(jsonBody[${endpoint.inputType?cap_first}])
+ .out(jsonBody[VersionedResponse])
+
+ #list>
+#list>
\ No newline at end of file
diff --git a/endpoints-templates/Protocol.ftl b/endpoints-templates/Protocol.ftl
new file mode 100644
index 0000000..96423b7
--- /dev/null
+++ b/endpoints-templates/Protocol.ftl
@@ -0,0 +1,10 @@
+package se.senashdev.projekt.api
+
+object Protocol:
+<#list typeDefinitions as type>
+ case class ${type.name?cap_first}(
+ <#list type.fields as field>
+ ${field.name} : ${field.type},
+ #list>
+ )
+#list>
diff --git a/parser/pom.xml b/parser/pom.xml
index 40af316..1f7e1d8 100644
--- a/parser/pom.xml
+++ b/parser/pom.xml
@@ -24,9 +24,9 @@
4.7.6
- gg.jte
- jte
- 3.2.0
+ org.freemarker
+ freemarker
+ 2.3.34
diff --git a/parser/src/main/java/nu/zoom/dsl/ast/EndpointsVisitorTransformer.java b/parser/src/main/java/nu/zoom/dsl/ast/EndpointsVisitorTransformer.java
index d175077..e5892c1 100644
--- a/parser/src/main/java/nu/zoom/dsl/ast/EndpointsVisitorTransformer.java
+++ b/parser/src/main/java/nu/zoom/dsl/ast/EndpointsVisitorTransformer.java
@@ -57,7 +57,7 @@ public class EndpointsVisitorTransformer extends EndpointsBaseVisitor generate() throws IOException {
- List templates = Files.list(templatesDir).filter(p -> p.toString().endsWith(".jte")).toList() ;
+ public List generate() throws IOException, TemplateException {
+ List templates = Files.list(templatesDir).filter(p -> p.toString().endsWith(".ftl")).toList() ;
ArrayList out = new ArrayList<>();
for (Path template : templates) {
// TODO file ending
- Path outpath = outputDir.resolve(template.getFileName());
- this.templateEngine.render(template.getFileName().toString(), this.data, new FileOutput(outpath));
- out.add(outpath);
+ Path outpath = outputDir.resolve(outputFilenameFromTemplate(template.getFileName()));
+ Template ftl = this.cfg.getTemplate(template.getFileName().toString()) ;
+ try (var outw = Files.newBufferedWriter(outpath, StandardCharsets.UTF_8)) {
+ ftl.process(this.data, outw);
+ out.add(outpath);
+ }
}
return out ;
}
+
+ private String outputFilenameFromTemplate(Path template) {
+ return template.getFileName().toString().replace(".ftl", ".scala");
+ }
}
diff --git a/test01.endpoints b/test01.endpoints
index 6ba4a95..0beb7d5 100644
--- a/test01.endpoints
+++ b/test01.endpoints
@@ -1,10 +1,2 @@
-{
- config:foo
-}
-
-SomeType(
- foo:bar
-)
-
-/some/endpoint < SomeType
-/some/other/endpoint < SomeOtherType(bar:String)
\ No newline at end of file
+/some/endpoint < SomeType(foo:String)
+/some/other/endpoint < SomeOtherType(bar:Embedded)
\ No newline at end of file