Skip to content

Commit

Permalink
feat: cleanup endpoint routes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMrMilchmann committed Oct 22, 2023
1 parent 767e8ac commit 6e12d0f
Show file tree
Hide file tree
Showing 12 changed files with 451 additions and 498 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ internal interface QueriesBuilder<T : IRAPIType> {
name: String,
type: DeferredPrimitiveType<*>,
description: String,
key: String = name,
camelCase: String = name.firstToLowerCase()
key: String = Name.deriveFromTitleCase(name).toSnakeCase(),
camelCase: String? = null
)

fun queryParameter(
Expand Down
14 changes: 4 additions & 10 deletions src/main/kotlin/com/gw2tb/apigen/internal/dsl/SpecBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@
@file:OptIn(LowLevelApiGenApi::class)
package com.gw2tb.apigen.internal.dsl

import com.gw2tb.apigen.*
import com.gw2tb.apigen.internal.impl.*
import com.gw2tb.apigen.ir.*
import com.gw2tb.apigen.ir.model.IRAPIQuery
import com.gw2tb.apigen.ir.model.IRAPIType
import com.gw2tb.apigen.model.*
import com.gw2tb.apigen.model.v2.*
import com.gw2tb.apigen.schema.*
import kotlin.time.*

@Suppress("FunctionName")
Expand Down Expand Up @@ -116,8 +114,7 @@ internal interface SpecBuilder<T : IRAPIType> {
internal interface SpecBuilderV1 : SpecBuilder<IRAPIType.V1> {

operator fun APIv1Endpoint.invoke(
endpointTitleCase: String = path,
route: String = path,
path: String = this.path.toSnakeCase(),
querySuffix: String? = null,
summary: String,
cache: Duration? = null,
Expand All @@ -126,8 +123,7 @@ internal interface SpecBuilderV1 : SpecBuilder<IRAPIType.V1> {
)

operator fun APIv1Endpoint.invoke(
endpointTitleCase: String = path,
route: String = path,
path: String = this.path.toSnakeCase(),
idTypeKey: String = "id",
summary: String,
queryTypes: QueryTypes,
Expand All @@ -141,8 +137,7 @@ internal interface SpecBuilderV1 : SpecBuilder<IRAPIType.V1> {
internal interface SpecBuilderV2 : SpecBuilder<IRAPIType.V2> {

operator fun APIv2Endpoint.invoke(
endpointTitleCase: String = path,
route: String = path,
path: String = this.path.toSnakeCase(),
querySuffix: String? = null,
summary: String,
cache: Duration? = null,
Expand All @@ -153,8 +148,7 @@ internal interface SpecBuilderV2 : SpecBuilder<IRAPIType.V2> {
)

operator fun APIv2Endpoint.invoke(
endpointTitleCase: String = path,
route: String = path,
path: String = this.path.toSnakeCase(),
idTypeKey: String = "id",
summary: String,
queryTypes: QueryTypes,
Expand Down
20 changes: 8 additions & 12 deletions src/main/kotlin/com/gw2tb/apigen/internal/impl/SpecBuilderImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ internal class SpecBuilderV1Impl : SpecBuilderImplBase<APIv1Endpoint, IRAPIQuery
}

override fun APIv1Endpoint.invoke(
endpointTitleCase: String,
route: String,
path: String,
querySuffix: String?,
summary: String,
cache: Duration?,
Expand All @@ -100,7 +99,7 @@ internal class SpecBuilderV1Impl : SpecBuilderImplBase<APIv1Endpoint, IRAPIQuery
) {
queries.computeIfAbsent(this) { mutableListOf() }.add { typeRegistry ->
QueriesBuilderV1Impl(
route = route,
path = path,
querySuffix = querySuffix,
endpoint = this,
idTypeKey = null,
Expand All @@ -115,8 +114,7 @@ internal class SpecBuilderV1Impl : SpecBuilderImplBase<APIv1Endpoint, IRAPIQuery
}

override fun APIv1Endpoint.invoke(
endpointTitleCase: String,
route: String,
path: String,
idTypeKey: String,
summary: String,
queryTypes: QueryTypes,
Expand All @@ -126,7 +124,7 @@ internal class SpecBuilderV1Impl : SpecBuilderImplBase<APIv1Endpoint, IRAPIQuery
) {
queries.computeIfAbsent(this) { mutableListOf() }.add { typeRegistry ->
QueriesBuilderV1Impl(
route = route,
path = path,
querySuffix = null,
endpoint = this,
idTypeKey = idTypeKey,
Expand Down Expand Up @@ -168,8 +166,7 @@ internal class SpecBuilderV2Impl : SpecBuilderImplBase<APIv2Endpoint, IRAPIQuery
}

override fun APIv2Endpoint.invoke(
endpointTitleCase: String,
route: String,
path: String,
querySuffix: String?,
summary: String,
cache: Duration?,
Expand All @@ -180,7 +177,7 @@ internal class SpecBuilderV2Impl : SpecBuilderImplBase<APIv2Endpoint, IRAPIQuery
) {
queries.computeIfAbsent(this) { mutableListOf() }.add { typeRegistry ->
QueriesBuilderV2Impl(
route = route,
path = path,
querySuffix = querySuffix,
endpoint = this,
idTypeKey = null,
Expand All @@ -197,8 +194,7 @@ internal class SpecBuilderV2Impl : SpecBuilderImplBase<APIv2Endpoint, IRAPIQuery
}

override fun APIv2Endpoint.invoke(
endpointTitleCase: String,
route: String,
path: String,
idTypeKey: String,
summary: String,
queryTypes: QueryTypes,
Expand All @@ -210,7 +206,7 @@ internal class SpecBuilderV2Impl : SpecBuilderImplBase<APIv2Endpoint, IRAPIQuery
) {
queries.computeIfAbsent(this) { mutableListOf() }.add { typeRegistry ->
QueriesBuilderV2Impl(
route = route,
path = path,
querySuffix = null,
endpoint = this,
idTypeKey = idTypeKey,
Expand Down
16 changes: 9 additions & 7 deletions src/main/kotlin/com/gw2tb/apigen/internal/impl/queries.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ internal abstract class QueriesBuilderImplBase<Q : IRAPIQuery, T : IRAPIType> :

protected abstract val typeRegistry: ScopedTypeRegistry<T>

protected abstract val route: String
protected abstract val path: String
protected abstract val endpoint: APIEndpoint
protected abstract val querySuffix: String?
protected abstract val idTypeKey: String?
Expand All @@ -50,8 +50,10 @@ internal abstract class QueriesBuilderImplBase<Q : IRAPIQuery, T : IRAPIType> :
protected abstract val apiTypeFactory: (SchemaVersionedDataImpl<out IRTypeDeclaration<*>>, APIType.InterpretationHint?, Boolean) -> T

protected val pathParameters: MutableMap<String, IRPathParameter> = mutableMapOf()
override fun pathParameter(name: String, type: DeferredPrimitiveType<*>, description: String, key: String, camelCase: String) {
check(":$key" in (route.split('/')))
override fun pathParameter(name: String, type: DeferredPrimitiveType<*>, description: String, key: String, camelCase: String?) {
println("$key in ${endpoint.path}")

check(":$key" in (path.split('/')))
check(key !in pathParameters)

pathParameters[key] = IRPathParameter(
Expand Down Expand Up @@ -116,7 +118,7 @@ internal abstract class QueriesBuilderImplBase<Q : IRAPIQuery, T : IRAPIType> :
}

internal class QueriesBuilderV1Impl(
override val route: String,
override val path: String,
override val querySuffix: String?,
override val endpoint: APIEndpoint,
override val idTypeKey: String?,
Expand All @@ -137,7 +139,7 @@ internal class QueriesBuilderV1Impl(

override fun collect(): Collection<IRAPIQuery.V1> = listOf(
IRAPIQuery.V1(
path = route,
path = path,
endpoint = endpoint,
summary = summary,
pathParameters = pathParameters,
Expand All @@ -151,7 +153,7 @@ internal class QueriesBuilderV1Impl(
}

internal class QueriesBuilderV2Impl(
override val route: String,
override val path: String,
override val querySuffix: String?,
override val endpoint: APIEndpoint,
override val idTypeKey: String?,
Expand Down Expand Up @@ -226,7 +228,7 @@ internal class QueriesBuilderV2Impl(
queryParameters: Map<String, IRQueryParameter>? = null,
queryDetails: IRAPIQuery.Details? = null
) = IRAPIQuery.V2(
path = route,
path = path,
endpoint = endpoint,
summary = summary,
pathParameters = pathParameters,
Expand Down
48 changes: 9 additions & 39 deletions src/main/kotlin/com/gw2tb/apigen/internal/spec/GW2v1.kt
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,7 @@ internal val GW2v1 = GW2APISpecV1 {
)
})
}
V1_EVENT_DETAILS(
endpointTitleCase = "/EventDetails",
summary = "Returns information about the events in the game."
) {
V1_EVENT_DETAILS(summary = "Returns information about the events in the game.") {
schema(record(name = "EventDetails", description = "Information about events.") {
"Events"(
description = "the events",
Expand Down Expand Up @@ -151,7 +148,6 @@ internal val GW2v1 = GW2APISpecV1 {
))
}
V1_GUILD_DETAILS(
endpointTitleCase = "/GuildDetails",
querySuffix = "ByID",
summary = "Returns information about a guild."
) {
Expand All @@ -160,18 +156,14 @@ internal val GW2v1 = GW2APISpecV1 {
schema(GuildDetails)
}
V1_GUILD_DETAILS(
endpointTitleCase = "/GuildDetails",
querySuffix = "ByName",
summary = "Returns information about a guild."
) {
queryParameter("GuildName", STRING, "the name of the guild", key = "guild_name")

schema(GuildDetails)
}
V1_ITEM_DETAILS(
endpointTitleCase = "/ItemDetails",
summary = "Returns information an item."
) {
V1_ITEM_DETAILS(summary = "Returns information an item.") {
queryParameter("ItemID", ITEM_ID, "the ID of the item", key = "item_id")

schema(conditional(
Expand Down Expand Up @@ -318,10 +310,7 @@ internal val GW2v1 = GW2APISpecV1 {
"Items"(array(ITEM_ID), "the IDs of the available items")
})
}
V1_MAP_FLOOR(
endpointTitleCase = "/MapFloor",
summary = "Returns information about a map floor."
) {
V1_MAP_FLOOR(summary = "Returns information about a map floor.") {
queryParameter("ContinentID", CONTINENT_ID, "the ID of the continent", key = "continent_id")
queryParameter("FloorID", FLOOR_ID, "the ID of the floor", key = "floor")

Expand Down Expand Up @@ -439,10 +428,7 @@ internal val GW2v1 = GW2APISpecV1 {
)
})
}
V1_MAP_NAMES(
endpointTitleCase = "/MapNames",
summary = "Returns information about maps."
) {
V1_MAP_NAMES(summary = "Returns information about maps.") {
schema(array(
description = "the available maps",
items = record(name = "MapName", description = "Information about a map.") {
Expand Down Expand Up @@ -475,10 +461,7 @@ internal val GW2v1 = GW2APISpecV1 {
)
})
}
V1_RECIPE_DETAILS(
endpointTitleCase = "/RecipeDetails",
summary = "Returns information about the recipes in the game."
) {
V1_RECIPE_DETAILS(summary = "Returns information about the recipes in the game.") {
queryParameter("RecipeID", RECIPE_ID, "the recipe's ID", key = "recipe_id")

schema(record(name = "RecipeDetails", description = "Information about a crafting recipe.") {
Expand All @@ -505,7 +488,6 @@ internal val GW2v1 = GW2APISpecV1 {
})
}
V1_SKIN_DETAILS(
endpointTitleCase = "/SkinDetails",
summary = "Returns information about the skins in the game.",
cache = 1.hours
) {
Expand Down Expand Up @@ -560,10 +542,7 @@ internal val GW2v1 = GW2APISpecV1 {
"Skins"(array(SKIN_ID), "the IDs of the available skins")
})
}
V1_WORLD_NAMES(
endpointTitleCase = "/WorldNames",
summary = "Returns information about the available worlds (or servers)."
) {
V1_WORLD_NAMES(summary = "Returns information about the available worlds (or servers).") {
schema(array(
description = "the available worlds",
items = record(name = "WorldName", description = "Information about an available world (or server).") {
Expand All @@ -572,10 +551,7 @@ internal val GW2v1 = GW2APISpecV1 {
}
))
}
V1_WVW_MATCH_DETAILS(
endpointTitleCase = "/WvW/MatchDetails",
summary = "Returns detailed information about a WvW match."
) {
V1_WVW_MATCH_DETAILS(summary = "Returns detailed information about a WvW match.") {
queryParameter("MatchID", WVW_MATCH_ID, "the ID of the match", key = "match_id")

schema(record(name = "WvWMatchDetails", description = "Information about a WvW match.") {
Expand Down Expand Up @@ -605,10 +581,7 @@ internal val GW2v1 = GW2APISpecV1 {
)
})
}
V1_WVW_MATCHES(
endpointTitleCase = "/WvW/Matches",
summary = "Returns information about WvW matches."
) {
V1_WVW_MATCHES(summary = "Returns information about WvW matches.") {
schema(record(name = "WvWMatches", description = "Information about WvW matches.") {
SerialName("wvw_matches").."WvWMatches"(
description = "the matches",
Expand All @@ -623,10 +596,7 @@ internal val GW2v1 = GW2APISpecV1 {
)
})
}
V1_WVW_OBJECTIVE_NAMES(
endpointTitleCase = "/WvW/ObjectivesNames",
summary = "Returns information about the available WvW objectives."
) {
V1_WVW_OBJECTIVE_NAMES(summary = "Returns information about the available WvW objectives.") {
schema(array(
description = "the available objectives",
items = record(name = "ObjectiveName", description = "Information about a WvW objective.") {
Expand Down
Loading

0 comments on commit 6e12d0f

Please sign in to comment.