Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ samtw.bat

# Random files used for debugging
specification/examples/debug.samt

# Codegen Output
out/
13 changes: 8 additions & 5 deletions codegen/src/main/kotlin/tools/samt/codegen/PublicApiMapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class PublicApiMapper(

fun toPublicApi(samtPackage: tools.samt.semantic.Package) = object : SamtPackage {
override val name = samtPackage.name
override val qualifiedName = samtPackage.nameComponents.joinToString(".")
override val qualifiedName = samtPackage.qualifiedName
override val records = samtPackage.records.map { it.toPublicRecord() }
override val enums = samtPackage.enums.map { it.toPublicEnum() }
override val services = samtPackage.services.map { it.toPublicService() }
Expand Down Expand Up @@ -146,7 +146,7 @@ class PublicApiMapper(
}

private fun tools.samt.semantic.ProviderType.Implements.toPublicImplements() = object : ProvidedService {
override val service = this@toPublicImplements.service.toPublicTypeReference().type as ServiceType
override val service by unsafeLazy { this@toPublicImplements.service.toPublicTypeReference().type as ServiceType }
private val implementedOperationNames by unsafeLazy { this@toPublicImplements.operations.mapTo(mutableSetOf()) { it.name } }
override val implementedOperations by unsafeLazy { service.operations.filter { it.name in implementedOperationNames } }
override val unimplementedOperations by unsafeLazy { service.operations.filter { it.name !in implementedOperationNames } }
Expand All @@ -155,7 +155,7 @@ class PublicApiMapper(
private fun tools.samt.semantic.ConsumerType.toPublicConsumer() = object : ConsumerType {
override val provider by unsafeLazy { this@toPublicConsumer.provider.toPublicTypeReference().type as ProviderType }
override val uses by unsafeLazy { this@toPublicConsumer.uses.map { it.toPublicUses() } }
override val samtPackage by unsafeLazy { this@toPublicConsumer.parentPackage.nameComponents.joinToString(".") }
override val samtPackage get() = this@toPublicConsumer.parentPackage.qualifiedName
}

private fun tools.samt.semantic.ConsumerType.Uses.toPublicUses() = object : ConsumedService {
Expand Down Expand Up @@ -283,7 +283,10 @@ class PublicApiMapper(
}

private fun tools.samt.semantic.UserDeclaredNamedType.getQualifiedName(): String {
val components = parentPackage.nameComponents + name
return components.joinToString(".")
return if (parentPackage.qualifiedName.isEmpty()) {
name
} else {
"${parentPackage.qualifiedName}.$name"
}
}
}
11 changes: 7 additions & 4 deletions compiler/src/main/kotlin/tools/samt/semantic/Package.kt
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,13 @@ class Package(val name: String, private val parent: Package?) {
val allSubPackages: List<Package>
get() = subPackages + subPackages.flatMap { it.allSubPackages }

val nameComponents: List<String>
get() = if (isRootPackage) {
emptyList() // root package
val qualifiedName: String by lazy(LazyThreadSafetyMode.NONE) {
if (parent == null) {
"" // root package
} else if (parent.isRootPackage) {
name
} else {
parent!!.nameComponents + name
"${parent.qualifiedName}.$name"
}
}
}
5 changes: 5 additions & 0 deletions specification/benchmarks/samt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source: ./todo-service

generators:
- name: kotlin-ktor-consumer
output: ./out
11 changes: 11 additions & 0 deletions specification/benchmarks/todo-service/common.samt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package tools.samt.examples.common

typealias UUID = String ( pattern("[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}") )

/*
record NotFoundFault extends Fault
record MissingPermissionsFault extends Fault
*/

record NotFoundFault
record MissingPermissionsFault
9 changes: 9 additions & 0 deletions specification/benchmarks/todo-service/todo-consumer.samt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package tools.samt.examples.somepackage

consume tools.samt.examples.todo.TodoEndpointHTTP {
uses tools.samt.examples.todo.TodoManager
uses tools.samt.examples.todo.TodoListManager {
addTodoToList,
removeTodoFromList
}
}
37 changes: 37 additions & 0 deletions specification/benchmarks/todo-service/todo-provider-file.samt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package tools.samt.examples.todo

provide TodosFileInput {
implements TodoManager { getTodos }

transport FILE {
serialization: "CSV",
options: {
delimiter: ",",
encoding: "UTF-8"
},
primitives: {
String: {
enquote: "AUTO"
}
},
records: {
TodoItem: {
id: {
enquote: "NEVER"
},
id: {
enquote: "NEVER"
},
description: {
enquote: "ALWAYS"
},
completed: {
boolean: {
^true: "1",
^false: "0"
}
}
}
}
}
}
35 changes: 35 additions & 0 deletions specification/benchmarks/todo-service/todo-provider-http.samt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package tools.samt.examples.todo

provide TodoEndpointHTTP {
implements TodoManager
implements TodoListManager

transport http {
serialization: "json",
operations: {
TodoManager: {
createTodo: "POST /todo {session in cookie}",
searchTodo: "GET /todo/search {title in query}",
getTodo: "GET /todo/{id}",
getTodos: "GET /todo",
updateTodo: "PUT /todo/{id}",
deleteTodo: "DELETE /todo/{id}",
markAsCompleted: "PUT /todo/{id}/completed {id in queryParam}"
},
TodoListManager: {
createTodoList: "POST /todo-list",
searchTodoList: "GET /todo-list {title in query}",
getTodoList: "GET /todo-list/{id}",
getTodoLists: "GET /todo-lists",
updateTodoList: "PUT /todo-list/{id}",
deleteTodoList: "DELETE /todo-list/{id}",
addTodoToList: "PUT /todo-list/{listId}/todo/{todoId}",
removeTodoFromList: "DELETE /todo-list/{listId}/todo/{todoId}"
}
},
faults: {
NotFoundFault: 404,
MissingPermissionsFault: 403
}
}
}
Loading