-
Notifications
You must be signed in to change notification settings - Fork 109
FieldDescriptor optional() is not working #172
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
Comments
I found ConstrainedFields that may fix my issue. |
Hey!
|
I want to generate 'nullable' property.
mockMvc.perform(
post("/api/v1/test")
.param("transaction_id", transactionId)
.contentType(MediaType.APPLICATION_JSON)
.content(json)
)
.andExpect(status().isOk)
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andDo(
MockMvcRestDocumentationWrapper.document(
"test/{methodName}",
requestParameters(requestParameterDescriptors()),
requestFields(requestFieldDescriptors()),
responseFields(responseFieldDescriptors())
)
)
private fun requestParameterDescriptors(): List<ParameterDescriptor> = listOf(
parameterWithName("transaction_id").description("transaction id")
)
private fun requestFieldDescriptors(): List<FieldDescriptor> =
listOf(
fieldWithPath("number1").type(JsonFieldType.STRING).description("desc"),
fieldWithPath("number2").type(JsonFieldType.STRING).description("desc"),
fieldWithPath("type").type(JsonFieldType.STRING).description("desc"),
fieldWithPath("content").type(JsonFieldType.STRING).description("desc"),
fieldWithPath("metadata").type(JsonFieldType.STRING).description("desc").optional(),
)
private fun responseFieldDescriptors(): List<FieldDescriptor> = listOf(
fieldWithPath("transaction_id").type(JsonFieldType.STRING)
.description("transaction id")
) the result of yml file is below. components:
schemas:
api-v1-test-hmac793873085:
type: object
properties:
metadata:
type: string
description: desc
number2:
type: string
description: desc
number1:
type: string
description: desc
type:
type: string
description: desc
content:
type: string
description: desc |
When add optional() to parameters:
- name: transaction_id
in: query
description: desc
required: true
schema:
type: string but.. components.schemas.properties.. required is not showing. |
Thanks for the additional info @traeper ! I could reproduce the issue for both OpenAPI 2 and OpenAPI 3 generators. The info is correctly gathered in How it should look like ( |
Seems to be a duplicate of #90 |
Should be fixed with #183 |
When can we use the version which this issue has been resolved? Is there a scheduled date? |
Hey @GoodGoodJM , Sorry for the inconvenience! |
Hello.
I'm gratefully use restdocs-api-spec in my company.
Overall, it seems that the API specification is well generated. However, even if the FieldDescriptor entering the requestFields/responseFields is written to perform optional(), the generated yml file does not display the optional value.
Could you please tell me how to display the nullable value in requestFields/responseFields
Thanks in advance.
The text was updated successfully, but these errors were encountered: