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

Cannot generate response model documentation via Enunciate #313

Closed
egemenvardar opened this issue Feb 16, 2016 · 9 comments
Closed

Cannot generate response model documentation via Enunciate #313

egemenvardar opened this issue Feb 16, 2016 · 9 comments
Labels
Milestone

Comments

@egemenvardar
Copy link

The generated Swagger documentation has always empty response model for all resource methods. I am using @typehint to give Enunciate a hint about the response type. An example resource method looks like this:

@GET
@Path(RestResourcePaths.CLIENT_GET)
@Produces(MediaType.APPLICATION_JSON)
@TypeHint(GetClientOutput.class)
public Response getClient(@Valid @BeanParam BaseClientInput input, @Context HttpServletRequest servletRequest) { ... }

whereas the generated Swagger documentation looks like this:

swagger_response_model_empty

Note that the input class (BaseClientInput) is rendered correctly and I could see the input parameters with documentation; however it's not the case for the output. Generated application.wadl file doesn't contain anything about GetClientOutput:

...
<wadl:response>
          <wadl:representation mediaType="application/json"/>
</wadl:response>
...

I am not sure what I am missing here. Any help would be appreciated.

EDIT: it's probably worth mentioning that I don't see any output classes under "Data Types":

enunciate_input_doc

Although I include them in enunciate.xml just like the input classes:

<api-classes>
        <include pattern="....rest.input.*"/>
        <include pattern="....rest.output.*"/>
        <include pattern="....services.*"/>
</api-classes>
@stoicflame stoicflame added the bug label Feb 16, 2016
@stoicflame stoicflame added this to the 2.3.0 milestone Feb 16, 2016
@stoicflame
Copy link
Owner

Weird. I can't explain it.

Are you using Maven? Does verbose output (mvn -X) mention anything about those output classes?

@egemenvardar
Copy link
Author

Yes I am using Maven. This is how it looks like in my pom file:

<plugin>
    <groupId>com.webcohesion.enunciate</groupId>
    <artifactId>enunciate-maven-plugin</artifactId>
    <version>${enunciate.version}</version>
    <executions>
        <execution>
            <goals>
                <goal>docs</goal>
            </goals>
            <configuration>
                <configFile>enunciate.xml</configFile>
                <docsDir>${project.build.directory}</docsDir>
            </configuration>
        </execution>
    </executions>
</plugin>

where the Enunciate version is 2.2.0.

I checked the Maven debug output. Here I see the output classes being logged:

[DEBUG] [ENUNCIATE] Compiler sources: [
....

But here I don't see them:

[DEBUG] [ENUNCIATE] Added XXX as a Jackson type definition.

Should I look for a specific log entry?

@stoicflame
Copy link
Owner

The only explanation I have is that the @TypeHint annotation isn't getting recognized or picked up.

Can you verify that you're using @com.webcohesion.enunciate.metadata.rs.TypeHint and not the org.codehaus one?

@egemenvardar
Copy link
Author

I was using the org.codehaus one actually. After changing it to com.webcohesion.enunciate.metadata.rs.TypeHint that output class appeared in the documentation, but it's empty:

empty_output

It's a pure POJO with no annotations other than @Getter and @Setter. I guess I need some annotation so that the Enunciate can pick up the fields. I can add @JsonProperty to each field, but it's a huge effort to go over all the output classes and do that. Is there a class annotation that Enunciate would recognize?

@patvong
Copy link
Contributor

patvong commented Feb 17, 2016

I think I have the same problem. @egemenvardar: do you have a multi module project that you setup following this: https://github.com/stoicflame/enunciate/wiki/Multi-Module-Projects?
Similar problem: #317

@stoicflame
Copy link
Owner

So @Getter and @Setter annotations are from Lombok, and Enunciate needs to use the Lombok-generated files instead of your pre-processed source files. See #182 for more information.

@egemenvardar
Copy link
Author

@patvong I have a multi-module project, but all REST related stuff (input, output, services etc.) resides in the same module. So I think we have different problems. My problem is about to get fixed by using com.webcohesion.enunciate.metadata.rs.TypeHint instead of org.codehaus.enunciate.jaxrs.TypeHint. (see my last comment)

@egemenvardar
Copy link
Author

@stoicflame I was able to fix the problem by adding

@JsonAutoDetect(getterVisibility = JsonAutoDetect.Visibility.ANY, fieldVisibility = JsonAutoDetect.Visibility.ANY)

to the output class. I didn't need to change any configuration. Now I can see the response schema and all field descriptions.

Thanks for the support. You could close this issue.

@stoicflame
Copy link
Owner

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

No branches or pull requests

3 participants