Skip to content

Conversation

FatalCatharsis
Copy link

@FatalCatharsis FatalCatharsis commented Apr 18, 2025

Fix #3428 find JsonSubTypes on supertype hierarchy and use specified property name

Description

Recurses up through all superclasses and finds the first instance of JsonSubTypes to use, instead of looking only at the direct ancestor. Also uses the property on the related JsonTypeInfo, instead of assuming it's the default @type property.

Just reported this today and figured I'd spend an hour or so since the fix was really obvious. A more aggressive change I kind of wanted to make was replacing the polymorphic type on the endpoint method with the created union type, but I couldn't grok the plugin logic enough to work out if that was possible, let me know if that's desirable and possible.

note: the provided eclipse settings file made a couple whitespace changes, so I'm thinking the file was made before you had the eclipse style xml. Either which way, I promise I applied it :)

Fixes #3428

Type of change

  • Bugfix
  • Feature

Checklist

  • I have read the contribution guide: https://vaadin.com/docs/latest/guide/contributing/overview/
  • I have added a description following the guideline.
  • The issue is created in the corresponding repository and I have referenced it.
  • I have added tests to ensure my change is effective and works as intended.
  • New and existing tests are passing locally with my change.
  • I have performed self-review and corrected misspellings.

@CLAassistant
Copy link

CLAassistant commented Apr 18, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@cromoteca cromoteca left a comment

Choose a reason for hiding this comment

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

Hi @FatalCatharsis,
Thank you for contributing this. It is really appreciated.
Before merging, I'm asking you to make some minor changes to better match existing code.
Also, please run mvn formatter:format before committing, as otherwise the PR check will fail.

import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.media.StringSchema;

import org.apache.commons.lang3.StringUtils;
Copy link
Contributor

Choose a reason for hiding this comment

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

lang3 is not a direct dependency in Hilla. If possible, avoid using it.

.stream().flatMap(Arrays::stream);
}

private static Optional<Pair<JsonTypeInfo, JsonSubTypes.Type[]>> getJsonSubTypeInHierarchy(
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use a record for better readability and to avoid using Pair.

package com.vaadin.hilla.parser.plugins.subtypes;

public class AdvancedAddEvent extends AddEvent {
private Boolean defer;
Copy link
Contributor

Choose a reason for hiding this comment

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

Private fields are not generated, so this field is probably useless in the test. You could make it public to match the other examples.

"info": {
"title": "Hilla Application",
"version": "1.0.0"
"openapi" : "3.0.1",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"openapi" : "3.0.1",
"openapi": "3.0.1",

In those files, remove the spaces before colons to reduce the number of changes in the PR.

Copy link

Copy link

codecov bot commented Apr 30, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.68%. Comparing base (2c9dc22) to head (511a5d8).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3429   +/-   ##
=======================================
  Coverage   86.68%   86.68%           
=======================================
  Files         115      115           
  Lines        8195     8195           
  Branches     1272     1272           
=======================================
  Hits         7104     7104           
  Misses       1075     1075           
  Partials       16       16           
Flag Coverage Δ
unittests 86.68% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Property name on JsonTypeInfo not used and type hierarchies don't generate the type field

3 participants