Skip to content

Commit

Permalink
Add openapi schema generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Joseph McKinsey committed Oct 22, 2024
1 parent c92657f commit 4699fbf
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 53 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/schema-gen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,19 @@ jobs:
run: |
datamodel-codegen --input schemas --input-file-type jsonschema --output python_models --output-model pydantic_v2.BaseModel
PYTHONPATH=. pytest test/load_models.py
- name: Run openapi-generation for python
shell: bash -l {0}
run: |
docker run --rm \
-v ${PWD}:/local openapitools/openapi-generator-cli generate \
-i /local/openapi.json \
-g python \
-o /local/out/python
- name: Run openapi-generation for python
shell: bash -l {0}
run: |
docker run --rm \
-v ${PWD}:/local openapitools/openapi-generator-cli generate \
-i /local/openapi.json \
-g julia-server \
-o /local/out/julia
15 changes: 15 additions & 0 deletions openapi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"openapi": "3.1.0",
"info": {
"title": "PowerSystemModels",
"version": "1.0.0"
},
"paths": {},
"components": {
"schemas": {
"ThermalStandard": {
"$ref": "./schemas/ThermalStandard.json"
}
}
}
}
31 changes: 4 additions & 27 deletions schemas/ThermalStandard.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,42 +41,19 @@
"type": "number"
},
"active_power_limits": {
"$ref": "common.json#/definitions/MinMax",
"default": {
"min": 0.0,
"max": 0.0
}
"$ref": "common.json#/definitions/MinMax"
},
"reactive_power_limits": {
"anyOf": [
{
"$ref": "common.json#/definitions/MinMax"
},
{
"type": "null"
}
],
"default": null
"$ref": "common.json#/definitions/MinMax"
},
"ramp_limits": {
"anyOf": [
{
"$ref": "common.json#/definitions/MinMax"
},
{
"type": "null"
}
],
"default": {
"min": 0.0,
"max": 0.0
}
"$ref": "common.json#/definitions/MinMax"
},
"operation_cost": {
"$ref": "common.json#/definitions/ThermalGenerationCost"
},
"time_limits": {
"anyOf": [
"oneOf": [
{
"$ref": "common.json#/definitions/UpDown"
},
Expand Down
130 changes: 104 additions & 26 deletions schemas/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"$ref": "#/definitions/StartUpStages"
}
],
"description": "Start-up cost can take linear or multi-stage cost",
"description": "Start-up cost can take linear or multi-stage cost"
},
"shut_down": {
"description": "Cost to turn the unit off",
Expand Down Expand Up @@ -72,25 +72,30 @@
{
"$ref": "#/definitions/FuelCurve"
}
]
],
"discriminator": {
"propertyName": "variable_cost_type",
"mapping": {
"COST": "#/definitions/CostCurve",
"FUEL": "#/definitions/FuelCurve"
}
}
},
"CostCurve": {
"title": "CostCurve",
"properties": {
"variable_cost_type": {
"type": "string",
"const": "COST"
},
"value_curve": {
"$ref": "#/definitions/ValueCurve"
},
"power_units": {
"$ref": "#/definitions/UnitSystem"
},
"vom_cost": {
"$ref": "#/definitions/InputOutputCurve",
"default": {
"function_data": {
"proportional_term": 0,
"constant_term": 0
},
"input_at_zero": 0
}
"$ref": "#/definitions/InputOutputCurve"
}
},
"required": [
Expand All @@ -101,7 +106,12 @@
"type": "object"
},
"FuelCurve": {
"title": "FuelCurve",
"properties": {
"variable_cost_type": {
"type": "string",
"const": "FUEL"
},
"value_curve": {
"$ref": "#/definitions/ValueCurve"
},
Expand All @@ -119,14 +129,7 @@
]
},
"vom_cost": {
"$ref": "#/definitions/InputOutputCurve",
"default": {
"function_data": {
"proportional_term": 0,
"constant_term": 0
},
"input_at_zero": 0
}
"$ref": "#/definitions/InputOutputCurve"
}
},
"required": [
Expand All @@ -148,7 +151,15 @@
{
"$ref": "#/definitions/AverageRateCurve"
}
]
],
"discriminator": {
"propertyName": "curve_type",
"mapping": {
"INPUT_OUTPUT": "#/definitions/InputOutputCurve",
"INCREMENTAL": "#/definitions/IncrementalCurve",
"AVERAGE_RATE": "#/definitions/AverageRateCurve"
}
}
},
"FunctionData": {
"oneOf": [
Expand All @@ -164,10 +175,24 @@
{
"$ref": "#/definitions/PiecewiseStepData"
}
]
],
"discriminator": {
"propertyName": "function_type",
"mapping": {
"LINEAR": "#/definitions/LinearFunctionData",
"QUADRATIC": "#/definitions/QuadraticFunctionData",
"PIECEWISE_LINEAR": "#/definitions/PiecewiseLinearData",
"PIECEWISE_STEP": "#/definitions/PiecewiseStepData"
}
}
},
"LinearFunctionData": {
"title": "LinearFunctionData",
"properties": {
"function_type": {
"type": "string",
"const": "LINEAR"
},
"proportional_term": {
"type": "number"
},
Expand All @@ -182,7 +207,12 @@
"type": "object"
},
"QuadraticFunctionData": {
"title": "QuadraticFunctionData",
"properties": {
"function_type": {
"type": "string",
"const": "QUADRATIC"
},
"quadratic_term": {
"type": "number"
},
Expand Down Expand Up @@ -216,8 +246,13 @@
]
},
"PiecewiseLinearData": {
"title": "PiecewiseLinearData",
"type": "object",
"properties": {
"function_type": {
"type": "string",
"const": "PIECEWISE_LINEAR"
},
"points": {
"type": "array",
"items": {
Expand All @@ -230,8 +265,13 @@
]
},
"PiecewiseStepData": {
"title": "PiecewiseStepData",
"type": "object",
"properties": {
"function_type": {
"type": "string",
"const": "PIECEWISE_STEP"
},
"x_coords": {
"type": "array",
"items": {
Expand All @@ -251,8 +291,13 @@
]
},
"InputOutputCurve": {
"title": "InputOutputCurve",
"type": "object",
"properties": {
"curve_type": {
"type": "string",
"const": "INPUT_OUTPUT"
},
"function_data": {
"oneOf": [
{
Expand All @@ -264,19 +309,39 @@
{
"$ref": "#/definitions/PiecewiseLinearData"
}
]
],
"discriminator": {
"propertyName": "function_type",
"mapping": {
"QUADRATIC": "#/definitions/QuadraticFunctionData",
"LINEAR": "#/definitions/LinearFunctionData",
"PIECEWISE_LINEAR": "#/definitions/PiecewiseLinearData"
}
}
},
"input_at_zero": {
"type": "number"
}
},
"required": [
"function_data"
]
],
"default": {
"function_data": {
"proportional_term": 0,
"constant_term": 0
},
"input_at_zero": 0
}
},
"IncrementalCurve": {
"title": "IncrementalCurve",
"type": "object",
"properties": {
"curve_type": {
"type": "string",
"const": "INCREMENTAL"
},
"function_data": {
"oneOf": [
{
Expand All @@ -299,8 +364,13 @@
]
},
"AverageRateCurve": {
"title": "AverageRateCurve",
"type": "object",
"properties": {
"curve_type": {
"type": "string",
"const": "AVERAGE_RATE"
},
"function_data": {
"oneOf": [
{
Expand All @@ -312,7 +382,15 @@
{
"$ref": "#/definitions/PiecewiseLinearData"
}
]
],
"discriminator": {
"propertyName": "function_type",
"mapping": {
"LINEAR": "#/definitions/LinearFunctionData",
"QUADRATIC": "#/definitions/QuadraticFunctionData",
"PIECEWISE_LINEAR": "#/definitions/PiecewiseLinearData"
}
}
},
"initial_input": {
"type": "number"
Expand All @@ -326,6 +404,8 @@
]
},
"MinMax": {
"title": "MinMax",
"type": "object",
"properties": {
"min": {
"title": "Min",
Expand All @@ -341,9 +421,7 @@
"number"
]
}
},
"title": "MinMax",
"type": "object"
}
},
"PrimeMovers": {
"type": "string",
Expand Down

0 comments on commit 4699fbf

Please sign in to comment.