gigaSproule / swagger-gradle-plugin

JAX-RS & SpringMVC supported gradle build plugin to generate Swagger documentation
Apache License 2.0
97 stars 52 forks source link

[Question/Issue] Static html file prevents json files creation #97

Open Tristan-Louvre opened 6 years ago

Tristan-Louvre commented 6 years ago

Hallo,

Excuse me if I am being blind from the documentation, but when doing the following:

swaggerDirectory = "${buildDir}/swagger/json"
templatePath = "${project.projectDir}/templates/strapdown.html.hbs"
outputPath = "${buildDir}/swagger/html/document.html"
attachSwaggerArtifact = true

or

swaggerDirectory = "${buildDir}/swagger/json"
swaggerFileName = "${buildDir}/swagger/json/swagger.json"
templatePath = "${project.projectDir}/templates/strapdown.html.hbs"
outputPath = "${buildDir}/swagger/html/document.html"
attachSwaggerArtifact = true

I receive only the static html file. I have altered the swaggerFileName value to just be swagger.json aswell but don't seem to be having any success. I only receive the document.html file and not both as I would ideally prefer.

Am I doing something wrong or is the only solution to have multiple apiSources?

This is using version 1.0.4.

Thank you for any feedback.

gigaSproule commented 6 years ago

You're trying to set the output path as a html file, so that's not going to work. The output path is meant to be a path to the directory where you want it to go.

I'll leave this issue open in case that's not the issue.

Tristan-Louvre commented 6 years ago

Hi @gigaSproule,

In the example within your README.md you had the snippet below, so I just mirrored that behaviour:

        templatePath = "${project.rootDir}/src/test/resources/strapdown.html.hbs"
        outputPath = "${project.rootDir}/generated/document.html"
        swaggerDirectory = "${project.rootDir}/generated/swagger-ui"
        swaggerApiReader = 'com.wordnik.swagger.jaxrs.reader.DefaultJaxrsApiReader'
        modelConverters = [ 'io.swagger.validator.BeanValidator' ]

I have just done a clean/build with the following:

        templatePath = "${projectDir}/templates/strapdown.html.hbs"
        swaggerDirectory = "${buildDir}/swagger"
        outputPath = "${buildDir}/html"

Which resulted in:

image

I also note that from the noun choice, path == file location including file and dir == directory location.

Finally, the image also shows an empty swagger directory. If I comment out templatePath and outputPath it will have the swagger file present.

I appreciate your feedback.

gigaSproule commented 6 years ago

I'll take a deeper look. As this started out as a wrapper around the maven plugin, there's a lot of things I've inherited and tried to keep the same. Maybe I'll need to reword some of these to make it clearer.

gigaSproule commented 6 years ago

I had a look at the tests I've got (specifically this one) and noticed that the outputPath is defning an actual output file location. Whether that's really a good idea or not, I'll need to re-think.

Either way, I'd expect you to have outputPath = "${buildDir}/html/swagger.html"

Tristan-Louvre commented 6 years ago

Hey @gigaSproule,

I have seen from our pre-existing projects that the behaviour of the maven plugin is to provide both the json and the html.

For me the wording is perfectly clear.

The issue is that as it stands if outputPath is set to any value it overrides the ability to also have the .json file as an output as part of the same process.

I recognise the code is inherited and I could be referring to an unintended side affect on the maven plugin version we have used (it also could be a later feature past the point of forking?), but to me it makes no sense to exclude one over the other.

Put clear: I ideally require both a .html file and a .json file from this plugin.

What do you think?

Thanks as always for your prompt replies.