Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions backend/app/api/v1/routes/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,6 @@ def get_event_json_schema(
include_descriptions: bool = Query(
True, description="Include field descriptions in schema"
),
include_examples: bool = Query(
True, description="Include field examples in schema"
),
additional_properties: bool = Query(
True, description="Allow additional properties in schema"
),
Expand All @@ -193,7 +190,6 @@ def get_event_json_schema(
schema = generate_json_schema_for_event(
event,
include_descriptions=include_descriptions,
include_examples=include_examples,
additional_properties=additional_properties,
)
return schema
Expand All @@ -213,9 +209,6 @@ def get_event_yaml_schema(
include_descriptions: bool = Query(
True, description="Include field descriptions in schema"
),
include_examples: bool = Query(
True, description="Include field examples in schema"
),
additional_properties: bool = Query(
True, description="Allow additional properties in schema"
),
Expand All @@ -235,7 +228,6 @@ def get_event_yaml_schema(
schema = generate_json_schema_for_event(
event,
include_descriptions=include_descriptions,
include_examples=include_examples,
additional_properties=additional_properties,
)
yaml_data = yaml.dump(schema, sort_keys=False)
Expand Down
3 changes: 1 addition & 2 deletions backend/app/modules/admin/io/schemas.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, List, Optional
from typing import List, Optional

from pydantic import BaseModel

Expand All @@ -14,7 +14,6 @@ class ExportField(BaseModel):
name: str
description: Optional[str]
field_type: FieldType
example: Optional[Any]


class ExportEvent(BaseModel):
Expand Down
2 changes: 0 additions & 2 deletions backend/app/modules/admin/io/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def export_bundle(db: Session) -> ExportBundle:
name=field.name,
description=field.description,
field_type=field.field_type,
example=field.example,
)
for field in fields
],
Expand Down Expand Up @@ -78,7 +77,6 @@ def import_bundle(bundle: ImportBundle, db: Session):
name=field_data.name,
description=field_data.description,
field_type=field_data.field_type,
example=field_data.example,
)
db.add(field)
db.flush()
Expand Down
4 changes: 0 additions & 4 deletions backend/app/modules/events/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def generate_json_schema_for_event(
*,
additional_properties: bool = True,
include_descriptions: bool = True,
include_examples: bool = True,
) -> dict:
schema = {
"type": "object",
Expand All @@ -36,9 +35,6 @@ def generate_json_schema_for_event(
if include_descriptions and field.description:
field_schema["description"] = field.description

if include_examples and field.example is not None:
field_schema["example"] = field.example

schema["properties"][field.name] = field_schema

# if not field.optional:
Expand Down
6 changes: 1 addition & 5 deletions backend/app/modules/fields/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@

def create_field(db: Session, field: schemas.FieldCreate):
db_field = models.Field(
name=field.name,
description=field.description,
field_type=field.field_type,
example=field.example,
name=field.name, description=field.description, field_type=field.field_type
)
db.add(db_field)
try:
Expand Down Expand Up @@ -41,7 +38,6 @@ def update_field(db: Session, field_id: int, field: schemas.FieldCreate):
db_field.name = field.name
db_field.description = field.description
db_field.field_type = field.field_type
db_field.example = field.example
db.commit()
db.refresh(db_field)
return db_field
Expand Down
3 changes: 1 addition & 2 deletions backend/app/modules/fields/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sqlalchemy import JSON, Column, Enum, Integer, String
from sqlalchemy import Column, Enum, Integer, String
from sqlalchemy.orm import relationship

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

events = relationship(
"Event", secondary="event_fields", back_populates="fields", viewonly=True
Expand Down
3 changes: 1 addition & 2 deletions backend/app/modules/fields/schemas.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datetime import datetime
from enum import Enum
from typing import Any, Optional
from typing import Optional

from pydantic import BaseModel, ConfigDict, Field

Expand All @@ -20,7 +20,6 @@ class FieldBase(BaseModel):
)
description: Optional[str] = None
field_type: FieldType
example: Optional[Any] = None


class FieldCreate(FieldBase):
Expand Down
26 changes: 1 addition & 25 deletions backend/app/modules/fields/seed/seeder.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,26 +97,6 @@ def generate_field_description():
)


def generate_field_example(field_type: FieldType):
if field_type == FieldType.string:
return fake.word()
elif field_type == FieldType.integer:
return random.randint(0, 1000000)
elif field_type == FieldType.number:
return random.uniform(0, 1000000)
elif field_type == FieldType.boolean:
return random.choice([True, False])
elif field_type == FieldType.array:
return [fake.word() for _ in range(random.randint(1, 10))]
elif field_type == FieldType.object:
return {
fake.word(part_of_speech="noun"): fake.word(part_of_speech="adjective")
for _ in range(random.randint(1, 5))
}
else:
return None


def seed(db: Session, count: int = 20):
existing_names = set()

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

field_type = random.choice(list(FieldType))
example = generate_field_example(field_type)

db_field = Field(
name=name,
description=generate_field_description(),
field_type=field_type,
example=example,
name=name, description=generate_field_description(), field_type=field_type
)
db.add(db_field)

Expand Down
7 changes: 0 additions & 7 deletions backend/tests/test_events_extended.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ def sample_field_for_event(auth_client):
name="user_id",
description="Unique user identifier",
field_type=FieldType.string,
example="user_12345",
)
response = auth_client.post("/v1/fields/", json=field_data.model_dump())
return response.json()
Expand Down Expand Up @@ -200,12 +199,6 @@ def test_export_schema_with_options(auth_client):
)
assert response.status_code == 200

# Test without examples
response = auth_client.get(
f"/v1/events/{event_id}/schema.json", params={"include_examples": False}
)
assert response.status_code == 200


def test_export_schema_nonexistent_event(auth_client):
"""Test schema export for nonexistent event"""
Expand Down
40 changes: 3 additions & 37 deletions backend/tests/test_fields_extended.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ def sample_field_complete():
name="transaction_amount",
description="Monetary amount of transaction in cents",
field_type=FieldType.number,
example=1299,
)


Expand All @@ -21,26 +20,21 @@ def sample_boolean_field():
name="is_premium_user",
description="Whether user has premium subscription",
field_type=FieldType.boolean,
example=True,
)


# Test different field types
def test_create_string_field(auth_client):
"""Test creating string field"""
field_data = FieldCreate(
name="user_email",
description="User email address",
field_type=FieldType.string,
example="user@example.com",
name="user_email", description="User email address", field_type=FieldType.string
)

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

data = response.json()
assert data["field_type"] == "string"
assert data["example"] == "user@example.com"


def test_create_number_field(auth_client, sample_field_complete):
Expand All @@ -50,7 +44,6 @@ def test_create_number_field(auth_client, sample_field_complete):

data = response.json()
assert data["field_type"] == "number"
assert data["example"] == 1299


def test_create_boolean_field(auth_client, sample_boolean_field):
Expand All @@ -60,7 +53,6 @@ def test_create_boolean_field(auth_client, sample_boolean_field):

data = response.json()
assert data["field_type"] == "boolean"
assert data["example"] is True


def test_create_array_field(auth_client):
Expand All @@ -69,15 +61,13 @@ def test_create_array_field(auth_client):
name="user_interests",
description="List of user interests",
field_type=FieldType.array,
example=["sports", "technology", "music"],
)

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

data = response.json()
assert data["field_type"] == "array"
assert isinstance(data["example"], list)


def test_create_object_field(auth_client):
Expand All @@ -86,32 +76,26 @@ def test_create_object_field(auth_client):
name="user_profile",
description="User profile object",
field_type=FieldType.object,
example={"name": "John", "age": 30},
)

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

data = response.json()
assert data["field_type"] == "object"
assert isinstance(data["example"], dict)


def test_create_integer_field(auth_client):
"""Test creating integer field"""
field_data = FieldCreate(
name="user_age",
description="User age in years",
field_type=FieldType.integer,
example=25,
name="user_age", description="User age in years", field_type=FieldType.integer
)

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

data = response.json()
assert data["field_type"] == "integer"
assert data["example"] == 25


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

fields = response.json()
assert isinstance(fields, list)
assert len(fields) >= 2 # Should have at least our created fields
assert len(fields) >= 2 # Should have at least the previously created fields


def test_get_field_with_event_count(auth_client):
Expand Down Expand Up @@ -159,7 +143,6 @@ def test_update_field(auth_client):
name="update_test_field",
description="Field to be updated",
field_type=FieldType.string,
example="original",
)

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

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

data = update_response.json()
assert data["description"] == "Updated description"
assert data["example"] == "updated"


def test_delete_field(auth_client):
Expand Down Expand Up @@ -294,21 +275,6 @@ def test_create_field_without_description(auth_client):
assert data["description"] is None


def test_create_field_without_example(auth_client):
"""Test creating field without optional example"""
field_data = FieldCreate(
name="no_example_field",
description="Field without example",
field_type=FieldType.string,
)

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

data = response.json()
assert data["example"] is None


# Test authentication
def test_list_fields_requires_auth(client):
"""Test that listing fields requires authentication"""
Expand Down
19 changes: 0 additions & 19 deletions backend/tests/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def sample_event_out():
name="user_id",
description="Unique user identifier",
field_type=FieldType.string,
example="user_12345",
created_at="2024-01-01T00:00:00Z",
updated_at="2024-01-01T00:00:00Z",
),
Expand All @@ -59,7 +58,6 @@ def sample_event_out():
name="signup_method",
description="How user signed up",
field_type=FieldType.string,
example="email",
created_at="2024-01-01T00:00:00Z",
updated_at="2024-01-01T00:00:00Z",
),
Expand Down Expand Up @@ -106,23 +104,6 @@ def test_generate_json_schema_without_descriptions(sample_event_out):
assert "description" not in properties["user_id"]


def test_generate_json_schema_with_examples(sample_event_out):
"""Test schema generation with examples enabled"""
schema = generate_json_schema_for_event(sample_event_out, include_examples=True)

properties = schema["properties"]
assert "example" in properties["user_id"]
assert properties["user_id"]["example"] == "user_12345"


def test_generate_json_schema_without_examples(sample_event_out):
"""Test schema generation with examples disabled"""
schema = generate_json_schema_for_event(sample_event_out, include_examples=False)

properties = schema["properties"]
assert "example" not in properties["user_id"]


def test_generate_json_schema_additional_properties_true(sample_event_out):
"""Test schema generation with additional properties allowed"""
schema = generate_json_schema_for_event(
Expand Down
Loading
Loading