swaggard 4.0.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c18dab011ccdb176dd6324a815a0138f051d85cb9383a60681a857c886d516a5
4
- data.tar.gz: b8bd9f253e75c56c5308bae421f92cd12b54457edc40aa3d2857b1ac15d1764a
3
+ metadata.gz: ddc21f0ceaac51adcd841ded044bc82165d666e1dc0fb832f86577a02839f21e
4
+ data.tar.gz: 1140599ec5d0ef899782beb4aec529ca642114eae19509638c4672a23b2982f7
5
5
  SHA512:
6
- metadata.gz: a8406ac609bb110a3cb6d67647e5d775db2d293f0ab754020920442a86f202b80064da43843e616144f084ec9d93694b4bd086119f92413c055bd68d80266bb0
7
- data.tar.gz: 5caa69ecc7b014dccca548a27cdad88428c30f423ff2d922104fef04d0861b7f083af89cd7c0aec21d5f9a52e4173bd822cfb5757cb7bfe245100e3f84481d27
6
+ metadata.gz: 0daa594c72416c1620e20d37da32ad90d4b5c6b5a3e16c8ff063366318d9f4d70c101675c249c23f4ad17b80d77975e5e52c251b9f259a8fae7577c9ac278f45
7
+ data.tar.gz: 813fc4f48af7ed3ee726820257f8410247fd96e0059797b6dccc0958b3d0dbb6503c19cb825ce0ddd46125419a365096276f805d88de020d652a247f8255e5b6
@@ -64,7 +64,11 @@ module Swaggard
64
64
  def to_doc
65
65
  result = @type.to_doc
66
66
  result['description'] = @description if @description
67
- result['enum'] = @options if @options.present?
67
+ if @options.present? && @type.is_array?
68
+ result['items']['enum'] = @options
69
+ elsif @options.present?
70
+ result['enum'] = @options
71
+ end
68
72
  result
69
73
  end
70
74
 
@@ -74,7 +78,6 @@ module Swaggard
74
78
  def parse(string)
75
79
  string.gsub!("\n", ' ')
76
80
  data_type, required, name, options_and_description = string.match(/\A\[(\S*)\](!)?\s*([\w\[\]]*)\s*(.*)\Z/).captures
77
- allow_multiple = name.gsub!('[]', '')
78
81
  options, description = options_and_description.match(/\A(\[.*\])?(.*)\Z/).captures
79
82
  options = options ? options.gsub(/\[?\]?\s?/, '').split(',') : []
80
83
 
@@ -26,15 +26,12 @@ module Swaggard
26
26
  # Example: [Integer] media[media_type_id] ID of the desired media type.
27
27
  def parse(string)
28
28
  data_type, name, required, description = string.match(/\A\[(\w*)\]\s*([\w\[\]]*)(\(required\))?\s*(.*)\Z/).captures
29
- allow_multiple = name.gsub!('[]', '')
30
29
 
31
30
  @name = name
32
31
  @description = description
33
32
  @data_type = data_type.downcase
34
33
  @is_required = required.present?
35
- @allow_multiple = allow_multiple.present?
36
34
  end
37
-
38
35
  end
39
36
  end
40
37
  end
@@ -13,8 +13,7 @@ module Swaggard
13
13
  doc = super
14
14
  doc['schema'] = {
15
15
  'type' => 'array',
16
- 'items' => { 'type' => @data_type },
17
- 'enum' => @list_values
16
+ 'items' => { 'type' => @data_type, 'enum' => @list_values },
18
17
  }
19
18
  doc
20
19
  end
@@ -12,7 +12,12 @@ module Swaggard
12
12
 
13
13
  def to_doc
14
14
  schema = @type.to_doc
15
- schema['enum'] = @options if @options.any?
15
+
16
+ if @options.present? && @type.is_array?
17
+ schema['items']['enum'] = @options
18
+ elsif @options.present?
19
+ schema['enum'] = @options
20
+ end
16
21
 
17
22
  {
18
23
  'name' => @name,
@@ -26,11 +31,10 @@ module Swaggard
26
31
  private
27
32
 
28
33
  # Example: [Array] status Filter by status. (e.g. status[]=1&status[]=2&status[]=3)
29
- # Example: [Array] status(required) Filter by status. (e.g. status[]=1&status[]=2&status[]=3)
34
+ # Example: [Array] status! Filter by status. (e.g. status[]=1&status[]=2&status[]=3)
30
35
  # Example: [Integer] media[media_type_id] ID of the desired media type.
31
36
  def parse(string)
32
37
  data_type, required, name, options_and_description = string.match(/\A\[(\S*)\](!)?\s*([\w\[\]]*)\s*(.*)\Z/).captures
33
- allow_multiple = name.gsub!('[]', '')
34
38
 
35
39
  options, description = options_and_description.match(/\A(\[.*\])?(.*)\Z/).captures
36
40
  options = options ? options.gsub(/\[?\]?\s?/, '').split(',') : []
@@ -39,7 +43,6 @@ module Swaggard
39
43
  @description = description
40
44
  @type = Parsers::Type.run(data_type)
41
45
  @is_required = required.present?
42
- @allow_multiple = allow_multiple.present?
43
46
  @options = options
44
47
  end
45
48
  end
@@ -21,7 +21,6 @@ module Swaggard
21
21
  # Example: [Integer] media[media_type_id] ID of the desired media type.
22
22
  def parse(string)
23
23
  data_type, name, options_and_description = string.match(/\A\[(\S*)\]\s*([\w\-\[\]]*)\s*(.*)\Z/).captures
24
- allow_multiple = name.gsub!('[]', '')
25
24
 
26
25
  options, description = options_and_description.match(/\A(\[.*\])?(.*)\Z/).captures
27
26
  options = options ? options.gsub(/\[?\]?\s?/, '').split(',') : []
@@ -29,7 +28,6 @@ module Swaggard
29
28
  @name = name
30
29
  @description = description
31
30
  @type = data_type
32
- @allow_multiple = allow_multiple.present?
33
31
  @options = options
34
32
  end
35
33
  end
@@ -24,6 +24,10 @@ module Swaggard
24
24
  @is_array = is_array
25
25
  end
26
26
 
27
+ def is_array?
28
+ @is_array
29
+ end
30
+
27
31
  def to_doc
28
32
  if @is_array
29
33
  { 'type' => 'array', 'items' => type_tag_and_name }
@@ -1,3 +1,3 @@
1
1
  module Swaggard
2
- VERSION = '4.0.0'
2
+ VERSION = '4.0.1'
3
3
  end
@@ -1 +1,111 @@
1
- {"openapi":"3.1.0","info":{"version":"0.1","title":"","description":"","contact":{"name":""},"license":{"name":""}},"servers":[{"url":"https://localhost:3000/"}],"tags":[{"name":"admin/pets","description":"This document describes the API for interacting with Pet resources"},{"name":"pets","description":"This document describes the API for interacting with Pet resources"}],"paths":{"/admin/pets":{"get":{"tags":["admin/pets"],"operationId":"index","summary":"return a list of Pets","description":"","parameters":[],"responses":{"default":{"description":"successful operation"}}}},"/pets":{"get":{"tags":["pets"],"operationId":"index","summary":"return a list of Pets","description":"","parameters":[],"responses":{"default":{"description":"successful operation"}}}},"/pets/{id}":{"get":{"tags":["pets"],"operationId":"show","summary":"return a Pet","description":"","parameters":[{"name":"id","in":"path","required":true,"description":"Scope response to id","schema":{"type":"string"}},{"name":"id","in":"query","required":false,"description":"The ID for the Pet","schema":{"type":"integer","format":"int32"}}],"responses":{"default":{"description":"successful operation"}}}}}}
1
+ {
2
+ "openapi": "3.1.0",
3
+ "info": {
4
+ "version": "0.1",
5
+ "title": "",
6
+ "description": "",
7
+ "contact": {
8
+ "name": ""
9
+ },
10
+ "license": {
11
+ "name": ""
12
+ }
13
+ },
14
+ "servers": [
15
+ {
16
+ "url": "https://localhost:3000/"
17
+ }
18
+ ],
19
+ "tags": [
20
+ {
21
+ "name": "admin/pets",
22
+ "description": "This document describes the API for interacting with Pet resources"
23
+ },
24
+ {
25
+ "name": "pets",
26
+ "description": "This document describes the API for interacting with Pet resources"
27
+ }
28
+ ],
29
+ "paths": {
30
+ "/admin/pets": {
31
+ "get": {
32
+ "tags": [
33
+ "admin/pets"
34
+ ],
35
+ "operationId": "index",
36
+ "summary": "return a list of Pets",
37
+ "description": "",
38
+ "parameters": [],
39
+ "responses": {
40
+ "default": {
41
+ "description": "successful operation"
42
+ }
43
+ }
44
+ }
45
+ },
46
+ "/pets": {
47
+ "get": {
48
+ "tags": [
49
+ "pets"
50
+ ],
51
+ "operationId": "index",
52
+ "summary": "return a list of Pets",
53
+ "description": "",
54
+ "parameters": [],
55
+ "responses": {
56
+ "default": {
57
+ "description": "successful operation"
58
+ }
59
+ }
60
+ }
61
+ },
62
+ "/pets/{id}": {
63
+ "get": {
64
+ "tags": [
65
+ "pets"
66
+ ],
67
+ "operationId": "show",
68
+ "summary": "return a Pet",
69
+ "description": "",
70
+ "parameters": [
71
+ {
72
+ "name": "id",
73
+ "in": "path",
74
+ "required": true,
75
+ "description": "Scope response to id",
76
+ "schema": {
77
+ "type": "string"
78
+ }
79
+ },
80
+ {
81
+ "name": "id",
82
+ "in": "query",
83
+ "required": false,
84
+ "description": "The ID for the Pet",
85
+ "schema": {
86
+ "type": "integer",
87
+ "format": "int32"
88
+ }
89
+ },
90
+ {
91
+ "name": "status",
92
+ "in": "query",
93
+ "required": false,
94
+ "description": "! [available, pending, sold] The status of the Pet",
95
+ "schema": {
96
+ "type": "array",
97
+ "items": {
98
+ "type": "string"
99
+ }
100
+ }
101
+ }
102
+ ],
103
+ "responses": {
104
+ "default": {
105
+ "description": "successful operation"
106
+ }
107
+ }
108
+ }
109
+ }
110
+ }
111
+ }
@@ -9,6 +9,7 @@ class PetsController < ApplicationController
9
9
  # return a Pet
10
10
  #
11
11
  # @query_parameter [Integer] id The ID for the Pet
12
+ # @query_parameter [Array<String>] status! [available, pending, sold] The status of the Pet
12
13
  def show
13
14
  end
14
15
 
@@ -15,7 +15,7 @@ describe Swaggard, '.get_doc' do
15
15
  config.ignore_untagged_controllers = false
16
16
  end
17
17
 
18
- swagger_json = JSON.dump(Swaggard.get_doc(host))
18
+ swagger_json = JSON.pretty_generate(Swaggard.get_doc(host))
19
19
 
20
20
  expect(swagger_json).to eq(api_json)
21
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swaggard
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrian Gomez