Skip to content

Commit

Permalink
feat: move isLocalized from query to schema property
Browse files Browse the repository at this point in the history
Closes #151
  • Loading branch information
TheMrMilchmann committed Apr 13, 2021
1 parent d54b998 commit 249580e
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 134 deletions.
2 changes: 2 additions & 0 deletions docs/changelog/0.4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ _Not Released Yet_
- Added support for `/v2/guild/search`. [[GH-91](https://github.com/GW2ToolBelt/api-generator/issues/91)]
- Added support for `/v2/recipes/search`. [[GH-127](https://github.com/GW2ToolBelt/api-generator/issues/127)]
- Reworked library entry-points and split them into available types and queries.
- Moved `isLocalized` from `APIQuery` to `SchemaType` to support better representation of the underlying data. [[GH-151](https://github.com/GW2ToolBelt/api-generator/issues/151)]

#### Fixes

Expand All @@ -32,6 +33,7 @@ _Not Released Yet_
- Changed `ID` type for `/v2/finishers` from `STRING` to `INTEGER`.
- Changed `ID` type for `/v2/minis` from `STRING` to `INTEGER`.
- Changed `ID` type for `/v2/pets` from `STRING` to `INTEGER`.
- Added missing `description` field to `/v2/pvp/heroes`.
- Updated a wrong record description for `/v2/quaggans`.
- Changed `ID` type for `/v2/quests` from `STRING` to `INTEGER`.
- Changed `ID` type for `/v2/recipes` from `STRING` to `INTEGER`.
Expand Down
4 changes: 0 additions & 4 deletions src/main/kotlin/com/gw2tb/apigen/internal/dsl/dsl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,6 @@ internal sealed class APIQueryBuilder<Q : APIQuery, T : APIType>(private val cre

var summary: String = ""

var isLocalized: Boolean = false

var cache: Duration? = null
var security: Set<TokenScope>? = null

Expand Down Expand Up @@ -431,7 +429,6 @@ internal sealed class APIQueryBuilder<Q : APIQuery, T : APIType>(private val cre
summary = summary,
pathParameters = pathParameters,
queryParameters = queryParameters,
isLocalized = isLocalized,
cache = cache,
schema = schema[V2SchemaVersion.V2_SCHEMA_CLASSIC]!!
)
Expand Down Expand Up @@ -485,7 +482,6 @@ internal sealed class APIQueryBuilder<Q : APIQuery, T : APIType>(private val cre
pathParameters = pathParameters,
queryParameters = queryParameters ?: this.queryParameters,
queryDetails = queryDetails,
isLocalized = isLocalized && (queryDetails?.queryType != QueryType.IDs),
cache = cache,
since = since,
until = until,
Expand Down
16 changes: 16 additions & 0 deletions src/main/kotlin/com/gw2tb/apigen/internal/dsl/schema.kt
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ internal class SchemaRecordBuilder<T : APIType>(val name: String) : SchemaBuilde
/** Marks a deprecated property. */
val deprecated = Modifiers.deprecated

/** Marks a localized property. */
val localized = Modifiers.localized

/** Marks an optional property. */
val optional = Modifiers.optional

Expand Down Expand Up @@ -283,6 +286,12 @@ internal class SchemaRecordPropertyBuilder(
field = value
}

var isLocalized = false
set(value) {
check(isUnused)
field = value
}

var optionality: Optionality? = null
set(value) {
check(isUnused)
Expand Down Expand Up @@ -322,6 +331,7 @@ internal class SchemaRecordPropertyBuilder(
description = description,
optionality = optionality ?: Optionality.REQUIRED,
isDeprecated = isDeprecated,
isLocalized = isLocalized,
since = since,
until = until,
serialName = serialName ?: propertyName.toLowerCase(),
Expand Down Expand Up @@ -355,6 +365,12 @@ internal object Modifiers {

}

val localized = object : PropertyModifier() {
override fun applyTo(property: SchemaRecordPropertyBuilder) {
property.isLocalized = true
}
}

val optional = object : PropertyModifier() {
override fun applyTo(property: SchemaRecordPropertyBuilder) {
property.optionality = Optionality.OPTIONAL
Expand Down
9 changes: 3 additions & 6 deletions src/main/kotlin/com/gw2tb/apigen/internal/spec/GW2v1.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,23 @@ internal val GW2v1 = GW2APIVersion({ APIVersionBuilder.V1() }) {
}
"/map_names"(endpoint = "MapNames") {
summary = "Returns information about maps."
isLocalized = true

schema(array(
description = "the available maps",
items = record(name = "MapName", description = "Information about a map.") {
CamelCase("id").."ID"(INTEGER, "the map's ID")
"Name"(STRING, "the map's name")
localized.."Name"(STRING, "the map's name")
}
))
}
"/skin_details"(endpoint = "SkinDetails") {
summary = "Returns information about the skins in the game."
cache = 1.hours
isLocalized = true

queryParameter("SkinID", INTEGER, "the amount to exchange", key = "skin_id")
schema(conditional("SkinDetails", "Information about a skin.", interpretationInNestedProperty = true, sharedConfigure = {
SerialName("skin_id").."SkinID"(INTEGER, "")
"Name"(STRING, "the skin's localized name")
localized.."Name"(STRING, "the skin's localized name")
"Type"(STRING, "the skin's type")
"Rarity"(STRING, "the skin's rarity")
"Flags"(array(STRING), "additional skin flags (ShowInWardrobe, NoCost, HideIfLocked, OverrideRarity)")
Expand Down Expand Up @@ -115,13 +113,12 @@ internal val GW2v1 = GW2APIVersion({ APIVersionBuilder.V1() }) {
}
"/world_names"(endpoint = "WorldNames") {
summary = "Returns information about the available worlds (or servers)."
isLocalized = true

schema(array(
description = "the available worlds",
items = record(name = "WorldName", description = "Information about an available world (or server).") {
CamelCase("id").."ID"(INTEGER, "the ID of the world")
"Name"(STRING, "the name of the world")
localized.."Name"(STRING, "the name of the world")
}
))
}
Expand Down
Loading

0 comments on commit 249580e

Please sign in to comment.