Problem statement
Build a bike share station directory that lists its stations, looks one up by number, keeps a retired dock listing open for older callers, and documents every operation it publishes.
Sample Data
The network in app/store.py holds four stations, filed under the numbers 1, 3, 5 and 8, so 2 and 99 are filed under nobody. Here is one station record:
{
"id": 1,
"name": "Riverside Park",
"docks_total": 18,
"bikes_available": 7,
"status": "open"
}
API Endpoints to Implement
The three handlers live in app/api/routes/stations.py. Their helpers, list_stations, find_station and list_docks, are in app/services/stations.py, and the three shapes they answer with, Station, Dock and Message, are in app/models/station.py.
GET /stations
- Answers 200 with every station in the order the network files them.
- Summary: List every station
- Description: Returns the whole network, one entry per station, in the order the network numbers them.
- Tag: Stations
- Response description: Every station in the network
- Answer: an array of the registered Station shape.
GET /stations/{station_id}
- station_id comes from the URL as a whole number, and is published as the operation's only path parameter, required, described as Number the network files the station under.
- Answers 200 with the station filed under that number.
- Summary: Look up one station
- Description: Returns the one station filed under the given number, and reports a miss when no station is filed under it.
- Tag: Stations
- Response description: The station filed under that number
- Answer: the registered Station shape.
- A number no station is filed under is answered with 404 and the body {"detail": "Station 2 was not found"}, naming the number that was asked for.
- The document publishes that 404 answer as the registered Message shape, described as No station is filed under that number.
GET /docks
- Answers 200 with the same four stations in the retired dock shape.
- Summary: List every dock
- Description: Returns the whole network in the retired dock shape, kept for callers that have not moved to the station listing.
- Tag: Legacy
- Response description: Every dock in the retired shape
- Answer: an array of the registered Dock shape.
- Marked as deprecated. The two station operations are not.
The published document
The service publishes its description at GET /openapi.json. Every fact above must be declared on the operation itself, not written into that document by hand.
A registered shape is listed once under components/schemas and referenced from the operation, not spelled out in place. Each of the three publishes every field as required, with a type and a description.
Sample Requests & Responses
GET /stations
Response (200 OK):
[
{"id": 1, "name": "Riverside Park", "docks_total": 18, "bikes_available": 7, "status": "open"},
{"id": 3, "name": "Market Square", "docks_total": 24, "bikes_available": 24, "status": "open"},
{"id": 5, "name": "Harbor Gate", "docks_total": 12, "bikes_available": 0, "status": "closed"},
{"id": 8, "name": "Elm Street Depot", "docks_total": 30, "bikes_available": 11, "status": "repair"}
]
GET /stations/3
Response (200 OK):
{
"id": 3,
"name": "Market Square",
"docks_total": 24,
"bikes_available": 24,
"status": "open"
}
GET /stations/2
Response (404 Not Found):
{
"detail": "Station 2 was not found"
}
GET /docks
Response (200 OK):
[
{"id": 1, "corner": "Riverside Park", "free_bikes": 7},
{"id": 3, "corner": "Market Square", "free_bikes": 24},
{"id": 5, "corner": "Harbor Gate", "free_bikes": 0},
{"id": 8, "corner": "Elm Street Depot", "free_bikes": 11}
]
