Skip to content

Gradle task openapi3 fails when a field is not given a description #121

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

Open
pangyikhei opened this issue Jan 7, 2020 · 2 comments
Open
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@pangyikhei
Copy link

Not sure if this is intended behavior, but when I don't specify a description for a response field, the output snippet resource.json outputs "description": null, which causes the openapi3 gradle task to fail.

Example:

The controller returns an array of objects.

[
  {
    "example": "blah"
  }
]

resources.json shows a null value for description

 "responseFields" : [ {
      "attributes" : { },
      "description" : null,
      "ignored" : false,
      "path" : "[].example",
      "type" : "STRING",
      "optional" : false
    },

Test uses Spring @WebMvcTest and MockMvc with MockMvcRestDocumentationWrapper

this.mockMvc.perform(get("/example"))
        .andExpect(status().isOk())
        .andDo(document("example", resource(ResourceSnippetParameters.builder()
            .responseFields(
                fieldWithPath("[].example").type(JsonFieldType.STRING)
            )
            .build()
        )));

Error:

Execution failed for task ':example:openapi3'.
> com.fasterxml.jackson.module.kotlin.MissingKotlinParameterException: Instantiation of [simple type, class com.epages.restdocs.apispec.model.FieldDescriptor] value failed for JSON property description due to missing (therefore NULL) value for creator parameter description which is a non-nullable type
...

com.epages.restdocs.apispec.model.ResourceModel["response"]->com.epages.restdocs.apispec.model.ResponseModel["responseFields"]->java.util.ArrayList[0]->com.epages.restdocs.apispec.model.FieldDescriptor["description"])

If I add any description to the FieldDescriptor, the task succeeds.

@ozscheyge
Copy link
Contributor

ozscheyge commented Jan 13, 2020

Interesting, we are always using FieldDescriptor with a description to leverage Spring restdocs throwing errors when not all/too many fields are documented (missing FieldDescriptor is equivalent to a missing description for us).

Your usage seems to be valid, however. So I'd consider it an error in the openapi3 generator.

Thanks for the report!

@ozscheyge ozscheyge added bug Something isn't working good first issue Good for newcomers labels Jan 13, 2020
@jmewes jmewes added good first issue Good for newcomers and removed good first issue Good for newcomers labels Feb 14, 2022
@seokjun7410
Copy link

I think I can solve this problem. Can I handle this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants