All Projects → swagger-api → Swagger Play

swagger-api / Swagger Play

Licence: apache-2.0

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Swagger Play

Validator Badge
Validate your Swagger JSON/YAML today!
Stars: ✭ 158 (-50.62%)
Mutual labels:  rest, swagger, restful-api, openapi-specification
Swagger Ui
Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
Stars: ✭ 21,279 (+6549.69%)
Mutual labels:  rest, swagger, openapi-specification
Swagger Node
Swagger module for node.js
Stars: ✭ 3,917 (+1124.06%)
Mutual labels:  rest, swagger, openapi-specification
Swagger Js
Javascript library to connect to swagger-enabled APIs via browser or nodejs
Stars: ✭ 2,319 (+624.69%)
Mutual labels:  rest, swagger, openapi-specification
Swurg
Parse OpenAPI documents into Burp Suite for automating OpenAPI-based APIs security assessments (approved by PortSwigger for inclusion in their official BApp Store).
Stars: ✭ 94 (-70.62%)
Mutual labels:  swagger, restful-api, openapi-specification
Swagger Parser
Swagger Spec to Java POJOs
Stars: ✭ 468 (+46.25%)
Mutual labels:  rest, swagger, openapi-specification
Swagger Core
Examples and server integrations for generating the Swagger API Specification, which enables easy access to your REST API
Stars: ✭ 6,898 (+2055.63%)
Mutual labels:  rest, swagger, openapi-specification
Swagger Editor
Swagger Editor
Stars: ✭ 7,365 (+2201.56%)
Mutual labels:  rest, swagger, openapi-specification
Appy Backend
A user system to bootstrap your app.
Stars: ✭ 96 (-70%)
Mutual labels:  rest, swagger, restful-api
Swagger Inflector
Stars: ✭ 131 (-59.06%)
Mutual labels:  rest, swagger, openapi-specification
Swagger Codegen
swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
Stars: ✭ 13,859 (+4230.94%)
Mutual labels:  rest, swagger, openapi-specification
Proteus
Lean, mean, and incredibly fast JVM framework for web and microservice development.
Stars: ✭ 178 (-44.37%)
Mutual labels:  rest, swagger, restful-api
Drf Yasg
Automated generation of real Swagger/OpenAPI 2.0 schemas from Django REST Framework code.
Stars: ✭ 2,523 (+688.44%)
Mutual labels:  rest, swagger, openapi-specification
Blogbackendproject
Backend code for my blogs, develop with Django Rest framework.
Stars: ✭ 204 (-36.25%)
Mutual labels:  rest, restful-api
Fastapi Gino Arq Uvicorn
High-performance Async REST API, in Python. FastAPI + GINO + Arq + Uvicorn (w/ Redis and PostgreSQL).
Stars: ✭ 204 (-36.25%)
Mutual labels:  rest, swagger
Json Server Heroku
Deploy json-server to Heroku & Azure 🆙 🆓
Stars: ✭ 310 (-3.12%)
Mutual labels:  rest, restful-api
Digital Restaurant
DDD. Event sourcing. CQRS. REST. Modular. Microservices. Kotlin. Spring. Axon platform. Apache Kafka. RabbitMQ
Stars: ✭ 222 (-30.62%)
Mutual labels:  rest, restful-api
Hapi Openapi
Build design-driven apis with OpenAPI (formerly swagger) 2.0 and hapi.
Stars: ✭ 196 (-38.75%)
Mutual labels:  rest, swagger
Restito
Restito - mocking framework for testing rest clients
Stars: ✭ 217 (-32.19%)
Mutual labels:  rest, restful-api
Flask Restplus
Fully featured framework for fast, easy and documented API development with Flask
Stars: ✭ 2,585 (+707.81%)
Mutual labels:  rest, swagger

Build Status

Swagger Play2 Module

Note

This branch (master) holds the latest version (major version 2.x) for latest play version supported (2.7); branch play-2.6 holds the swagger-play version for play 2.6 version (major.minor version 1.6.x).

Older versions are available though not anymore supported in the archive branch.

Overview

This is a module to support Swagger annotations within Play Framework controllers. It is based on the library https://github.com/swagger-api/swagger-play with several improvements. This library uses Swagger 1.5 and Play 2.7. It can be used for both Scala and Java based applications.

We also would like to support Swagger 2.0 in the future and contributions to that end will be gladly accepted.

New and Noteworthy

Usage

You can depend on pre-built libraries in maven central by adding the following dependency:

libraryDependencies ++= Seq(
  "io.swagger" %% "swagger-play2" % "2.0.1-SNAPSHOT"
)

Or you can build from source.

sbt publishLocal

Adding Swagger to your Play2 app

There are just a couple steps to integrate your Play2 app with swagger.

1. Add the Swagger module to your application.conf

play.modules.enabled += "play.modules.swagger.SwaggerModule"

2. Add the resource listing to your routes file (you can read more about the resource listing here)


GET     /swagger.json           controllers.ApiHelpController.getResources

3. Annotate your REST endpoints with Swagger annotations. This allows the Swagger framework to create the api-declaration automatically!

In your controller for, say your "pet" resource:

  @ApiResponses(Array(
    new ApiResponse(code = 400, message = "Invalid ID supplied"),
    new ApiResponse(code = 404, message = "Pet not found")))
  def getPetById(
    @ApiParam(value = "ID of the pet to fetch") id: String) = Action {
    implicit request =>
      petData.getPetbyId(getLong(0, 100000, 0, id)) match {
        case Some(pet) => JsonResponse(pet)
        case _ => JsonResponse(new value.ApiResponse(404, "Pet not found"), 404)
      }
  }

What this does is the following:

  • Tells swagger that the methods in this controller should be described under the /api-docs/pet path

  • The Routes file tells swagger that this API listens to /{id}

  • Describes the operation as a GET with the documentation Find pet by Id with more detailed notes Returns a pet ....

  • Takes the param id, which is a datatype string and a path param

  • Returns error codes 400 and 404, with the messages provided

In the routes file, you then wire this api as follows:

GET     /pet/:id                 controllers.PetApiController.getPetById(id)

This will "attach" the /api-docs/pet api to the swagger resource listing, and the method to the getPetById method above

Please note that the minimum configuration needed to have a route/controller be exposed in swagger declaration is to have an Api annotation at class level.

The ApiParam annotation

Swagger for play has two types of ApiParams--they are ApiParam and ApiImplicitParam. The distinction is that some paramaters (variables) are passed to the method implicitly by the framework. ALL body parameters need to be described with ApiImplicitParam annotations. If they are queryParams or pathParams, you can use ApiParam annotations.

application.conf - config options

api.version (String) - version of API | default: "beta"
swagger.api.basepath (String) - base url | default: "http://localhost:9000"
swagger.filter (String) - classname of swagger filter | default: empty
swagger.api.info = {
  contact : (String) - Contact Information | default : empty,
  description : (String) - Description | default : empty,
  title : (String) - Title | default : empty,
  termsOfService : (String) - Terms Of Service | default : empty,
  license : (String) - Terms Of Service | default : empty,
  licenseUrl : (String) - Terms Of Service | default : empty
}

Note on Dependency Injection

This plugin works by default if your application uses Runtime dependency injection.

Nevertheless, the plugin can be initialized using compile time dependency injection. For example, you can add the following to your class that extends BuiltInComponentsFromContext:

// This needs to be eagerly instantiated because this sets global state for swagger
val swaggerPlugin = new SwaggerPluginImpl(environment, configuration)
lazy val apiHelpController = new ApiHelpController(controllerComponents, swaggerPlugin)

Security contact

Please disclose any security-related issues or vulnerabilities by emailing [email protected], instead of using the public issue tracker.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].