-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
02c2302
commit 9d6e432
Showing
8 changed files
with
218 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
defmodule SimpleWeb.UserSocket do | ||
use Phoenix.Socket | ||
use PhoenixSwagger | ||
|
||
## Channels | ||
# channel "room:*", Simple.RoomChannel | ||
|
@@ -34,4 +35,33 @@ defmodule SimpleWeb.UserSocket do | |
# | ||
# Returning `nil` makes this socket anonymous. | ||
def id(_socket), do: nil | ||
|
||
swagger_path(:test) do | ||
get("/api/users/test") | ||
summary("Test function") | ||
description("List tests in db") | ||
produces("application/json") | ||
deprecated(false) | ||
|
||
response(200, "OK", Schema.ref(:UsersResponse), | ||
example: %{ | ||
data: [ | ||
%{ | ||
id: 1, | ||
name: "Joe", | ||
email: "[email protected]", | ||
inserted_at: "2017-02-08T12:34:55Z", | ||
updated_at: "2017-02-12T13:45:23Z" | ||
}, | ||
%{ | ||
id: 2, | ||
name: "Jack", | ||
email: "[email protected]", | ||
inserted_at: "2017-02-04T11:24:45Z", | ||
updated_at: "2017-02-15T23:15:43Z" | ||
} | ||
] | ||
} | ||
) | ||
end | ||
end |
24 changes: 24 additions & 0 deletions
24
examples/simple/lib/simple_web/controllers/helpers/common_schemas.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
defmodule SimpleWeb.Helpers.CommonSchemas do | ||
use PhoenixSwagger | ||
|
||
def swagger_definitions do | ||
%{ | ||
Error: | ||
swagger_schema do | ||
title("Error") | ||
description("An error response") | ||
|
||
properties do | ||
success(:boolean, "Success bool") | ||
msg(:string, "Error response", required: true) | ||
end | ||
|
||
example(%{ | ||
success: false, | ||
msg: "User ID missing" | ||
}) | ||
end | ||
} | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,6 +124,49 @@ | |
"description": "Delete a user by ID" | ||
} | ||
}, | ||
"/api/users/test": { | ||
"get": { | ||
"tags": [ | ||
"UserSocket" | ||
], | ||
"summary": "Test function", | ||
"responses": { | ||
"200": { | ||
"schema": { | ||
"$ref": "#/definitions/UsersResponse" | ||
}, | ||
"examples": { | ||
"application/json": { | ||
"data": [ | ||
{ | ||
"updated_at": "2017-02-12T13:45:23Z", | ||
"name": "Joe", | ||
"inserted_at": "2017-02-08T12:34:55Z", | ||
"id": 1, | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"updated_at": "2017-02-15T23:15:43Z", | ||
"name": "Jack", | ||
"inserted_at": "2017-02-04T11:24:45Z", | ||
"id": 2, | ||
"email": "[email protected]" | ||
} | ||
] | ||
} | ||
}, | ||
"description": "OK" | ||
} | ||
}, | ||
"produces": [ | ||
"application/json" | ||
], | ||
"parameters": [], | ||
"operationId": "SimpleWeb.UserSocket.test", | ||
"description": "List tests in db", | ||
"deprecated": false | ||
} | ||
}, | ||
"/api/users": { | ||
"post": { | ||
"tags": [ | ||
|
@@ -297,6 +340,28 @@ | |
"email": "[email protected]" | ||
}, | ||
"description": "A user of the app" | ||
}, | ||
"Error": { | ||
"type": "object", | ||
"title": "Error", | ||
"required": [ | ||
"msg" | ||
], | ||
"properties": { | ||
"success": { | ||
"type": "boolean", | ||
"description": "Success bool" | ||
}, | ||
"msg": { | ||
"type": "string", | ||
"description": "Error response" | ||
} | ||
}, | ||
"example": { | ||
"success": false, | ||
"msg": "User ID missing" | ||
}, | ||
"description": "An error response" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
defmodule Helpers.MiscHelpers do | ||
|
||
def merge_definitions(definitions, swagger_map = %{definitions: existing}) do | ||
%{swagger_map | definitions: Map.merge(existing, definitions)} | ||
end | ||
|
||
def merge_paths(path, swagger_map) do | ||
paths = Map.merge(swagger_map.paths, path, &merge_conflicts/3) | ||
%{swagger_map | paths: paths} | ||
end | ||
|
||
defp merge_conflicts(_key, value1, value2) do | ||
Map.merge(value1, value2) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters