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

Some changes recommended by ratemyopenapi.com #221

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions API/auth/routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
router = APIRouter(prefix="/auth", tags=["Auth"])


@router.get("/login/")
@router.get("/login")
def login_url(request: Request):
"""Generate Login URL for authentication using OAuth2 Application registered with OpenStreetMap.
Click on the download url returned to get access_token.
Expand All @@ -25,7 +25,7 @@ def login_url(request: Request):
return login_url


@router.get("/callback/")
@router.get("/callback")
def callback(request: Request):
"""Performs token exchange between OpenStreetMap and Raw Data API

Expand All @@ -42,7 +42,7 @@ def callback(request: Request):
return access_token


@router.get("/me/", response_model=AuthUser)
@router.get("/me", response_model=AuthUser)
def my_data(user_data: AuthUser = Depends(login_required)):
"""Read the access token and provide user details from OSM user's API endpoint,
also integrated with underpass .
Expand All @@ -64,7 +64,7 @@ class User(BaseModel):


# Create user
@router.post("/users/", response_model=dict)
@router.post("/users", response_model=dict)
async def create_user(params: User, user_data: AuthUser = Depends(admin_required)):
"""
Creates a new user and returns the user's information.
Expand Down Expand Up @@ -155,7 +155,7 @@ async def delete_user(osm_id: int, user_data: AuthUser = Depends(admin_required)


# Get all users
@router.get("/users/", response_model=list)
@router.get("/users", response_model=list)
async def read_users(
skip: int = 0, limit: int = 10, user_data: AuthUser = Depends(staff_required)
):
Expand Down
2 changes: 1 addition & 1 deletion API/custom_exports.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
router = APIRouter(prefix="/custom", tags=["Custom Exports"])


@router.post("/snapshot/")
@router.post("/snapshot")
@limiter.limit(f"{RATE_LIMIT_PER_MIN}/minute")
@version(1)
async def process_custom_requests(
Expand Down
2 changes: 1 addition & 1 deletion API/hdx.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async def read_hdx_list(
return hdx_list


@router.get("/search/", response_model=List[dict])
@router.get("/search", response_model=List[dict])
@limiter.limit(f"{RATE_LIMIT_PER_MIN}/minute")
@version(1)
async def search_hdx(
Expand Down
2 changes: 2 additions & 0 deletions API/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@
"info": {
"title": "Raw Data API",
"version": "1.0",
"description": "Raw Data API is a set of high-performant APIs for transforming and exporting OpenStreetMap (OSM) data in different GIS file formats."
},
"tags": [],
"security": [{"OAuth2PasswordBearer": []}],
}

Expand Down
10 changes: 5 additions & 5 deletions API/raw_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@
redis_client = redis.StrictRedis.from_url(CELERY_BROKER_URL)


@router.get("/status/", response_model=StatusResponse)
@router.get("/status", response_model=StatusResponse)
@version(1)
def check_database_last_updated():
"""Gives status about how recent the osm data is , it will give the last time that database was updated completely"""
result = RawData().check_status()
return {"last_updated": result}


@router.post("/snapshot/", response_model=SnapshotResponse)
@router.post("/snapshot", response_model=SnapshotResponse)
@limiter.limit(f"{export_rate_limit}/minute")
@version(1)
def get_osm_current_snapshot_as_file(
Expand Down Expand Up @@ -462,7 +462,7 @@ def get_osm_current_snapshot_as_file(
)


@router.post("/snapshot/plain/")
@router.post("/snapshot/plain")
@version(1)
def get_osm_current_snapshot_as_plain_geojson(
request: Request,
Expand Down Expand Up @@ -494,14 +494,14 @@ def get_osm_current_snapshot_as_plain_geojson(
return result


@router.get("/countries/")
@router.get("/countries")
@version(1)
def get_countries(q: str = ""):
result = RawData().get_countries_list(q)
return result


@router.get("/osm_id/")
@router.get("/osm_id")
@version(1)
def get_osm_feature(osm_id: int):
return RawData().get_osm_feature(osm_id)
2 changes: 1 addition & 1 deletion API/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
paginator = s3.get_paginator("list_objects_v2")


@router.get("/files/")
@router.get("/files")
@limiter.limit(f"{RATE_LIMIT_PER_MIN}/minute")
@version(1)
async def list_s3_files(
Expand Down
2 changes: 1 addition & 1 deletion API/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
router = APIRouter(prefix="/stats", tags=["Stats"])


@router.post("/polygon/")
@router.post("/polygon")
@limiter.limit(f"{POLYGON_STATISTICS_API_RATE_LIMIT}/minute")
@version(1)
async def get_polygon_stats(
Expand Down
21 changes: 12 additions & 9 deletions API/tasks.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import json
from datetime import datetime
from typing import Any

import redis
from celery.result import AsyncResult
from fastapi import APIRouter, Depends, HTTPException, Query, Request
from fastapi import APIRouter, Depends, HTTPException, Query, Request, Path
from fastapi.responses import JSONResponse
from fastapi_versioning import version

Expand All @@ -16,10 +17,12 @@
router = APIRouter(prefix="/tasks", tags=["Tasks"])


@router.get("/status/{task_id}/", response_model=SnapshotTaskResponse)
@router.get("/status/{task_id}", response_model=SnapshotTaskResponse)
@version(1)
def get_task_status(
task_id,
task_id: Any = Path(
description="Unique id provided on response from /snapshot",
),
only_args: bool = Query(
default=False,
description="Fetches arguments of task",
Expand Down Expand Up @@ -78,7 +81,7 @@ def get_task_status(
return JSONResponse(result)


@router.get("/revoke/{task_id}/")
@router.get("/revoke/{task_id}")
@version(1)
def revoke_task(task_id, user: AuthUser = Depends(staff_required)):
"""Revokes task , Terminates if it is executing
Expand All @@ -93,7 +96,7 @@ def revoke_task(task_id, user: AuthUser = Depends(staff_required)):
return JSONResponse({"id": task_id})


@router.get("/inspect/")
@router.get("/inspect")
@version(1)
def inspect_workers(
request: Request,
Expand Down Expand Up @@ -134,7 +137,7 @@ def inspect_workers(
return JSONResponse(content=response_data)


@router.get("/ping/")
@router.get("/ping")
@version(1)
def ping_workers():
"""Pings available workers
Expand All @@ -145,7 +148,7 @@ def ping_workers():
return JSONResponse(inspected_ping)


@router.get("/purge/")
@router.get("/purge")
@version(1)
def discard_all_waiting_tasks(user: AuthUser = Depends(admin_required)):
"""
Expand All @@ -159,7 +162,7 @@ def discard_all_waiting_tasks(user: AuthUser = Depends(admin_required)):
queues = [DEFAULT_QUEUE_NAME, DAEMON_QUEUE_NAME]


@router.get("/queue/")
@router.get("/queue")
@version(1)
def get_queue_info():
queue_info = {}
Expand All @@ -176,7 +179,7 @@ def get_queue_info():
return JSONResponse(content=queue_info)


@router.get("/queue/details/{queue_name}/")
@router.get("/queue/details/{queue_name}")
@version(1)
def get_list_details(
queue_name: str,
Expand Down
Binary file added cli
Binary file not shown.
19 changes: 11 additions & 8 deletions docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
"openapi": "3.0.2",
"info": {
"title": "Raw Data API ",
"version": "1"
"version": "1",
"description": "Raw Data API is a set of high-performant APIs for transforming and exporting OpenStreetMap (OSM) data in different GIS file formats."
},
"tags": [],
"servers": [
{
"url": "/latest"
}
],
"paths": {
"/status/": {
"/status": {
"get": {
"summary": "Check Database Last Updated",
"description": "Gives status about how recent the osm data is , it will give the last time that database was updated completely",
Expand All @@ -29,7 +31,7 @@
}
}
},
"/snapshot/": {
"/snapshot": {
"post": {
"summary": "Get Osm Current Snapshot As File",
"description": "Generates the current raw OpenStreetMap data available on database based on the input geometry, query and spatial features.\n\nSteps to Run Snapshot :\n\n1. Post the your request here and your request will be on queue, endpoint will return as following :\n {\n \"task_id\": \"your task_id\",\n \"track_link\": \"/tasks/task_id/\"\n }\n2. Now navigate to /tasks/ with your task id to track progress and result",
Expand Down Expand Up @@ -546,7 +548,7 @@
}
}
},
"/snapshot/plain/": {
"/snapshot/plain": {
"post": {
"summary": "Get Current Snapshot As Plain Geojson",
"description": "Simple API to get osm features as geojson for small region. This is designed only for querying small data for large data follow /snapshot/\n\nParams ::\n\n bbox: Optional List = takes xmin, ymin, xmax, ymax uses srid=4326\n select: List = this is select query you can pass [*] to select all attribute\n where: List[WhereCondition] = [{'key': 'building', 'value': ['*']},{'key':'amenity','value':['school','college']}]\n join_by: Optional[JoinFilterType] = or/ and\n look_in: Optional[List[OsmFeatureType]] = [\"nodes\", \"ways_poly\",\"ways_line\",\"relations\"] : tables name",
Expand Down Expand Up @@ -659,7 +661,7 @@
}
}
},
"/tasks/status/{task_id}/": {
"/tasks/status/{task_id}": {
"get": {
"summary": "Get Task Status",
"description": "Tracks the request from the task id provided by Raw Data API for the request\n\nArgs:\n\n task_id ([type]): [Unique id provided on response from /snapshot/]\n\nReturns:\n\n id: Id of the task\n status : SUCCESS / PENDING\n result : Result of task\n\nSuccessful task will have additional nested json inside",
Expand All @@ -671,7 +673,8 @@
"title": "Task Id"
},
"name": "task_id",
"in": "path"
"in": "path",
"description": "Unique id provided on response from /snapshot/"
}
],
"responses": {
Expand Down Expand Up @@ -1016,7 +1019,7 @@
"type": "boolean",
"description": "Intersects the passed geom to country boundary if set to true and exports whole country : Use with Caution , May take hours",
"default": false,
"example": "false"
"example": false
},
"filters": {
"title": "Filters",
Expand Down Expand Up @@ -1285,7 +1288,7 @@
},
"additionalProperties": false,
"example": {
"task_id": "aa539af6-83d4-4aa3-879e-abf14fffa03f",
"taskId": "aa539af6-83d4-4aa3-879e-abf14fffa03f",
"track_link": "/tasks/status/aa539af6-83d4-4aa3-879e-abf14fffa03f/"
}
},
Expand Down
4 changes: 2 additions & 2 deletions src/validation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ class SnapshotResponse(BaseModel):
class Config:
json_schema_extra = {
"example": {
"task_id": "aa539af6-83d4-4aa3-879e-abf14fffa03f",
"track_link": "/tasks/status/aa539af6-83d4-4aa3-879e-abf14fffa03f/",
"taskId": "aa539af6-83d4-4aa3-879e-abf14fffa03f",
"trackLink": "/tasks/status/aa539af6-83d4-4aa3-879e-abf14fffa03f/",
}
}

Expand Down