apiwork 0.3.0 → 0.3.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: eb5f681a0f08e4bebe2d0f5ebf4edac733f3787e4144f019bc4babfa7a7ef84a
4
- data.tar.gz: e5d1d87115d2902295d66567c324d73ef15d01b0ac106c1fa9739b56a276aeb3
3
+ metadata.gz: 61f7ef3c54d36ed6bced4d7e84233b2ab4879c697a29468202c09b811074e2f6
4
+ data.tar.gz: 0b285cc8cd1b5e5ad64b85d8e1bbe17cb82d281b2b69bf7b51a5468db2a9e43a
5
5
  SHA512:
6
- metadata.gz: bb539d87fcd3b065d643711616f7f9f5589d574cbf12bcc06c69aafe7000f6fafa4e19d7fd34cd165d2734076d3b192472a6f51459074241fabbf5dd3faece42
7
- data.tar.gz: 692745d73d86c3f5c377ae2a7962b38efe351b1fc893df6af45bd8de025622f61257307dedcd1b6aac15df8f3112874e92c54d3b3e316ef9aaa59ef6fcca0338
6
+ metadata.gz: 31a41407721690942c50e1db93d5e602e67ee4dde083ff3e44b3a86e4935f874463856ee0217306156d4c7e29c994c46c9a21da9b185b9c6477a0b96b71aa6bd
7
+ data.tar.gz: 4e197e9a7d1301ca771867b0ab85a777fdf0ab1e2951871ec156370f8118805cf0c502c65da8e6ed629d52eaab4ea8c7222639d2a6f0802077d401bb6c49588a
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Apiwork
2
2
 
3
+ ![Apiwork](docs/public/logo-light.svg#gh-light-mode-only)
4
+ ![Apiwork](docs/public/logo-dark.svg#gh-dark-mode-only)
5
+
3
6
  [![Gem Version](https://img.shields.io/gem/v/apiwork)](https://rubygems.org/gems/apiwork)
4
7
  [![CI](https://github.com/skiftle/apiwork/actions/workflows/ci.yml/badge.svg)](https://github.com/skiftle/apiwork/actions/workflows/ci.yml)
5
8
  [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE.txt)
@@ -44,7 +44,7 @@ module Apiwork
44
44
  .reject { |_, type_definition| type_definition.fragment? }
45
45
  .sort_by { |name, _type_definition| name.to_s }
46
46
  .each_with_object({}) do |(name, type_definition), result|
47
- result[name] = @type_dump.build_type(name, type_definition)
47
+ result[name] = @type_dump.build_type(name, type_definition)
48
48
  end
49
49
  end
50
50
 
@@ -53,7 +53,7 @@ module Apiwork
53
53
  .select { |_name, enum_definition| enum_definition.scope == @contract_class }
54
54
  .sort_by { |name, _enum_definition| name.to_s }
55
55
  .each_with_object({}) do |(name, enum_definition), result|
56
- result[name] = @type_dump.build_enum(name, enum_definition)
56
+ result[name] = @type_dump.build_enum(name, enum_definition)
57
57
  end
58
58
  end
59
59
 
@@ -4,9 +4,8 @@ module Apiwork
4
4
  module Introspection
5
5
  module Dump
6
6
  class Param
7
- def initialize(contract_param, visited: Set.new)
7
+ def initialize(contract_param)
8
8
  @contract_param = contract_param
9
- @visited = visited
10
9
  @import_prefix_cache = {}
11
10
  end
12
11
 
@@ -247,7 +246,7 @@ module Apiwork
247
246
  elsif shape.is_a?(Apiwork::API::Union)
248
247
  dump_api_union(shape)
249
248
  else
250
- Param.new(shape, visited: @visited).to_h
249
+ Param.new(shape).to_h
251
250
  end
252
251
  end
253
252
 
@@ -4,11 +4,12 @@ module Apiwork
4
4
  module Introspection
5
5
  module Dump
6
6
  class Resource
7
- def initialize(resource, api_class, parent_identifiers: [], parent_param: nil)
7
+ def initialize(resource, api_class, parent_identifiers: [], parent_param: nil, parent_singular: false)
8
8
  @resource = resource
9
9
  @api_class = api_class
10
10
  @parent_identifiers = parent_identifiers
11
11
  @parent_param = parent_param
12
+ @parent_singular = parent_singular
12
13
  end
13
14
 
14
15
  def to_h
@@ -57,6 +58,7 @@ module Apiwork
57
58
 
58
59
  def build_resource_path(formatted_segment)
59
60
  return formatted_segment if @parent_identifiers.empty?
61
+ return formatted_segment if @parent_singular
60
62
 
61
63
  ":#{@parent_param || "#{@parent_identifiers.last.singularize}_id"}/#{formatted_segment}"
62
64
  end
@@ -65,15 +67,15 @@ module Apiwork
65
67
  return {} unless @resource.resources.any?
66
68
 
67
69
  child_parent_identifiers = @parent_identifiers + [@resource.name.to_s]
68
- child_parent_param = @resource.param&.to_s || "#{@resource.name.to_s.singularize}_id"
70
+
71
+ nested_options = {
72
+ parent_identifiers: child_parent_identifiers,
73
+ parent_singular: @resource.singular,
74
+ }
75
+ nested_options[:parent_param] = @resource.param&.to_s || "#{@resource.name.to_s.singularize}_id" unless @resource.singular
69
76
 
70
77
  @resource.resources.transform_values do |nested_resource|
71
- Resource.new(
72
- nested_resource,
73
- @api_class,
74
- parent_identifiers: child_parent_identifiers,
75
- parent_param: child_parent_param,
76
- ).to_h
78
+ Resource.new(nested_resource, @api_class, **nested_options).to_h
77
79
  end
78
80
  end
79
81
 
@@ -82,17 +84,23 @@ module Apiwork
82
84
  end
83
85
 
84
86
  def action_path_segment(action_name, adapter_action)
87
+ param = @resource.param || :id
88
+
85
89
  if adapter_action.crud?
86
90
  case action_name
87
91
  when :index, :create
88
92
  ''
89
93
  when :show, :update, :destroy
90
- '/:id'
94
+ @resource.singular ? '' : "/:#{param}"
91
95
  else
92
96
  ''
93
97
  end
94
98
  elsif adapter_action.member?
95
- "/:id/#{@api_class.transform_path(action_name)}"
99
+ if @resource.singular
100
+ "/#{@api_class.transform_path(action_name)}"
101
+ else
102
+ "/:#{param}/#{@api_class.transform_path(action_name)}"
103
+ end
96
104
  elsif adapter_action.collection?
97
105
  "/#{@api_class.transform_path(action_name)}"
98
106
  else
@@ -19,7 +19,7 @@ module Apiwork
19
19
  @api_class.type_registry.each_pair
20
20
  .reject { |_, type_definition| type_definition.fragment? }
21
21
  .sort_by do |name, _type_definition|
22
- name.to_s
22
+ name.to_s
23
23
  end.each_with_object({}) do |(qualified_name, type_definition), result|
24
24
  result[qualified_name] = build_type(qualified_name, type_definition)
25
25
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Apiwork
4
- VERSION = '0.3.0'
4
+ VERSION = '0.3.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apiwork
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - skiftle
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-02-28 00:00:00.000000000 Z
11
+ date: 2026-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: lefthook
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -128,7 +142,6 @@ executables: []
128
142
  extensions: []
129
143
  extra_rdoc_files: []
130
144
  files:
131
- - LICENSE.txt
132
145
  - README.md
133
146
  - Rakefile
134
147
  - app/controllers/apiwork/errors_controller.rb
data/LICENSE.txt DELETED
@@ -1,21 +0,0 @@
1
- Copyright (c) 2026 skiftle
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.