6
6
require 'tempfile'
7
7
rescue LoadError => e
8
8
puts "Load error: #{ e . message } "
9
- exit
9
+ exit 1
10
10
end
11
11
12
12
DEBUG_LEVEL = 1
@@ -277,7 +277,7 @@ def get_docs_type_for_value(schema, value)
277
277
@logger . error "Schema instance type and value type are a mismatch, which should not happen."
278
278
@logger . error "Schema instance type: #{ schema_instance_type } "
279
279
@logger . error "Value: #{ value } (type: #{ value_type } )"
280
- exit
280
+ exit 1
281
281
end
282
282
283
283
# For any numeric type, extract the value of `docs::numeric_type`, which must always be present in
@@ -288,7 +288,7 @@ def get_docs_type_for_value(schema, value)
288
288
numeric_type = get_schema_metadata ( schema , 'docs::numeric_type' )
289
289
if numeric_type . nil?
290
290
@logger . error "All fields with numeric types should have 'docs::numeric_type' metadata included."
291
- exit
291
+ exit 1
292
292
end
293
293
294
294
return numeric_type
@@ -461,7 +461,7 @@ def get_schema_by_name(root_schema, schema_name)
461
461
schema_def = root_schema . dig ( 'definitions' , schema_name )
462
462
if schema_def . nil?
463
463
@logger . error "Could not find schema definition '#{ schema_name } ' in given schema."
464
- exit
464
+ exit 1
465
465
end
466
466
467
467
schema_def
@@ -713,7 +713,7 @@ def resolve_schema_by_name(root_schema, schema_name)
713
713
cycles with `#[configurable(metadata(docs::cycle_entrypoint))]`. As such a field will have no type \
714
714
information rendered, it is advised to supply a sufficiently detailed field description that \
715
715
describes the allowable values, etc."
716
- exit
716
+ exit 1
717
717
end
718
718
719
719
# It wasn't already cached, so we actually have to resolve it.
@@ -949,7 +949,7 @@ def resolve_bare_schema(root_schema, schema)
949
949
grouped
950
950
else
951
951
@logger . error "Failed to resolve the schema. Schema: #{ schema } "
952
- exit
952
+ exit 1
953
953
end
954
954
955
955
{ 'type' => resolved }
@@ -985,7 +985,7 @@ def resolve_enum_schema(root_schema, schema)
985
985
@logger . error 'Enum schemas should never be missing the metadata for the enum tagging mode.'
986
986
@logger . error "Schema: #{ JSON . pretty_generate ( schema ) } "
987
987
@logger . error "Filter subschemas: #{ JSON . pretty_generate ( subschemas ) } "
988
- exit
988
+ exit 1
989
989
end
990
990
991
991
enum_tag_field = get_schema_metadata ( schema , 'docs::enum_tag_field' )
@@ -1098,12 +1098,12 @@ def resolve_enum_schema(root_schema, schema)
1098
1098
if tag_value . nil?
1099
1099
@logger . error 'All enum subschemas representing an internally-tagged enum must have the tag field use a const value.'
1100
1100
@logger . error "Tag subschema: #{ tag_subschema } "
1101
- exit
1101
+ exit 1
1102
1102
end
1103
1103
1104
1104
if unique_tag_values . key? ( tag_value )
1105
1105
@logger . error "Found duplicate tag value '#{ tag_value } ' when resolving enum subschemas."
1106
- exit
1106
+ exit 1
1107
1107
end
1108
1108
1109
1109
unique_tag_values [ tag_value ] = tag_subschema
@@ -1122,7 +1122,7 @@ def resolve_enum_schema(root_schema, schema)
1122
1122
@logger . error "Had overlapping property '#{ property_name } ' from resolved enum subschema, but schemas differed:"
1123
1123
@logger . error "Existing property schema (reduced): #{ to_pretty_json ( reduced_existing_property ) } "
1124
1124
@logger . error "New property schema (reduced): #{ to_pretty_json ( reduced_new_property ) } "
1125
- exit
1125
+ exit 1
1126
1126
end
1127
1127
1128
1128
@logger . debug "Adding relevant tag to existing resolved property schema for '#{ property_name } '."
@@ -1185,8 +1185,14 @@ def resolve_enum_schema(root_schema, schema)
1185
1185
}
1186
1186
}
1187
1187
}
1188
+
1188
1189
tag_description = get_schema_metadata ( schema , 'docs::enum_tag_description' )
1189
- resolved_tag_property [ 'description' ] = tag_description unless tag_description . nil?
1190
+ if tag_description . nil?
1191
+ @logger . error "A unique tag description must be specified for enums which are internally tagged (i.e. `#[serde(tag = \" ...\" )/`). This can be specified via `#[configurable(metadata(docs::enum_tag_description = \" ...\" ))]`."
1192
+ @logger . error "Schema being generated: #{ JSON . pretty_generate ( schema ) } "
1193
+ exit 1
1194
+ end
1195
+ resolved_tag_property [ 'description' ] = tag_description
1190
1196
unique_resolved_properties [ enum_tag_field ] = resolved_tag_property
1191
1197
1192
1198
@logger . debug "Resolved as 'internally-tagged with named fields' enum schema."
@@ -1366,7 +1372,7 @@ def apply_schema_default_value!(source_schema, resolved_schema)
1366
1372
Source schema: #{ to_pretty_json ( source_schema ) } \
1367
1373
Default value: #{ to_pretty_json ( default_value ) } (type: #{ default_value_type } ) \
1368
1374
Resolved schema: #{ to_pretty_json ( resolved_schema ) } "
1369
- exit
1375
+ exit 1
1370
1376
end
1371
1377
1372
1378
case default_value_type
@@ -1487,7 +1493,7 @@ def apply_schema_metadata!(source_schema, resolved_schema)
1487
1493
if !syntax_override . nil?
1488
1494
if resolved_schema_type? ( resolved_schema ) != "string"
1489
1495
@logger . error "Non-string schemas should not use the `syntax_override` metadata attribute."
1490
- exit
1496
+ exit 1
1491
1497
end
1492
1498
1493
1499
resolved_schema [ 'type' ] [ 'string' ] [ 'syntax' ] = syntax_override . to_s
@@ -1656,7 +1662,7 @@ def render_and_import_schema(root_schema, schema_name, friendly_name, config_map
1656
1662
unwrapped_resolved_schema = resolved_schema . dig ( 'type' , 'object' , 'options' )
1657
1663
if unwrapped_resolved_schema . nil?
1658
1664
@logger . error 'Configuration types must always resolve to an object schema.'
1659
- exit
1665
+ exit 1
1660
1666
end
1661
1667
1662
1668
unwrapped_resolved_schema = sort_hash_nested ( unwrapped_resolved_schema )
@@ -1689,7 +1695,7 @@ def render_and_import_schema(root_schema, schema_name, friendly_name, config_map
1689
1695
cue_output_file = "website/cue/reference/components/#{ cue_relative_path } "
1690
1696
unless system ( @cue_binary_path , 'import' , '-f' , '-o' , cue_output_file , '-p' , 'metadata' , json_output_file )
1691
1697
@logger . error "[!] Failed to import #{ friendly_name } schema as valid Cue."
1692
- exit
1698
+ exit 1
1693
1699
end
1694
1700
@logger . info "[✓] Imported #{ friendly_name } schema to '#{ cue_output_file } '."
1695
1701
end
@@ -1716,13 +1722,13 @@ def render_and_import_component_schema(root_schema, schema_name, component_type,
1716
1722
1717
1723
if ARGV . empty?
1718
1724
puts 'usage: extract-component-schema.rb <configuration schema path>'
1719
- exit
1725
+ exit 1
1720
1726
end
1721
1727
1722
1728
# Ensure that Cue is present since we need it to import our intermediate JSON representation.
1723
1729
if @cue_binary_path . nil?
1724
1730
puts 'Failed to find \'cue\' binary on the current path. Install \'cue\' (or make it available on the current path) and try again.'
1725
- exit
1731
+ exit 1
1726
1732
end
1727
1733
1728
1734
schema_path = ARGV [ 0 ]
0 commit comments