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

There is a way to hide resource properties? #87

Closed
rmpestano opened this issue Dec 21, 2016 · 8 comments
Closed

There is a way to hide resource properties? #87

rmpestano opened this issue Dec 21, 2016 · 8 comments

Comments

@rmpestano
Copy link
Contributor

rmpestano commented Dec 21, 2016

In swagger-doclet we used @exclude javadoc annotation at resource/method or field level to remove a resource from generated swagger json.

There is a way to achieve that with this plugin?

@sdaschner
Copy link
Owner

Not really. There was a similar request in #36. We could include an analysis configuration (like <excludes> in the Maven plugin config) to control that. So far the scope of the tool was to stay as close to the actual JAX-RS output as possible.

Do you see a big advantage in make that controllable? If yes then we should incorporate that feature.

@rmpestano
Copy link
Contributor Author

So If you create dedicated pojos for each endpoint you will NOT benefit from this but If you reuse your JPA entities and mark undesired properties with @JsonIgnore for example, it would be nice to exclude them from swagger too.

@rmpestano
Copy link
Contributor Author

rmpestano commented Dec 27, 2016

I've got it working here but it needs some changes.

As JaxRS doesn't have any standard for ignoring properties I've added jackson-annotations to the project which doesn't bring any transitive dependencies.

Then I've reworked JavaTypeAnalyzer to look for @JsonIgnore in analyze method. Here is the diff: http://www.diff-online.com/view/586277a8ed8ee

The only thing I could not make was to read the annotation @JsonIgnoreProperties value here:

private static boolean shouldIgnore(Field field) {
        if (isAnnotationPresent(field,JsonIgnore.class) || isAnnotationPresent(field.getDeclaringClass(), JsonIgnoreType.class)) {
            return true;
        }

 if(isAnnotationPresent(field.getDeclaringClass(),JsonIgnoreProperties.class)) {
            JsonIgnoreProperties jsonIgnoreProperties = 
getAnnotation(field.getDeclaringClass(), JsonIgnoreProperties.class); //class cast exception Proxy cannot be cast to JsonIgnoreProperties
            for (String ignoreField : jsonIgnoreProperties.value()) {
                if (field.getName().equals(ignoreField)) {
                    return true;
                }
            }
        } 
        return false;

Any idea on how to read the annotation values?

@sdaschner
Copy link
Owner

Ah ok, so I got it. Have you tried excluding the unwanted property with @XmlTransient? That is a workaround for some JSON mapping frameworks like Jackson for not having JSON related annotations in the standard (yet). The Analyzer should ignore these properties then.

@sdaschner
Copy link
Owner

I like your approach, though the initial idea of the tool was to stay as close to the standards as possible -- and as soon as that works completely to go on from that with the most commonly used frameworks. What do you think?

@rmpestano
Copy link
Contributor Author

The main problem is that APIs using @JsonIgnore will have responses in swagger-ui that differs from what the API documentation is saying.

What other frameworks se should handle?

@rmpestano
Copy link
Contributor Author

rmpestano commented Dec 29, 2016

Have you tried excluding the unwanted property with @XmlTransient?

So @XmlTransient excludes de field from swagger definition BUT when I invoke the endpoint in swagger-ui the field is present in response because my JaxRS implementation (resteasy) doesn't take @XmlTransient into account.

rmpestano added a commit to rmpestano/jaxrs-analyzer that referenced this issue Dec 29, 2016
rmpestano pushed a commit to rmpestano/jaxrs-analyzer that referenced this issue Jan 2, 2017
- adds tests for @JsonIgnore and @JsonIgnoreType
@rmpestano
Copy link
Contributor Author

rmpestano commented Jan 2, 2017

About @XmlTransient, RestEasy will not support it in favor of Jackson as stated here: https://issues.jboss.org/browse/WFLY-801

rmpestano pushed a commit to rmpestano/jaxrs-analyzer that referenced this issue Jan 2, 2017
- changelog update
rmpestano pushed a commit to rmpestano/jaxrs-analyzer that referenced this issue Jan 2, 2017
- removes wrong comment
rmpestano added a commit to rmpestano/jaxrs-analyzer that referenced this issue Jan 2, 2017
JsonIgnore in superclass
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

2 participants