open_api_import 0.7.0 → 0.7.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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/open_api_import.rb +47 -45
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e8d4b1c2a378d443f3f313c29b44dbedcae5bfcf199849f28919a6905fbff5f
4
- data.tar.gz: b1ceb93d102bd424b914b85c95cdfdfa59013b2648bf41d6bd747563269002cf
3
+ metadata.gz: f90808a3947a8a9a3959f0db36d9880f1754fcc02c4a2da84a3102f07311ae60
4
+ data.tar.gz: d58962782d54e780988c02ef5df6d8777c16f55b8545d432266f7a689ba1de01
5
5
  SHA512:
6
- metadata.gz: a3d262b0a3908a2a925e62dd72c309e494de9e8c4b0d1b7e42167e99a176d2ca5b69a9723df79080548b4c424ede7b1071ace391de563f66388f953ed22c229c
7
- data.tar.gz: 96810873bc0c93c64569b100f3e73328ea34e88a3330aba7ce51692ec358b98e7e623dec18399e1f8be445421da67337cd8d13509ccae8e03dce5652d0f120fe
6
+ metadata.gz: a4058dbc2bc5d3c0515c9a986e1827730768bf8f300c85204332b9763593aa35b008c4ac1db1f1fb239bb0e22db61e94430d0b697fa5a6c1307cd181a40241df
7
+ data.tar.gz: 89f0896c5411ef3a27b3826971e62326511963ca06d1f8a766a5af4f4090da5e1482004e4a3a70ea56949b00b6f3d47a99e24af45c16106231cef9036efa9ddc
@@ -307,7 +307,7 @@ class OpenApiImport
307
307
  else
308
308
  if dpv.type == "object"
309
309
  if dpv.key?(:properties)
310
- valv = get_examples(dpv[:properties]).join("\n")
310
+ valv = get_examples(dpv[:properties], :key_value, true).join("\n")
311
311
  else
312
312
  valv = "{}"
313
313
  end
@@ -558,68 +558,70 @@ class OpenApiImport
558
558
 
559
559
  class << self
560
560
  # Retrieve the examples from the properties hash
561
- private def get_examples(properties, type=:key_value)
561
+ private def get_examples(properties, type=:key_value, remove_read_only=false)
562
562
  #todo: consider using this method also to get data examples
563
563
  example = []
564
564
  example << "{" unless properties.empty? or type==:only_value
565
565
  properties.each do |prop, val|
566
- if val.key?(:properties) and !val.key?(:example) and !val.key?(:type)
567
- val[:type]='object'
568
- end
569
- if val.key?(:example)
570
- example << if val[:example].is_a?(String) or val[:example].is_a?(Time)
571
- " #{prop.to_sym}: \"#{val[:example]}\", "
572
- else
573
- " #{prop.to_sym}: #{val[:example]}, "
566
+ unless remove_read_only and val.key?(:readOnly) and val[:readOnly]==true
567
+ if val.key?(:properties) and !val.key?(:example) and !val.key?(:type)
568
+ val[:type]='object'
574
569
  end
575
- elsif val.key?(:type)
576
- format = val[:format]
577
- format = val[:type] if format.to_s == ""
578
- case val[:type].downcase
579
- when "string"
580
- example << " #{prop.to_sym}: \"#{format}\", "
581
- when "integer", "number"
582
- example << " #{prop.to_sym}: 0, "
583
- when "boolean"
584
- example << " #{prop.to_sym}: true, "
585
- when "array"
586
- if val.key?(:items) and val[:items].size==1 and val[:items].is_a?(Hash) and val[:items].key?(:type)
587
- val[:items][:enum]=[val[:items][:type]]
570
+ if val.key?(:example)
571
+ example << if val[:example].is_a?(String) or val[:example].is_a?(Time)
572
+ " #{prop.to_sym}: \"#{val[:example]}\", "
573
+ else
574
+ " #{prop.to_sym}: #{val[:example]}, "
588
575
  end
576
+ elsif val.key?(:type)
577
+ format = val[:format]
578
+ format = val[:type] if format.to_s == ""
579
+ case val[:type].downcase
580
+ when "string"
581
+ example << " #{prop.to_sym}: \"#{format}\", "
582
+ when "integer", "number"
583
+ example << " #{prop.to_sym}: 0, "
584
+ when "boolean"
585
+ example << " #{prop.to_sym}: true, "
586
+ when "array"
587
+ if val.key?(:items) and val[:items].size==1 and val[:items].is_a?(Hash) and val[:items].key?(:type)
588
+ val[:items][:enum]=[val[:items][:type]]
589
+ end
589
590
 
590
- if val.key?(:items) and val[:items].key?(:enum)
591
- if type==:only_value
592
- if val[:items][:enum][0].is_a?(String)
593
- example << " [\"" + val[:items][:enum].sample + "\"] "
591
+ if val.key?(:items) and val[:items].key?(:enum)
592
+ if type==:only_value
593
+ if val[:items][:enum][0].is_a?(String)
594
+ example << " [\"" + val[:items][:enum].sample + "\"] "
595
+ else
596
+ example << " [" + val[:items][:enum].sample + "] "
597
+ end
594
598
  else
595
- example << " [" + val[:items][:enum].sample + "] "
599
+ if val[:items][:enum][0].is_a?(String)
600
+ example << " #{prop.to_sym}: [\"" + val[:items][:enum].sample + "\"], "
601
+ else
602
+ example << " #{prop.to_sym}: [" + val[:items][:enum].sample + "], "
603
+ end
596
604
  end
597
605
  else
598
- if val[:items][:enum][0].is_a?(String)
599
- example << " #{prop.to_sym}: [\"" + val[:items][:enum].sample + "\"], "
606
+ #todo: differ between response examples and data examples
607
+ if type == :only_value
608
+ example << get_response_examples({schema: val}).join("\n")
600
609
  else
601
- example << " #{prop.to_sym}: [" + val[:items][:enum].sample + "], "
610
+ example << " #{prop.to_sym}: " + get_response_examples({schema: val}).join("\n") + ", "
602
611
  end
603
612
  end
604
- else
613
+ when "object"
605
614
  #todo: differ between response examples and data examples
606
- if type == :only_value
607
- example << get_response_examples({schema: val}).join("\n")
615
+ res_ex = get_response_examples({schema: val})
616
+ if res_ex.size == 0
617
+ res_ex = "{ }"
608
618
  else
609
- example << " #{prop.to_sym}: " + get_response_examples({schema: val}).join("\n") + ", "
619
+ res_ex = res_ex.join("\n")
610
620
  end
611
- end
612
- when "object"
613
- #todo: differ between response examples and data examples
614
- res_ex = get_response_examples({schema: val})
615
- if res_ex.size == 0
616
- res_ex = "{ }"
621
+ example << " #{prop.to_sym}: " + res_ex + ", "
617
622
  else
618
- res_ex = res_ex.join("\n")
623
+ example << " #{prop.to_sym}: \"#{format}\", "
619
624
  end
620
- example << " #{prop.to_sym}: " + res_ex + ", "
621
- else
622
- example << " #{prop.to_sym}: \"#{format}\", "
623
625
  end
624
626
  end
625
627
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: open_api_import
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mario Ruiz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-14 00:00:00.000000000 Z
11
+ date: 2019-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oas_parser