Adding Swagger to Kotlin Spring

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 doc…


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


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » Adding Swagger to Kotlin Spring." Dennis | Sciencx - Thursday May 5, 2022, https://www.scien.cx/2022/05/05/adding-swagger-to-kotlin-spring/
HARVARD
Dennis | Sciencx Thursday May 5, 2022 » Adding Swagger to Kotlin Spring., viewed ,<https://www.scien.cx/2022/05/05/adding-swagger-to-kotlin-spring/>
VANCOUVER
Dennis | Sciencx - » Adding Swagger to Kotlin Spring. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/05/05/adding-swagger-to-kotlin-spring/
CHICAGO
" » Adding Swagger to Kotlin Spring." Dennis | Sciencx - Accessed . https://www.scien.cx/2022/05/05/adding-swagger-to-kotlin-spring/
IEEE
" » Adding Swagger to Kotlin Spring." Dennis | Sciencx [Online]. Available: https://www.scien.cx/2022/05/05/adding-swagger-to-kotlin-spring/. [Accessed: ]
rf:citation
» Adding Swagger to Kotlin Spring | Dennis | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.