This content originally appeared on Level Up Coding - Medium and was authored by Dennis
Spring makes it extremely easy to create REST API, but as a consumer of APIs, we need documentation to know what is available and how to use it. That’s where Swagger comes in and solved the problem.
In short, Swagger defines the structure of the API documentation in the form of a json schema, specifying what are the paths available, the parameters required by the various paths, and what type of results can be expected. As such, humans and machines both can have a standard way to read the API. Reading is easy for a human, the naming conventions are very well defined for most people to understand easily without the need to refer to the schema documentation. However, writing it can be tricky as you got to remember the exact wording for each item.
There’s an easy way out for Spring users. By simply adding the SpringDoc dependencies to your classpath, the Swagger documentation can be generated automatically when you run the project.
dependencies {
...
implementation("org.springdoc:springdoc-openapi-data-rest")
implementation("org.springdoc:springdoc-openapi-ui")
implementation("org.springdoc:springdoc-openapi-kotlin")
}
After you bootRun the application, the swagger ui will be available on your application accessible by the path - /swagger-ui/index.html, e.g. http://localhost:8080/swagger-ui/index.html.
And the link to the actual json schema file is on the page /v3/api-docs, e.g. http://localhost:8080/v3/api-docs.
This article was originally published on https://thecodinganalyst.github.io/knowledgebase/Adding-swagger-to-Kotlin-Spring/.
Adding Swagger to Kotlin Spring was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.
This content originally appeared on Level Up Coding - Medium and was authored by Dennis
Dennis | Sciencx (2022-05-05T10:36:55+00:00) Adding Swagger to Kotlin Spring. Retrieved from https://www.scien.cx/2022/05/05/adding-swagger-to-kotlin-spring/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.