Git Product home page Git Product logo

javabypatel / guice-grizzly-jersey-openapi-swagger-example Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 1.0 9 KB

Sample project to demonstrate OpenAPI Swagger configuration in Guice grizzly jersey example.

Home Page: https://javabypatel.blogspot.com/2020/11/swagger-openapi-rest-java-example-using-guice-jersey.html

License: MIT License

Java 100.00%
grizzly guice openapi swagger openapi3 jersey swagger-documentation openapi-documentation swagger-json openapi-json

guice-grizzly-jersey-openapi-swagger-example's Introduction

guice-grizzly-jersey-openapi-swagger-example

Sample project to show dynamic generation of OpenAPI Swagger documentation in project using Guice and Jersey.
https://javabypatel.blogspot.com/2020/11/swagger-openapi-rest-java-example-using-guice-jersey.html

Build the application

mvn clean install

Run the application

Go to App.java which contains main method, run it as java application.

Demo application URL

http://localhost:8080/OpenAPIExample/greet?name=JavaByPatel

For getting the OpenAPI resource description,

In json format: http://localhost:8080/OpenAPIExample/openapi.json
In yaml format: http://localhost:8080/OpenAPIExample/openapi.yaml

sample json

{
  "openapi" : "3.0.1",
  "info" : {
    "title" : "Guice Grizzly Jersey Openapi Swagger Example API",
    "description" : "OpenAPI swagger configuration example in sample project that uses Guice, Grizzly, Jersey.",
    "contact" : {
      "email" : "[email protected]"
    },
    "license" : {
      "name" : "MIT License",
      "url" : "https://en.wikipedia.org/wiki/MIT_License"
    },
    "version" : "1.0.0"
  },
  "servers" : [ {
    "url" : "http://localhost:8080/OpenAPIExample/",
    "description" : "Guice Grizzly Jersey Openapi Swagger Example API server"
  } ],
  "paths" : {
    "/greet" : {
      "get" : {
        "summary" : "This is a sample test API to greet user.",
        "operationId" : "greet",
        "parameters" : [ {
          "name" : "name",
          "in" : "query",
          "schema" : {
            "type" : "string"
          }
        } ],
        "responses" : {
          "200" : {
            "description" : "Greeted successfully.",
            "content" : {
              "application/json" : {
                "schema" : {
                  "type" : "array",
                  "items" : {
                    "$ref" : "#/components/schemas/GreetResponse"
                  }
                }
              }
            }
          },
          "400" : {
            "description" : "Bad request. Request is not well formed."
          }
        }
      }
    }
  },
  "components" : {
    "schemas" : {
      "GreetResponse" : {
        "type" : "object",
        "properties" : {
          "message" : {
            "type" : "string"
          }
        }
      }
    }
  }
}

sample yaml

openapi: 3.0.1
info:
  title: Guice Grizzly Jersey Openapi Swagger Example API
  description: "OpenAPI swagger configuration example in sample project that uses\
    \ Guice, Grizzly, Jersey."
  contact:
    email: [email protected]
  license:
    name: MIT License
    url: https://en.wikipedia.org/wiki/MIT_License
  version: 1.0.0
servers:
- url: http://localhost:8080/OpenAPIExample/
  description: Guice Grizzly Jersey Openapi Swagger Example API server
paths:
  /greet:
    get:
      summary: This is a sample test API to greet user.
      operationId: greet
      parameters:
      - name: name
        in: query
        schema:
          type: string
      responses:
        "200":
          description: Greeted successfully.
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/GreetResponse'
        "400":
          description: Bad request. Request is not well formed.
components:
  schemas:
    GreetResponse:
      type: object
      properties:
        message:
          type: string

guice-grizzly-jersey-openapi-swagger-example's People

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

theraz

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.