ePages-de / restdocs-api-spec

Adds API specification support to Spring REST Docs
MIT License
391 stars 103 forks source link

fix/wrong generation of default values for headers and queries #195

Closed jackcat13 closed 2 years ago

jackcat13 commented 2 years ago

Hello,

I create this issue to follow the fix provided in the following issue : https://github.com/ePages-de/restdocs-api-spec/issues/187

There is a bug with default values of headers/queries when generating the openapi files using the open api generator classes. Even if the default values are set when defining the resources, it appears that no default value is present when calling the generate methods. It has not been identified because no automatic test was written for the openapi generation step for the mentioned fix.

After digging into the code, I've been able to figure out why it fails and I have already created this PR: https://github.com/ePages-de/restdocs-api-spec/pull/194

Actually, it's not able to generate the default values because of the attribute name (defaultValue) in AbstractParameterDescriptor interface:

interface AbstractParameterDescriptor {
    val name: String
    val description: String
    val type: String
    val defaultValue: Any? //Here the name is wrong
    val optional: Boolean
    val attributes: Attributes
}

The attribute defaultValue needs to be renamed into default because this is the name of the attribute in generated snippets. I've done the change in the PR and I've also written an additional test case to validate the behavior.

Thanks in advance.

jackcat13 commented 2 years ago

Change done because i've been informed that we need to keep the defaultValue name so it does not fail for java code.

I have reverted the attribute name back to defaultValue and I've added the use of @JsonProperty annotation on the attribute itself to override the name in the generated json.

Meaning the change is now on the defaultValue of the two following classes:

I can't apply the JsonProperty directly to the interface attribute.

ozscheyge commented 2 years ago

Thanks for the contribution @jackcat13 !

Your assessment is correct and the fix lgtm! I'll prob. draft the release on Monday.