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

Discussion: Ignoring properties #184

Closed
sauterl opened this issue May 12, 2023 · 5 comments
Closed

Discussion: Ignoring properties #184

sauterl opened this issue May 12, 2023 · 5 comments
Labels
question Further information is requested

Comments

@sauterl
Copy link
Contributor

sauterl commented May 12, 2023

When using javalin, one way to handle serialization / deserialization could be done by Jackson and thus, properties that should be ignored are annotated with @JsonIgnore.

Unfortunately, the openapi plugin corresponding annotation, @OpenApiIgnore is not applicable to FIELD, as @JsonIgnore is.

My thoughts on this are as follows:

  • Is there a reason why @OpenApiIgnore is configured to not target FIELDs? And if not, could we expand the target list accordingly?
  • Regarding compatibility and reduced writing, is there a way to instruct the openapi plugin to also ignore @JsonIgnore annotated elements?

Thanks in advance!

@dzikoysk dzikoysk added the question Further information is requested label May 15, 2023
@dzikoysk
Copy link
Member

dzikoysk commented May 15, 2023

Sorry for late response, I didn't notice this issue.

  1. By default, OpenApi plugin reads only getters and thus fields are ignored. Do you use @OpenApiByFields?
  2. Not really, I guess it could be possible if we'd support custom annotations, so you could create sth like:
@OpenApiIgnore
@JacksonAnnotationsInside
@JsonIgnore
annotation class IgnoreInJacksonAndOpenApi

or with some custom handler in our scripting API.

@sauterl
Copy link
Contributor Author

sauterl commented May 16, 2023

No worries, and thanks for the reply.

No, we do not use @OpenApiByFields.

I guess then this might be a bug:

We do have the following setup:

interface IMyLittleMoreThanPojo {
 val propertyWeWantInTheApi: ISomeType
val propertyWeDontWant: IOtherType
}

data class ApiMyLittleMoreThanPojo(
 override val propertyWeWantInTheApi = ApiSomeType()
) : IMyLittleMoreThanPojo {
 @JsonIgnore
 override lateinit var propertyWeDontWant: ApiOtherType
 internal set
} : 

This setup then results in the following OpenApi JSON:

"ApiMyLittleMoreThanPojo": {
 "type": "object",
 "additionalProperties": false,
 "properties":{
    "propertyWeWantInTheApi": {
     "$ref":"#/components/schemas/ApiSomeType"
    },
   "propertyWeDontWant":{
     "$ref":"#/components/schemas/ApiOtherType"
   }
 },
 "required":["propertyWeWantInTheApi", "propertyWeDontWant"]
}

Due to our setup, we cannot use @OpenApiIgnore, since propertyWeDontWant is a member property with backing field -- it might be worthwhile to simply adjust @OpenApiIgnore ?

@dzikoysk
Copy link
Member

Oh, that's a property, not a field - I thought you're using Java, not Kotlin. You should annotate this with site target, like that:

@get:OpenApiIgnore
val propertyWeDontWant: IOtherType

@sauterl
Copy link
Contributor Author

sauterl commented May 16, 2023

Thanks for pointing this out! I wasn't aware of site targeted annotations and my apologies for not properly label this as a kotlin problem.

@sauterl sauterl closed this as completed May 16, 2023
@dzikoysk
Copy link
Member

There's a nice plugin that can simplify this btw: #171

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants