blueprinter_schema 1.1.0 → 1.2.0

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: 79f76768380ae6cbe77da6ec153325e079ca2d5ee30df459378e0ebb90f674c2
4
- data.tar.gz: 50a119f7dd0fb32789a24ed6ccddd05026a0bb8525f4c5c60f94f232edcc3e31
3
+ metadata.gz: c3dd0981a3be1b7ee216a5b81d3ea24069cb937e291e2c2c7bb590d98db2e698
4
+ data.tar.gz: 00211a94280dd1dfd0f4cb5a93ef56d1ae77fc17e312cf7c5c11799a7fe4fc74
5
5
  SHA512:
6
- metadata.gz: f057fdac75f35be16f955cbc083326ab32940ed5210ec8ed26922b4614741e0371e0e762371081d7afdf31dbee97d7fc14794650bde811ef636f3de64a2cb52f
7
- data.tar.gz: e82e0011242c7838709c55c2d4d6ca8d2a43e620a6ff7c244c9fc70b816e6dd7c211a995ebea6fd57390744c0523d2b467168e9fc52e8bdec02ecebb10888811
6
+ metadata.gz: 16674fa11cdd54d134cdf32b2366e5c4be600fc0c455d2fa6f30ca2bb9c80daf6ea4e6008ab92ad6ae0fe29308da3aff739ff052bdeb6e1679d0604f5cc7cc69
7
+ data.tar.gz: fbe7899df7288fc0520f8103ec846439fd1cecf04ee36dd3387923cfd59879eee63c5c2bfec8e6cca4db313393829e369df5311adf0c5f2608cbcd39c8dee444
data/AGENTS.md ADDED
@@ -0,0 +1,23 @@
1
+ # BlueprinterSchema
2
+
3
+ A gem to create JSON Schemas from [Blueprinter](https://github.com/procore-oss/blueprinter) Serializers.
4
+
5
+ ## Instructions
6
+
7
+ - Specs MUST assert the full expected schema, so that they serve as clear documentation of what is generated
8
+
9
+ ## Development Commands
10
+
11
+ ### Setup
12
+
13
+ ```sh
14
+ mise install
15
+ bin/setup
16
+ ```
17
+
18
+ ### Test, lint
19
+
20
+ ```sh
21
+ bundle exec rspec
22
+ bundle exec rubocop -A
23
+ ```
data/README.md CHANGED
@@ -18,6 +18,8 @@ class UserSerializer < Blueprinter::Base
18
18
  field :last_name, type: [:string, :null]
19
19
  field :full_name, type: [:string, :null], description: "The concatendated first and last name."
20
20
  field :email, type: :string, format: :email
21
+ field :role, type: :string, enum: ["user", "admin"]
22
+ field :tags, type: :array, items: { type: :string }
21
23
  end
22
24
 
23
25
  BlueprinterSchema.generate(serializer: UserSerializer)
@@ -40,9 +42,17 @@ BlueprinterSchema.generate(serializer: UserSerializer)
40
42
  "email" => {
41
43
  "type" => "string",
42
44
  "format" => "email"
45
+ },
46
+ "role" => {
47
+ "type" => "string",
48
+ "enum" => ["user", "admin"]
49
+ },
50
+ "tags" => {
51
+ "type" => "array",
52
+ "items" => { "type" => "string" }
43
53
  }
44
54
  },
45
- "required" => ["first_name", "last_name", "full_name", "email"],
55
+ "required" => ["first_name", "last_name", "full_name", "email", "role", "tags"],
46
56
  "additionalProperties" => false
47
57
  }
48
58
  ```
@@ -63,7 +63,6 @@ module BlueprinterSchema
63
63
  .keys.map(&:to_s)
64
64
  end
65
65
 
66
- # rubocop:disable Metrics/AbcSize
67
66
  def field_to_json_schema(field)
68
67
  type_definition = @fallback_definition.dup
69
68
 
@@ -74,12 +73,16 @@ module BlueprinterSchema
74
73
  type_definition = ar_column_to_json_schema(column)
75
74
  end
76
75
 
77
- type_definition['items'] = field.options[:items].deep_stringify_keys if field.options[:items]
78
- type_definition['format'] = field.options[:format] if field.options[:format]
79
- type_definition['description'] = field.options[:description] if field.options[:description]
76
+ merge_field_options(type_definition, field.options)
77
+ end
78
+
79
+ def merge_field_options(type_definition, options)
80
+ type_definition['enum'] = options[:enum] if options[:enum]
81
+ type_definition['items'] = options[:items].deep_stringify_keys if options[:items]
82
+ type_definition['format'] = options[:format] if options[:format]
83
+ type_definition['description'] = options[:description] if options[:description]
80
84
  type_definition
81
85
  end
82
- # rubocop:enable Metrics/AbcSize
83
86
 
84
87
  def ensure_valid_json_schema_types!(field)
85
88
  types = [field.options[:type]].flatten.map(&:to_s)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BlueprinterSchema
4
- VERSION = '1.1.0'
4
+ VERSION = '1.2.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blueprinter_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thisismydesign
@@ -19,6 +19,7 @@ files:
19
19
  - ".rspec"
20
20
  - ".rubocop.yml"
21
21
  - ".tool-versions"
22
+ - AGENTS.md
22
23
  - Dockerfile
23
24
  - LICENSE.txt
24
25
  - README.md