Skip to content

Commit

Permalink
Merge branch 'master' of github.com:icyleaf/swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
icyleaf committed May 6, 2020
2 parents cce09eb + b41225a commit b743db2
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
jobs:
build:
docker:
- image: "crystallang/crystal:0.27.0"
- image: "crystallang/crystal:0.34.0"
environment:
DOCS_PATH: "docs"
GIT_USER: "icyleaf"
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ builder = Swagger::Builder.new(
title: "App API",
version: "1.0.0",
description: "This is a sample api for users",
terms: "http://yourapp.com/terms",
terms_url: "http://yourapp.com/terms",
contact: Swagger::Contact.new("icyleaf", "[email protected]", "http://icyleaf.com"),
license: Swagger::License.new("MIT", "https://github.com/icyleaf/swagger/blob/master/LICENSE"),
authorizations: [
Expand All @@ -35,21 +35,23 @@ builder = Swagger::Builder.new(
)

builder.add(Swagger::Controller.new("Users", "User resources", [
Swagger::Action.new("get", "/users", "All users"),
Swagger::Action.new("get", "/users/{id}", "Get user by id", parameters: [
Swagger::Action.new("get", "/users", description: "All users", responses: [
Swagger::Response.new("200", "Success response")
]),
Swagger::Action.new("get", "/users/{id}", description: "Get user by id", parameters: [
Swagger::Parameter.new("id", "path")
], responses: [
Swagger::Response.new("200", "Success response"),
Swagger::Response.new("404", "Not found user")
], authorization: true),
Swagger::Action.new("post", "/users", "Create User", responses: [
Swagger::Action.new("post", "/users", description: "Create User", responses: [
Swagger::Response.new("201", "Return user resource after created"),
Swagger::Response.new("401", "Unauthorizated")
], authorization: false)
]))

document = builder.built
p document
puts document.to_json
```

## Structure
Expand Down
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ version: 0.2.0
authors:
- icyleaf <[email protected]>

crystal: 0.33.0
crystal: 0.34.0

license: MIT
4 changes: 3 additions & 1 deletion src/swagger/http/handlers/api.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ require "semantic_version"
module Swagger::HTTP
class APIHandler
include Swagger::HTTP::Handler


@json : String

def initialize(document : Document, @endpoint : String, @debug_mode = true)
major = SemanticVersion.parse(document.openapi_version).major
@swagger_path = "/v#{major}/swagger.json"
Expand Down
2 changes: 1 addition & 1 deletion src/swagger/http/handlers/web.cr
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module Swagger::HTTP
private def asset_uri?(context)
original_path = context.request.path.not_nil!
is_dir_path = original_path.ends_with?("/")
request_path = self.request_path(URI.decode(original_path))
request_path = self.request_path(URI.decode_www_form(original_path))

expanded_path = File.expand_path(request_path, "/")
if is_dir_path && !expanded_path.ends_with? "/"
Expand Down
2 changes: 2 additions & 0 deletions src/swagger/objects/security_scheme.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ module Swagger::Objects
api_key(auth.api_key_name.not_nil!, auth.parameter_location.not_nil!, auth.description)
when Authorization::Type::OAuth2
oauth2(auth.oauth2_flows.not_nil!, auth.description)
else
nil
end
end

Expand Down

0 comments on commit b743db2

Please sign in to comment.