Skip to content

Commit

Permalink
Allow numbers in path like /v1/todos (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
wilmveel authored Jul 2, 2024
1 parent 06ea1a9 commit 13cf2a7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ object WirespecSpec : LanguageSpec {
Regex("^[1-5][0-9][0-9]") to StatusCode,
Regex("^[a-z`][a-zA-Z0-9`]*") to CustomValue,
Regex("^[A-Z][a-zA-Z0-9_]*") to CustomType,
Regex("^/[a-zA-Z-_]+") to Path,
Regex("^/[a-zA-Z0-9-_]+") to Path,
Regex("^\\/\\*(\\*(?!\\/)|[^*])*\\*\\/") to WsComment,
Regex("^/") to ForwardSlash,
Regex("^.") to Invalid // Catch all regular expression if none of the above matched
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CompileEndpointTest {

private val compiledTodo = compile(
"""
|endpoint Todo GET /todo ? {done:Boolean} # {auth:String} -> {
|endpoint Todo GET /v1/todo ? {done:Boolean} # {auth:String} -> {
| 200 -> Todo
|}
|type Todo {
Expand Down Expand Up @@ -58,7 +58,7 @@ class CompileEndpointTest {
| override val content: Wirespec.Content<Unit>? = null
| ) : Request<Unit> {
| constructor(done: Boolean, auth: String) : this(
| path = "/todo",
| path = "/v1/todo",
| method = Wirespec.Method.GET,
| query = mapOf<String, List<Any?>>("done" to listOf(done)),
| headers = mapOf<String, List<Any?>>("auth" to listOf(auth)),
Expand All @@ -77,7 +77,7 @@ class CompileEndpointTest {
| )
| }
| companion object {
| const val PATH = "/todo"
| const val PATH = "/v1/todo"
| const val METHOD = "GET"
| fun <B> REQUEST_MAPPER(contentMapper: Wirespec.ContentMapper<B>) = { request: Wirespec.Request<B> ->
| when {
Expand Down Expand Up @@ -190,7 +190,7 @@ class CompileEndpointTest {
|import java.util.function.Function;
|
|public interface TodoEndpoint extends Wirespec.Endpoint {
| static String PATH = "/todo";
| static String PATH = "/v1/todo";
| static String METHOD = "GET";
|
| sealed interface Request<T> extends Wirespec.Request<T> {
Expand Down Expand Up @@ -221,7 +221,7 @@ class CompileEndpointTest {
| Boolean done,
| String auth
| ) {
| this.path = "/" + "todo";
| this.path = "/" + "v1" + "/" + "todo";
| this.method = Wirespec.Method.GET;
| this.query = java.util.Map.ofEntries(java.util.Map.entry("done", java.util.List.of(done)));
| this.headers = java.util.Map.ofEntries(java.util.Map.entry("auth", java.util.List.of(auth)));
Expand Down Expand Up @@ -499,17 +499,17 @@ class CompileEndpointTest {
| export type Response<T> = { status:number, headers?: Record<string, any[]>, content?:Content<T> }
|}
|export module Todo {
| export const PATH = "/todo"
| export const PATH = "/v1/todo"
| export const METHOD = "GET"
| type RequestUndefined = { path: `/todo`, method: "GET", headers: { "auth": string}, query: { "done": boolean} }
| type RequestUndefined = { path: `/v1/todo`, method: "GET", headers: { "auth": string}, query: { "done": boolean} }
| export type Request = RequestUndefined
| type Response200ApplicationJson = { status: 200, content: { type: "application/json", body: Todo } }
| export type Response = Response200ApplicationJson
| export type Handler = (request:Request) => Promise<Response>
| export type Call = {
| todo: Handler
| }
| export const requestUndefined = (props:{ "done": boolean, "auth": string}) => ({path: `/todo`, method: "GET", query: {"done": props.done}, headers: {"auth": props.auth}} as const)
| export const requestUndefined = (props:{ "done": boolean, "auth": string}) => ({path: `/v1/todo`, method: "GET", query: {"done": props.done}, headers: {"auth": props.auth}} as const)
| export const response200ApplicationJson = (props:{ "body": Todo}) => ({status: 200, headers: {}, content: {type: "application/json", body: props.body}} as const)
|}
|
Expand All @@ -527,7 +527,7 @@ class CompileEndpointTest {
@Test
fun testEndpointWirespec() {
val wirespec = """
|endpoint Todo GET /todo ? {done: Boolean} -> {
|endpoint Todo GET /v1/todo ? {done: Boolean} -> {
| 200 -> Todo
|}
|
Expand Down

0 comments on commit 13cf2a7

Please sign in to comment.