-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathapplication.py
More file actions
142 lines (126 loc) · 5.01 KB
/
application.py
File metadata and controls
142 lines (126 loc) · 5.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
from fastapi import FastAPI
from stapi_pydantic import Product, Provider
from pystapi_schema_generator import STAPI_BASE_URL, STAPI_VERSION
from pystapi_schema_generator.root_router import RootRouter
def create_app() -> FastAPI:
"""Create and configure the FastAPI application for OpenAPI spec generation."""
app = FastAPI(
title="STAPI API",
description=(
"The Sensor Tasking API (STAPI) defines a JSON-based web API to query for "
"spatio-temporal analytic and data products derived from remote sensing "
"(satellite or airborne) providers. The specification supports both products "
"derived from new tasking and products from provider archives."
),
version=STAPI_VERSION,
openapi_tags=[
{
"name": "Core",
"description": "Core endpoints for API discovery and metadata.",
"externalDocs": {
"description": "STAPI Core Specification",
"url": "https://github.com/stapi-spec/stapi-spec/blob/main/core/README.md",
},
},
{
"name": "Products",
"description": "Endpoints for discovering and accessing remote sensing data products.",
"externalDocs": {
"description": "STAPI Product Specification",
"url": "https://github.com/stapi-spec/stapi-spec/blob/main/product/README.md",
},
},
{
"name": "Orders",
"description": "Endpoints for creating and managing remote sensing data orders.",
"externalDocs": {
"description": "STAPI Order Specification",
"url": "https://github.com/stapi-spec/stapi-spec/blob/main/order/README.md",
},
},
{
"name": "Opportunities",
"description": "Endpoints for searching remote sensing acquisition opportunities.",
"externalDocs": {
"description": "STAPI Opportunity Specification",
"url": "https://github.com/stapi-spec/stapi-spec/blob/main/opportunity/README.md",
},
},
],
docs_url="/docs",
redoc_url="/redoc",
openapi_url="/openapi.json",
# Enhanced OpenAPI configuration
openapi_extra={
"info": {
"contact": {
"name": "STAPI Specification Organization",
"url": "https://github.com/stapi-spec",
}
},
"externalDocs": {
"description": "STAPI Specification Documentation",
"url": "https://github.com/stapi-spec/stapi-spec",
},
},
# Swagger UI customization
swagger_ui_parameters={
"deepLinking": True,
"docExpansion": "list", # list endpoints but details are collapsed
"defaultModelsExpandDepth": 0, # Show schemas at the bottom but collapsed
"supportedSubmitMethods": [], # Disable all submit methods to prevent "Try it out"
},
# ReDoc customization
redoc_ui_parameters={
# TODO: Add Redoc customization parameters here if needed
},
)
router = RootRouter()
router.add_product(
Product(
id="{productId}",
title="Example Product",
description=(
"This is an example product that demonstrates the STAPI specification. "
"Implementers should replace this with their actual product definitions, "
"including specific metadata, queryable properties, and order parameters."
),
license="proprietary",
providers=[
Provider(
name="Example Provider",
roles=["producer"],
url="https://example.com/provider",
description="Example provider for demonstration purposes",
)
],
links=[],
stapi_type="Product",
stapi_version=STAPI_VERSION,
conformsTo=[
f"{STAPI_BASE_URL}/{STAPI_VERSION}/core",
"https://geojson.org/schema/Polygon.json",
],
)
)
app.include_router(router, prefix="")
return app
# Create the FastAPI application instance
app = create_app()
def main() -> None:
"""Generate OpenAPI schema for STAPI."""
import argparse
import yaml
parser = argparse.ArgumentParser(description="Generate OpenAPI schema for STAPI")
parser.add_argument(
"--output",
"-o",
default="openapi.yml",
help="Output file path for the OpenAPI schema (default: openapi.yml)",
)
args = parser.parse_args()
with open(args.output, "w") as f:
yaml.dump(app.openapi(), f)
print(f"OpenAPI schema saved to '{args.output}'.")
if __name__ == "__main__":
main()