Git Product home page Git Product logo

swagger-akka-http-sample's Introduction

swagger-akka-http-sample

Check out this git repo and use sbt run to start the Akka Http server.

Uses swagger-akka-http which is built using swagger.io libs.

Test using the Swagger UI at http://localhost:12345/api-docs. You can view the swagger doc itself at http://localhost:12345/api-docs/swagger.json and http://localhost:12345/api-docs/swagger.yaml.

The Swagger UI can be used to send sample requests.

http://localhost:12345/api-docs redirects to https://petstore.swagger.io/ but provides a 'url' parameter that causes this sample's swagger.json to be loaded.

Swagger 1.5/1.6 version

Current swagger.json

{
  "openapi" : "3.0.1",
  "info" : {
    "title" : "",
    "description" : "",
    "termsOfService" : "",
    "version" : "1.0"
  },
  "externalDocs" : {
    "description" : "Core Docs",
    "url" : "http://acme.com/docs"
  },
  "servers" : [ {
    "url" : "http://localhost:12345"
  } ],
  "security" : [ ],
  "paths" : {
    "/add" : {
      "post" : {
        "summary" : "Add integers",
        "description" : "Add integers",
        "operationId" : "add",
        "requestBody" : {
          "content" : {
            "application/json" : {
              "schema" : {
                "$ref" : "#/components/schemas/AddRequest"
              }
            }
          },
          "required" : true
        },
        "responses" : {
          "200" : {
            "description" : "Add response",
            "content" : {
              "application/json" : {
                "schema" : {
                  "$ref" : "#/components/schemas/AddResponse"
                }
              }
            }
          },
          "500" : {
            "description" : "Internal server error"
          }
        }
      }
    },
    "/addOption" : {
      "post" : {
        "summary" : "Add integers",
        "description" : "Add integers",
        "operationId" : "addOption",
        "requestBody" : {
          "content" : {
            "application/json" : {
              "schema" : {
                "$ref" : "#/components/schemas/AddOptionRequest"
              }
            }
          },
          "required" : true
        },
        "responses" : {
          "200" : {
            "description" : "Add response",
            "content" : {
              "application/json" : {
                "schema" : {
                  "$ref" : "#/components/schemas/AddOptionResponse"
                }
              }
            }
          },
          "500" : {
            "description" : "Internal server error"
          }
        }
      }
    },
    "/echoenum" : {
      "post" : {
        "summary" : "Echo Enum",
        "description" : "Echo Enum",
        "operationId" : "echo",
        "requestBody" : {
          "content" : {
            "application/json" : {
              "schema" : {
                "$ref" : "#/components/schemas/EchoEnum"
              }
            }
          },
          "required" : true
        },
        "responses" : {
          "200" : {
            "description" : "Echo Enum",
            "content" : {
              "application/json" : {
                "schema" : {
                  "$ref" : "#/components/schemas/EchoEnum"
                }
              }
            }
          },
          "400" : {
            "description" : "Bad Request"
          }
        }
      }
    },
    "/echoenumeratum" : {
      "post" : {
        "summary" : "Echo Enumeratum",
        "description" : "Echo Enumeratum",
        "operationId" : "echo_1",
        "requestBody" : {
          "content" : {
            "application/json" : {
              "schema" : {
                "$ref" : "#/components/schemas/EchoEnumeratum"
              }
            }
          },
          "required" : true
        },
        "responses" : {
          "200" : {
            "description" : "Echo Enumeratum",
            "content" : {
              "application/json" : {
                "schema" : {
                  "$ref" : "#/components/schemas/EchoEnumeratum"
                }
              }
            }
          },
          "400" : {
            "description" : "Bad Request"
          }
        }
      }
    },
    "/echolist" : {
      "post" : {
        "summary" : "Echo List",
        "description" : "Echo List",
        "operationId" : "echo_2",
        "requestBody" : {
          "content" : {
            "application/json" : {
              "schema" : {
                "$ref" : "#/components/schemas/EchoList"
              }
            }
          },
          "required" : true
        },
        "responses" : {
          "200" : {
            "description" : "Echo List",
            "content" : {
              "application/json" : {
                "schema" : {
                  "$ref" : "#/components/schemas/EchoList"
                }
              }
            }
          },
          "400" : {
            "description" : "Bad Request"
          }
        }
      }
    },
    "/hello" : {
      "get" : {
        "summary" : "Return Hello greeting (anonymous)",
        "description" : "Return Hello greeting for anonymous request",
        "operationId" : "getHello",
        "responses" : {
          "200" : {
            "description" : "Hello response",
            "content" : {
              "application/json" : {
                "schema" : {
                  "$ref" : "#/components/schemas/Greeting"
                }
              }
            }
          },
          "500" : {
            "description" : "Internal server error"
          }
        }
      }
    },
    "/hello/{name}" : {
      "get" : {
        "summary" : "Return Hello greeting",
        "description" : "Return Hello greeting for named user",
        "operationId" : "getHelloSegment",
        "parameters" : [ {
          "name" : "name",
          "in" : "path",
          "description" : "user name",
          "required" : true,
          "schema" : {
            "type" : "string"
          }
        } ],
        "responses" : {
          "200" : {
            "description" : "Hello response",
            "content" : {
              "application/json" : {
                "schema" : {
                  "$ref" : "#/components/schemas/Greeting"
                }
              }
            }
          },
          "500" : {
            "description" : "Internal server error"
          }
        }
      }
    }
  },
  "components" : {
    "schemas" : {
      "AddRequest" : {
        "required" : [ "numbers" ],
        "type" : "object",
        "properties" : {
          "numbers" : {
            "type" : "array",
            "items" : {
              "type" : "integer",
              "format" : "int32"
            }
          }
        }
      },
      "SeqString" : {
        "type" : "array",
        "items" : {
          "type" : "string"
        }
      },
      "Greeting" : {
        "required" : [ "greeting" ],
        "type" : "object",
        "properties" : {
          "greeting" : {
            "type" : "string"
          }
        }
      },
      "EchoList" : {
        "required" : [ "listName", "values" ],
        "type" : "object",
        "properties" : {
          "listName" : {
            "type" : "string"
          },
          "values" : {
            "type" : "array",
            "items" : {
              "type" : "string"
            }
          }
        }
      },
      "AddOptionResponse" : {
        "required" : [ "sum" ],
        "type" : "object",
        "properties" : {
          "sum" : {
            "type" : "integer",
            "format" : "int32"
          }
        }
      },
      "AddOptionRequest" : {
        "required" : [ "number" ],
        "type" : "object",
        "properties" : {
          "number" : {
            "type" : "integer",
            "format" : "int32"
          },
          "number2" : {
            "type" : "integer",
            "format" : "int32"
          }
        }
      },
      "EchoEnumeratum" : {
        "required" : [ "enumValue" ],
        "type" : "object",
        "properties" : {
          "enumValue" : {
            "type" : "string",
            "enum" : [ "TALL", "GRANDE", "VENTI" ]
          }
        }
      },
      "EchoEnum" : {
        "required" : [ "enumValue" ],
        "type" : "object",
        "properties" : {
          "enumValue" : {
            "type" : "string",
            "enum" : [ "TALL", "GRANDE", "VENTI" ]
          }
        }
      },
      "AddResponse" : {
        "required" : [ "sum" ],
        "type" : "object",
        "properties" : {
          "sum" : {
            "type" : "integer",
            "format" : "int32"
          }
        }
      }
    }
  }
}

swagger-akka-http-sample's People

Contributors

dschmitz avatar gerbrand avatar pjfanning avatar willemjiang avatar yiksanchan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

swagger-akka-http-sample's Issues

Request body added to GET requests

Hello,

I have the same issue than https://stackoverflow.com/questions/51372542/swagger-is-adding-additional-body-parameter-for-get-method and https://stackoverflow.com/questions/57202122/swagger-why-is-swagger-creating-a-request-body-field-when-i-have-not-written-a and I cannot find a solution to this issue:

  @GET
  @Path("foo/{id}")
  @Produces(Array(MediaType.APPLICATION_JSON))
  @Operation(summary = "returns something", description = "",
    responses = Array(
      new ApiResponse(responseCode = "200", description = "return",
        content = Array(new Content(schema = new Schema(implementation = classOf[ReturnResponse])))),
      new ApiResponse(responseCode = "500", description = "Internal server error"))
  )
  def getId(@PathParam("id") id: String)(user: User): Route = {

Is it possible to remove the User message added to the request body ?

Thank you !

Examples in resources/swagger would be nice

Examples are always the best way to understand something as prose is usually full of ambiguity and other problems. Adding the swagger.json and/or swagger.yaml would be a good way to make this example more complete and useful.

How to add sample authentication in this project

First of all - this is not an issue at all. I am pretty new to Scala, learning Scala 2.x. However I am experienced JavaScript/NodeJs world developer, writes REST APIs and writes swagger (OAS2/OAS3) pretty frequently.

I am doing the same stuff to see if I can achieve using Akka Scala 2.x for my work.

Thanks a lot for this repo. It's definitely helps a lot. Thank You.

I saw the JSON and webui in http://localhost:12345/api-docs/#/. I have three questions:

  1. I want to add a few html string into this swagger. E.g. I want to add bit more explanation in the top or against the category (say renaming Default to MyTag and add one explanation there of what it is).
    My purpose is to write those in nice markdown format and get the markdown format read as html string (like I used markdown-it in NodeJS world).
    How can I do the same here?
    Any pointer is highly appreciated.

  2. If I want to add a demo authentication - how can I do it here? (Like any pointer of swagger-akka-http that helps me to do this?)

  3. How can I override some of the styles in swagger-ui? Some css styling I meant.

Thanks in advanced,
Pradip

Can't Use @ApiModelProperty on case classes properties

Hello @pjfanning , thanks for the great work with this example

I am reaching you out because I am trying to use @ApiModelProperty following the instructions specified here https://github.com/swagger-akka-http/swagger-akka-http#model-definitions but it's not working, all I get is Type not found errors for @apimodel and @ApiModelProperty annotations

I am interested in Swagger-2.0 branch of this project as an example to generate OpenApi 3.0.0

Do you have any experience or could point me the right direction on how properly use those annotations in this project?

I am trying this code.

@ApiModel( description = "Add Request object")
  case class AddRequest(
                         @ApiModelProperty( value = "numbers", example = "999", dataType = "string")
                         numbers: Array[Int]
                       )

FYI I also tried to install swagger-jaxrs2 (https://mvnrepository.com/artifact/io.swagger.core.v3/swagger-jaxrs2/2.0.0)

libraryDependencies += "io.swagger.core.v3" % "swagger-jaxrs2" % "2.0.0"

But didn't have any luck with that, the same error keeps coming up.

I really appreciate your help in advance.
Thanks

Fix the swagger UI request issue

It looks like the swagger UI request issue is caused by the Hello and Add route is not support CORS. I will submit a PR for it shortly.

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.