Skip to content

Commit

Permalink
Fix up openapi spec for smartAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
maximusunc committed Oct 3, 2023
1 parent dd878d4 commit ad962ef
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


class Settings(BaseSettings):
openapi_server_url: Optional[AnyUrl]
openapi_server_url: AnyUrl = "http://localhost:9096"
openapi_server_maturity: str = "development"
openapi_server_location: str = "RENCI"
trapi_version: str = "1.4.0"
Expand Down
14 changes: 6 additions & 8 deletions app/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
LOGGER = logging.getLogger(__name__)

openapi_args = dict(
title="Answer Appraiser",
version="0.3.4",
title="SRI Answer Appraiser",
version="0.3.5",
terms_of_service="",
translator_component="Utility",
translator_teams=["Standards Reference Implementation Team"],
infores="infores:answer-appraiser",
description="SRI service that provides metrics for scoring and ordering of results",
trapi="1.4.0",
biolink_version="3.4.2",
contact={
"name": "Max Wang",
"email": "[email protected]",
"x-id": "maximusunc",
"x-id": "https://github.com/maximusunc",
"x-role": "responsible developer",
},
)
Expand All @@ -43,8 +43,6 @@
},
]

openapi_args["trapi"] = settings.trapi_version

APP = TRAPI(**openapi_args)

APP.add_middleware(
Expand Down
21 changes: 16 additions & 5 deletions app/trapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,26 @@ def __init__(
self,
*args,
contact: Optional[Dict[str, Any]] = None,
description: Optional[str] = "",
terms_of_service: Optional[str] = None,
translator_component: Optional[str] = None,
translator_teams: Optional[List[str]] = None,
infores: Optional[str] = None,
trapi: Optional[str] = None,
biolink_version: Optional[str] = None,
servers: Optional[List[Dict]] = None,
**kwargs,
):
super().__init__(*args, **kwargs)
self.contact = contact
self.description = description
self.terms_of_service = terms_of_service
self.translator_component = translator_component
self.translator_teams = translator_teams
self.infores = infores
self.trapi = trapi
self.biolink_version = biolink_version
self.servers = servers

def openapi(self) -> Dict[str, Any]:
"""Build custom OpenAPI schema."""
Expand All @@ -51,24 +57,29 @@ def openapi(self) -> Dict[str, Any]:

openapi_schema["servers"] = self.servers

openapi_schema["info"]["contact"] = self.contact

openapi_schema["info"]["x-translator"] = {
"component": self.translator_component,
"team": self.translator_teams,
"biolink-version": self.biolink_version,
"component": "Utility",
"team": "Standards Reference Implementation Team",
"externalDocs": {
"description": "The values for component and team are restricted according to this external JSON schema. See schema and examples at url",
"url": "https://github.com/NCATSTranslator/translator_extensions/blob/production/x-translator/",
},
"infores": self.infores,
"infores": "infores:sri-answer-appraiser",
}
openapi_schema["info"]["x-trapi"] = {
"version": self.trapi,
"externalDocs": {
"description": "The values for version are restricted according to the regex in this external JSON schema. See schema and examples at url",
"url": "https://github.com/NCATSTranslator/translator_extensions/blob/production/x-trapi/",
},
"operations": [],
}
openapi_schema["info"]["contact"] = self.contact
openapi_schema["info"]["termsOfService"] = self.terms_of_service

if self.terms_of_service:
openapi_schema["info"]["termsOfService"] = self.terms_of_service

self.openapi_schema = openapi_schema
return self.openapi_schema

0 comments on commit ad962ef

Please sign in to comment.