Skip to content

Instantly share code, notes, and snippets.

@moritztim
Created January 13, 2025 22:26
Show Gist options
  • Save moritztim/592cd9815df5f7fc55d1dffdd38c8a94 to your computer and use it in GitHub Desktop.
Save moritztim/592cd9815df5f7fc55d1dffdd38c8a94 to your computer and use it in GitHub Desktop.
Meta-Schema for abstracting URL parameters into a JSON Schema
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "URL Param Schema",
"description": "Schema to be converted to URL parameters",
"definitions": {
"urlParamSchema": {
"oneOf": [
{
"type": "object",
"properties": {
"key": {
"type": "string",
"description": "Actual parameter key, will be transformed to the globally specified case"
},
"case": {
"type": "string",
"description": "Case to convert the value to (or, if globally set, the keys)",
"default": "snake",
"$comment": "Informed by stringcase.org",
"oneOf": [
{
"const": "snake",
"title": "snake_case"
},
{
"const": "kebab",
"title": "kebab-case"
},
{
"const": "cobol",
"title": "COBOL-CASE"
},
{
"const": "train",
"title": "Train-Case"
},
{
"const": "camel",
"title": "camelCase"
},
{
"const": "pascal",
"title": "PascalCase"
},
{
"const": "constant",
"title": "CONSTANT_CASE"
},
{
"const": "upper",
"title": "UPPERCASE"
},
{
"const": "lower",
"title": "lowercase"
},
{
"const": "capitalized",
"title": "Capitalized"
}
]
},
"inverse": {
"type": "boolean",
"description": "The value should be inverted",
"default": false
}
},
"patternProperties": {
".*": { "$ref": "#/definitions/urlParamSchema" }
}
},
{
"type": "array",
"items": { "$ref": "#/definitions/urlParamSchema" }
},
{
"type": "string"
},
{
"type": "number"
},
{
"type": "boolean"
},
{
"type": "null"
}
]
}
},
"allOf": [
{ "$ref": "http://json-schema.org/draft-07/schema#" },
{ "$ref": "#/definitions/urlParamSchema" }
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment