Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kotlin: Some of my properties are ignored #858

Closed
Tomucha opened this issue Nov 27, 2022 · 5 comments · Fixed by #867
Closed

Kotlin: Some of my properties are ignored #858

Tomucha opened this issue Nov 27, 2022 · 5 comments · Fixed by #867

Comments

@Tomucha
Copy link

Tomucha commented Nov 27, 2022

Expected Behavior

I have two Kotlin classes, one extends the other.

@Schema(name = "EntityRelationFilterWithViewDataDTO",
    description = "Filtr umožňující hledání podle cesty, fulltext hledaním, hleanim pres relations a určení výběru dat," +
            " které bude výsledný pohled obsahovat",
)
@Introspected
class EntityRelationFilterWithViewDataDTO(
    @field:Schema(hidden = true)
    val entityType: String?,
    val entitySubType: String?,
    val path: String?, val query: String?,
    @field:Schema(description = "Podmínky, které musí splňovat vazby hledaných entit (např. hledám všechnny ZOGy)")
    val relationFilters: Array<RelationFilter>? = null,
    @field:Schema(description = "Podmínky, které musí splňovat custom data entity.")
    val conditionFilters: Array<ConditionFilter>? = null,
    @field:Schema(name = "_viewDataPath",
        description = "Určení custom dat, které bude výsledný pohled obsahovat (formou path v custom data aka generich key)." +
                " Defaultně se nevrací žádná custom data, pouze základní vlastností entity.")
    val _viewDataPath: Array<String>?,
    page: Int?,
    pageSize: Int?) : FilterDTO(page, pageSize)
    
@Schema(name = "FilterDTO", description = "Obecný filtr stránkování.")
@Introspected
open class FilterDTO(
    @field:Schema(name="page", description = "Číslo stránky (pořadí), která se má vrátit", type = "integer", defaultValue = "0")
    val page: Int? = 0,
    @field:Schema(name="pageSize", description = "Velikost stránky výsledků (např. 30)", type = "integer", defaultValue = "30")
    val pageSize: Int? = 30) {
}    

Resulting openapi scheme should contain all these properties, expect entityType, which is hidden.

Actual Behaviour

But this is the result. property with name starting with underscore is omited, and page and pageSize which are inherited from the parent object are missing too:

    EntityRelationFilterWithViewDataDTO:
      type: object
      properties:
        entitySubType:
          type: string
          nullable: true
        path:
          type: string
          nullable: true
        query:
          type: string
          nullable: true
        relationFilters:
          type: array
          description: "Podmínky, které musí splňovat vazby hledaných entit (např\
            . hledám všechnny ZOGy)"
          nullable: true
          items:
            $ref: '#/components/schemas/RelationFilter'
        conditionFilters:
          type: array
          description: "Podmínky, které musí splňovat custom data entity."
          nullable: true
          items:
            $ref: '#/components/schemas/ConditionFilter'
      description: "Filtr umožňující hledání podle cesty, fulltext hledaním, hleanim\
        \ pres relations a určení výběru dat, které bude výsledný pohled obsahovat"

I can see that some field:Scheme annotations are applied correctly ( @field:Schema(hidden = true) val entityType: String? ), but some are completely ignored: @field:Schema(name = "_viewDataPath", description = "Určení custom dat ...") val _viewDataPath: Array<String>?,

Steps To Reproduce

I'm trying this with:
<micronaut.version>3.7.4</micronaut.version>
<micronaut.openapi.version>4.7.1</micronaut.openapi.version>

My controller looks like this:

@Operation(summary = "Vrací seznam resortů daných filtrem.")
@Post("/filter")
@ContinueSpan
fun filterDepartments(@Body filterDTO: EntityRelationFilterWithViewDataDTO): HttpResponse<List<DepartmentBean?>> {
....

Environment Information

No response

Example Application

No response

Version

3.7.4

@altro3
Copy link
Collaborator

altro3 commented Nov 28, 2022

@Tomucha Hi! I fixed bug with lost properties. About _ prefix for properties: yes, this is bug, but in micronaut core. The problem is that micronaut checks the first character for uppercase in the getter method (get_viewDataPath()), and, as you understand, the _ symbol is not in uppercase

@Tomucha
Copy link
Author

Tomucha commented Nov 28, 2022

Great, thanks!

About the underscore ... unfortunately I'm not familiar with inner clockwork of Micronaut, but in general it seems to me, that users' annotation should be "sacred", once there is an explicit annotation, no matter how seemingly rediculous, it MUST be applied as is.

I understand that in this specific case I might be forced to place such annotation in my class, but once it's here ...

Do you think there is a workaround, or should I just rename it? Underscore here signalizes a "virtual/transient nature" of the property.

@altro3
Copy link
Collaborator

altro3 commented Nov 28, 2022

@Tomucha As I wrote in the previous message - this is a bug, a bug in the core, not in this project. I fixed it here micronaut-projects/micronaut-core#8435.

But, if you don't want to wait until the changes are released, just rename the field and replace the first character with some letter

@Tomucha
Copy link
Author

Tomucha commented Nov 28, 2022

Oh, ok, I didn't know that the core is fixed too. Great, I'll wait, thanks!

@altro3
Copy link
Collaborator

altro3 commented Nov 28, 2022

@Tomucha You didn't know about it because no one knew and made a fix a few minutes ago :-))))) You found 2 bugs :-) - in the core and here

graemerocher added a commit that referenced this issue Dec 2, 2022
Changed processing logic for inheritance. 

Fixed #858
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 a pull request may close this issue.

2 participants