Merging loses original reference
Closed this issue · 4 comments
The following code causes original references to be lost during a merge:
If the new "merged" (allOf) map replaces a map in the jsonContext that was also stored in $Refs.originalRefsList, then the external reference is lost. This means that in a later stage (in the processor) no x--original-ref item will be added and the original schema item name is unavailable.
My suggestion would be to add a check if the originalAllOfRoot exists in the originalRefsList and if so replace this item with the merged object. Something like this:
var mergedAllOfObject = allOfObject.buildAllOfObject();
$Ref originalRef = refs.getOriginalRef(originalAllOfRoot);
if (originalRef != null) {
refs.saveOriginalRef(originalRef, mergedAllOfObject);
}
refs.jsonContext.set(jsonPath, mergedAllOfObject);
refs.saveOriginalAllOf(mergedAllOfObject, allOf); Regards,
Michel
@micheldeblok-dvb thanks for reporting this
do you have an example for testing this?
I tested it on the following spec:
asyncapi: 3.0.0
info:
title: my-eventing-app
version: 1.0.0
description: This service is in charge of processing user signups
servers:
development:
host: localhost:5672
description: Development Kafka broker.
protocol: kafka
channels:
user-signed-up:
address: example.user-signed-up
messages:
userSignedUp:
$ref: '#/components/messages/UserSignedUpMessage'
operations:
userSignUp:
action: send
channel:
$ref: '#/channels/user-signed-up'
onUserSignedUp:
action: receive
channel:
$ref: '#/channels/user-signed-up'
components:
messages:
UserSignedUpMessage:
name: UserSignedUpMessage
title: User signed up event
summary: Inform about a new user registration in the system
contentType: application/cloudevents+json
payload:
$ref: '#/components/schemas/UserSignedUpPayload'
schemas:
UserSignedUpPayload:
name: userSignedUpPayload
type: object
allOf:
- $ref: >-
https://<our-schema-registry>/schemas/common/components/schemas/event/business/1.0.1/schema.yaml#/BusinessEventMetadata
- type: object
properties:
data:
$ref: "#/components/schemas/UserSignedUp"
required:
- data
UserSignedUp:
type: object
properties:
id:
type: string
description: The id of the created user
name:
type: string
description: The first name of the user
created_at:
type: string
format: date-time
description: The user creation time
The BusinessEventMetadata object also contains an "allOf" to another external schema that doesn't have an "allOf"
I then notice that the originalRefsList for BusinessEventMetadata was lost. So you should be able to replicate it if an "allOf" refers to an object that also has an "allOf"..
Regards,
Michel
I've just released your proposed change as v0.8.10
If you are using this with zenwave maven plugin you need to add this version to the pluging dependencies as I will not release a patch version of zenwave right now..
Let me know if it worked for you or you have any issues
Thnks
Hi Iván,
yes this works for me, thanks for the quick fix!
Regards,
Michel