Skip to content
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

Automated HTTP API documentation #85

Open
sdeleuze opened this issue Jul 16, 2018 · 13 comments
Open

Automated HTTP API documentation #85

sdeleuze opened this issue Jul 16, 2018 · 13 comments
Assignees
Labels
type: enhancement A general enhancement

Comments

@sdeleuze
Copy link
Collaborator

OpenAPI: we should try springfox/springfox#1773 which has been merged and see if functional support is ok.

Spring REST docs: we should test WebTestClient support, see spring-projects/spring-restdocs#384.

@wilkinsona
Copy link

Unfortunately, I don't think it's possible to generate an OpenAPI spec via code inspection alone when you take a functional approach. The request predicates are too free-form to be able to introspect them and generate an accurate specification. For this reason, AFAIK, SpringFox quite reasonably doesn't even try – I can't find any references to WebFlux in their code.

@sdeleuze
Copy link
Collaborator Author

Indeed, but we can maybe leverage RouterFunctions.Visitor like we do for logging is order to build such OpenAPI spec. Any thoughts @poutsma?

@poutsma
Copy link

poutsma commented Aug 1, 2018

Not sure if that is going to work. Like @wilkinsona said, the request predicates is an open set, and (unless we make the predicates aware of OpenAPI) the only thing of use for a visitor is the String representation. This is what we use for logging: all pre-defined predicates have a toString that generates useful logging information. You could theoretically parse that string representation to come up with an OpenAPI spec, but that seems very fragile.

@tgirard12
Copy link
Contributor

Using a Visitor should be possible if subclass of RequestPredicate like HeadersPredicate or QueryParamPredicate were public.

Maybe Webflux framework could have another Visitor who generate a kind of RouterFunction data structure with all the RequestPredicate informations.

This kind of data structure will be used for automated API documentation.

@tgirard12
Copy link
Contributor

To explain what I'm saying in my previous message, I've wrote a RouterFunctions.Visitor in spring-framework.

It's in a very early stage and provide a kind of schema for all routes with RequestPredicate :
spring-projects/spring-framework@master...tgirard12:webflux-visitor

@sdeleuze sdeleuze added this to the 0.0.2 milestone Sep 19, 2018
@sdeleuze
Copy link
Collaborator Author

I will work on that before Spring Boot 2.1 GA.

@sdeleuze
Copy link
Collaborator Author

Since I am a big fan of Spring REST docs but also recognize the need to document REST API in a machine readable way, I think I will prototype something based on @tgirard12 RouterFunctions.Visitor approach used with https://github.com/ePages-de/restdocs-openapi mentioned in spring-projects/spring-restdocs#213.

@sdeleuze sdeleuze modified the milestones: 0.0.2, 0.0.3 Sep 29, 2018
@sdeleuze
Copy link
Collaborator Author

@tgirard12 Do you think it would be possible for you to play a little bit with the Spring Framework branch Arjen Poutsma has been working on (targeting upcoming 5.1.2, see this JIRA comment) to see if that fit the need from your POV?

@tgirard12
Copy link
Contributor

I have play a little with this branch. I think it will possible to get all the RequestPredicates for all routes if we use both a RouterFunctions.Visitor and a RequestPredicates.Visitor.

The current implementation have some limitations with the Kotlin RouterFunction Dsl because when we declare a route with GET("/foo") { ok() }, we can't use the RequestPredicates.Visitor.

The only missing information for generating a kind of automatic documentation is the return type, we need to create a custom RequestPredicate only used to specify the return type of the route.

@sdeleuze
Copy link
Collaborator Author

@tgirard12 Could you please detail the limitations with Kotlin RouterFunction Dsl? I don't see what would prevent the Kotlin version to work while this Java version is working.

@tgirard12
Copy link
Contributor

It will work fine with the Kotlin DSL and a RouterFunctionDsl.
The only limitation is when your want to use the RequestPredicates.Visitor for only one route in a Router. But I think it will not be the common use case.

@sdeleuze sdeleuze modified the milestones: 0.0.4, 0.0.5 Dec 20, 2018
@sdeleuze sdeleuze removed this from the 0.0.5 milestone Jan 9, 2019
@sdeleuze
Copy link
Collaborator Author

https://github.com/springdoc/springdoc-openapi README mentions "spring-webflux with Functional Endpoints, will be available in the future release". Maybe worth contacting them for functional WebMvc and WebFlux support?

@sdeleuze sdeleuze added this to the 0.5.0 milestone Oct 28, 2020
@sdeleuze
Copy link
Collaborator Author

We have been collaborating with @poutsma and the project lead of Springdoc to implement functional support of OpenAPI, and it is done, see springdoc/springdoc-openapi#891. Let's try to integrate that in Spring Fu for 0.5.0.

@sdeleuze sdeleuze added the type: enhancement A general enhancement label Jan 8, 2021
@sdeleuze sdeleuze modified the milestones: 0.5.1, 0.6.0, General backlog Dec 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

5 participants