Skip to content

Commit

Permalink
fix: added spec to main
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexPatrie committed Jan 10, 2025
1 parent 1ea224d commit 2775610
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 26 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ services:
build:
context: .
dockerfile: ./gateway/Dockerfile-gateway
image: ghcr.io/biosimulators/bio-compose-server-gateway:0.0.5-dev
image: ghcr.io/biosimulators/bio-compose-server-gateway:0.0.6-dev
container_name: gateway
networks:
- compnet
Expand Down
35 changes: 20 additions & 15 deletions gateway/main.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import dataclasses
import json
import os
import uuid
from typing import *

import dotenv
from tempfile import mkdtemp
from typing import *
# from tempfile import mkdtemp

import uvicorn
from fastapi import FastAPI, File, UploadFile, HTTPException, Query, APIRouter, Body
from fastapi.responses import FileResponse
# from fastapi.responses import FileResponse
from pydantic import BeforeValidator
from starlette.middleware.cors import CORSMiddleware

Expand All @@ -19,21 +17,28 @@
# ReaddyParticleConfig,
# ReaddyRun,
# SmoldynRun,
DbClientResponse,
# AgentParameters,
BigraphRegistryAddresses,
# IncompleteJob,
# JobStatus,
BigraphRegistryAddresses,
DbClientResponse,
CompositionNode,
CompositionSpec,
CompositionRun,
OutputData
OutputData,
ValidatedComposition
)
from shared.database import MongoConnector
# from shared.io import write_uploaded_file, download_file_from_bucket
from shared.log_config import setup_logging
from shared.utils import get_project_version
from shared.environment import ENV_PATH, DEFAULT_DB_NAME, DEFAULT_DB_TYPE, DEFAULT_JOB_COLLECTION_NAME, DEFAULT_BUCKET_NAME
from shared.environment import (
ENV_PATH,
DEFAULT_DB_NAME,
DEFAULT_DB_TYPE,
DEFAULT_JOB_COLLECTION_NAME,
DEFAULT_BUCKET_NAME
)
# from shared.io import write_uploaded_file, download_file_from_bucket


logger = setup_logging(__file__)
Expand Down Expand Up @@ -148,16 +153,15 @@ async def get_process_bigraph_addresses() -> BigraphRegistryAddresses:

@app.post(
"/validate-composition",
# response_model=CompositionRun,
response_model=ValidatedComposition,
tags=["Composition"],
operation_id="validate-composition",
summary="Validate Simulation Experiment Design specification file.",
)
async def validate_composition(
spec_file: UploadFile = File(..., description="Composition JSON File"),
simulators: List[str] = Query(..., description="Simulator package names to use for implementation"),
duration: int = Query(..., description="Duration of simulation"),
):
) -> ValidatedComposition:
from process_bigraph import Composite
from bsp import app_registrar

Expand All @@ -173,11 +177,12 @@ async def validate_composition(
config={'state': document_data},
core=app_registrar.core
)
return {'state': composite.state}
return ValidatedComposition(state=composite.state, valid=True)
except json.JSONDecodeError:
raise HTTPException(status_code=400, detail="Invalid JSON format.")
except Exception as e:
raise HTTPException(status_code=400, detail=str(e))
# raise HTTPException(status_code=400, detail=str(e))
return ValidatedComposition(state={'fail': str(e)}, valid=False)


@app.post(
Expand Down
24 changes: 15 additions & 9 deletions gateway/spec/openapi_3_1_0_generated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,6 @@ paths:
description: Simulator package names to use for implementation
title: Simulators
description: Simulator package names to use for implementation
- name: duration
in: query
required: true
schema:
type: integer
description: Duration of simulation
title: Duration
description: Duration of simulation
requestBody:
required: true
content:
Expand All @@ -62,7 +54,8 @@ paths:
description: Successful Response
content:
application/json:
schema: {}
schema:
$ref: '#/components/schemas/ValidatedComposition'
'422':
description: Validation Error
content:
Expand Down Expand Up @@ -267,6 +260,19 @@ components:
- last_updated
- results
title: OutputData
ValidatedComposition:
properties:
state:
type: object
title: State
valid:
type: boolean
title: Valid
type: object
required:
- state
- valid
title: ValidatedComposition
ValidationError:
properties:
loc:
Expand Down
2 changes: 1 addition & 1 deletion kustomize/overlays/compose/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ images:
- name: mongo
newTag: 8.0-rc
- name: ghcr.io/biosimulators/bio-compose-server-gateway
newTag: 0.0.5-dev
newTag: 0.0.6-dev
- name: ghcr.io/biosimulators/bio-compose-server-worker
newTag: 0.0.2-dev

Expand Down
6 changes: 6 additions & 0 deletions shared/data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,9 @@ class OutputData(BaseClass):
status: str
last_updated: str
results: Dict


@dataclass
class ValidatedComposition(BaseClass):
state: Dict[str, Any]
valid: bool

0 comments on commit 2775610

Please sign in to comment.