Skip to content

Commit

Permalink
fix: OAS for the enum types (wip)
Browse files Browse the repository at this point in the history
Signed-off-by: Yurii Shynbuiev <yurii.shynbuiev@iohk.io>
  • Loading branch information
yshyn-iohk committed Sep 25, 2024
1 parent 40661de commit ecc7699
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 7,468 deletions.
11 changes: 10 additions & 1 deletion cloud-agent/client/kotlin/.openapi-generator-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ settings.gradle
build.gradle
docs

# igore broken files
# ignore broken files
src/main/kotlin/org/hyperledger/identus/client/models/UpdateManagedDIDServiceAction.kt
src/main/kotlin/org/hyperledger/identus/client/models/UpdateManagedDIDServiceActionType.kt

Expand All @@ -15,3 +15,12 @@ src/main/kotlin/org/hyperledger/identus/client/models/CredentialSubject.kt
src/main/kotlin/org/hyperledger/identus/client/models/DateTimeParameter.kt
src/main/kotlin/org/hyperledger/identus/client/models/DidParameter.kt
src/main/kotlin/org/hyperledger/identus/client/models/VcVerificationParameter.kt

src/test/kotlin/org/hyperledger/identus/client/models/UpdateManagedDIDServiceActionTest.kt
src/test/kotlin/org/hyperledger/identus/client/models/UpdateManagedDIDServiceActionTypeTest.kt

src/test/kotlin/org/hyperledger/identus/client/models/ServiceTest.kt
src/test/kotlin/org/hyperledger/identus/client/models/ServiceTypeTest.kt

src/test/kotlin/org/hyperledger/identus/client/models/StatusPurposeTest.kt
src/test/kotlin/org/hyperledger/identus/client/models/CredentialSubjectTest.kt
1 change: 1 addition & 0 deletions cloud-agent/client/kotlin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ test {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1")
implementation "com.google.code.gson:gson:2.9.0"
implementation "com.squareup.okhttp3:okhttp:4.10.0"
testImplementation "io.kotlintest:kotlintest-runner-junit5:3.4.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

package org.hyperledger.identus.client.models

import kotlinx.serialization.json.JsonPrimitive
import kotlinx.serialization.json.JsonElement
import com.google.gson.annotations.SerializedName
import com.google.gson.JsonElement
import com.google.gson.JsonPrimitive


/**
Expand Down
7,449 changes: 0 additions & 7,449 deletions cloud-agent/service/api/http/cloud-agent-openapi-spec.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,9 @@ object StatusListCredential {
|""".stripMargin

given StatusPurposeCodec: JsonCodec[StatusPurpose] = JsonCodec[StatusPurpose](
JsonEncoder[String].contramap[StatusPurpose](_.str),
JsonDecoder[String].mapOrFail {
case StatusPurpose.Revocation.str => Right(StatusPurpose.Revocation)
case StatusPurpose.Suspension.str => Right(StatusPurpose.Suspension)
case str => Left(s"no enum value matched for \"$str\"")
JsonEncoder[String].contramap[StatusPurpose](_.toString),
JsonDecoder[String].mapOrFail { input =>
StatusPurpose.values.find(_.toString.compareToIgnoreCase(input) == 0).toRight("Unknown StatusPurpose")
},
)

Expand Down Expand Up @@ -176,7 +174,7 @@ object StatusListCredential {

given credentialSubjectSchema: Schema[CredentialSubject] = Schema.derived

given statusPurposeSchema: Schema[StatusPurpose] = Schema.derived
given statusPurposeSchema: Schema[StatusPurpose] = Schema.derivedEnumeration.defaultStringBased

given credentialIssuerSchema: Schema[CredentialIssuer] = Schema.derived

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package org.hyperledger.identus.pollux.credentialschema.http

import org.hyperledger.identus.api.http.*
import org.hyperledger.identus.pollux.core.model
import org.hyperledger.identus.pollux.core.model.schema.CredentialSchema
import org.hyperledger.identus.pollux.core.model.ResourceResolutionMethod
import org.hyperledger.identus.pollux.core.model.ResourceResolutionMethod.*
import org.hyperledger.identus.pollux.core.model.schema.CredentialSchema
import org.hyperledger.identus.pollux.credentialschema.http.CredentialSchemaResponse.annotations
import sttp.model.Uri
import sttp.tapir.json.zio.schemaForZioJsonValue
import sttp.tapir.Schema
import sttp.tapir.Schema.annotations.{default, description, encodedExample, encodedName}
import sttp.tapir.json.zio.schemaForZioJsonValue
import zio.json.*
import zio.json.ast.Json

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ given statusPurposeGet: Get[StatusPurpose] = Get[String].map {
case purpose => throw RuntimeException(s"Invalid status purpose - $purpose")
}

given statusPurposePut: Put[StatusPurpose] = Put[String].contramap {
case StatusPurpose.Revocation => StatusPurpose.Revocation.str
case StatusPurpose.Suspension => StatusPurpose.Suspension.str
}
given statusPurposePut: Put[StatusPurpose] = Put[String].contramap(_.toString)

given urlGet: Get[URL] = Get[String].map(s => URI.create(s).toURL())
given urlPut: Put[URL] = Put[String].contramap(_.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ case class W3cVerifiableCredentialPayload(payload: W3cCredentialPayload, proof:

case class JwtVerifiableCredentialPayload(jwt: JWT) extends VerifiableCredentialPayload

enum StatusPurpose(val str: String) {
case Revocation extends StatusPurpose("Revocation")
case Suspension extends StatusPurpose("Suspension")
enum StatusPurpose {
case Revocation
case Suspension
}

case class CredentialStatus(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ object VCStatusList2021 {
} yield {
val claims = JsonObject()
.add("type", "StatusList2021".asJson)
.add("statusPurpose", purpose.str.asJson)
.add("statusPurpose", purpose.toString.asJson)
.add("encodedList", encodedBitString.asJson)
val w3Credential = W3cCredentialPayload(
`@context` = Set(
Expand Down

0 comments on commit ecc7699

Please sign in to comment.