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

[Request] Ignore certain fields on @ApiObject classes #153

Open
lukasbradley opened this issue Oct 2, 2015 · 5 comments
Open

[Request] Ignore certain fields on @ApiObject classes #153

lukasbradley opened this issue Oct 2, 2015 · 5 comments

Comments

@lukasbradley
Copy link

I'm using Groovy for several of my ApiObject classes. Here is an example:

@ApiObject(name="UserCreateRequest")
class UserCreateRequest {
   @NotNull
   @ApiObjectField(description="Desired username", required=true)
   @Length(min=6,max=255)
   String name
}

Behind the scenes, Groovy adds a handful of properties to the class to support its "magic." Unfortunately, the class is then rendered in the UI like so:

{
  "$callSiteArray": {},
  "$staticClassInfo": {},
  "$staticClassInfo$": {},
  "__$stMC": true,
  "metaClass": {},
  "name": ""
}

I'd love to have those default Groovy properties like $callSiteArray and metaClass ignored in the JSON example.

The request is to be able to ignore some fields by default. The first thing that comes to mind is to add a new property to the configuration. Example:

jsondoc.apiObjectFields.ignore=$callSiteArray,$staticClassInfo....etc

Then ignore those fields on either the JSON output, the model creation, or possibly within the org.reflections code (I'm not sure if there is support for that functionality).

Thoughts? I'd be happy to do the work, but I wanted to get your input first.

@nisabek
Copy link

nisabek commented Oct 25, 2015

yeah, have the same issue here, using grails with the jsonDoc.
I was wondering, what is than the meaning of @ApiObjectField , if you still get the fields that are NOT annotated with this, into your object's view.
Maybe show only the ones that are annotated?...

@ysavourel
Copy link

+1 for showing only the annotated fields.

@nodoze
Copy link

nodoze commented Feb 13, 2016

+1 for ignore annotation

Since the SpringObjectBuilder does not require the @ApiObjectFieldannotation one could add a @ApiObjectIgnoreField annotation that if present would ignore the field. Using the exclusionary approach.

Alternatively a more generic annotation (e.g. @ApiIgnore) could be added to also support skipping of API methods.

for (Field field : clazz.getDeclaredFields()) {
   if (field.getAnnotation(ApiIgnore.class) != null)  continue;
}

@krishghata
Copy link

+1 for @ApiObjectIgnoreField

@charlesgoddard
Copy link

+1

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

No branches or pull requests

6 participants