Publish a JSON Schema file for the configuration file
Publish a JSON Schema file for the configuration file.
This will allow adopters to add a line like:
# $schema: https://...
and extensions such as https://github.com/redhat-developer/vscode-yaml provide autocompletion and validation.
Part if this would be adding this comment to our examples and docs.
Would be a very nice usability improvement.
Hi @czechboy0, I can pick this up.
Plan: add a schema file at the repo root, a test that keeps it in sync with the config options, and the $schema line in the docs and examples.
Thanks @nandan-varma - just one note, let's add the file under Public (new folder), not the root. And the link to it should be using the raw.githubusercontent URL, ensuring it can be downloaded over HTTPS without any authentication.
Before you move ahead - how are you planning to test that the JSON Schema is in sync with the parsing code? If we can find a reasonable way to do this, that'd be great, but it's not a hard blocker - it might be difficult to do in practice. Unless we use the JSON Schema file for generating the Swift code for parsing itself, but that won't work out of the box with Swift OpenAPI Generator itself, since that only handles OpenAPI docs, not standalone JSON Schema files. Thoughts?
Agreed on Public and raw url.
For keeping it in sync, I'm thinking of a unit test that loads the schema and compares it against the config types:
- top-level and nested keys against the
CodingKeys - enum values against
GeneratorMode,FeatureFlag,AccessModifierandNamingStrategy - a basic type check for each property
So adding a key or an enum case without updating the schema would fail CI. It will not catch every kind of type change, but those are rare and would be breaking anyway. Agreed that generating the parser from the schema isn't really practical here.
Sounds great, thanks @nandan-varma
Great, works now, just add the following to the top of your openapi-generator-config.yaml:
# yaml-language-server: $schema=https://raw.githubusercontent.com/apple/swift-openapi-generator/main/Public/openapi-generator-config.schema.json