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 +4 -4
- data/AGENTS.md +23 -0
- data/README.md +11 -1
- data/lib/blueprinter_schema/generator.rb +8 -5
- data/lib/blueprinter_schema/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c3dd0981a3be1b7ee216a5b81d3ea24069cb937e291e2c2c7bb590d98db2e698
|
|
4
|
+
data.tar.gz: 00211a94280dd1dfd0f4cb5a93ef56d1ae77fc17e312cf7c5c11799a7fe4fc74
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
78
|
-
|
|
79
|
-
|
|
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)
|
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.
|
|
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
|