Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-generate JSON Schema from TypeScript #27

Conversation

alexiswl
Copy link
Contributor

Summary

  1. Run typescript-json-schema over the Workflow schema.
  2. Refine the schema (see .github/scripts/curate_autogenerated_schema.py)

Schema refining process steps

  1. Remove loadingOptions and extensionFields properties

  2. Rename class_, type_ etc to class, type

  3. Add $import and $include options and update requirements that allow for them (SchemaDefRequirementa and InlineJavascriptRequirement)

  4. Fix inputs / outputs / steps, so not just an array but can be an object where the key is the id attribute.

  5. Fix Requirements / Hints, so not just an array but can be an object where the key is the class attribute.

  6. Fix descriptions by removing Auto-generated... from the start

  7. Generate the CWLFile definition, which can be one of Workflow, CommandLineTool, or ExpressionTool and also fits the CWLMetadata

  8. Fix issues with additionalProperties and nested definitions as shown here https://stoic-agnesi-d0ac4a.netlify.app/1

  9. Write out the schema

  10. Generate the CWLGraph definition, which is an array of CWLFile objects with CWLMetadata

  11. Write out the graph schema to a separate file

@alexiswl
Copy link
Contributor Author

Installation

JetBrains

Settings -> Languages & Frameworks -> Schemas and DTDs -> JSON Schema Mappings:

Set Schema file or URL to https://github.com/alexiswl/cwl-ts-auto/blob/enhancement/generate-json-schema/cwl_schema.json

Set Schema Version to 'JSON Schema version 7'

Click Apply

image

VSCode

  1. Install the RedHat YAML Extension (this will enable the yaml.schemas key in the settings.json

image

  1. Open the settings json file and paste in the following keys

Screenshot 2024-02-13 at 3 02 49 pm

The settings.json can be accessed via the command pallete.

We also need to update the files.associations so that .cwl files are seen as YAML files by the compiler.

{
    "yaml.schemas": {
        "https://raw.githubusercontent.com/alexiswl/cwl-ts-auto/enhancement/generate-json-schema/cwl_schema.json": "*.cwl"
    },
    "files.associations": {
        "*.cwl": "yaml"
    }
}

image

Uses

Highlight invalid keys

image

image

image

image

image

image

Show documentation

image

image

image

Provide Valid Suggestions

image

image

image

image

Copy link

codecov bot commented Feb 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (0c14cfc) 55.62% compared to head (08dee13) 55.62%.

❗ Current head 08dee13 differs from pull request most recent head 7bdbfd7. Consider uploading reports for the commit 7bdbfd7 to get more accurate results

Additional details and impacted files
@@                              Coverage Diff                               @@
##           enhancement/auto-generate-json-schema-from-ts      #27   +/-   ##
==============================================================================
  Coverage                                          55.62%   55.62%           
==============================================================================
  Files                                                127      127           
  Lines                                               7837     7837           
  Branches                                            1572     1572           
==============================================================================
  Hits                                                4359     4359           
  Misses                                              3111     3111           
  Partials                                             367      367           
Flag Coverage Δ
unittests 55.62% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@alexiswl
Copy link
Contributor Author

alexiswl commented Feb 15, 2024

Ah makes sense, this is a cross-fork write out error.

Can we merge this into a branch on the origin repo first and then retry the GH action test? I don't think I have permission to make a branch on this repository

@mr-c
Copy link
Member

mr-c commented Feb 18, 2024

@alexiswl I sent you an invitation to join https://github.com/orgs/common-workflow-lab/teams/people/members which gives you permission to make branches in this and many other CWL repos. Feel free to re-open this PR from a local branch and thanks again for your contributions!

@@ -0,0 +1,6270 @@
{
"$ref": "#/definitions/CWLFile",
"$schema": "http://json-schema.org/draft-07/schema#",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any advantages to producing a schema using the newer drafts of the JSON schema spec?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potentially, JetBrains only seems to support version 7 though from the drop down menus, but I don't know if they actually support more recent versions (2019 and 2020). From the JSON Schema Store, GitHub Actions schema is also on version 7 still

Allow for type to be the string for unnamed map,
Allow for type to be the array for unnamed map
Allow pattern string for SecondaryFile def
Fixed record field maps
Fixed schema field maps (related to record field maps)
Fixed EnvVar requirement
Allowed for a few extra miscell metadata types
@alexiswl alexiswl changed the base branch from main to enhancement/auto-generate-json-schema-from-ts February 19, 2024 05:32
@alexiswl
Copy link
Contributor Author

Updated base branch to equivalent branch name on the common-workflow-lab/cwl-ts-auto repo.

Merging and will then create the PR to main from the common-workflow-lab branch instead.

@alexiswl alexiswl merged commit 84a192a into common-workflow-lab:enhancement/auto-generate-json-schema-from-ts Feb 19, 2024
@alexiswl alexiswl deleted the enhancement/generate-json-schema branch February 19, 2024 05:36
@alexiswl alexiswl mentioned this pull request Feb 19, 2024
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants