Skip to content

Commit d93976f

Browse files
authored
Hardcode remaining common schemas to deduplicate generated schema (#40)
Added the remaining schemas from the [Utility section of the documentation](https://pokeapi.co/docs/v2.html#utility-section) to the `COMMON_MODELS` list. This will make `ditto analyze` generate a simpler result by matching more duplicated schemas to the common models instead. This will be useful when I use the generated schema to create an OpenAPI spec and generate API clients.
1 parent 7d8d47f commit d93976f

File tree

1 file changed

+105
-4
lines changed

1 file changed

+105
-4
lines changed

pokeapi_ditto/commands/models.py

Lines changed: 105 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22

33
from odictliteral import odict
44

5+
# noinspection DuplicatedCode
56
COMMON_MODELS: OrderedDict = odict[
6-
f"/schema/v2/api_resource.json":{
7+
"/schema/v2/api_resource.json":{
78
"properties": {"url": {"type": "string"}},
89
"required": ["url"],
910
"type": "object",
1011
},
11-
f"/schema/v2/named_api_resource.json":{
12+
"/schema/v2/named_api_resource.json":{
1213
"properties": {"name": {"type": "string"}, "url": {"type": "string"}},
1314
"required": ["name", "url"],
1415
"type": "object",
1516
},
16-
f"/schema/v2/api_resource_list.json":{
17+
"/schema/v2/api_resource_list.json":{
1718
"properties": {
1819
"count": {"type": "integer"},
1920
"next": {"type": "null"},
@@ -26,7 +27,7 @@
2627
"required": ["count", "next", "previous", "results"],
2728
"type": "object",
2829
},
29-
f"/schema/v2/named_api_resource_list.json":{
30+
"/schema/v2/named_api_resource_list.json":{
3031
"properties": {
3132
"count": {"type": "integer"},
3233
"next": {"type": "null"},
@@ -39,4 +40,104 @@
3940
"required": ["count", "next", "previous", "results"],
4041
"type": "object",
4142
},
43+
"/schema/v2/description.json":{
44+
"properties": {
45+
"description": {"type": "string"},
46+
"language": {"$ref": f"/schema/v2/named_api_resource.json"},
47+
},
48+
"required": ["description", "language"],
49+
"type": "object",
50+
},
51+
"/schema/v2/effect.json":{
52+
"properties": {
53+
"effect": {"type": "string"},
54+
"language": {"$ref": f"/schema/v2/named_api_resource.json"},
55+
},
56+
"required": ["effect", "language"],
57+
"type": "object",
58+
},
59+
"/schema/v2/encounter.json":{
60+
"properties": {
61+
"chance": {"type": "integer"},
62+
"condition_values": {
63+
"items": {"$ref": f"/schema/v2/named_api_resource.json"},
64+
"type": "array",
65+
},
66+
"max_level": {"type": "integer"},
67+
"method": {"$ref": f"/schema/v2/named_api_resource.json"},
68+
"min_level": {"type": "integer"},
69+
},
70+
"required": ["chance", "condition_values", "max_level", "method", "min_level"],
71+
"type": "object",
72+
},
73+
"/schema/v2/flavor_text.json":{
74+
"properties": {
75+
"flavor_text": {"type": "string"},
76+
"language": {"$ref": f"/schema/v2/named_api_resource.json"},
77+
},
78+
"required": ["flavor_text", "language"],
79+
"type": "object",
80+
},
81+
"/schema/v2/generation_game_index.json":{
82+
"properties": {
83+
"game_index": {"type": "integer"},
84+
"generation": {"$ref": f"/schema/v2/named_api_resource.json"},
85+
},
86+
"required": ["game_index", "generation"],
87+
"type": "object",
88+
},
89+
"/schema/v2/machine_version_detail.json":{
90+
"properties": {
91+
"machine": {"$ref": f"/schema/v2/api_resource.json"},
92+
"version_group": {"$ref": f"/schema/v2/named_api_resource.json"},
93+
},
94+
"required": ["machine", "version_group"],
95+
"type": "object",
96+
},
97+
"/schema/v2/name.json":{
98+
"properties": {
99+
"language": {"$ref": f"/schema/v2/named_api_resource.json"},
100+
"name": {"type": "string"},
101+
},
102+
"required": ["language", "name"],
103+
"type": "object",
104+
},
105+
"/schema/v2/verbose_effect.json":{
106+
"properties": {
107+
"effect": {"type": "string"},
108+
"language": {"$ref": f"/schema/v2/named_api_resource.json"},
109+
"short_effect": {"type": "string"},
110+
},
111+
"required": ["effect", "language", "short_effect"],
112+
"type": "object",
113+
},
114+
"/schema/v2/version_encounter_detail.json":{
115+
"properties": {
116+
"encounter_details": {
117+
"items": {"$ref": "/schema/v2/encounter.json"},
118+
"type": "array",
119+
},
120+
"max_chance": {"type": "integer"},
121+
"version": {"$ref": "/schema/v2/named_api_resource.json"},
122+
},
123+
"required": ["encounter_details", "max_chance", "version"],
124+
"type": "object",
125+
},
126+
"/schema/v2/version_game_index.json":{
127+
"properties": {
128+
"game_index": {"type": "integer"},
129+
"version": {"$ref": f"/schema/v2/named_api_resource.json"},
130+
},
131+
"required": ["game_index", "version"],
132+
"type": "object",
133+
},
134+
"/schema/v2/version_group_flavor_text.json":{
135+
"properties": {
136+
"language": {"$ref": "/schema/v2/named_api_resource.json"},
137+
"text": {"type": "string"},
138+
"version_group": {"$ref": "/schema/v2/named_api_resource.json"},
139+
},
140+
"required": ["language", "text", "version_group"],
141+
"type": "object",
142+
},
42143
]

0 commit comments

Comments
 (0)