fakeit 0.9.2 → 0.10.0

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: b6a7f204912168334397f27d77e2c94a8b29a748b19c2e2e6d5b8aff656c1c88
4
- data.tar.gz: 35140a1ac79a93701b7b9047aa641e4ae3eeca482ada20889d5a8eb2c26354e9
3
+ metadata.gz: 12f260511e656b09583cd6c2d2dba67d5b7f947c3242eca95c7b3cf2cec34c0a
4
+ data.tar.gz: 48625a13975517595721666508dbaa4f151a421ed24bae0e8a6c053e94e995c3
5
5
  SHA512:
6
- metadata.gz: 46497c7741b4e7e411260492b3c3d452ff0dbcd6ecce1177e7290646f945b5bb2f6bf19f21d80b3bcac4197623bb605be6f99d61223f25c1ff73bf0da69bd8e0
7
- data.tar.gz: 14730bd843f9c48a0544435d48f297f8403b553a85a80eb7b882bdc41f92977a94f33205d8d8b5bb3ed35a8282edda6f5dbbe0efcd7a62fb7eee52d6b2ad4200
6
+ metadata.gz: 82d5e751a1591754f540d4fad85caffc8d697d4a81cb92a0d0ce000c4571a08613565aef6e43919db5712579162f96b676541129b071acaf95c55c3da4ffb200
7
+ data.tar.gz: f480f86e2f9fda5944ee31996b641f1bc0fb3384cab6df126ce2b238cb3759aeb6b2d53dee7d881239369a2f3d8233b315ad3a6e7a592c8f2eb39509b63cd3d9
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## [v0.9.2](https://github.com/JustinFeng/fakeit/tree/v0.9.2) (2021-08-14)
4
+
5
+ [Full Changelog](https://github.com/JustinFeng/fakeit/compare/v0.9.1...v0.9.2)
6
+
7
+ **Closed issues:**
8
+
9
+ - "Tried to load unspecified class: Date" error is given when spec contains a text that resembles a date [\#25](https://github.com/JustinFeng/fakeit/issues/25)
10
+
11
+ **Merged pull requests:**
12
+
13
+ - Bump rexml from 3.2.4 to 3.2.5 [\#24](https://github.com/JustinFeng/fakeit/pull/24) ([dependabot[bot]](https://github.com/apps/dependabot))
14
+
3
15
  ## [v0.9.1](https://github.com/JustinFeng/fakeit/tree/v0.9.1) (2021-04-18)
4
16
 
5
17
  [Full Changelog](https://github.com/JustinFeng/fakeit/compare/v0.9.0...v0.9.1)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fakeit (0.9.2)
4
+ fakeit (0.10.0)
5
5
  faker (= 2.18.0)
6
6
  openapi_parser (= 0.14.1)
7
7
  rack (~> 2.0)
@@ -21,7 +21,7 @@ GEM
21
21
  docile (1.4.0)
22
22
  faker (2.18.0)
23
23
  i18n (>= 1.6, < 2)
24
- i18n (1.8.10)
24
+ i18n (1.8.11)
25
25
  concurrent-ruby (~> 1.0)
26
26
  openapi_parser (0.14.1)
27
27
  parallel (1.20.1)
data/README.md CHANGED
@@ -62,6 +62,7 @@ Or use the [docker image](https://hub.docker.com/r/realfengjia/fakeit)
62
62
  --static generate static response
63
63
  --static-types generate static value for specified types, e.g. --static-types integer,string
64
64
  --static-properties generate static value for specified properties, e.g. --static-properties id,uuid
65
+ --base-path mounts the mock server at the given path, e.g. --base-path /api
65
66
 
66
67
  other options:
67
68
  -v, --version
@@ -96,7 +97,8 @@ Request and response:
96
97
  ],
97
98
  "static_properties": [
98
99
  "id"
99
- ]
100
+ ],
101
+ "base_path": "/"
100
102
  }
101
103
  ```
102
104
 
data/bin/fakeit CHANGED
@@ -16,6 +16,7 @@ begin
16
16
  o.bool '--static', 'generate static response'
17
17
  o.array '--static-types', 'generate static value for specified types, e.g. --static-types integer,string'
18
18
  o.array '--static-properties', 'generate static value for specified properties, e.g. --static-properties id,uuid'
19
+ o.string '--base-path', 'mounts the mock server at the given path, e.g. --base-path /api'
19
20
  o.separator ''
20
21
  o.separator 'other options:'
21
22
  o.on '-v', '--version' do
@@ -50,7 +51,8 @@ options = Fakeit::App::Options.new(
50
51
  use_example: opts.use_example?,
51
52
  static: opts.static?,
52
53
  static_types: opts[:static_types],
53
- static_properties: opts[:static_properties]
54
+ static_properties: opts[:static_properties],
55
+ base_path: opts[:base_path]
54
56
  )
55
57
  app = Fakeit.build(opts[:spec], options)
56
58
 
@@ -2,6 +2,7 @@ module Fakeit
2
2
  module App
3
3
  class AppBuilder
4
4
  def initialize(spec_file, options)
5
+ @options = options
5
6
  @config_route = Routes::ConfigRoute.new(options)
6
7
  @openapi_route = Routes::OpenapiRoute.new(spec_file)
7
8
  end
@@ -14,10 +15,21 @@ module Fakeit
14
15
  when '/__fakeit_config__'
15
16
  @config_route.call(request)
16
17
  else
18
+ request.path_info = trim_base_from_path(request.path_info)
17
19
  @openapi_route.call(request, @config_route.options)
18
20
  end
19
21
  end
20
22
  end
23
+
24
+ private
25
+
26
+ def trim_base_from_path(path)
27
+ return path if @options.base_path == '/'
28
+
29
+ return path unless path.start_with?(@options.base_path)
30
+
31
+ path[@options.base_path.length-1..]
32
+ end
21
33
  end
22
34
  end
23
35
  end
@@ -1,14 +1,17 @@
1
1
  module Fakeit
2
2
  module App
3
3
  class Options
4
- attr_reader :permissive, :use_example
4
+ attr_reader :permissive, :use_example, :base_path
5
5
 
6
- def initialize(permissive: false, use_example: false, static: false, static_types: [], static_properties: [])
6
+ def initialize(permissive: false, use_example: false, static: false, static_types: [], static_properties: [], base_path: "/")
7
7
  @permissive = permissive
8
8
  @use_example = use_example
9
9
  @static = static
10
10
  @static_types = static_types
11
11
  @static_properties = static_properties
12
+ # Standardize the base path to include trailing slash
13
+ # so that `/base` matches `/base/path` but doesn't match `/basement/path`
14
+ @base_path = base_path[-1] == '/' ? base_path : "#{base_path}/"
12
15
  end
13
16
 
14
17
  def use_static?(type: nil, property: nil)
@@ -21,7 +24,8 @@ module Fakeit
21
24
  use_example: @use_example,
22
25
  static: @static,
23
26
  static_types: @static_types,
24
- static_properties: @static_properties
27
+ static_properties: @static_properties,
28
+ base_path: @base_path
25
29
  }
26
30
  end
27
31
  end
@@ -1,3 +1,3 @@
1
1
  module Fakeit
2
- VERSION = '0.9.2'.freeze
2
+ VERSION = '0.10.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fakeit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Feng
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-14 00:00:00.000000000 Z
11
+ date: 2021-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler