Introduce schema reference support#30
Conversation
af17934 to
7df9847
Compare
Allow multi schema references
| @ManyToMany | ||
| private List<Schema> references = new ArrayList<>(); | ||
|
|
||
| @Column(name = "DEFINITION", columnDefinition = "text", nullable = false, length = 8192) |
There was a problem hiding this comment.
Removed @Lob annotation as it was creating problems while fetching references field during schema validation by throwing:
org.postgresql.util.PSQLException: Large Objects may not be used in auto-commit mode.
when using PostgreSQL.
It was replaced by columnDefinition = "test" and effectively creates the same type of column for the definition field.
References:
https://shred.zone/cilla/page/299/string-lobs-on-postgresql-with-hibernate-36.html
| String subject; | ||
| Integer version; | ||
| Matcher schemaReferenceMatcher; | ||
| for (String schemaReferenceEntry : schemaReferenceHeader.split(";")) { |
There was a problem hiding this comment.
Method needs some refactoring.
Can you advice any "springy" way of doing schema reference resolution (header parsing, schema fetching, etc)?
| @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "subject") | ||
| @JsonIdentityReference(alwaysAsId = true) | ||
| @ManyToMany | ||
| private List<Schema> references = new ArrayList<>(); |
There was a problem hiding this comment.
Another issue I stumbled upon, since now instead of returning all Schema references, I only return their subject names i.e.:
{
"subject": "test",
"id": 1,
"version": 1,
"format": "avro",
"references": [
"subject.reference"
],
"definition": "..."
}
as opposed to:
{
"subject": "test",
"id": 1,
"version": 1,
"format": "avro",
"references": [
{
"subject": "subject.reference",
"id": 2,
...
}
],
"definition": "..."
}
This however, now breaking tests since MappingJackson2HttpMessageConverter's object mapper is trying to map REST's response payload directly to Schema.class where Schema.references is List<Schema> not List<String>.
I am not entirely sure how to solve this for now.
- Write an interceptor to fetch referenced schemas during serialization
- Map REST's response payload to
String, then perform manual parsing - Somehow deactivate
@Json*annotations underSchema.classduring tests, so that the latter payload format gets returned
What do you think?
Addresses 3rd solution from #29
Looks up optional
Schema-Referenceheader that is suppose to contain referenced subjects in the following format:Schema-Reference: <referenced-subject-1>; <referenced-subject-2>; // without versionSchema-Reference: <referenced-subject>+v<version-number>;Example usage:
First request:
Response:
201 CreatedSecond request (referencing
test.subschema):Response:
201 CreatedExplanation: while creating the second schema, it:
Schema-Referenceheadersubsubject with version1in the repositorysubsubject's schema definitionmainsubject's schema definition (since it parsedsubschema, now it successfully validatestest.subtype)