Skip to content

Commit

Permalink
improves API docs
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielBarberini committed Sep 23, 2023
1 parent 675b917 commit b295e35
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 21 deletions.
18 changes: 9 additions & 9 deletions lib/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from fastapi.middleware.cors import CORSMiddleware
from fastapi.openapi.utils import get_openapi

from lib.views.flight import FlightSummary, FlightCreated, FlightUpdated, FlightDeleted
from lib.views.environment import EnvSummary, EnvCreated, EnvUpdated, EnvDeleted
from lib.views.rocket import RocketSummary, RocketCreated, RocketUpdated, RocketDeleted
from lib.views.motor import MotorSummary, MotorCreated, MotorUpdated, MotorDeleted
from lib.views.flight import FlightSummary, FlightCreated, FlightUpdated, FlightDeleted, FlightPickle
from lib.views.environment import EnvSummary, EnvCreated, EnvUpdated, EnvDeleted, EnvPickle
from lib.views.rocket import RocketSummary, RocketCreated, RocketUpdated, RocketDeleted, RocketPickle
from lib.views.motor import MotorSummary, MotorCreated, MotorUpdated, MotorDeleted, MotorPickle
from lib.models.environment import Env
from lib.models.flight import Flight
from lib.models.rocket import Rocket
Expand All @@ -20,7 +20,7 @@
from lib.controllers.rocket import RocketController
from lib.controllers.motor import MotorController

app = FastAPI()
app = FastAPI(swagger_ui_parameters={"defaultModelsExpandDepth": 0})
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
Expand Down Expand Up @@ -81,7 +81,7 @@ async def read_flight(flight_id: int) -> "Flight":
return FlightController.get_flight(flight_id)

@app.get("/flights/rocketpy/{flight_id}", tags=["FLIGHT"])
async def read_rocketpy_flight(flight_id: int) -> "BaseModel":
async def read_rocketpy_flight(flight_id: int) -> "FlightPickle":
"""
Reads a rocketpy flight object.
Expand Down Expand Up @@ -255,7 +255,7 @@ async def delete_env(env_id: int) -> "EnvDeleted":
return EnvController.delete_env(env_id)

@app.get("/environments/rocketpy/{env_id}", tags=["ENVIRONMENT"])
async def read_rocketpy_env(env_id: int) -> "Dict[str, Any]":
async def read_rocketpy_env(env_id: int) -> "EnvPickle":
"""
Reads a rocketpy environment.
Expand Down Expand Up @@ -356,7 +356,7 @@ async def delete_motor(motor_id: int) -> "MotorDeleted":
return MotorController.delete_motor(motor_id)

@app.get("/motors/rocketpy/{motor_id}", tags=["MOTOR"])
async def read_rocketpy_motor(motor_id: int) -> "Dict[str, Any]":
async def read_rocketpy_motor(motor_id: int) -> "MotorPickle":
"""
Reads a rocketpy motor.
Expand Down Expand Up @@ -457,7 +457,7 @@ async def delete_rocket(rocket_id: int) -> "RocketDeleted":
return RocketController.delete_rocket(rocket_id)

@app.get("/rockets/rocketpy/{rocket_id}", tags=["ROCKET"])
async def read_rocketpy_rocket(rocket_id: int) -> "Dict[str, Any]":
async def read_rocketpy_rocket(rocket_id: int) -> "RocketPickle":
"""
Reads a rocketpy rocket.
Expand Down
5 changes: 2 additions & 3 deletions lib/controllers/environment.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from typing import Dict, Any, Union
from pydantic import BaseModel

import jsonpickle
from rocketpy import Environment
from fastapi import Response, status

from lib.models.environment import Env
from lib.repositories.environment import EnvRepository
from lib.views.environment import EnvSummary, EnvData, EnvPlots, EnvCreated, EnvDeleted, EnvUpdated
from lib.views.environment import EnvSummary, EnvData, EnvPlots, EnvCreated, EnvDeleted, EnvUpdated, EnvPickle

class EnvController():
"""
Expand Down Expand Up @@ -88,7 +87,7 @@ def get_rocketpy_env(env_id: int) -> "Union[Dict[str, Any], Response]":
successfully_read_rocketpy_env = \
EnvController( successfully_read_env ).rocketpy_env

return BaseModel(jsonpickle_rocketpy_env=jsonpickle.encode(successfully_read_rocketpy_env))
return EnvPickle(jsonpickle_rocketpy_env=jsonpickle.encode(successfully_read_rocketpy_env))

def update_env(self, env_id: int) -> "Union[Dict[str, Any], Response]":
"""
Expand Down
5 changes: 2 additions & 3 deletions lib/controllers/flight.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from typing import Dict, Any, Union
from pydantic import BaseModel
from fastapi import Response, status

import rocketpy.Flight
Expand All @@ -8,7 +7,7 @@
from lib.models.rocket import Rocket
from lib.models.flight import Flight
from lib.models.environment import Env
from lib.views.flight import FlightSummary, SurfaceWindConditions, OutOfRailConditions, BurnoutConditions, ApogeeConditions, MaximumValues, InitialConditions, NumericalIntegrationSettings, ImpactConditions, EventsRegistered, LaunchRailConditions, FlightData, FlightCreated, FlightUpdated, FlightDeleted
from lib.views.flight import FlightSummary, SurfaceWindConditions, OutOfRailConditions, BurnoutConditions, ApogeeConditions, MaximumValues, InitialConditions, NumericalIntegrationSettings, ImpactConditions, EventsRegistered, LaunchRailConditions, FlightData, FlightCreated, FlightUpdated, FlightDeleted, FlightPickle
from lib.repositories.flight import FlightRepository
from lib.controllers.environment import EnvController
from lib.controllers.rocket import RocketController
Expand Down Expand Up @@ -100,7 +99,7 @@ def get_rocketpy_flight(flight_id: int) -> "Union[Dict[str, Any], Response]":
successfully_read_rocketpy_flight = \
FlightController(successfully_read_flight).rocketpy_flight

return BaseModel(jsonpickle_rocketpy_flight=jsonpickle.encode(successfully_read_rocketpy_flight))
return FlightPickle(jsonpickle_rocketpy_flight=jsonpickle.encode(successfully_read_rocketpy_flight))

def update_flight(self, flight_id: int) -> "Union[Dict[str, Any], Response]":
"""
Expand Down
5 changes: 2 additions & 3 deletions lib/controllers/motor.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from fastapi import Response, status
from pydantic import BaseModel
from typing import Any, Dict, Union
from rocketpy import SolidMotor
import jsonpickle

from lib.models.motor import Motor
from lib.repositories.motor import MotorRepository
from lib.views.motor import MotorSummary, MotorData, MotorCreated, MotorUpdated, MotorDeleted
from lib.views.motor import MotorSummary, MotorData, MotorCreated, MotorUpdated, MotorDeleted, MotorPickle

class MotorController():
"""
Expand Down Expand Up @@ -94,7 +93,7 @@ def get_rocketpy_motor(motor_id: int) -> "Union[Dict[str, Any], Response]":
successfully_read_rocketpy_motor = \
MotorController( successfully_read_motor ).rocketpy_motor

return BaseModel(jsonpickle_rocketpy_motor=jsonpickle.encode(successfully_read_rocketpy_motor))
return MotorPickle(jsonpickle_rocketpy_motor=jsonpickle.encode(successfully_read_rocketpy_motor))

def update_motor(self, motor_id: int) -> "Union[Dict[str, Any], Response]":
"""
Expand Down
5 changes: 2 additions & 3 deletions lib/controllers/rocket.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from typing import Dict, Any, Union
from pydantic import BaseModel
import jsonpickle
import ast

Expand All @@ -17,7 +16,7 @@
from lib.models.aerosurfaces import NoseCone, TrapezoidalFins, Tail
from lib.models.parachute import Parachute
from lib.repositories.rocket import RocketRepository
from lib.views.rocket import InertiaDetails, RocketGeometricalParameters, RocketAerodynamicsQuantities, ParachuteData, RocketData, RocketSummary, RocketCreated, RocketUpdated, RocketDeleted
from lib.views.rocket import InertiaDetails, RocketGeometricalParameters, RocketAerodynamicsQuantities, ParachuteData, RocketData, RocketSummary, RocketCreated, RocketUpdated, RocketDeleted, RocketPickle

class RocketController():
"""
Expand Down Expand Up @@ -279,7 +278,7 @@ def get_rocketpy_rocket(rocket_id: int) -> "Union[Dict[str, Any], Response]":
successfully_read_rocketpy_rocket = \
RocketController( successfully_read_rocket ).rocketpy_rocket

return BaseModel(jsonpickle_rocketpy_rocket=jsonpickle.encode(successfully_read_rocketpy_rocket))
return RocketPickle(jsonpickle_rocketpy_rocket=jsonpickle.encode(successfully_read_rocketpy_rocket))

def update_rocket(self, rocket_id: int) -> "Union[Dict[str, Any], Response]":
"""
Expand Down
3 changes: 3 additions & 0 deletions lib/views/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ class EnvUpdated(BaseModel):
class EnvDeleted(BaseModel):
deleted_env_id: str
message: str = "Environment successfully deleted"

class EnvPickle(BaseModel):
jsonpickle_rocketpy_env: str
3 changes: 3 additions & 0 deletions lib/views/flight.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,6 @@ class FlightUpdated(BaseModel):
class FlightDeleted(BaseModel):
deleted_flight_id: str
message: str = "Flight successfully deleted"

class FlightPickle(BaseModel):
jsonpickle_rocketpy_flight: str
3 changes: 3 additions & 0 deletions lib/views/motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ class MotorUpdated(BaseModel):
class MotorDeleted(BaseModel):
deleted_motor_id: str
message: str = "Motor successfully deleted"

class MotorPickle(BaseModel):
jsonpickle_rocketpy_motor: str
3 changes: 3 additions & 0 deletions lib/views/rocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,6 @@ class RocketUpdated(BaseModel):
class RocketDeleted(BaseModel):
deleted_rocket_id: str
message: str = "Rocket successfully deleted"

class RocketPickle(BaseModel):
jsonpickle_rocketpy_rocket: str

0 comments on commit b295e35

Please sign in to comment.