Added types declarations
This commit is contained in:
parent
857f9c63a6
commit
127e4013e0
7 changed files with 42 additions and 41 deletions
23
.gitignore
vendored
23
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
||||||
|
tapir-out/**
|
||||||
# ---> Scala
|
# ---> Scala
|
||||||
*.class
|
*.class
|
||||||
*.log
|
*.log
|
||||||
|
@ -39,25 +40,6 @@ replay_pid*
|
||||||
.idea/**
|
.idea/**
|
||||||
*.iml
|
*.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
|
# Gradle and Maven with auto-import
|
||||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
# 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
|
# since they will be recreated, and may cause churn. Uncomment if using
|
||||||
|
@ -74,9 +56,6 @@ replay_pid*
|
||||||
# CMake
|
# CMake
|
||||||
cmake-build-*/
|
cmake-build-*/
|
||||||
|
|
||||||
# Mongo Explorer plugin
|
|
||||||
.idea/**/mongoSettings.xml
|
|
||||||
|
|
||||||
# File-based project format
|
# File-based project format
|
||||||
*.iws
|
*.iws
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,15 @@
|
||||||
projekt/create/ -> createProjekt(
|
ProjektProperties(
|
||||||
|
id: String,
|
||||||
|
title: String,
|
||||||
|
description: String
|
||||||
|
)
|
||||||
|
|
||||||
|
/projekt/create -> createProjekt(
|
||||||
id: ProjektId,
|
id: ProjektId,
|
||||||
properties: ProjektProperties
|
properties: ProjektProperties
|
||||||
)
|
)
|
||||||
|
|
||||||
projekt/update/ -> updateProjekt(
|
/projekt/update -> updateProjekt(
|
||||||
id: ProjektId,
|
id: ProjektId,
|
||||||
properties: ProjektProperties
|
properties: ProjektProperties
|
||||||
)
|
)
|
|
@ -65,7 +65,8 @@ public class Generator implements Callable<Integer> {
|
||||||
this.verbose,
|
this.verbose,
|
||||||
this.outputDir,
|
this.outputDir,
|
||||||
this.templateDir,
|
this.templateDir,
|
||||||
transformer.getEndpoints()
|
transformer.getEndpoints(),
|
||||||
|
transformer.getDataTypes()
|
||||||
);
|
);
|
||||||
targetGenerator.generate();
|
targetGenerator.generate();
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -146,7 +146,7 @@ public class NodeTransformer {
|
||||||
SimpleNode payloadFieldParseNode =
|
SimpleNode payloadFieldParseNode =
|
||||||
assertSimpleNodeType(
|
assertSimpleNodeType(
|
||||||
compoundDatatTypeFields.jjtGetChild(i),
|
compoundDatatTypeFields.jjtGetChild(i),
|
||||||
TapirParserTreeConstants.JJTDATATYPEFIELDS
|
TapirParserTreeConstants.JJTDATATYPEFIELD
|
||||||
);
|
);
|
||||||
int numFieldNodes = payloadFieldParseNode.jjtGetNumChildren();
|
int numFieldNodes = payloadFieldParseNode.jjtGetNumChildren();
|
||||||
if (numFieldNodes != 2) {
|
if (numFieldNodes != 2) {
|
||||||
|
@ -173,7 +173,7 @@ public class NodeTransformer {
|
||||||
int numPathSegments = pathsParseNode.jjtGetNumChildren();
|
int numPathSegments = pathsParseNode.jjtGetNumChildren();
|
||||||
ArrayList<String> segments = new ArrayList<>();
|
ArrayList<String> segments = new ArrayList<>();
|
||||||
for (int i = 0; i < numPathSegments; i++) {
|
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));
|
segments.add(getStringValue(segmentParseNode));
|
||||||
}
|
}
|
||||||
return new PathsNode(segments);
|
return new PathsNode(segments);
|
||||||
|
|
|
@ -19,6 +19,7 @@ public class TargetGenerator {
|
||||||
private final boolean verbose;
|
private final boolean verbose;
|
||||||
public static String ENDPOINTS_TEMPLATE_NAME = "endpoints.ftl";
|
public static String ENDPOINTS_TEMPLATE_NAME = "endpoints.ftl";
|
||||||
private final List<EndpointNode> endpoints;
|
private final List<EndpointNode> endpoints;
|
||||||
|
private final List<DataTypeNode> dataTypes;
|
||||||
|
|
||||||
public static class TargetGeneratorException extends Exception {
|
public static class TargetGeneratorException extends Exception {
|
||||||
public TargetGeneratorException(String message) {
|
public TargetGeneratorException(String message) {
|
||||||
|
@ -34,7 +35,8 @@ public class TargetGenerator {
|
||||||
final boolean verbose,
|
final boolean verbose,
|
||||||
Path outputPath,
|
Path outputPath,
|
||||||
Path templatePath,
|
Path templatePath,
|
||||||
List<EndpointNode> endpoints
|
List<EndpointNode> endpoints,
|
||||||
|
List<DataTypeNode> dataTypes
|
||||||
) {
|
) {
|
||||||
this.verbose = verbose;
|
this.verbose = verbose;
|
||||||
this.outputPath = Objects.requireNonNull(
|
this.outputPath = Objects.requireNonNull(
|
||||||
|
@ -46,6 +48,7 @@ public class TargetGenerator {
|
||||||
"Template path is required"
|
"Template path is required"
|
||||||
);
|
);
|
||||||
this.endpoints = Objects.requireNonNull(endpoints);
|
this.endpoints = Objects.requireNonNull(endpoints);
|
||||||
|
this.dataTypes = Objects.requireNonNull(dataTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void generate() throws TargetGeneratorException {
|
public void generate() throws TargetGeneratorException {
|
||||||
|
@ -63,8 +66,9 @@ public class TargetGenerator {
|
||||||
StandardOpenOption.CREATE,
|
StandardOpenOption.CREATE,
|
||||||
StandardOpenOption.TRUNCATE_EXISTING
|
StandardOpenOption.TRUNCATE_EXISTING
|
||||||
)) {
|
)) {
|
||||||
HashMap<String, List<EndpointNode>> templateData = new HashMap<>();
|
HashMap<String, Object> templateData = new HashMap<>();
|
||||||
templateData.put("endpoints", endpoints);
|
templateData.put("endpoints", endpoints);
|
||||||
|
templateData.put("datatypes", dataTypes);
|
||||||
temp.process(templateData, outputFile);
|
temp.process(templateData, outputFile);
|
||||||
}
|
}
|
||||||
} catch (TemplateException | IOException ex) {
|
} catch (TemplateException | IOException ex) {
|
||||||
|
|
|
@ -36,7 +36,7 @@ TOKEN : {
|
||||||
void pathSegment() :
|
void pathSegment() :
|
||||||
{Token t;}
|
{Token t;}
|
||||||
{
|
{
|
||||||
t=<IDENTIFIER>{jjtThis.value = t.image;} <SLASH>
|
<SLASH> t=<IDENTIFIER>{jjtThis.value = t.image;}
|
||||||
}
|
}
|
||||||
|
|
||||||
void path() :
|
void path() :
|
||||||
|
|
|
@ -10,6 +10,14 @@ import sttp.tapir.Schema
|
||||||
class Endpoints(override val config: OAuthUtils.OAuthConfig) extends framework.service.api.Endpoints with RutTapir with RutUtilsCodec:
|
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]
|
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>
|
<#list endpoints as endpoint>
|
||||||
case class ${endpoint.handler.name?cap_first}(
|
case class ${endpoint.handler.name?cap_first}(
|
||||||
<#list endpoint.handler.fields as field>
|
<#list endpoint.handler.fields as field>
|
||||||
|
@ -18,20 +26,23 @@ class Endpoints(override val config: OAuthUtils.OAuthConfig) extends framework.s
|
||||||
)
|
)
|
||||||
</#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
|
given Codec[${endpoint.handler.name?cap_first}] = deriveCodec
|
||||||
</#list>
|
</#list>
|
||||||
|
|
||||||
<#list endpoints as endpoint>
|
<#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}, VersionedResponse] =
|
||||||
<#list endpoint.paths.paths>
|
<#list endpoint.paths.paths>
|
||||||
apiV1Endpoint
|
apiV1Endpoint
|
||||||
.post
|
.post
|
||||||
<#items as segment>
|
<#items as segment>
|
||||||
.in("${segment}")
|
.in("${segment}")
|
||||||
</#items>
|
</#items>
|
||||||
.post
|
.post
|
||||||
.in(jsonBody[${endpoint.handler.name?cap_first}])
|
.in(jsonBody[${endpoint.handler.name?cap_first}])
|
||||||
.out(jsonBody[VersionedResponse])
|
.out(jsonBody[VersionedResponse])
|
||||||
</#list>
|
</#list>
|
||||||
</#list>
|
</#list>
|
||||||
|
|
Loading…
Add table
Reference in a new issue