feat: enhance identifier handling with new generated model#64
feat: enhance identifier handling with new generated model#64Sotatek-DucPhung wants to merge 25 commits intomainfrom
Conversation
Sotatek-DucPhung
commented
Dec 1, 2025
- Introduced IdentifierModelConverter for converting generated KERIA models to domain models.
- Added IdentifierPayloadMapper to build request payloads for identifier endpoints.
- Updated Identifier class to utilize GeneratedModelMapper for JSON parsing.
- Modified IdentifierListResponse to use a list of Identifier objects instead of generic Object.
- Implemented KeyStateRecordDeserializer to handle deserialization of KeyStateRecord.
- Centralized Jackson configuration in GeneratedModelConfig for better management of generated models.
- Updated various tests to reflect changes in identifier handling and ensure consistency.
- Introduced IdentifierModelConverter for converting generated KERIA models to domain models. - Added IdentifierPayloadMapper to build request payloads for identifier endpoints. - Updated Identifier class to utilize GeneratedModelMapper for JSON parsing. - Modified IdentifierListResponse to use a list of Identifier objects instead of generic Object. - Implemented KeyStateRecordDeserializer to handle deserialization of KeyStateRecord. - Centralized Jackson configuration in GeneratedModelConfig for better management of generated models. - Updated various tests to reflect changes in identifier handling and ensure consistency.
src/main/java/org/cardanofoundation/signify/app/config/GeneratedModelMapper.java
Outdated
Show resolved
Hide resolved
| ObjectNode node = mapper.readTree(p); | ||
|
|
||
| coerceToString(node, "kt"); | ||
| coerceToString(node, "nt"); |
There was a problem hiding this comment.
Do we really ever get ints back from the API? I thought it was always strings. (I know the API for creating an identifier accepts both though, which is different)
There was a problem hiding this comment.
We hit a parse failure when kt/nt came back as an array (rotation thresholds), so this coerces non-text (array/number) to a string before binding.
If the API is guaranteed to return strings only, I can tighten this to handle only arrays (or drop the coercion and let it fail loudly). Let me know your prefer
There was a problem hiding this comment.
Ah yes, but it's an array of strings. I think @Sotatek-Patrick-Vu might be fixing this, or have fixed it. We should return the string array, not a string.
There was a problem hiding this comment.
updated in coerceToString method
There was a problem hiding this comment.
Right but is it possible to receive a numeric response from the API? I don't think it is (may be a mistake in Patrick's generated models)
There was a problem hiding this comment.
@Sotatek-Patrick-Vu could you please take a look for these field ?
There was a problem hiding this comment.
We are expecting kt, nt properties are string or array string or array of array string But It seems we cannot generate correct in java
There was a problem hiding this comment.
@Sotatek-DucPhung @Sotatek-PhongVu @Sotatek-Patrick-Vu It's also not generated correctly in Signify-TS: https://github.com/WebOfTrust/signify-ts/blob/main/src/types/keria-api-schema.ts#L363
This is referring to the Key State only.
So I think there are missing changes in KERIA to generate this correctly in both Signify-TS and Signify-Java: cardano-foundation/keria#16
There was a problem hiding this comment.
After fixing keria and here is the new type in signify-ts:
KeyStateRecord {
...
kt: string | string[];
nt: string | string[];
...
}
There was a problem hiding this comment.
Indeed @Sotatek-Patrick-Vu if you can fix this PR to remove coerceToString and have proper types that'd be great!
src/main/java/org/cardanofoundation/signify/app/aiding/IdentifierPayloadMapper.java
Outdated
Show resolved
Hide resolved
src/main/java/org/cardanofoundation/signify/app/aiding/IdentifierPayloadMapper.java
Outdated
Show resolved
Hide resolved
src/main/java/org/cardanofoundation/signify/app/aiding/IdentifierModelConverter.java
Outdated
Show resolved
Hide resolved
src/main/java/org/cardanofoundation/signify/app/config/GeneratedModelMapper.java
Outdated
Show resolved
Hide resolved
src/main/java/org/cardanofoundation/signify/app/aiding/Identifier.java
Outdated
Show resolved
Hide resolved
src/main/java/org/cardanofoundation/signify/app/aiding/IdentifierPayloadMapper.java
Outdated
Show resolved
Hide resolved
src/main/java/org/cardanofoundation/signify/app/aiding/IdentifierPayloadMapper.java
Outdated
Show resolved
Hide resolved
src/main/java/org/cardanofoundation/signify/app/aiding/IdentifierModelConverter.java
Outdated
Show resolved
Hide resolved
…ds and using direct calls
src/main/java/org/cardanofoundation/signify/app/aiding/IdentifierModelConverter.java
Outdated
Show resolved
Hide resolved
src/main/java/org/cardanofoundation/signify/app/aiding/IdentifierPayloadMapper.java
Outdated
Show resolved
Hide resolved
src/main/java/org/cardanofoundation/signify/app/aiding/IdentifierModelConverter.java
Outdated
Show resolved
Hide resolved
…hods for consistency
6666b59 to
c099e48
Compare
…onsistency and clarity
…ier-model refactor: replace States with Tier in multiple classes for improved c…
src/main/java/org/cardanofoundation/signify/app/aiding/IdentifierPayloadMapper.java
Outdated
Show resolved
Hide resolved
| ObjectNode node = mapper.readTree(p); | ||
|
|
||
| coerceToString(node, "kt"); | ||
| coerceToString(node, "nt"); |
There was a problem hiding this comment.
Still pending a response here!
src/main/java/org/cardanofoundation/signify/app/config/GeneratedModelMapper.java
Outdated
Show resolved
Hide resolved
src/test/java/org/cardanofoundation/signify/app/RegistryTest.java
Outdated
Show resolved
Hide resolved
src/main/java/org/cardanofoundation/signify/app/aiding/IdentifierPayloadMapper.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pointer to https://github.com/cardano-foundation/cf-signify-java/pull/59/files#r2604004041
Should be resolved before this PR is merged!
There was a problem hiding this comment.
@Sotatek-DucPhung Please check my comment there: #59 (comment)
Those changes MUST be fixed in this PR before merging.
There was a problem hiding this comment.
If it will take time to fix those, and we resolve the other comment in this thread first. We could defer fixing these until the next PR
There was a problem hiding this comment.
yep, sounds good to me
|
@iFergal please take a look again! Thanks |
src/main/java/org/cardanofoundation/signify/app/aiding/IdentifierController.java
Outdated
Show resolved
Hide resolved
| return Optional.empty(); | ||
| } | ||
|
|
||
| // Note: KERIA can return either a single object or an array |
There was a problem hiding this comment.
I don't believe this is true:
states = []
for pre in pres:
if pre not in agent.hby.kevers:
continue
kever = agent.hby.kevers[pre]
states.append(asdict(kever.state()))
rep.status = falcon.HTTP_200
rep.content_type = "application/json"
rep.data = json.dumps(states).encode("utf-8")
In fact, this endpoint could just take pre and call .list([pre]) or something
There was a problem hiding this comment.
so this keria endpoint return an array right ?
There was a problem hiding this comment.
Yep. For both .get and .list it will return a list from the endpoint. If .get, it will be an array of length 1 at most.
(It could be [] if you call .get with an AID that KERIA does not know about (the continue line above))
| return Optional.of(Utils.fromJson(res.body(), Object.class)); | ||
|
|
||
| String body = res.body(); | ||
| if (body == null || body.isBlank()) { |
There was a problem hiding this comment.
It will always at least return an empty array
| ObjectNode node = mapper.readTree(p); | ||
|
|
||
| coerceToString(node, "kt"); | ||
| coerceToString(node, "nt"); |
There was a problem hiding this comment.
This is incorrect, we are not meant to have strings of JSON arrays. We are meant to have arrays.
Please work with Patrick to get the OpenAPI changes needed to update the generated model and have the correct format.
There was a problem hiding this comment.
@Sotatek-DucPhung Please check my comment there: #59 (comment)
Those changes MUST be fixed in this PR before merging.
| import static org.cardanofoundation.signify.core.Httping.parseRangeHeaders; | ||
|
|
||
| public class Identifier { | ||
| public class IdentifierController { |
There was a problem hiding this comment.
I'm wondering why we need to change this class name?
There was a problem hiding this comment.
This class name is defined in Signify itself (not a type from KERIA), so I guess it was renamed to not conflict with the generated Identifier.java. But if we update that, we should be updating the others to be consistent.
However, it's not really a HTTP controller. This is the class used in client.identifiers()
|
@iFergal Do you think we need to re-generate models because we changed this in keria? WebOfTrust/keria@262b7ce |
|
@Sotatek-Patrick-Vu imo lets do this:
That way, this PR just shows the changes as a result of updating the type generation config for the plugin, and not mixed with changes from the new KERIA API. |