Duplicate a schema
Creating a new schema based on an existing one is a common practice for developing new versions, creating localized variants, or simply using a pre-existing schema as a template. This process, called duplication, allows you to leverage existing work without altering the original schema.
Using the SDK
When using the SDK, a schema is defined as a class. To duplicate a schema, you can either copy the UDT definition and create a new class or use class extension. This allows you to easily create a new schema resource based on an existing one. The example below shows how to duplicate a schema using class extension:
- Java
// Existing UDT definition
@VcSchema(slug = "proof-of-identity")
class ProofOfIdentity {
@NotEmpty
String firstName;
@NotEmpty
String lastName;
}
// Duplicated UDT using class extension
@VcSchema(slug = "duplicated-proof-of-identity")
class DuplicatedProofOfIdentity extends ProofOfIdentity {}
Using the API
To duplicate a schema using the API, use the POST /schemas endpoint. This endpoint allows you to create a new schema by referencing an existing one using either its internal ID or its public URL.
From an internal schema ID
This method is useful for duplicating a schema that has not yet been published, or one that is only available within your tenant. You must have the ID of the original schema.
To duplicate the schema, use the POST /schemas endpoint and provide the following in the request body:
{
"from_schema": "b4d2e7a1-c9f3-d5a8-b7c6-e1f0a3b9c2d5",
"labels": {
"variant": "german"
}
}
From a public URL
This method is useful for duplicating a schema that has been published by another tenant or is publicly available. You must use the full public URL of the schema.
To duplicate the schema, use the POST /schemas endpoint and provide the following in the request body:
{
"from_published_schema_url": "https://ssi.truvity.com/tenants/123/schemas/meta/basic-profile/v1"
}