Skip to content

Commit ea8ee4d

Browse files
authored
chore: remove field examples (#37)
* chore: removed field example logic from frontend * chore: removed field example logic from backend
1 parent 76225a9 commit ea8ee4d

File tree

19 files changed

+9
-291
lines changed

19 files changed

+9
-291
lines changed

backend/app/api/v1/routes/events.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,6 @@ def get_event_json_schema(
171171
include_descriptions: bool = Query(
172172
True, description="Include field descriptions in schema"
173173
),
174-
include_examples: bool = Query(
175-
True, description="Include field examples in schema"
176-
),
177174
additional_properties: bool = Query(
178175
True, description="Allow additional properties in schema"
179176
),
@@ -193,7 +190,6 @@ def get_event_json_schema(
193190
schema = generate_json_schema_for_event(
194191
event,
195192
include_descriptions=include_descriptions,
196-
include_examples=include_examples,
197193
additional_properties=additional_properties,
198194
)
199195
return schema
@@ -213,9 +209,6 @@ def get_event_yaml_schema(
213209
include_descriptions: bool = Query(
214210
True, description="Include field descriptions in schema"
215211
),
216-
include_examples: bool = Query(
217-
True, description="Include field examples in schema"
218-
),
219212
additional_properties: bool = Query(
220213
True, description="Allow additional properties in schema"
221214
),
@@ -235,7 +228,6 @@ def get_event_yaml_schema(
235228
schema = generate_json_schema_for_event(
236229
event,
237230
include_descriptions=include_descriptions,
238-
include_examples=include_examples,
239231
additional_properties=additional_properties,
240232
)
241233
yaml_data = yaml.dump(schema, sort_keys=False)

backend/app/modules/admin/io/schemas.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, List, Optional
1+
from typing import List, Optional
22

33
from pydantic import BaseModel
44

@@ -14,7 +14,6 @@ class ExportField(BaseModel):
1414
name: str
1515
description: Optional[str]
1616
field_type: FieldType
17-
example: Optional[Any]
1817

1918

2019
class ExportEvent(BaseModel):

backend/app/modules/admin/io/service.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ def export_bundle(db: Session) -> ExportBundle:
3535
name=field.name,
3636
description=field.description,
3737
field_type=field.field_type,
38-
example=field.example,
3938
)
4039
for field in fields
4140
],
@@ -78,7 +77,6 @@ def import_bundle(bundle: ImportBundle, db: Session):
7877
name=field_data.name,
7978
description=field_data.description,
8079
field_type=field_data.field_type,
81-
example=field_data.example,
8280
)
8381
db.add(field)
8482
db.flush()

backend/app/modules/events/service.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ def generate_json_schema_for_event(
1717
*,
1818
additional_properties: bool = True,
1919
include_descriptions: bool = True,
20-
include_examples: bool = True,
2120
) -> dict:
2221
schema = {
2322
"type": "object",
@@ -36,9 +35,6 @@ def generate_json_schema_for_event(
3635
if include_descriptions and field.description:
3736
field_schema["description"] = field.description
3837

39-
if include_examples and field.example is not None:
40-
field_schema["example"] = field.example
41-
4238
schema["properties"][field.name] = field_schema
4339

4440
# if not field.optional:

backend/app/modules/fields/crud.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010

1111
def create_field(db: Session, field: schemas.FieldCreate):
1212
db_field = models.Field(
13-
name=field.name,
14-
description=field.description,
15-
field_type=field.field_type,
16-
example=field.example,
13+
name=field.name, description=field.description, field_type=field.field_type
1714
)
1815
db.add(db_field)
1916
try:
@@ -41,7 +38,6 @@ def update_field(db: Session, field_id: int, field: schemas.FieldCreate):
4138
db_field.name = field.name
4239
db_field.description = field.description
4340
db_field.field_type = field.field_type
44-
db_field.example = field.example
4541
db.commit()
4642
db.refresh(db_field)
4743
return db_field

backend/app/modules/fields/models.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from sqlalchemy import JSON, Column, Enum, Integer, String
1+
from sqlalchemy import Column, Enum, Integer, String
22
from sqlalchemy.orm import relationship
33

44
from app.core.database import Base
@@ -13,7 +13,6 @@ class Field(Base, TimestampMixin):
1313
name = Column(String, unique=True, index=True)
1414
description = Column(String, nullable=True)
1515
field_type = Column(Enum(FieldType), nullable=False)
16-
example = Column(JSON, nullable=True)
1716

1817
events = relationship(
1918
"Event", secondary="event_fields", back_populates="fields", viewonly=True

backend/app/modules/fields/schemas.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from datetime import datetime
22
from enum import Enum
3-
from typing import Any, Optional
3+
from typing import Optional
44

55
from pydantic import BaseModel, ConfigDict, Field
66

@@ -20,7 +20,6 @@ class FieldBase(BaseModel):
2020
)
2121
description: Optional[str] = None
2222
field_type: FieldType
23-
example: Optional[Any] = None
2423

2524

2625
class FieldCreate(FieldBase):

backend/app/modules/fields/seed/seeder.py

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -97,26 +97,6 @@ def generate_field_description():
9797
)
9898

9999

100-
def generate_field_example(field_type: FieldType):
101-
if field_type == FieldType.string:
102-
return fake.word()
103-
elif field_type == FieldType.integer:
104-
return random.randint(0, 1000000)
105-
elif field_type == FieldType.number:
106-
return random.uniform(0, 1000000)
107-
elif field_type == FieldType.boolean:
108-
return random.choice([True, False])
109-
elif field_type == FieldType.array:
110-
return [fake.word() for _ in range(random.randint(1, 10))]
111-
elif field_type == FieldType.object:
112-
return {
113-
fake.word(part_of_speech="noun"): fake.word(part_of_speech="adjective")
114-
for _ in range(random.randint(1, 5))
115-
}
116-
else:
117-
return None
118-
119-
120100
def seed(db: Session, count: int = 20):
121101
existing_names = set()
122102

@@ -125,13 +105,9 @@ def seed(db: Session, count: int = 20):
125105
existing_names.add(name)
126106

127107
field_type = random.choice(list(FieldType))
128-
example = generate_field_example(field_type)
129108

130109
db_field = Field(
131-
name=name,
132-
description=generate_field_description(),
133-
field_type=field_type,
134-
example=example,
110+
name=name, description=generate_field_description(), field_type=field_type
135111
)
136112
db.add(db_field)
137113

backend/tests/test_events_extended.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ def sample_field_for_event(auth_client):
1111
name="user_id",
1212
description="Unique user identifier",
1313
field_type=FieldType.string,
14-
example="user_12345",
1514
)
1615
response = auth_client.post("/v1/fields/", json=field_data.model_dump())
1716
return response.json()
@@ -200,12 +199,6 @@ def test_export_schema_with_options(auth_client):
200199
)
201200
assert response.status_code == 200
202201

203-
# Test without examples
204-
response = auth_client.get(
205-
f"/v1/events/{event_id}/schema.json", params={"include_examples": False}
206-
)
207-
assert response.status_code == 200
208-
209202

210203
def test_export_schema_nonexistent_event(auth_client):
211204
"""Test schema export for nonexistent event"""

backend/tests/test_fields_extended.py

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ def sample_field_complete():
1010
name="transaction_amount",
1111
description="Monetary amount of transaction in cents",
1212
field_type=FieldType.number,
13-
example=1299,
1413
)
1514

1615

@@ -21,26 +20,21 @@ def sample_boolean_field():
2120
name="is_premium_user",
2221
description="Whether user has premium subscription",
2322
field_type=FieldType.boolean,
24-
example=True,
2523
)
2624

2725

2826
# Test different field types
2927
def test_create_string_field(auth_client):
3028
"""Test creating string field"""
3129
field_data = FieldCreate(
32-
name="user_email",
33-
description="User email address",
34-
field_type=FieldType.string,
35-
example="user@example.com",
30+
name="user_email", description="User email address", field_type=FieldType.string
3631
)
3732

3833
response = auth_client.post("/v1/fields/", json=field_data.model_dump())
3934
assert response.status_code == 201
4035

4136
data = response.json()
4237
assert data["field_type"] == "string"
43-
assert data["example"] == "user@example.com"
4438

4539

4640
def test_create_number_field(auth_client, sample_field_complete):
@@ -50,7 +44,6 @@ def test_create_number_field(auth_client, sample_field_complete):
5044

5145
data = response.json()
5246
assert data["field_type"] == "number"
53-
assert data["example"] == 1299
5447

5548

5649
def test_create_boolean_field(auth_client, sample_boolean_field):
@@ -60,7 +53,6 @@ def test_create_boolean_field(auth_client, sample_boolean_field):
6053

6154
data = response.json()
6255
assert data["field_type"] == "boolean"
63-
assert data["example"] is True
6456

6557

6658
def test_create_array_field(auth_client):
@@ -69,15 +61,13 @@ def test_create_array_field(auth_client):
6961
name="user_interests",
7062
description="List of user interests",
7163
field_type=FieldType.array,
72-
example=["sports", "technology", "music"],
7364
)
7465

7566
response = auth_client.post("/v1/fields/", json=field_data.model_dump())
7667
assert response.status_code == 201
7768

7869
data = response.json()
7970
assert data["field_type"] == "array"
80-
assert isinstance(data["example"], list)
8171

8272

8373
def test_create_object_field(auth_client):
@@ -86,32 +76,26 @@ def test_create_object_field(auth_client):
8676
name="user_profile",
8777
description="User profile object",
8878
field_type=FieldType.object,
89-
example={"name": "John", "age": 30},
9079
)
9180

9281
response = auth_client.post("/v1/fields/", json=field_data.model_dump())
9382
assert response.status_code == 201
9483

9584
data = response.json()
9685
assert data["field_type"] == "object"
97-
assert isinstance(data["example"], dict)
9886

9987

10088
def test_create_integer_field(auth_client):
10189
"""Test creating integer field"""
10290
field_data = FieldCreate(
103-
name="user_age",
104-
description="User age in years",
105-
field_type=FieldType.integer,
106-
example=25,
91+
name="user_age", description="User age in years", field_type=FieldType.integer
10792
)
10893

10994
response = auth_client.post("/v1/fields/", json=field_data.model_dump())
11095
assert response.status_code == 201
11196

11297
data = response.json()
11398
assert data["field_type"] == "integer"
114-
assert data["example"] == 25
11599

116100

117101
# Test field operations
@@ -130,7 +114,7 @@ def test_list_fields_returns_all(auth_client):
130114

131115
fields = response.json()
132116
assert isinstance(fields, list)
133-
assert len(fields) >= 2 # Should have at least our created fields
117+
assert len(fields) >= 2 # Should have at least the previously created fields
134118

135119

136120
def test_get_field_with_event_count(auth_client):
@@ -159,7 +143,6 @@ def test_update_field(auth_client):
159143
name="update_test_field",
160144
description="Field to be updated",
161145
field_type=FieldType.string,
162-
example="original",
163146
)
164147

165148
create_response = auth_client.post("/v1/fields/", json=create_data.model_dump())
@@ -170,7 +153,6 @@ def test_update_field(auth_client):
170153
name="update_test_field", # Name should stay same due to unique constraint
171154
description="Updated description",
172155
field_type=FieldType.string,
173-
example="updated",
174156
)
175157

176158
update_response = auth_client.put(
@@ -180,7 +162,6 @@ def test_update_field(auth_client):
180162

181163
data = update_response.json()
182164
assert data["description"] == "Updated description"
183-
assert data["example"] == "updated"
184165

185166

186167
def test_delete_field(auth_client):
@@ -294,21 +275,6 @@ def test_create_field_without_description(auth_client):
294275
assert data["description"] is None
295276

296277

297-
def test_create_field_without_example(auth_client):
298-
"""Test creating field without optional example"""
299-
field_data = FieldCreate(
300-
name="no_example_field",
301-
description="Field without example",
302-
field_type=FieldType.string,
303-
)
304-
305-
response = auth_client.post("/v1/fields/", json=field_data.model_dump())
306-
assert response.status_code == 201
307-
308-
data = response.json()
309-
assert data["example"] is None
310-
311-
312278
# Test authentication
313279
def test_list_fields_requires_auth(client):
314280
"""Test that listing fields requires authentication"""

0 commit comments

Comments
 (0)