swagui 0.4.1 → 0.5.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
  SHA1:
3
- metadata.gz: 96796f626d96d5277a24f656bf40e6edbcb1609b
4
- data.tar.gz: f4f429bf1cee4358b5e5fafd5dbbfdc6efe677fc
3
+ metadata.gz: 6283c63492294c679588387d93c8617c67d96d80
4
+ data.tar.gz: 175c97e8b663689735910c234db51c3a887bf179
5
5
  SHA512:
6
- metadata.gz: aa17d33e7927c59cdc493e12646a6f1d679a441887208b025d80e29e4fa3db682b40af8c73b391d4bc469e9b534ee40ea3bc502626874fcc8b31c79f91ab7584
7
- data.tar.gz: 2e1507962d3e600d29fbaccd6e1b90e86497436a6de088b7cc6952360b35fb2388e1014d3a19bbf584beb39ea58abd4a4594d9e043dcf6c5ddd9bd6af65ed013
6
+ metadata.gz: 85328db2dcd3ad910dc884915dd485f238eabeb5e68f273783ce142b1c04da6d86de6d39e8e70cffc6fa7cf1627df59e104c3275f612ce25900f367d172c1f18
7
+ data.tar.gz: 0218d3fef78074e8602d1bcd2ab49fbf6d5441c25521ee089ee9948c52bc9098a882d3cffa303abd3cacd6b5b80a026c19bbe84f27039e2677c42dec5a2fc54a
data/README.md CHANGED
@@ -54,6 +54,7 @@ You will be able to access the [swagger-ui] loaded with your api documentation a
54
54
  consumes:
55
55
  - application/json
56
56
  ```
57
+ 5. __example value__: in current swagger ui, according to [swagui ui default value code], the render json structure is displayed with some empty values, such as `0`, `0.0`, `""`, etc, depends on the data type. This could make it hard to visualize how the json structure really looks like. Swagui provides an optional `example` attribute for each property, for the sample value that populates the json display.
57
58
 
58
59
  With this approach, swagger api docs are now a lot more concise and readible, let alone having dynamic `basePath`.
59
60
 
@@ -117,6 +118,7 @@ You will then able to view the [swagger-ui] loaded with your api documentation a
117
118
 
118
119
  [swagger-ui]: https://github.com/wordnik/swagger-ui
119
120
  [original swagger doc format]: https://github.com/wordnik/swagger-spec/blob/master/fixtures/v1.2/helloworld/static/api-docs
121
+ [swagui ui default value code]: https://github.com/wordnik/swagger-ui/blob/6b448c1faecc5816d90de41ee6e90bb6322816c1/dist/lib/swagger.js#L660-L676
120
122
  ## Contributing
121
123
 
122
124
  1. Fork it ( https://github.com/jackxxu/swagui/fork )
@@ -18,7 +18,7 @@ module Swagui
18
18
  else
19
19
  @type = 'class'
20
20
  (@schema_hash['properties'] ||= []).each do |pname, pattributes|
21
- if pattributes['type'] == 'object' || (pattributes['type'] == 'array' && !pattributes['items'].nil?)
21
+ if pattributes['type'] == 'object' || (pattributes['type'] == 'array' && !pattributes['items'].nil? && (pattributes['items']['type'] == 'object'))
22
22
  nested_object_name = "#{@name}-#{pname}"
23
23
  if pattributes['type'] == 'object'
24
24
  @schema_hash['properties'][pname] = {'$ref' => nested_object_name }
@@ -1,3 +1,3 @@
1
1
  module Swagui
2
- VERSION = "0.4.1"
2
+ VERSION = "0.5.1"
3
3
  end
@@ -591,6 +591,7 @@ var SwaggerModelProperty = function(name, obj) {
591
591
  this.isCollection = this.dataType && (this.dataType.toLowerCase() === 'array' || this.dataType.toLowerCase() === 'list' || this.dataType.toLowerCase() === 'set');
592
592
  this.descr = obj.description;
593
593
  this.required = obj.required;
594
+ this.sampleValue = obj.example; // sets the sample value
594
595
  if (obj.items != null) {
595
596
  if (obj.items.type != null) {
596
597
  this.refDataType = obj.items.type;
@@ -620,6 +621,9 @@ SwaggerModelProperty.prototype.getSampleValue = function(modelsToIgnore) {
620
621
  var result;
621
622
  if ((this.refModel != null) && (modelsToIgnore.indexOf(prop.refModel.name) === -1)) {
622
623
  result = this.refModel.createJSONSample(modelsToIgnore);
624
+ } else if (this.sampleValue) {
625
+ // displays sample value, if any
626
+ result = this.sampleValue
623
627
  } else {
624
628
  if (this.isCollection) {
625
629
  result = this.toSampleValue(this.refDataType);
@@ -1489,7 +1493,7 @@ SwaggerAuthorizations.prototype.apply = function(obj, authorizations) {
1489
1493
  if (result === true)
1490
1494
  status = true;
1491
1495
  }
1492
- }
1496
+ }
1493
1497
  }
1494
1498
  }
1495
1499
 
@@ -38,6 +38,15 @@
38
38
  "warehouseLocation": {
39
39
  "description": "Coordinates of the warehouse with the product",
40
40
  "$ref": "http://json-schema.org/geo"
41
+ },
42
+ "userIds": {
43
+ "type":"array",
44
+ "required":false,
45
+ "items": {
46
+ "type":"string",
47
+ "required":false,
48
+ "example": "1823257618648445648"
49
+ }
41
50
  }
42
51
  },
43
52
  "required": ["id", "name", "price"]
@@ -12,20 +12,20 @@ class TestJsonSchema < Minitest::Test
12
12
 
13
13
  def test_objects_method_returns_array
14
14
  schema = Swagui::JsonSchema.new(@schema_json, 'PostAccount')
15
- assert_equal schema.all_objects.size, 4
15
+ assert_equal schema.all_objects.size, 3
16
16
  end
17
17
 
18
18
  def test_models_methods_return_array_of_hash
19
19
  schema = Swagui::JsonSchema.new(@schema_json, 'PostAccount')
20
- assert_equal schema.models.size, 4
21
- assert_equal schema.models.map {|x| x['id']}, ["PostAccount", "PostAccount-contact", "PostAccount-contact-phones", "PostAccount-entries"]
20
+ assert_equal schema.models.size, 3
21
+ assert_equal schema.models.map {|x| x['id']}, ["PostAccount", "PostAccount-contact", "PostAccount-entries"]
22
22
  assert_equal schema.models.first['properties']['entries'], {'type' => 'array', 'items' => {"$ref"=>"PostAccount-entries"}}
23
23
  end
24
24
 
25
25
  def test_array_schema
26
26
  schema = Swagui::JsonSchema.new(@array_schema_json, 'GetAccount')
27
- assert_equal schema.models.size, 3
28
- assert_equal schema.models.map {|m| m['id']}, %w(GetAccount GetAccount-tags GetAccount-dimensions)
27
+ assert_equal schema.models.size, 2
28
+ assert_equal schema.models.map {|m| m['id']}, %w(GetAccount GetAccount-dimensions)
29
29
  end
30
30
 
31
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swagui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jack Xu