ePages-de / restdocs-api-spec

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

Feature: Support Request Parts #271

Open belljun3395 opened 2 months ago

belljun3395 commented 2 months ago

Related Isssue: #105 , #205

I am not good at English. If there's anything you don't understand, please leave a comment.

I know swagger and postman support file type.

- Swagger 스크린샷 2024-09-07 오후 3 06 58

- Postman 스크린샷 2024-09-07 오후 3 07 19

So I wrote the code to implement to support request with file.

RequestModel

private data class RequestModel(
    ....
    val requestParts: List<OperationRequestPart>,
)

Add requestParts for multipart request.

FileSchema, FormData

class FileSchema(
    builder: BinarySchemaBuilder
) : StringSchema(builder) {
    ...
    val format: String
}
@JsonPropertyOrder({
    "key",
    "type",
    "src",
    "description",

})
public class FormData {
    ....
}

Make FileSchema/FormData for OpenApiGenerator/PostmanGenerator to handle spec for file type.

In Generator they are added to RequestModel and Body

data class RequestModel(
    ...
    // FileSchema -> RequestPartFieldDescriptor
    val requestParts: List<RequestPartFieldDescriptor>,
)
@JsonPropertyOrder({
    "mode",
    "raw",
    "urlencoded",
    "formdata"
})
public class Body  { ... }