Skip to content

Commit

Permalink
docs(jobs): generate combined json schema for render
Browse files Browse the repository at this point in the history
also split the openapi/json schema links between different resources types
  • Loading branch information
AntoineDao committed Feb 15, 2021
1 parent 537d1b7 commit d74bb51
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/schemas/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ executor.

plugins
recipes
repository
jobs
repository
14 changes: 11 additions & 3 deletions docs/schemas/jobs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Schema
NProgress.start();
</script>
<script>
jsonSchemaViewer(window, '../_static/schemas/job-schema.json')
jsonSchemaViewer(window, '../_static/schemas/job-schemas-combined.json')
</script>
<script>
NProgress.done();
Expand All @@ -40,15 +40,23 @@ Schema

OpenAPI Docs
-------------
You can find the Open API Docs formatted by redoc `here <../_static/redoc-job.html#tag/job_model>`_.
You can find the Open API Docs formatted by redoc:

- `Job Schema <../_static/redoc-job.html#tag/job_model>`_.
- `Job Status Schema <../_static/redoc-job.html#tag/jobstatus_model>`_.
- `Run Status Schema <../_static/redoc-job.html#tag/runstatus_model>`_.

OpenAPI Definition
-------------------
You can find the OpenAPI JSON definition `here <../_static/schemas/job-openapi.json>`_.

JSON Schema Definition
-----------------------
You can find the JSON Schema definition `here <../_static/schemas/job-schema.json>`_.
You can find the JSON Schema definitions:

- `Job Schema <../_static/schemas/job-schema.json>`_.
- `Job Status Schema <../_static/schemas/job-status-schema.json>`_.
- `Run Status Schema <../_static/schemas/run-status-schema.json>`_.


Examples
Expand Down
24 changes: 22 additions & 2 deletions gen_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pydantic_openapi_helper.inheritance import class_mapper

from queenbee.repository import RepositoryIndex
from queenbee.job import Job, JobStatus
from queenbee.job import Job, JobStatus, RunStatus
from queenbee.recipe import Recipe, RecipeInterface
from queenbee.plugin import Plugin

Expand Down Expand Up @@ -52,7 +52,7 @@
with open(os.path.join(folder, 'job-openapi.json'), 'w') as out_file:
json.dump(
get_openapi(
base_object=[Job], title='Queenbee Job Schema',
base_object=[Job, JobStatus, RunStatus], title='Queenbee Job Schema',
description='Schema documentation for Queenbee Jobs',
version=VERSION
),
Expand Down Expand Up @@ -93,9 +93,29 @@
indent=2
)


with open(os.path.join(folder, 'job-schemas-combined.json'), 'w') as out_file:
from pydantic import BaseModel
from queenbee.io.inputs.step import StepInputs
from queenbee.io.outputs.step import StepOutputs
from typing import List, Union
class JobSchemas(BaseModel):
job: Job
job_status: JobStatus
run_status: RunStatus
results: List[Union[StepInputs, StepOutputs]]

out_file.write(JobSchemas.schema_json())

with open(os.path.join(folder, 'job-schema.json'), 'w') as out_file:
out_file.write(Job.schema_json())

with open(os.path.join(folder, 'job-status-schema.json'), 'w') as out_file:
out_file.write(JobStatus.schema_json())

with open(os.path.join(folder, 'run-status-schema.json'), 'w') as out_file:
out_file.write(RunStatus.schema_json())

with open(os.path.join(folder, 'plugin-schema.json'), 'w') as out_file:
out_file.write(Plugin.schema_json())

Expand Down

0 comments on commit d74bb51

Please sign in to comment.