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

Show All Objects that have annotation @ApiObject? #223

Open
cnfn opened this issue Feb 27, 2017 · 5 comments
Open

Show All Objects that have annotation @ApiObject? #223

cnfn opened this issue Feb 27, 2017 · 5 comments

Comments

@cnfn
Copy link

cnfn commented Feb 27, 2017

Now, JSONDoc only care that the objects with annotation ApiPathParam, ApiQueryParam, ApiBodyObject, ApiResponseObject.

If my custom object not use those annotations, I will not get JSONDoc for it.

In my team, HTTP API's ApiResponseObject is:

public class HttpResult {
    private String msg;
    private Integer code;
    private Object data;

    // getter and setter
}

JSONDoc not support my custom object by HttpResult.data property.

So I had modfied JSONDoc to support all objects that have annotation ApiObject, and use it in my team.

Would I can commit it?

@ST-DDT
Copy link

ST-DDT commented Feb 28, 2017

The @APIObjects will only be detected if they are used as a return type of a controller method.

See AbstractSpringJSONDocScanner#jsondocObjects()

But I agree that detecting more types would be nice. However I'm not sure whether it should support ALL of the annotated things.
Maybe it would be a good idea to add a flag for this (detectUsedObjects, detectAnnotatedObjects).
As an alternative I would suggest a new annotation. @APIDynamicType with a Class<?>[]value.

public class HttpResult {
    private String msg;
    private Integer code;

    @APIDynamicType({FooBar.class, AnyBar.class, FourtyTwo.class, MyDataContainer.class})
    private Object data;
}

This would allow the user to see what can actually be in there instead of just *Any*.

@cnfn
Copy link
Author

cnfn commented Feb 28, 2017

@ST-DDT @APIDynamicType is a very very good idea because it's more friendly for reader. And it would be more wonderful that JSONDoc support link them between API and Objects.

I have a question, why only small different between has or not has @ApiObject? So I want do something to enhance it...

@joffrey-bion
Copy link

I find it strange that even with the annotation, it does not appear in JsonDoc.

I mean, if the developer made the effort to put the annotation ApiObject (and didn't specify show=false), then I can't see any scenario in which he does not want to see that object in the doc.
What is the purpose of blocking these?

@cnfn
Copy link
Author

cnfn commented Mar 30, 2017

I also have this question.

@ST-DDT
Copy link

ST-DDT commented May 23, 2017

Example fix:

Add the following to AbstractSpringJSONDocScanner#jsondocObjects()

[...]
for (final Method method : methodsAnnotatedWith) {
	buildJSONDocObjectsCandidates(candidates, method.getReturnType(), method.getGenericReturnType(),
			this.reflections);
	final Integer requestBodyParameterIndex = JSONDocUtils.getIndexOfParameterWithAnnotation(method,
			RequestBody.class);
	if (requestBodyParameterIndex != -1) {
		candidates.addAll(
				buildJSONDocObjectsCandidates(candidates, method.getParameterTypes()[requestBodyParameterIndex],
						method.getGenericParameterTypes()[requestBodyParameterIndex], this.reflections));
	}
}

// NEWLY ADDED - START
candidates.addAll(this.reflections.getTypesAnnotatedWith(ApiObject.class, true));
// NEWLY ADDED - END

// This is to get objects' fields that are not returned nor part of the
// body request of a method, but that are a field
// of an object returned or a body of a request of a method
for (final Class<?> clazz : candidates) {
	appendSubCandidates(clazz, subCandidates, this.reflections);
}
[...]

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

3 participants