Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove all non-serializer extend_schema_field usages #174

Merged
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
1 change: 1 addition & 0 deletions .github/workflows/canopeum_backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
pull_request:
branches:
- main
- production
paths:
- "canopeum_backend/**"
- ".github/workflows/canopeum_backend.yml"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/canopeum_frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
pull_request:
branches:
- main
- production
paths:
- "canopeum_frontend/**"
- ".github/workflows/canopeum_frontend.yml"
Expand Down
38 changes: 14 additions & 24 deletions canopeum_backend/canopeum_backend/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# pyright: reportIncompatibleVariableOverride=false

import random
from decimal import Decimal
from typing import Any

from django.contrib.auth.password_validation import validate_password
Expand Down Expand Up @@ -353,10 +354,8 @@ class Meta:
"widget",
)

# https://github.com/tfranzel/drf-spectacular/issues/1212
@extend_schema_field(list[str]) # type: ignore[arg-type] # pyright: ignore[reportArgumentType]
def get_sponsors(self, obj):
return self.context.get("sponsors")
def get_sponsors(self, obj) -> list[str]:
return self.context.get("sponsors", list[str]()) # type: ignore[no-any-return]

@extend_schema_field(WidgetSerializer(many=True))
def get_widget(self, obj):
Expand Down Expand Up @@ -589,27 +588,21 @@ class Meta:
"batches",
)

@extend_schema_field(int)
def get_plant_count(self, obj):
def get_plant_count(self, obj) -> int:
return random.randint(100, 200) # noqa: S311

@extend_schema_field(int)
def get_survived_count(self, obj):
def get_survived_count(self, obj) -> int:
return random.randint(50, 100) # noqa: S311

@extend_schema_field(int)
def get_propagation_count(self, obj):
def get_propagation_count(self, obj) -> int:
return random.randint(5, 50) # noqa: S311

@extend_schema_field(float)
def get_progress(self, obj):
return random.randint(0, 100) # noqa: S311
def get_progress(self, obj) -> float:
return random.randint(0, 10000) / 100 # noqa: S311

# https://github.com/tfranzel/drf-spectacular/issues/1212
@extend_schema_field(list[str]) # type: ignore[arg-type] # pyright: ignore[reportArgumentType]
def get_sponsors(self, obj):
def get_sponsors(self, obj) -> list[str]:
batches = Batch.objects.filter(site=obj)
return [batch.sponsor for batch in batches]
return [batch.sponsor for batch in batches if batch.sponsor]


class CoordinatesMapSerializer(serializers.ModelSerializer[Coordinate]):
Expand All @@ -620,12 +613,10 @@ class Meta:
model = Coordinate
fields = ("latitude", "longitude", "address")

@extend_schema_field(float)
def get_latitude(self, obj):
def get_latitude(self, obj: Coordinate) -> Decimal | None:
return obj.dd_latitude

@extend_schema_field(float)
def get_longitude(self, obj):
def get_longitude(self, obj: Coordinate) -> Decimal | None:
return obj.dd_longitude


Expand Down Expand Up @@ -719,11 +710,10 @@ class Meta:
model = Comment
fields = ("id", "body", "author_id", "author_username", "created_at")

@extend_schema_field(int)
def get_author_id(self, obj):
def get_author_id(self, obj: Comment) -> int:
return obj.user.id

def get_author_username(self, obj):
def get_author_username(self, obj: Comment):
return obj.user.username


Expand Down
40 changes: 16 additions & 24 deletions canopeum_frontend/src/services/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//----------------------
// <auto-generated>
// Generated using the NSwag toolchain v14.0.7.0 (NJsonSchema v11.0.0.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org)
// Generated using the NSwag toolchain v14.0.8.0 (NJsonSchema v11.0.1.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org)
// </auto-generated>
//----------------------

Expand Down Expand Up @@ -2456,8 +2456,8 @@ export interface IAsset {

export class Batch implements IBatch {
readonly id!: number;
readonly createdAt!: Date | undefined;
readonly updatedAt!: Date | undefined;
createdAt?: Date | undefined;
updatedAt?: Date | undefined;
name?: string | undefined;
sponsor?: string | undefined;
size?: number | undefined;
Expand Down Expand Up @@ -2488,8 +2488,8 @@ export class Batch implements IBatch {
this[property] = _data[property];
}
(<any>this).id = _data["id"];
(<any>this).createdAt = _data["createdAt"] ? new Date(_data["createdAt"].toString()) : <any>undefined;
(<any>this).updatedAt = _data["updatedAt"] ? new Date(_data["updatedAt"].toString()) : <any>undefined;
this.createdAt = _data["createdAt"] ? new Date(_data["createdAt"].toString()) : <any>undefined;
this.updatedAt = _data["updatedAt"] ? new Date(_data["updatedAt"].toString()) : <any>undefined;
this.name = _data["name"];
this.sponsor = _data["sponsor"];
this.size = _data["size"];
Expand Down Expand Up @@ -2537,8 +2537,8 @@ export class Batch implements IBatch {

export interface IBatch {
id: number;
createdAt: Date | undefined;
updatedAt: Date | undefined;
createdAt?: Date | undefined;
updatedAt?: Date | undefined;
name?: string | undefined;
sponsor?: string | undefined;
size?: number | undefined;
Expand Down Expand Up @@ -3263,8 +3263,8 @@ export interface ICoordinates {
}

export class CoordinatesMap implements ICoordinatesMap {
readonly latitude!: number;
readonly longitude!: number;
readonly latitude!: number | undefined;
readonly longitude!: number | undefined;
address?: string | undefined;

[key: string]: any;
Expand Down Expand Up @@ -3311,8 +3311,8 @@ export class CoordinatesMap implements ICoordinatesMap {
}

export interface ICoordinatesMap {
latitude: number;
longitude: number;
latitude: number | undefined;
longitude: number | undefined;
address?: string | undefined;

[key: string]: any;
Expand Down Expand Up @@ -3707,8 +3707,8 @@ export interface IPatchedAnnouncement {

export class PatchedBatch implements IPatchedBatch {
readonly id?: number;
readonly createdAt?: Date | undefined;
readonly updatedAt?: Date | undefined;
createdAt?: Date | undefined;
updatedAt?: Date | undefined;
name?: string | undefined;
sponsor?: string | undefined;
size?: number | undefined;
Expand Down Expand Up @@ -3739,8 +3739,8 @@ export class PatchedBatch implements IPatchedBatch {
this[property] = _data[property];
}
(<any>this).id = _data["id"];
(<any>this).createdAt = _data["createdAt"] ? new Date(_data["createdAt"].toString()) : <any>undefined;
(<any>this).updatedAt = _data["updatedAt"] ? new Date(_data["updatedAt"].toString()) : <any>undefined;
this.createdAt = _data["createdAt"] ? new Date(_data["createdAt"].toString()) : <any>undefined;
this.updatedAt = _data["updatedAt"] ? new Date(_data["updatedAt"].toString()) : <any>undefined;
this.name = _data["name"];
this.sponsor = _data["sponsor"];
this.size = _data["size"];
Expand Down Expand Up @@ -5613,10 +5613,6 @@ export class Seeds implements ISeeds {
data["quantity"] = this.quantity;
return data;
}

toString() {
return JSON.stringify(this.toJSON());
}
}

export interface ISeeds {
Expand Down Expand Up @@ -5669,10 +5665,6 @@ export class Species implements ISpecies {
data["quantity"] = this.quantity;
return data;
}

toString() {
return JSON.stringify(this.toJSON());
}
}

export interface ISpecies {
Expand Down Expand Up @@ -5796,7 +5788,7 @@ export interface FileParameter {
}

export class ApiException extends Error {
message: string;
override message: string;
status: number;
response: string;
headers: { [key: string]: any; };
Expand Down
Loading