Skip to content

Commit

Permalink
Static typing: Fix code_gen of enum values with underscores (#743)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruixhuang authored Nov 11, 2024
1 parent 30bc0d9 commit f1368b7
Show file tree
Hide file tree
Showing 26 changed files with 183 additions and 177 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ allprojects {
}

group = "exchange.dydx.abacus"
version = "1.13.20"
version = "1.13.21"

repositories {
google()
Expand Down
220 changes: 95 additions & 125 deletions integration/iOS/Pods/Pods.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ internal class MarketProcessor(
): PerpetualMarket? {
cachedIndexerSparklines[marketId] = payload.mapNotNull { parser.asDouble(it) }.reversed()
when (period) {
IndexerSparklineTimePeriod.ONEDAY -> {
IndexerSparklineTimePeriod.ONE_DAY -> {
return createPerpetualMarket(marketId)
}
IndexerSparklineTimePeriod.SEVENDAYS -> {
IndexerSparklineTimePeriod.SEVEN_DAYS -> {
val sevenDaySparklineEntries = 42
cachedIsNew[marketId] = payload.size < sevenDaySparklineEntries
return createPerpetualMarket(marketId)
Expand Down Expand Up @@ -249,7 +249,7 @@ internal class MarketProcessor(
canTrade = true,
canReduce = true,
)
IndexerPerpetualMarketStatus.CANCELONLY -> MarketStatus(
IndexerPerpetualMarketStatus.CANCEL_ONLY -> MarketStatus(
canTrade = false,
canReduce = true,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ internal fun TradingStateMachine.sparklines(
return if (sparklines != null) {
marketsProcessor.processSparklines(internalState.marketsSummary, sparklines, period)
when (period) {
IndexerSparklineTimePeriod.ONEDAY -> {
IndexerSparklineTimePeriod.ONE_DAY -> {
StateChanges(iListOf(Changes.sparklines, Changes.markets), null)
}
IndexerSparklineTimePeriod.SEVENDAYS -> {
IndexerSparklineTimePeriod.SEVEN_DAYS -> {
StateChanges(iListOf(Changes.markets), null)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ internal class MarketsSupervisor(
val url = helper.configs.publicApiUrl("sparklines")
if (url != null) {
// Get 1 day sparkline for market display
val period = IndexerSparklineTimePeriod.ONEDAY
val period = IndexerSparklineTimePeriod.ONE_DAY
helper.get(url, iMapOf("timePeriod" to period.value), null) { _, response, httpCode, _ ->
if (helper.success(httpCode) && response != null) {
parseSparklinesResponse(response, period)
Expand All @@ -159,7 +159,7 @@ internal class MarketsSupervisor(

if (configs.retrieveSevenDaySparkline) {
// Get 7 day sparkline to determine if market is new
val period = IndexerSparklineTimePeriod.SEVENDAYS
val period = IndexerSparklineTimePeriod.SEVEN_DAYS
helper.get(url, iMapOf("timePeriod" to period.value), null) { _, response, httpCode, _ ->
if (helper.success(httpCode) && response != null) {
parseSparklinesResponse(response, period)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import kotlin.js.JsExport
* @param affiliateReferredUsers
* @param affiliateReferredNetProtocolEarnings
* @param affiliateReferredTotalVolume
* @param affiliateReferredMakerFees
* @param affiliateReferredTakerFees
* @param affiliateReferredMakerRebates
*/
@JsExport
@Serializable
Expand All @@ -36,5 +39,8 @@ data class IndexerAffiliateSnapshotResponseObject(
val affiliateTotalReferredFees: kotlin.Double? = null,
val affiliateReferredUsers: kotlin.Double? = null,
val affiliateReferredNetProtocolEarnings: kotlin.Double? = null,
val affiliateReferredTotalVolume: kotlin.Double? = null
val affiliateReferredTotalVolume: kotlin.Double? = null,
val affiliateReferredMakerFees: kotlin.Double? = null,
val affiliateReferredTakerFees: kotlin.Double? = null,
val affiliateReferredMakerRebates: kotlin.Double? = null
)
12 changes: 6 additions & 6 deletions src/commonMain/kotlin/indexer/codegen/IndexerComplianceReason.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ import kotlin.js.JsExport

/**
*
* Values: MANUAL,USGEO,CAGEO,GBGEO,SANCTIONEDGEO,COMPLIANCEPROVIDER
* Values: MANUAL,US_GEO,CA_GEO,GB_GEO,SANCTIONED_GEO,COMPLIANCE_PROVIDER
*/
@JsExport
@Serializable
enum class IndexerComplianceReason(val value: kotlin.String) {
MANUAL("MANUAL"), // :/
USGEO("US_GEO"), // :/
CAGEO("CA_GEO"), // :/
GBGEO("GB_GEO"), // :/
SANCTIONEDGEO("SANCTIONED_GEO"), // :/
COMPLIANCEPROVIDER("COMPLIANCE_PROVIDER"); // :/
US_GEO("US_GEO"), // :/
CA_GEO("CA_GEO"), // :/
GB_GEO("GB_GEO"), // :/
SANCTIONED_GEO("SANCTIONED_GEO"), // :/
COMPLIANCE_PROVIDER("COMPLIANCE_PROVIDER"); // :/
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ import kotlin.js.JsExport

/**
*
* Values: COMPLIANT,FIRSTSTRIKECLOSEONLY,FIRSTSTRIKE,CLOSEONLY,BLOCKED
* Values: COMPLIANT,FIRST_STRIKE_CLOSE_ONLY,FIRST_STRIKE,CLOSE_ONLY,BLOCKED
*/
@JsExport
@Serializable
enum class IndexerComplianceStatus(val value: kotlin.String) {
COMPLIANT("COMPLIANT"), // :/
FIRSTSTRIKECLOSEONLY("FIRST_STRIKE_CLOSE_ONLY"), // :/
FIRSTSTRIKE("FIRST_STRIKE"), // :/
CLOSEONLY("CLOSE_ONLY"), // :/
FIRST_STRIKE_CLOSE_ONLY("FIRST_STRIKE_CLOSE_ONLY"), // :/
FIRST_STRIKE("FIRST_STRIKE"), // :/
CLOSE_ONLY("CLOSE_ONLY"), // :/
BLOCKED("BLOCKED"); // :/
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ import kotlin.js.JsExport

/**
*
* Values: ACTIVE,PAUSED,CANCELONLY,POSTONLY,INITIALIZING,FINALSETTLEMENT
* Values: ACTIVE,PAUSED,CANCEL_ONLY,POST_ONLY,INITIALIZING,FINAL_SETTLEMENT
*/
@JsExport
@Serializable
enum class IndexerPerpetualMarketStatus(val value: kotlin.String) {
ACTIVE("ACTIVE"), // :/
PAUSED("PAUSED"), // :/
CANCELONLY("CANCEL_ONLY"), // :/
POSTONLY("POST_ONLY"), // :/
CANCEL_ONLY("CANCEL_ONLY"), // :/
POST_ONLY("POST_ONLY"), // :/
INITIALIZING("INITIALIZING"), // :/
FINALSETTLEMENT("FINAL_SETTLEMENT"); // :/
FINAL_SETTLEMENT("FINAL_SETTLEMENT"); // :/
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import kotlin.js.JsExport

/**
*
* Values: ONEDAY,SEVENDAYS
* Values: ONE_DAY,SEVEN_DAYS
*/
@JsExport
@Serializable
enum class IndexerSparklineTimePeriod(val value: kotlin.String) {
ONEDAY("ONE_DAY"), // :/
SEVENDAYS("SEVEN_DAYS"); // :/
ONE_DAY("ONE_DAY"), // :/
SEVEN_DAYS("SEVEN_DAYS"); // :/
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,21 +153,21 @@ class MarketProcessorTests {
val output = processor.processSparklines(
marketId = "BTC-USD",
payload = listOf("1", "2", "3"),
period = IndexerSparklineTimePeriod.ONEDAY,
period = IndexerSparklineTimePeriod.ONE_DAY,
)
assertEquals(output?.perpetual?.line, listOf(3.0, 2.0, 1.0).toIList())

val output2 = processor.processSparklines(
marketId = "BTC-USD",
payload = listOf("1", "2", "3"),
period = IndexerSparklineTimePeriod.SEVENDAYS,
period = IndexerSparklineTimePeriod.SEVEN_DAYS,
)
assertEquals(output2?.perpetual?.isNew, true)

val output3 = processor.processSparklines(
marketId = "BTC-USD",
payload = MutableList(42) { "1" }, // 42 elements
period = IndexerSparklineTimePeriod.SEVENDAYS,
period = IndexerSparklineTimePeriod.SEVEN_DAYS,
)
assertEquals(output3?.perpetual?.isNew, false)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class MarketsProcessorTests {
"BTC-USD" to listOf("1", "2", "3"),
"ETH-USD" to listOf("1", "2", "3"),
)
val result = processor.processSparklines(state, sparklines, IndexerSparklineTimePeriod.ONEDAY)
val result = processor.processSparklines(state, sparklines, IndexerSparklineTimePeriod.ONE_DAY)
assertEquals(2, marketProcessor.processSparklinesCallCount)
assertEquals(2, result.markets.size)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ fun TradingStateMachine.rest(
}

"/v4/sparklines" -> {
changes = sparklines(payload, IndexerSparklineTimePeriod.ONEDAY)
changes = sparklines(payload, IndexerSparklineTimePeriod.ONE_DAY)
}

"/v4/fills" -> {
Expand Down
38 changes: 38 additions & 0 deletions swagger_codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,44 @@ sed -i '' 's/_4HOURS("4HOURS")/@SerialName("4HOURS")\n _4HOURS("4HOURS")/' ge
# add @SerialName("1DAY") to _1DAY("1DAY") in CandleResolution.kt
sed -i '' 's/_1DAY("1DAY")/@SerialName("1DAY")\n _1DAY("1DAY")/' generated/src/main/kotlin/indexer/codegen/CandleResolution.kt

# replace CANCELONLY with CANCEL_ONLY in PerpetualMarketStatus.kt
sed -i '' 's/CANCELONLY/CANCEL_ONLY/' generated/src/main/kotlin/indexer/codegen/PerpetualMarketStatus.kt

# replace POSTONLY with POST_ONLY in PerpetualMarketStatus.kt
sed -i '' 's/POSTONLY/POST_ONLY/' generated/src/main/kotlin/indexer/codegen/PerpetualMarketStatus.kt

# replace FINALSETTLEMENT with FINAL_SETTLEMENT in PerpetualMarketStatus.kt
sed -i '' 's/FINALSETTLEMENT/FINAL_SETTLEMENT/' generated/src/main/kotlin/indexer/codegen/PerpetualMarketStatus.kt

# replace SANCTIONEDGEO with SANCTIONED_GEO in ComplianceReason.kt
sed -i '' 's/SANCTIONEDGEO/SANCTIONED_GEO/' generated/src/main/kotlin/indexer/codegen/ComplianceReason.kt

# replace COMPLIANCEPROVIDER with COMPLIANCE_PROVIDER in ComplianceReason.kt
sed -i '' 's/COMPLIANCEPROVIDER/COMPLIANCE_PROVIDER/' generated/src/main/kotlin/indexer/codegen/ComplianceReason.kt

# replace USGEO with US_GEO in ComplianceReason.kt
sed -i '' 's/USGEO/US_GEO/' generated/src/main/kotlin/indexer/codegen/ComplianceReason.kt

# replace CAGEO with CA_GEO in ComplianceReason.kt
sed -i '' 's/CAGEO/CA_GEO/' generated/src/main/kotlin/indexer/codegen/ComplianceReason.kt

# replace GBGEO with GB_GEO in ComplianceReason.kt
sed -i '' 's/GBGEO/GB_GEO/' generated/src/main/kotlin/indexer/codegen/ComplianceReason.kt

# replace FIRSTSTRIKECLOSEONLY with FIRST_STRIKE_CLOSE_ONLY in ComplianceStatus.kt
sed -i '' 's/FIRSTSTRIKECLOSEONLY/FIRST_STRIKE_CLOSE_ONLY/' generated/src/main/kotlin/indexer/codegen/ComplianceStatus.kt

# replace FIRSTSTRIKE with FIRST_STRIKE in ComplianceStatus.kt
sed -i '' 's/FIRSTSTRIKE/FIRST_STRIKE/' generated/src/main/kotlin/indexer/codegen/ComplianceStatus.kt

# replace CLOSEONLY with CLOSE_ONLY in ComplianceStatus.kt
sed -i '' 's/CLOSEONLY/CLOSE_ONLY/' generated/src/main/kotlin/indexer/codegen/ComplianceStatus.kt

# replace ONEDAY with ONE_DAY in SparklineTimePeriod.kt
sed -i '' 's/ONEDAY/ONE_DAY/' generated/src/main/kotlin/indexer/codegen/SparklineTimePeriod.kt

# replace SEVENDAYS with SEVEN_DAYS in SparklineTimePeriod.kt
sed -i '' 's/SEVENDAYS/SEVEN_DAYS/' generated/src/main/kotlin/indexer/codegen/SparklineTimePeriod.kt

# for each of the time in the generated code, run "swagger_update_file.sh <file>"
find generated/src/main/kotlin/indexer -type f \
Expand Down
2 changes: 1 addition & 1 deletion v4_abacus.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'v4_abacus'
spec.version = '1.13.20'
spec.version = '1.13.21'
spec.homepage = 'https://github.com/dydxprotocol/v4-abacus'
spec.source = { :http=> ''}
spec.authors = ''
Expand Down

0 comments on commit f1368b7

Please sign in to comment.