Skip to content

avoid base field substitution#123

Open
droslbl wants to merge 6 commits intoFIWARE:mainfrom
droslbl:hotfix/schemalocation_changes
Open

avoid base field substitution#123
droslbl wants to merge 6 commits intoFIWARE:mainfrom
droslbl:hotfix/schemalocation_changes

Conversation

@droslbl
Copy link
Contributor

@droslbl droslbl commented Nov 28, 2025

Greetings @wistefan

I got a ticket because apparently it is possible to change base fields in TMForum using @schemalocation, I dont think this is intended since in the documentation @schemalocation is described for adding additional attributes rather than changing existing ones. Although I might be wrong...

In case it is not intented, here is a PR that tries to solve that problem by checking with beanDescription the fields in the target class as well as the commons

Here is a curl that can trigger this substitution:

curl --location 'http://localhost:8632/productOffering' \
--header 'Content-Type: application/json' \
--data-raw '{
    "href": "adsadada",
    "name": "Premium Internet Package",
    "description": "Ultra high-speed fiber internet",
    "isBundle": false,
    "isSellable": true,
    "lifecycleStatus": "Active",
    "version": "1.0",
    "statusReason": "Available for purchase",
    "validFor": {
        "startDateTime": "2025-01-01T00:00:00Z",
        "endDateTime": "2025-12-31T23:59:59Z"
    },
    "@schemaLocation": "https://raw.githubusercontent.com/fge/sample-json-schemas/refs/heads/master/json-home/json-home.json",
    "property2": "value2",
    "property1": "value1",
    "resources": ""
}'

Best regards

@Sh3rd3n
Copy link

Sh3rd3n commented Dec 23, 2025

Guys, when are you planning to merge this PR?

@wistefan wistefan added the patch Should be applied for dependency updates and small bugfixes. label Jan 6, 2026

private void checkForExplicitFieldOverrides(JsonSchema schema) {
var schemaNode = schema.getSchemaNode();
var propertiesNode = schemaNode.get("definitions");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't the propertiesNode be under "properties", instead of "definitions"? Please do not use magic constants, make them actual constants


log.debug("Getting all fields for class: {}", clazz.getName());

// Traverse the class hierarchy
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add a test for this. I'm pretty sure that this wont give you the fieldnames used in the json-schema, since the json property names are defined via Jackson-Annotation, rather than the raw-property names.

existingProperties.addAll(getAllFieldNames(beanDescription.getBeanClass()));

// Add standard TMForum properties that should never be overridden by schemas
existingProperties.add("id");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not every extendable entity has an id or href defined. With this, none such entity could be extended with an id or href.

@droslbl droslbl requested a review from wistefan March 11, 2026 07:19
Copy link
Collaborator

@wistefan wistefan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make this functionality configurable. It should be deactivated by default and just activated by configuration, since its a quite expensive solution for such an edge case.

String className = voClass.getName();
String baseClassName = null;

if (className.endsWith("CreateVO")) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to check if something is overwritten by a schema, check the class, not some other connected class. We will not hardcode semantic into the class-names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

patch Should be applied for dependency updates and small bugfixes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants