A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
content: JSON Schemas for people, offices, parties and events (fixes #265) (#279)
Guy Shohamc6ee8e50985f
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 74cced799..3fef57b1c 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -8,6 +8,11 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIB## [Unreleased]### Added+- JSON Schemas for `people.yaml`, `offices.yaml`, `parties.yaml` and the event files (#265), in `content/schema/`. Each file+ names its schema on the first line, so an editor with a YAML language server flags a wrong field name or a missing+ `sources:` as you type. `SchemaTests` checks all real content against them, keeps their field names equal to the loader+ types and checks that they reject the usual mistakes. The comment changes the content hash, so an old save shows the+ content-changed warning once. The golden hashes do not move.- The Fourth to Seventh Governments (24 December 1952 to 1956) with their coalitions and the ministers' dated terms,the 1953-1956 deputy ministers, the Ministries of Postal Services (from 3 November 1952) and Development (from15 June 1953), and the Chiefs of Staff Maklef and Dayan. Dates follow the Knesset's own position records and plenumdiff --git a/content/events/altalena.yaml b/content/events/altalena.yamlindex fa5af7cb9..2f88687da 100644--- a/content/events/altalena.yaml+++ b/content/events/altalena.yaml@@ -1,3 +1,4 @@+# yaml-language-server: $schema=../schema/event.schema.jsonid: altalenatitle: The Altalenatext: 'The Altalena, a ship carrying arms for the Irgun, is due at Kfar Vitkin. Begin asks that a fifth of the arms go to the Irgun''s battalion in Jerusalem and the rest to Irgun battalions inside the IDF. {defense_minister} must decide.'diff --git a/content/events/armistice_egypt.yaml b/content/events/armistice_egypt.yamlindex 1977417ab..524409142 100644--- a/content/events/armistice_egypt.yaml+++ b/content/events/armistice_egypt.yaml@@ -1,3 +1,4 @@+# yaml-language-server: $schema=../schema/event.schema.jsonid: armistice_egypttitle: Armistice with Egypttext: 'Talks in Rhodes have produced an armistice agreement with Egypt. {prime_minister} must decide whether Israel signs.'diff --git a/content/events/armistice_jordan.yaml b/content/events/armistice_jordan.yamlindex fd7a84205..58629fb28 100644--- a/content/events/armistice_jordan.yaml+++ b/content/events/armistice_jordan.yaml@@ -1,3 +1,4 @@+# yaml-language-server: $schema=../schema/event.schema.jsonid: armistice_jordantitle: Armistice with Jordantext: 'Negotiators have reached an armistice agreement with Jordan. {prime_minister} must decide whether Israel signs.'diff --git a/content/events/armistice_lebanon.yaml b/content/events/armistice_lebanon.yamlindex a10d93083..864e214e7 100644--- a/content/events/armistice_lebanon.yaml+++ b/content/events/armistice_lebanon.yaml@@ -1,3 +1,4 @@+# yaml-language-server: $schema=../schema/event.schema.jsonid: armistice_lebanontitle: Armistice with Lebanontext: 'Negotiators have reached an armistice agreement with Lebanon. {prime_minister} must decide whether Israel signs.'diff --git a/content/events/armistice_syria.yaml b/content/events/armistice_syria.yamlindex 87372a425..21f058395 100644--- a/content/events/armistice_syria.yaml+++ b/content/events/armistice_syria.yaml@@ -1,3 +1,4 @@+# yaml-language-server: $schema=../schema/event.schema.jsonid: armistice_syriatitle: Armistice with Syriatext: 'Negotiators have reached an armistice agreement with Syria. {prime_minister} must decide whether Israel signs.'diff --git a/content/events/austerity_1949.yaml b/content/events/austerity_1949.yamlindex 760238793..a5054e3d5 100644--- a/content/events/austerity_1949.yaml+++ b/content/events/austerity_1949.yaml@@ -1,3 +1,4 @@+# yaml-language-server: $schema=../schema/event.schema.jsonid: austerity_1949title: Austeritytext: 'Food and foreign currency cannot keep pace with the immigrants arriving every week. {rationing_minister}, heading the new Ministry of Rationing and Supply, proposes strict rationing.'diff --git a/content/events/bernadotte_assassination.yaml b/content/events/bernadotte_assassination.yamlindex a991ab273..b400fd99b 100644--- a/content/events/bernadotte_assassination.yaml+++ b/content/events/bernadotte_assassination.yaml@@ -1,3 +1,4 @@+# yaml-language-server: $schema=../schema/event.schema.jsonid: bernadotte_assassinationtitle: The Mediator Assassinatedtext: 'Lehi gunmen have assassinated the UN mediator, Count Folke Bernadotte, in Jerusalem, a day after he completed his second plan. {prime_minister} must decide how the government answers the armed groups still outside the IDF: Lehi, and the Irgun battalions in Jerusalem.'diff --git a/content/events/clothing_rationing_1950.yaml b/content/events/clothing_rationing_1950.yamlindex 03e718b4a..00d7d0e47 100644--- a/content/events/clothing_rationing_1950.yaml+++ b/content/events/clothing_rationing_1950.yaml@@ -1,3 +1,4 @@+# yaml-language-server: $schema=../schema/event.schema.jsonid: clothing_rationing_1950title: Rationing Clothes and Shoestext: 'Prices on the black market are climbing. {rationing_minister} proposes extending rationing to clothing and footwear and fighting the black market.'diff --git a/content/events/education_registration_1951.yaml b/content/events/education_registration_1951.yamlindex 396406fed..34be00d60 100644--- a/content/events/education_registration_1951.yaml+++ b/content/events/education_registration_1951.yaml@@ -1,3 +1,4 @@+# yaml-language-server: $schema=../schema/event.schema.jsonid: education_registration_1951title: Schools in the Transit Campstext: 'The coalition is split over schooling for immigrant children in the transit camps: the religious parties oppose a religious stream run by the labour movement. {education_minister} brings a registration plan to the Knesset.'diff --git a/content/events/elections_1949.yaml b/content/events/elections_1949.yamlindex 87e2052c9..d43c33004 100644--- a/content/events/elections_1949.yaml+++ b/content/events/elections_1949.yaml@@ -1,3 +1,4 @@+# yaml-language-server: $schema=../schema/event.schema.jsonid: elections_1949title: Electing the Constituent Assemblytext: 'The Provisional State Council has set the Constituent Assembly at 120 seats, elected nationwide by proportional representation, and a national registration taken under curfew on 8 November built the voters'' roll. Postponed because of the war, the vote is set for 25 January.'diff --git a/content/events/first_truce.yaml b/content/events/first_truce.yamlindex 66ad5ec1f..eef6ce24f 100644--- a/content/events/first_truce.yaml+++ b/content/events/first_truce.yaml@@ -1,3 +1,4 @@+# yaml-language-server: $schema=../schema/event.schema.jsonid: first_trucetitle: The First Trucetext: 'The Security Council has called for a four-week cease-fire, supervised by the UN mediator, Count Folke Bernadotte. Neither side may bring fighting men or war material into Palestine or the Arab states, and the Council has warned of Chapter VII action if the terms are broken. {prime_minister} must decide whether Israel accepts.'diff --git a/content/events/forex_crisis_1951.yaml b/content/events/forex_crisis_1951.yamlindex 798e8663c..6b966670e 100644--- a/content/events/forex_crisis_1951.yaml+++ b/content/events/forex_crisis_1951.yaml@@ -1,3 +1,4 @@+# yaml-language-server: $schema=../schema/event.schema.jsonid: forex_crisis_1951title: Foreign Currency Runs Outtext: 'Drought has forced larger wheat imports, immigration in the first half of the year far exceeded the plan, and about 45 million dollars of short-term credit falls due by December. {finance_minister} proposes asking the United States for about 15 million dollars in immediate aid.'diff --git a/content/events/frumkin_commission.yaml b/content/events/frumkin_commission.yamlindex 4982e1cec..409003c95 100644--- a/content/events/frumkin_commission.yaml+++ b/content/events/frumkin_commission.yaml@@ -1,3 +1,4 @@+# yaml-language-server: $schema=../schema/event.schema.jsonid: frumkin_commissiontitle: Education in the Immigrant Campstext: 'Religious Yemenite parents report coercion in the immigrant-camp schools, which the uniform system put under the Culture Department, including the cutting of sidelocks. The religious parties demand action. {prime_minister} must decide whether to appoint an inquiry.'diff --git a/content/events/hula_drainage.yaml b/content/events/hula_drainage.yamlindex 17768f026..7838333a3 100644--- a/content/events/hula_drainage.yaml+++ b/content/events/hula_drainage.yaml@@ -1,3 +1,4 @@+# yaml-language-server: $schema=../schema/event.schema.jsonid: hula_drainagetitle: Draining the Hulatext: 'Drainage works south of Lake Hula, under the Palestine Land Development Company''s concession, reach into the demilitarised zone with Syria. Syria has complained, and the chairman of the armistice commission asks that work stop pending agreement. {prime_minister} must decide.'diff --git a/content/events/idf_founding.yaml b/content/events/idf_founding.yamlindex 2f9a2e57b..19c0237b6 100644--- a/content/events/idf_founding.yaml+++ b/content/events/idf_founding.yaml@@ -1,3 +1,4 @@+# yaml-language-server: $schema=../schema/event.schema.jsonid: idf_foundingtitle: One Armytext: 'Armed forces are being brought into the new Israel Defense Forces, while the Irgun and Lehi still keep their own units. {defense_minister} proposes an order that forbids any armed force other than the IDF.'diff --git a/content/events/iraqi_exodus.yaml b/content/events/iraqi_exodus.yamlindex 65aea419c..a9f828dc2 100644--- a/content/events/iraqi_exodus.yaml+++ b/content/events/iraqi_exodus.yaml@@ -1,3 +1,4 @@+# yaml-language-server: $schema=../schema/event.schema.jsonid: iraqi_exodustitle: The Jews of Iraqtext: 'Iraq has frozen the assets of the Jews who gave up their citizenship to leave, and some 64,000 people are still waiting to fly. The transit camps are already crowded. {immigration_minister} asks whether to bring everyone at once.'diff --git a/content/events/israel_bonds.yaml b/content/events/israel_bonds.yamlindex acc12307b..989a5a026 100644--- a/content/events/israel_bonds.yaml+++ b/content/events/israel_bonds.yaml@@ -1,3 +1,4 @@+# yaml-language-server: $schema=../schema/event.schema.jsonid: israel_bondstitle: Israel Bondstext: 'The Knesset authorised a bond issue in February; it launches on 10 May. {finance_minister} proposes selling State of Israel bonds to Jews abroad, alongside the United Jewish Appeal donations.'diff --git a/content/events/jerusalem_ceasefire.yaml b/content/events/jerusalem_ceasefire.yamlindex eb2dddbd6..d61f6da20 100644--- a/content/events/jerusalem_ceasefire.yaml+++ b/content/events/jerusalem_ceasefire.yaml@@ -1,3 +1,4 @@+# yaml-language-server: $schema=../schema/event.schema.jsonid: jerusalem_ceasefiretitle: Cease-fire in Jerusalemtext: 'Talks began on 28 November between Dayan and Abdullah el-Tell on a full cease-fire for the Jerusalem area, with UN observers present. {prime_minister} must decide whether Israel signs it at Government House.'diff --git a/content/events/jerusalem_military_government.yaml b/content/events/jerusalem_military_government.yamlindex b8eacf3cf..7be6c7fd1 100644--- a/content/events/jerusalem_military_government.yaml+++ b/content/events/jerusalem_military_government.yaml@@ -1,3 +1,4 @@+# yaml-language-server: $schema=../schema/event.schema.jsonid: jerusalem_military_governmenttitle: Jerusalemtext: 'Count Bernadotte''s proposals would put Jerusalem under UN authority, and he has suggested demilitarising the city. The alternative is to put the part of Jerusalem held by the IDF under Israeli military government, with Dov Yosef as military governor. {prime_minister} must decide.'diff --git a/content/events/latrun_proposal.yaml b/content/events/latrun_proposal.yamlindex a346651af..19b4673b6 100644--- a/content/events/latrun_proposal.yaml+++ b/content/events/latrun_proposal.yaml@@ -1,3 +1,4 @@+# yaml-language-server: $schema=../schema/event.schema.jsonid: latrun_proposaltitle: Latruntext: '{prime_minister} proposes to the cabinet that the IDF break the truce to attack and take Latrun. Most ministers, among them {finance_minister}, {justice_minister} and {immigration_minister}, oppose it.'diff --git a/content/events/law_of_return.yaml b/content/events/law_of_return.yamlindex 7c8b247d3..ac86853f2 100644--- a/content/events/law_of_return.yaml+++ b/content/events/law_of_return.yaml@@ -1,3 +1,4 @@+# yaml-language-server: $schema=../schema/event.schema.jsonid: law_of_returntitle: The Law of Returntext: 'The Knesset is ready to vote on the Law of Return, which gives every Jew the right to come to Israel as an oleh. {prime_minister} must decide whether the government backs it.'diff --git a/content/events/maabarot_policy.yaml b/content/events/maabarot_policy.yamlindex 4072fd7ab..656a6f673 100644--- a/content/events/maabarot_policy.yaml+++ b/content/events/maabarot_policy.yaml@@ -1,3 +1,4 @@+# yaml-language-server: $schema=../schema/event.schema.jsonid: maabarot_policytitle: Transit Campstext: 'The immigrant camps, which house and feed new arrivals free of charge, are overflowing. Levi Eshkol of the Jewish Agency Settlement Department proposes transit camps near towns and work, where residents earn their own living. {prime_minister} must decide.'diff --git a/content/events/ministry_supply_crisis.yaml b/content/events/ministry_supply_crisis.yamlindex eb84e06d6..3dc7653a4 100644--- a/content/events/ministry_supply_crisis.yaml+++ b/content/events/ministry_supply_crisis.yaml@@ -1,3 +1,4 @@+# yaml-language-server: $schema=../schema/event.schema.jsonid: ministry_supply_crisistitle: Closing the Ministry of Rationingtext: 'Mapai is divided over closing the Ministry of Rationing and Supply, and {prime_minister} wants a businessman, Ya''akov Geri, who is not a Knesset member, at Trade and Industry. Under the law of the time, adding a minister means the government must resign and win a new vote of confidence.'diff --git a/content/events/operation_hiram.yaml b/content/events/operation_hiram.yamlindex 3e1c08c1c..a1985257d 100644--- a/content/events/operation_hiram.yaml+++ b/content/events/operation_hiram.yaml@@ -1,3 +1,4 @@+# yaml-language-server: $schema=../schema/event.schema.jsonid: operation_hiramtitle: Operation Hiramtext: 'In breach of the truce, the Arab Liberation Army has attacked the Sheikh Abd position above Kibbutz Manara, and Qawuqji refuses to withdraw. Israel has told the UN that it feels free to act. {defense_minister} must decide whether Moshe Carmel''s forces clear the Upper Galilee.'diff --git a/content/events/operation_horev.yaml b/content/events/operation_horev.yamlindex efaae8546..16b7bc28a 100644--- a/content/events/operation_horev.yaml+++ b/content/events/operation_horev.yaml@@ -1,3 +1,4 @@+# yaml-language-server: $schema=../schema/event.schema.jsonid: operation_horevtitle: Operation Horevtext: '{defense_minister} proposes an offensive against the Egyptian army in the south, under Yigal Allon, with five brigades.'diff --git a/content/events/operation_yoav.yaml b/content/events/operation_yoav.yamlindex e1fd30596..2ba26ac40 100644--- a/content/events/operation_yoav.yaml+++ b/content/events/operation_yoav.yaml@@ -1,3 +1,4 @@+# yaml-language-server: $schema=../schema/event.schema.jsonid: operation_yoavtitle: Operation Yoavtext: 'An Israeli supply convoy was fired on as it passed the Egyptian positions on 14 October, and the offensive the cabinet approved on 6 October is under way under Yigal Allon. {defense_minister} must decide how far it goes.'diff --git a/content/events/reparations_claim.yaml b/content/events/reparations_claim.yamlindex b2221e739..f44af52d4 100644--- a/content/events/reparations_claim.yaml+++ b/content/events/reparations_claim.yaml@@ -1,3 +1,4 @@+# yaml-language-server: $schema=../schema/event.schema.jsonid: reparations_claimtitle: A Claim on Germanytext: '{foreign_minister} proposes a note to the four occupying powers claiming 1.5 billion dollars from Germany: the cost of absorbing 500,000 survivors of the Holocaust, at 3,000 dollars each.'diff --git a/content/events/rhodes_talks.yaml b/content/events/rhodes_talks.yamlindex 0392d8137..1ae5d4388 100644--- a/content/events/rhodes_talks.yaml+++ b/content/events/rhodes_talks.yaml@@ -1,3 +1,4 @@+# yaml-language-server: $schema=../schema/event.schema.jsonid: rhodes_talkstitle: Talks at Rhodestext: 'Egypt announced on 6 January that it will negotiate, and Israel accepted the cease-fire on 7 January. The talks are to open at Rhodes. {foreign_minister} must decide whether Israel sends a delegation.'diff --git a/content/events/second_truce.yaml b/content/events/second_truce.yamlindex 3c11dbeea..f4206851b 100644--- a/content/events/second_truce.yaml+++ b/content/events/second_truce.yaml@@ -1,3 +1,4 @@+# yaml-language-server: $schema=../schema/event.schema.jsonid: second_trucetitle: The Second Trucetext: 'The Security Council has found a threat to the peace under Article 39 of the Charter and ordered a cease-fire within three days, and an immediate cease-fire in Jerusalem. {prime_minister} must decide whether Israel complies.'diff --git a/content/events/sinai_withdrawal.yaml b/content/events/sinai_withdrawal.yamlindex b8ad8ea44..6b636b0ea 100644--- a/content/events/sinai_withdrawal.yaml+++ b/content/events/sinai_withdrawal.yaml@@ -1,3 +1,4 @@+# yaml-language-server: $schema=../schema/event.schema.jsonid: sinai_withdrawaltitle: The British Ultimatumtext: 'Israeli forces have crossed into Sinai and reached the outskirts of El-Arish airfield. The Security Council has called for a cease-fire, the United States has added its pressure, and Britain threatens to act against Israel under its 1936 treaty with Egypt. {prime_minister} must decide whether to pull back to the Negev frontier.'diff --git a/content/events/ten_days.yaml b/content/events/ten_days.yamlindex 7458c094f..6f46930dc 100644--- a/content/events/ten_days.yaml+++ b/content/events/ten_days.yaml@@ -1,3 +1,4 @@+# yaml-language-server: $schema=../schema/event.schema.jsonid: ten_daystitle: The Ten Daystext: 'The first truce is due to end on 9 July. Where should the main effort go when the fighting resumes? In the centre, Operation Dani under Yigal Allon would take Lydda airport and secure the road to Jerusalem. {defense_minister} must decide.'diff --git a/content/offices.yaml b/content/offices.yamlindex c05670c0e..c81d13d58 100644--- a/content/offices.yaml+++ b/content/offices.yaml@@ -1,3 +1,4 @@+# yaml-language-server: $schema=./schema/offices.schema.jsonoffices:- { id: prime_minister, title: Prime Minister }# Spelling is deliberate, do not "fix" it (playtest 1, item 8): the office title keeps Israel's official English,diff --git a/content/parties.yaml b/content/parties.yamlindex 68be61ae5..d7a0d1fff 100644--- a/content/parties.yaml+++ b/content/parties.yaml@@ -1,3 +1,4 @@+# yaml-language-server: $schema=./schema/parties.schema.json# Names as listed in the Provisional State Council, 1949 and 1951 election sources (see legislatures.yaml).parties:- { id: mapai, name: Mapai }diff --git a/content/people.yaml b/content/people.yamlindex dfa333914..098375bb9 100644--- a/content/people.yaml+++ b/content/people.yaml@@ -1,3 +1,4 @@+# yaml-language-server: $schema=./schema/people.schema.json# Offices and dates are historical facts (sourced per term). competence/loyalty are game-balance values, not facts. A# term's `party` (when set) is the list the holder sat for in that government; otherwise `party` of the person applies.# An empty person `party` means the person sat for no list (non-MK ministers, the President). Periods are [from, to).diff --git a/content/schema/event.schema.json b/content/schema/event.schema.jsonnew file mode 100644index 000000000..015d2d662--- /dev/null+++ b/content/schema/event.schema.json@@ -0,0 +1,87 @@+{+ "$schema": "http://json-schema.org/draft-07/schema#",+ "title": "content/events/*.yaml",+ "description": "One event per file. Field names follow the GameEvent type in sim/Statecraft.Sim/Content.cs; a test keeps them equal. See docs/WRITING_EVENTS.md.",+ "type": "object",+ "additionalProperties": false,+ "required": ["id", "title", "text", "from", "options", "sources"],+ "definitions": {+ "date": { "type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}$", "description": "A day, YYYY-MM-DD." },+ "id": { "type": "string", "pattern": "^[a-z][a-z0-9_]*$", "description": "Lowercase letters, digits and underscores, starting with a letter." }+ },+ "properties": {+ "id": { "$ref": "#/definitions/id", "description": "Unique across all events." },+ "title": { "type": "string", "minLength": 1, "description": "May contain office placeholders such as {prime_minister}." },+ "text": { "type": "string", "minLength": 1, "description": "May contain office placeholders. No invented quotes." },+ "tags": { "type": "array", "items": { "type": "string" }, "description": "holocaust, terror, massacre and war-casualties are sensitive." },+ "anchor": { "enum": ["hard", "soft"], "description": "Default soft. A hard anchor needs a historical option." },+ "office": { "$ref": "#/definitions/id", "description": "The office the event goes to when the player does not answer." },+ "from": { "$ref": "#/definitions/date", "description": "First day of the window." },+ "to": { "$ref": "#/definitions/date", "description": "End of the window (exclusive). Leave out for an open window." },+ "conditions": {+ "type": "array",+ "items": {+ "type": "object",+ "additionalProperties": false,+ "required": ["indicator"],+ "properties": {+ "indicator": { "$ref": "#/definitions/id" },+ "min": { "type": "number" },+ "max": { "type": "number" }+ }+ }+ },+ "requires": {+ "type": "object",+ "additionalProperties": false,+ "required": ["event", "option"],+ "properties": {+ "event": { "$ref": "#/definitions/id" },+ "option": { "$ref": "#/definitions/id" }+ }+ },+ "options": {+ "type": "array",+ "minItems": 1,+ "items": {+ "type": "object",+ "additionalProperties": false,+ "required": ["id", "text"],+ "properties": {+ "id": { "$ref": "#/definitions/id" },+ "text": { "type": "string", "minLength": 1 },+ "historical": { "type": "boolean" },+ "recommended": { "type": "boolean" },+ "effects": {+ "type": "array",+ "items": {+ "type": "object",+ "additionalProperties": false,+ "required": ["target", "delta"],+ "properties": {+ "target": { "type": "string", "minLength": 1 },+ "delta": { "type": "number" }+ }+ }+ },+ "set_rung": { "type": "integer" },+ "set_policy": { "type": "object", "additionalProperties": { "type": "number", "minimum": 0, "maximum": 1 }, "description": "Policy id to a level in [0, 1]." }+ }+ }+ },+ "sources": {+ "type": "array",+ "minItems": 1,+ "items": {+ "type": "object",+ "additionalProperties": false,+ "required": ["url", "checked"],+ "properties": {+ "url": { "type": "string", "pattern": "^https://", "description": "An https:// address (RealContentTests checks this)." },+ "checked": { "$ref": "#/definitions/date", "description": "The day you opened the source." }+ }+ }+ },+ "status": { "enum": ["draft", "fact-checked", "historian-reviewed", "sensitivity-reviewed"], "description": "The review status. Default draft." }+ }+}diff --git a/content/schema/offices.schema.json b/content/schema/offices.schema.jsonnew file mode 100644index 000000000..f00e59332--- /dev/null+++ b/content/schema/offices.schema.json@@ -0,0 +1,29 @@+{+ "$schema": "http://json-schema.org/draft-07/schema#",+ "title": "content/offices.yaml",+ "description": "The offices of the state. Field names follow the Office type in sim/Statecraft.Sim/Content.cs; a test keeps them equal.",+ "type": "object",+ "additionalProperties": false,+ "required": ["offices"],+ "properties": {+ "offices": {+ "type": "array",+ "items": { "$ref": "#/definitions/office" }+ }+ },+ "definitions": {+ "date": { "type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}$", "description": "A day, YYYY-MM-DD." },+ "office": {+ "type": "object",+ "additionalProperties": false,+ "required": ["id", "title"],+ "properties": {+ "id": { "type": "string", "pattern": "^[a-z][a-z0-9_]*$", "description": "Lowercase letters, digits and underscores, starting with a letter. Unique." },+ "title": { "type": "string", "minLength": 1, "description": "The official English title, as the player sees it." },+ "historical_only": { "type": "boolean", "description": "Historical record only: no Cabinet seat, no player appointment, no gameplay." },+ "from": { "$ref": "#/definitions/date", "description": "Day the office was established (inclusive). Leave out if it exists from the start." },+ "until": { "$ref": "#/definitions/date", "description": "Day the office was abolished (exclusive). Leave out while it still exists." }+ }+ }+ }+}diff --git a/content/schema/parties.schema.json b/content/schema/parties.schema.jsonnew file mode 100644index 000000000..3d91342e8--- /dev/null+++ b/content/schema/parties.schema.json@@ -0,0 +1,22 @@+{+ "$schema": "http://json-schema.org/draft-07/schema#",+ "title": "content/parties.yaml",+ "description": "The parties. Field names follow the Party type in sim/Statecraft.Sim/Content.cs; a test keeps them equal.",+ "type": "object",+ "additionalProperties": false,+ "required": ["parties"],+ "properties": {+ "parties": {+ "type": "array",+ "items": {+ "type": "object",+ "additionalProperties": false,+ "required": ["id", "name"],+ "properties": {+ "id": { "type": "string", "pattern": "^[a-z][a-z0-9_]*$", "description": "Lowercase letters, digits and underscores, starting with a letter. Unique." },+ "name": { "type": "string", "minLength": 1 }+ }+ }+ }+ }+}diff --git a/content/schema/people.schema.json b/content/schema/people.schema.jsonnew file mode 100644index 000000000..804b8bb21--- /dev/null+++ b/content/schema/people.schema.json@@ -0,0 +1,81 @@+{+ "$schema": "http://json-schema.org/draft-07/schema#",+ "title": "content/people.yaml",+ "description": "People and their office terms. Field names follow the Person, OfficeTerm, Portrait and Source types in sim/Statecraft.Sim/Content.cs; a test keeps them equal.",+ "type": "object",+ "additionalProperties": false,+ "required": ["people"],+ "properties": {+ "people": {+ "type": "array",+ "items": { "$ref": "#/definitions/person" }+ }+ },+ "definitions": {+ "date": { "type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}$", "description": "A day, YYYY-MM-DD." },+ "id": { "type": "string", "pattern": "^[a-z][a-z0-9_]*$", "description": "Lowercase letters, digits and underscores, starting with a letter." },+ "source": {+ "type": "object",+ "additionalProperties": false,+ "required": ["url", "checked"],+ "properties": {+ "url": { "type": "string", "pattern": "^https://", "description": "An https:// address (RealContentTests checks this)." },+ "checked": { "$ref": "#/definitions/date", "description": "The day you opened the source." }+ }+ },+ "sources": { "type": "array", "minItems": 1, "items": { "$ref": "#/definitions/source" } },+ "person": {+ "type": "object",+ "additionalProperties": false,+ "required": ["id", "name", "living"],+ "properties": {+ "id": { "$ref": "#/definitions/id", "description": "Unique across people." },+ "name": { "type": "string", "minLength": 1 },+ "name_he": { "type": "string" },+ "born": { "$ref": "#/definitions/date" },+ "died": { "$ref": "#/definitions/date", "description": "Every office term must end by this day." },+ "biography_sources": {+ "type": "object",+ "description": "Sources for each biography value. Keep a source for every value you set.",+ "additionalProperties": false,+ "properties": {+ "name_he": { "$ref": "#/definitions/sources" },+ "born": { "$ref": "#/definitions/sources" },+ "died": { "$ref": "#/definitions/sources" }+ }+ },+ "living": { "type": "boolean", "description": "Required. A living person is left out of release builds." },+ "party": { "type": "string", "description": "A party id from parties.yaml. Empty means no list." },+ "competence": { "type": "integer", "minimum": 0, "maximum": 10, "description": "A game-balance value, not a fact." },+ "loyalty": { "type": "integer", "minimum": 0, "maximum": 10, "description": "A game-balance value, not a fact." },+ "portrait": {+ "type": "object",+ "additionalProperties": false,+ "required": ["file", "license", "source", "focus_y"],+ "properties": {+ "file": { "type": "string" },+ "license": { "type": "string" },+ "source": { "type": "string" },+ "focus_y": { "type": "number", "minimum": 0, "maximum": 1, "description": "Height of the face centre as a share of the picture: 0 top, 1 bottom." }+ }+ },+ "offices": {+ "type": "array",+ "items": {+ "type": "object",+ "additionalProperties": false,+ "required": ["office", "from", "sources"],+ "properties": {+ "office": { "$ref": "#/definitions/id", "description": "An office id from offices.yaml." },+ "from": { "$ref": "#/definitions/date", "description": "First day of the term (inclusive)." },+ "to": { "$ref": "#/definitions/date", "description": "End of the term (exclusive). Leave out if it continues." },+ "party": { "type": "string", "description": "The list the holder sat for in this term. Empty means the person's party." },+ "sources": { "$ref": "#/definitions/sources" }+ }+ }+ },+ "status": { "enum": ["draft", "fact-checked", "historian-reviewed", "sensitivity-reviewed"] }+ }+ }+ }+}diff --git a/docs/WRITING_EVENTS.md b/docs/WRITING_EVENTS.mdindex c46696322..dab39433f 100644--- a/docs/WRITING_EVENTS.md+++ b/docs/WRITING_EVENTS.md@@ -20,6 +20,12 @@ topics. The worked example below is [content/events/hula_drainage.yaml](../conteThe loader is strict. An unknown key is an error, so a typo such as `titel:` fails loudly instead of being ignored.A key written with no value (`tags:`) is an error for lists.+Editor help: the first line of every event file, `people.yaml`, `offices.yaml` and `parties.yaml` is a+`# yaml-language-server: $schema=...` comment. With the YAML extension (Red Hat YAML, in VS Code and others) a wrong+field name or a missing `sources:` gets a red line as you type. The schemas are in `content/schema/`. They are written+by hand, and `SchemaTests` keeps them equal to the loader types. If you add a field to a content type, add it to the+schema too, or that test fails. Keep the comment when you copy a file.+| Field | Required | What it is ||---|---|---|| `id` | yes | Unique across all events. Lowercase letters, digits and underscores, starting with a letter. |diff --git a/sim/Statecraft.Sim.Tests/SchemaTests.cs b/sim/Statecraft.Sim.Tests/SchemaTests.csnew file mode 100644index 000000000..a91a27a91--- /dev/null+++ b/sim/Statecraft.Sim.Tests/SchemaTests.cs@@ -0,0 +1,310 @@+using System;+using System.Collections.Generic;+using System.Globalization;+using System.IO;+using System.Linq;+using System.Reflection;+using System.Text.Json;+using System.Text.Json.Nodes;+using System.Text.RegularExpressions;+using Statecraft.Sim;+using YamlDotNet.RepresentationModel;+using YamlDotNet.Serialization;+using YamlDotNet.Serialization.NamingConventions;++/// <summary>The JSON Schemas in content/schema/ (#265). They give editors (yaml-language-server) a red line under a wrong+/// field name or a missing <c>sources:</c>. They are written by hand, so these tests keep them honest: every real file+/// must pass, the field names must equal the loader types' properties, and the schemas must reject the mistakes they exist for.+/// The validator is small and covers only the keywords the schemas use. A schema that uses any other keyword fails the+/// tests, so no rule can be silently ignored.</summary>+public class SchemaTests+{+ static readonly string Root = RealContentTests.ContentRoot();++ static JsonElement LoadSchema(string name) =>+ JsonDocument.Parse(File.ReadAllText(Path.Combine(Root, "schema", name))).RootElement;++ // ---- the validator -------------------------------------------------------------------------------------------++ static readonly HashSet<string> Supported = new HashSet<string>+ {+ "$schema", "$ref", "title", "description", "definitions", "type", "properties", "additionalProperties", "required",+ "items", "minItems", "minLength", "pattern", "minimum", "maximum", "enum",+ };++ static void Check(JsonElement schema, JsonElement root, JsonNode? value, string path, List<string> errors)+ {+ foreach (var k in schema.EnumerateObject())+ if (!Supported.Contains(k.Name)) throw new InvalidOperationException($"schema keyword '{k.Name}' at {path} is not supported by this test's validator");++ if (schema.TryGetProperty("$ref", out var r))+ {+ var target = root;+ foreach (var part in r.GetString()!.Substring(2).Split('/')) target = target.GetProperty(part);+ Check(target, root, value, path, errors);+ return;+ }+ if (schema.TryGetProperty("enum", out var en) && !en.EnumerateArray().Any(e => value is JsonValue v && v.TryGetValue<string>(out var s) && s == e.GetString()))+ errors.Add($"{path}: must be one of {string.Join(", ", en.EnumerateArray().Select(e => e.GetString()))}");+ if (schema.TryGetProperty("type", out var type) && !TypeOk(type.GetString()!, value)) { errors.Add($"{path}: must be {type.GetString()}"); return; }++ if (value is JsonValue val)+ {+ if (val.TryGetValue<string>(out var str))+ {+ if (schema.TryGetProperty("minLength", out var ml) && str.Length < ml.GetInt32()) errors.Add($"{path}: must not be empty");+ if (schema.TryGetProperty("pattern", out var pat) && !Regex.IsMatch(str, pat.GetString()!)) errors.Add($"{path}: '{str}' does not match {pat.GetString()}");+ }+ else if (val.TryGetValue<double>(out var num) || (val.TryGetValue<long>(out var whole) && (num = whole) == whole))+ {+ if (schema.TryGetProperty("minimum", out var mn) && num < mn.GetDouble()) errors.Add($"{path}: must be at least {mn.GetDouble()}");+ if (schema.TryGetProperty("maximum", out var mx) && num > mx.GetDouble()) errors.Add($"{path}: must be at most {mx.GetDouble()}");+ }+ }+ else if (value is JsonArray arr)+ {+ if (schema.TryGetProperty("minItems", out var mi) && arr.Count < mi.GetInt32()) errors.Add($"{path}: needs at least {mi.GetInt32()} entries");+ if (schema.TryGetProperty("items", out var items))+ for (int i = 0; i < arr.Count; i++) Check(items, root, arr[i], $"{path}[{i}]", errors);+ }+ else if (value is JsonObject obj)+ {+ if (schema.TryGetProperty("required", out var req))+ foreach (var name in req.EnumerateArray().Select(x => x.GetString()!).Where(n => !obj.ContainsKey(n)))+ errors.Add($"{path}: missing '{name}'");+ var props = schema.TryGetProperty("properties", out var p) ? p : default;+ schema.TryGetProperty("additionalProperties", out var extra);+ foreach (var kv in obj)+ {+ var sub = path + "." + kv.Key;+ if (props.ValueKind == JsonValueKind.Object && props.TryGetProperty(kv.Key, out var propSchema)) Check(propSchema, root, kv.Value, sub, errors);+ else if (extra.ValueKind == JsonValueKind.Object) Check(extra, root, kv.Value, sub, errors);+ else if (extra.ValueKind == JsonValueKind.False) errors.Add($"{sub}: unknown field");+ }+ }+ }++ static bool TypeOk(string type, JsonNode? v) => type switch+ {+ "object" => v is JsonObject,+ "array" => v is JsonArray,+ "string" => v is JsonValue s && s.TryGetValue<string>(out _),+ "boolean" => v is JsonValue b && b.TryGetValue<bool>(out _),+ "integer" => v is JsonValue i && i.TryGetValue<long>(out _),+ "number" => v is JsonValue n && (n.TryGetValue<long>(out _) || n.TryGetValue<double>(out _)) && !n.TryGetValue<string>(out _),+ _ => throw new InvalidOperationException($"schema type '{type}' is not supported by this test's validator"),+ };++ // ---- YAML to JSON (YAML 1.2 core rules: only plain scalars are typed; a date stays a string) ---------------------++ static readonly Regex IntRe = new Regex(@"^[-+]?\d+$");+ static readonly Regex FloatRe = new Regex(@"^[-+]?(\.\d+|\d+(\.\d*)?)([eE][-+]?\d+)?$");++ static JsonNode? ToJson(YamlNode node)+ {+ switch (node)+ {+ case YamlMappingNode m:+ var o = new JsonObject();+ foreach (var kv in m.Children) o.Add(((YamlScalarNode)kv.Key).Value!, ToJson(kv.Value));+ return o;+ case YamlSequenceNode s:+ return new JsonArray(s.Children.Select(ToJson).ToArray());+ case YamlScalarNode sc:+ var t = sc.Value ?? "";+ if (sc.Style != YamlDotNet.Core.ScalarStyle.Plain) return JsonValue.Create(t);+ if (t == "" || t == "~" || t == "null") return null;+ if (t == "true" || t == "false") return JsonValue.Create(t == "true");+ if (IntRe.IsMatch(t)) return JsonValue.Create(long.Parse(t, CultureInfo.InvariantCulture));+ if (FloatRe.IsMatch(t)) return JsonValue.Create(double.Parse(t, CultureInfo.InvariantCulture));+ return JsonValue.Create(t);+ default:+ throw new InvalidOperationException("unsupported YAML node " + node.GetType().Name);+ }+ }++ static JsonNode? ParseYaml(string text)+ {+ var ys = new YamlStream();+ ys.Load(new StringReader(text));+ return ToJson(ys.Documents[0].RootNode);+ }++ static List<string> Errors(string schemaFile, string yaml)+ {+ var schema = LoadSchema(schemaFile);+ var errors = new List<string>();+ Check(schema, schema, ParseYaml(yaml), "$", errors);+ return errors;+ }++ // ---- every real file passes, and points at its schema ----------------------------------------------------------++ public static IEnumerable<object[]> RealFiles()+ {+ yield return new object[] { "people.yaml", "people.schema.json" };+ yield return new object[] { "offices.yaml", "offices.schema.json" };+ yield return new object[] { "parties.yaml", "parties.schema.json" };+ foreach (var f in Directory.GetFiles(Path.Combine(Root, "events"), "*.yaml").OrderBy(f => f, StringComparer.Ordinal))+ yield return new object[] { "events/" + Path.GetFileName(f), "event.schema.json" };+ }++ [Theory]+ [MemberData(nameof(RealFiles))]+ public void RealContentPassesItsSchema(string file, string schemaFile)+ {+ var errors = Errors(schemaFile, File.ReadAllText(Path.Combine(Root, file)));+ Assert.True(errors.Count == 0, file + ":\n" + string.Join("\n", errors.Take(20)));+ }++ [Theory]+ [MemberData(nameof(RealFiles))]+ public void RealContentNamesItsSchemaInTheFirstLine(string file, string schemaFile)+ {+ var first = File.ReadLines(Path.Combine(Root, file)).First();+ var depth = file.Count(c => c == '/');+ var expected = "# yaml-language-server: $schema=" + string.Concat(Enumerable.Repeat("../", depth)) + (depth == 0 ? "./" : "") + "schema/" + schemaFile;+ Assert.Equal(expected, first);+ Assert.True(File.Exists(Path.Combine(Root, "schema", schemaFile)));+ }++ // ---- the schemas cannot drift from the loader types ------------------------------------------------------------++ static HashSet<string> LoaderFields(Type t) =>+ t.GetProperties().Where(p => p.GetCustomAttribute<YamlIgnoreAttribute>() == null)+ .Select(p => UnderscoredNamingConvention.Instance.Apply(p.Name)).ToHashSet();++ static JsonElement At(JsonElement schema, string pointer)+ {+ var e = schema;+ foreach (var part in pointer.Split('/', StringSplitOptions.RemoveEmptyEntries)) e = e.GetProperty(part);+ return e;+ }++ public static IEnumerable<object[]> TypeMap()+ {+ yield return new object[] { "offices.schema.json", "/definitions/office", typeof(Office) };+ yield return new object[] { "parties.schema.json", "/properties/parties/items", typeof(Party) };+ yield return new object[] { "people.schema.json", "/definitions/person", typeof(Person) };+ yield return new object[] { "people.schema.json", "/definitions/person/properties/portrait", typeof(Portrait) };+ yield return new object[] { "people.schema.json", "/definitions/person/properties/offices/items", typeof(OfficeTerm) };+ yield return new object[] { "people.schema.json", "/definitions/source", typeof(Source) };+ yield return new object[] { "event.schema.json", "", typeof(GameEvent) };+ yield return new object[] { "event.schema.json", "/properties/conditions/items", typeof(EventCondition) };+ yield return new object[] { "event.schema.json", "/properties/requires", typeof(EventRequirement) };+ yield return new object[] { "event.schema.json", "/properties/options/items", typeof(EventOption) };+ yield return new object[] { "event.schema.json", "/properties/options/items/properties/effects/items", typeof(OptionEffect) };+ yield return new object[] { "event.schema.json", "/properties/sources/items", typeof(Source) };+ }++ [Theory]+ [MemberData(nameof(TypeMap))]+ public void SchemaFieldsEqualTheLoaderTypeFields(string schemaFile, string pointer, Type type)+ {+ var node = At(LoadSchema(schemaFile), pointer);+ var fromSchema = node.GetProperty("properties").EnumerateObject().Select(p => p.Name).ToHashSet();+ Assert.True(fromSchema.SetEquals(LoaderFields(type)),+ $"{schemaFile}{pointer} vs {type.Name}: only in schema [{string.Join(", ", fromSchema.Except(LoaderFields(type)))}], only in loader [{string.Join(", ", LoaderFields(type).Except(fromSchema))}]");+ Assert.True(node.GetProperty("additionalProperties").ValueKind == JsonValueKind.False, "unknown fields must be an error");+ var required = node.TryGetProperty("required", out var req) ? req.EnumerateArray().Select(x => x.GetString()!) : Enumerable.Empty<string>();+ Assert.True(required.All(fromSchema.Contains), "a required name is not a property");+ }++ [Fact]+ public void BiographySourceKeysAndStatusesEqualTheLoader()+ {+ var people = LoadSchema("people.schema.json");+ var keys = At(people, "/definitions/person/properties/biography_sources/properties").EnumerateObject().Select(p => p.Name);+ Assert.Equal(new[] { "born", "died", "name_he" }, keys.OrderBy(k => k, StringComparer.Ordinal)); // ContentLoader.Validate allows these three+ var statuses = (HashSet<string>)typeof(ContentLoader).GetField("Statuses", BindingFlags.NonPublic | BindingFlags.Static)!.GetValue(null)!;+ var inPeople = At(people, "/definitions/person/properties/status/enum").EnumerateArray().Select(x => x.GetString()!);+ var inEvent = At(LoadSchema("event.schema.json"), "/properties/status/enum").EnumerateArray().Select(x => x.GetString()!);+ Assert.True(statuses.SetEquals(inPeople));+ Assert.True(statuses.SetEquals(inEvent));+ }++ [Fact]+ public void TopLevelKeysEqualTheFiles()+ {+ Assert.Equal("offices", Assert.Single(At(LoadSchema("offices.schema.json"), "/properties").EnumerateObject()).Name);+ Assert.Equal("parties", Assert.Single(At(LoadSchema("parties.schema.json"), "/properties").EnumerateObject()).Name);+ Assert.Equal("people", Assert.Single(At(LoadSchema("people.schema.json"), "/properties").EnumerateObject()).Name);+ }++ // ---- the schemas reject the mistakes they exist for ------------------------------------------------------------++ const string GoodPerson = @"+people:+ - id: a_person+ name: A Person+ living: false+ competence: 5+ offices:+ - { office: prime_minister, from: 1948-05-14, sources: [{ url: ""https://example.org"", checked: 2026-10-09 }] }+";++ [Fact]+ public void AGoodPersonPasses() => Assert.Empty(Errors("people.schema.json", GoodPerson));++ [Fact]+ public void AWrongFieldNameInPeopleFails() =>+ Assert.Contains(Errors("people.schema.json", GoodPerson.Replace("competence", "competance")), e => e.Contains("competance") && e.Contains("unknown field"));++ [Fact]+ public void AWrongFieldNameInATermFails() =>+ Assert.Contains(Errors("people.schema.json", GoodPerson.Replace("from:", "form:")), e => e.Contains("form") && e.Contains("unknown field"));++ [Fact]+ public void ATermWithoutSourcesFails() =>+ Assert.Contains(Errors("people.schema.json", GoodPerson.Replace(", sources: [{ url: \"https://example.org\", checked: 2026-10-09 }]", "")), e => e.Contains("missing 'sources'"));++ [Fact]+ public void ATermWithEmptySourcesFails() =>+ Assert.Contains(Errors("people.schema.json", GoodPerson.Replace("[{ url: \"https://example.org\", checked: 2026-10-09 }]", "[]")), e => e.Contains("at least 1"));++ [Fact]+ public void ASourceWithoutACheckedDateFails() =>+ Assert.Contains(Errors("people.schema.json", GoodPerson.Replace(", checked: 2026-10-09", "")), e => e.Contains("missing 'checked'"));++ [Fact]+ public void ASourceThatIsNotHttpsFails()+ {+ Assert.Contains(Errors("people.schema.json", GoodPerson.Replace("https://example.org", "http://example.org")), e => e.Contains("does not match"));+ Assert.Contains(Errors("people.schema.json", GoodPerson.Replace("https://example.org", "")), e => e.Contains("does not match"));+ }++ [Fact]+ public void LivingIsRequiredAndCompetenceIsBounded()+ {+ Assert.Contains(Errors("people.schema.json", GoodPerson.Replace(" living: false\n", "")), e => e.Contains("missing 'living'"));+ Assert.Contains(Errors("people.schema.json", GoodPerson.Replace("competence: 5", "competence: 11")), e => e.Contains("at most"));+ Assert.Contains(Errors("people.schema.json", GoodPerson.Replace("a_person", "A-Person")), e => e.Contains("does not match"));+ }++ [Fact]+ public void AWrongFieldNameInOfficesFails()+ {+ Assert.Empty(Errors("offices.schema.json", "offices:\n - { id: prime_minister, title: Prime Minister, until: 1951-10-08 }\n"));+ Assert.Contains(Errors("offices.schema.json", "offices:\n - { id: prime_minister, titel: Prime Minister }\n"), e => e.Contains("titel") && e.Contains("unknown field"));+ Assert.Contains(Errors("offices.schema.json", "offices:\n - { id: prime_minister }\n"), e => e.Contains("missing 'title'"));+ }++ [Fact]+ public void AnEventWithoutSourcesOrWithATypoFails()+ {+ var good = "id: e\ntitle: T\ntext: X\nfrom: 1950-01-01\noptions:\n - { id: a, text: A }\nsources: [{ url: \"https://example.org\", checked: 2026-10-09 }]\n";+ Assert.Empty(Errors("event.schema.json", good));+ Assert.Contains(Errors("event.schema.json", good.Replace("sources:", "source:")), e => e.Contains("missing 'sources'") || e.Contains("unknown field"));+ Assert.Contains(Errors("event.schema.json", good.Replace("title:", "titel:")), e => e.Contains("titel"));+ Assert.Contains(Errors("event.schema.json", good.Replace("A }", "A, historcal: true }")), e => e.Contains("historcal"));+ Assert.Contains(Errors("event.schema.json", good.Replace("https://", "http://")), e => e.Contains("does not match"));+ }++ [Fact]+ public void ThePartiesSchemaRejectsATypo() =>+ Assert.Contains(Errors("parties.schema.json", "parties:\n - { id: mapai, nmae: Mapai }\n"), e => e.Contains("nmae"));++ [Fact]+ public void AnUnsupportedKeywordIsRefusedNotIgnored() =>+ Assert.Throws<InvalidOperationException>(() => Check(JsonDocument.Parse("{\"oneOf\": []}").RootElement, default, JsonValue.Create("x"), "$", new List<string>()));+}