swagger-api 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9fbb0b691f22e9a8410e6923082bd718d6b819add2b320b217c562257de06bc2
4
- data.tar.gz: 53d0c0006966b5148dc20c4f46a0f597594243419cd78766571804e3bd71d9dd
3
+ metadata.gz: 16f8848d68d8e83e8d88c3e6bbf3974c79c1f85149ebe59b7e208ab22b78524d
4
+ data.tar.gz: f55a8a8a95c9097ba09b0312eb61dd4eb0aa10f508e70fcfbfaab619ef0ca2f3
5
5
  SHA512:
6
- metadata.gz: a86ec3dfbd76eaeb29402cd05b5dc7d5f0dac2ab4e110fe3b41fd06efaa4bd49483f21fbdb335be0a95cc8fadd5ec159d019bb02f8254dfe6faee39ed75beeaa
7
- data.tar.gz: 9840e634c340cfd2ceab7f7985f70e4e18f48d382a0415aa231525fe6a076900201c4e5e4d75c45d4213fd4fa46f5b653d56e0e9a514e51f188f72af77064e0d
6
+ metadata.gz: 4fabfda39fd77b0302505de767de179db91cdcb88f5b45d2423021284499b8acc04430ce4fb314443e0a742f60c8642438199eb438bad1234cad4e41f7d0752d
7
+ data.tar.gz: 8dd7a9ac27ed97a88303dac2d2cc49a52c368f34e2c8eac6fd8bed07f32b3d00367ac186c5a4e05fa73e3056930512eaf0edb0e7f1e299e00af5ea13e5059a7c
@@ -1,7 +1,112 @@
1
- require "swagger/api/version"
2
-
3
1
  module Swagger
4
- module Api
5
- # Your code goes here...
2
+ class Api
3
+ include ActiveAttr::Model
4
+ include ActiveModel::Validations
5
+ attribute :openapi, type: String, default: '3.0.0'
6
+ attribute :servers, default: []
7
+ attribute :info, type: Object
8
+ attribute :security, default: [{api_key: []}]
9
+ attribute :paths, default: []
10
+ attribute :components, default: {}
11
+
12
+ def self.prettify
13
+ JSON.pretty_generate(JSON.parse(json))
14
+ end
15
+
16
+ def self.json
17
+ create.to_json
18
+ end
19
+
20
+ def self.create
21
+ @config ||= Swagger::Api.new(
22
+ info: info,
23
+ servers: [{url: server_url}],
24
+ paths: Paths.new(controllers: config.controllers).create,
25
+ components: {
26
+ responses: responses,
27
+ schemas: Components.new(controllers: config.controllers).create,
28
+ requestBodies: Swagger::RequestBodies.new(controllers: config.controllers).create,
29
+ securitySchemes: security_schemes,
30
+ },
31
+ )
32
+ end
33
+
34
+ def self.config
35
+ @yaml_config ||= JSON.parse(YAML.load_file("#{Rails.root.to_s}/config/swagger.yml").to_json, object_class: OpenStruct)
36
+ end
37
+
38
+ def self.security_schemes
39
+ {
40
+ api_key: {
41
+ type: 'apiKey',
42
+ name: 'Authorization',
43
+ in: 'header'
44
+ }
45
+ }
46
+ end
47
+
48
+ def self.responses
49
+ {
50
+ NotFound: {
51
+ description: "The specified resource was not found",
52
+ content: {
53
+ 'application/json; charset=utf-8' => {
54
+ schema: {
55
+ type: 'string',
56
+ example: 'Not Found'
57
+ }
58
+ }
59
+ }
60
+ },
61
+ Unauthorized: {
62
+ description: "Unauthorized",
63
+ content: {
64
+ 'application/json; charset=utf-8' => {
65
+ schema: {
66
+ type: 'string',
67
+ example: 'Not Authorized'
68
+ }
69
+ }
70
+ }
71
+ },
72
+ BadRequest: {
73
+ description: "Bad Request",
74
+ content: {
75
+ 'application/json; charset=utf-8' => {
76
+ schema: {
77
+ example: ['The field name is invalid.', 'The id must be present'],
78
+ type: 'array',
79
+ items: {
80
+ type: 'string'
81
+ }
82
+ }
83
+ }
84
+ }
85
+ },
86
+ Unexpected: {
87
+ description: "Unexpected Error",
88
+ content: {
89
+ 'application/json; charset=utf-8' => {
90
+ schema: {
91
+ type: 'string',
92
+ example: 'Unexpected Error'
93
+ }
94
+ }
95
+ }
96
+ }
97
+ }
98
+ end
99
+
100
+ def self.info
101
+ {
102
+ version: config.info.version,
103
+ title: config.info.title,
104
+ description: config.info.description,
105
+ }
106
+ end
107
+
108
+ def self.server_url
109
+ config.servers.send(Rails.env).url
110
+ end
6
111
  end
7
112
  end
@@ -1,5 +1,5 @@
1
1
  module Swagger
2
2
  module Api
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swagger-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Full Measure Education