swift-openapi-generator icon indicating copy to clipboard operation
swift-openapi-generator copied to clipboard

Publish a JSON Schema file for the configuration file

Open czechboy0 opened this issue 1 month ago • 5 comments

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.

czechboy0 avatar Oct 12 '26 13:10 czechboy0

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.

nandan-varma avatar Oct 13 '26 06:10 nandan-varma

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?

czechboy0 avatar Oct 13 '26 12:10 czechboy0

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, AccessModifier and NamingStrategy
  • 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.

nandan-varma avatar Oct 13 '26 17:10 nandan-varma

Sounds great, thanks @nandan-varma

czechboy0 avatar Oct 13 '26 19:10 czechboy0

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

czechboy0 avatar Oct 14 '26 13:10 czechboy0