Skip to content

Commit

Permalink
fix(execution): allOf usage in schema generation
Browse files Browse the repository at this point in the history
  • Loading branch information
matkoch committed Nov 6, 2024
1 parent 45063fd commit f36586e
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 165 deletions.
170 changes: 88 additions & 82 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
@@ -1,86 +1,5 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"properties": {
"AutoStash": {
"type": "boolean"
},
"CodecovToken": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"Configuration": {
"type": "string",
"enum": [
"Debug",
"Release"
]
},
"DiscordWebhook": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"FeedzNuGetApiKey": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"GitHubReleaseGitHubToken": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"IgnoreFailedSources": {
"type": "boolean",
"description": "Ignore unreachable sources during Restore"
},
"Major": {
"type": "boolean"
},
"MastodonAccessToken": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"PublicNuGetApiKey": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"SignPathApiToken": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"SignPathSettings": {
"$ref": "#/definitions/SignPathSettings"
},
"SlackWebhook": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"Solution": {
"type": "string",
"description": "Path to a solution file that is automatically loaded"
},
"TestDegreeOfParallelism": {
"type": "integer",
"format": "int32"
},
"TwitterAccessToken": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"TwitterAccessTokenSecret": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"TwitterConsumerKey": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"TwitterConsumerSecret": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"UseHttps": {
"type": "boolean"
}
},
"definitions": {
"Host": {
"type": "string",
Expand Down Expand Up @@ -231,5 +150,92 @@
}
}
},
"$ref": "#/definitions/NukeBuild"
"allOf": [
{
"properties": {
"AutoStash": {
"type": "boolean"
},
"CodecovToken": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"Configuration": {
"type": "string",
"enum": [
"Debug",
"Release"
]
},
"DiscordWebhook": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"FeedzNuGetApiKey": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"GitHubReleaseGitHubToken": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"IgnoreFailedSources": {
"type": "boolean",
"description": "Ignore unreachable sources during Restore"
},
"Major": {
"type": "boolean"
},
"MastodonAccessToken": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"PublicNuGetApiKey": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"SignPathApiToken": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"SignPathSettings": {
"$ref": "#/definitions/SignPathSettings"
},
"SlackWebhook": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"Solution": {
"type": "string",
"description": "Path to a solution file that is automatically loaded"
},
"TestDegreeOfParallelism": {
"type": "integer",
"format": "int32"
},
"TwitterAccessToken": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"TwitterAccessTokenSecret": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"TwitterConsumerKey": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"TwitterConsumerSecret": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"UseHttps": {
"type": "boolean"
}
}
},
{
"$ref": "#/definitions/NukeBuild"
}
]
}
9 changes: 5 additions & 4 deletions source/Nuke.Build.Shared/CompletionUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ public static IReadOnlyDictionary<string, string[]> GetItemsFromSchema(
Func<JsonProperty, bool> filter = null)
{
filter ??= _ => true;
var definitions = schema.RootElement.GetProperty("definitions").EnumerateObject().ToDictionary(x => x.Name, x => x);
var rootElement = schema.RootElement;
var definitions = rootElement.GetProperty("definitions").EnumerateObject().ToDictionary(x => x.Name, x => x);

var parameterProperties = schema.RootElement.GetProperty("definitions").TryGetProperty("NukeBuild", out var nukebuildProperty)
? nukebuildProperty.GetProperty("properties").EnumerateObject()
.Concat(schema.RootElement.TryGetProperty("properties", out var properties) ? properties.EnumerateObject() : [])
var parameterProperties = rootElement.GetProperty("definitions").TryGetProperty("NukeBuild", out var baseSchema)
? baseSchema.GetProperty("properties").EnumerateObject()
.Concat(rootElement.GetProperty("allOf")[0].TryGetProperty("properties", out var properties) ? properties.EnumerateObject() : [])
: definitions["build"].Value.GetProperty("properties").EnumerateObject();

return parameterProperties
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"properties": {
"ComplexTypeParamWithAttribute": {
"type": "string"
}
},
"definitions": {
"Host": {
"type": "string",
Expand Down Expand Up @@ -86,5 +81,16 @@
}
}
},
"$ref": "#/definitions/NukeBuild"
}
"allOf": [
{
"properties": {
"ComplexTypeParamWithAttribute": {
"type": "string"
}
}
},
{
"$ref": "#/definitions/NukeBuild"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,10 @@
}
}
},
"$ref": "#/definitions/NukeBuild"
"allOf": [
{},
{
"$ref": "#/definitions/NukeBuild"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,65 +1,5 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"properties": {
"BooleanParam": {
"type": "boolean"
},
"ComplexTypeArrayParam": {
"type": "array",
"items": {
"$ref": "#/definitions/ComplexType"
}
},
"ComplexTypeParam": {
"$ref": "#/definitions/ComplexType"
},
"ComponentInheritedParam": {
"type": "string"
},
"CustomEnumerationArrayParam": {
"type": "array",
"items": {
"type": "string",
"enum": [
"Debug",
"Release"
]
}
},
"CustomEnumerationParam": {
"type": "string",
"enum": [
"Debug",
"Release"
]
},
"IntegerArrayParam": {
"type": "array",
"items": {
"type": "integer",
"format": "int32"
}
},
"NullableBooleanParam": {
"type": [
"boolean",
"null"
]
},
"RegularParam": {
"type": "string"
},
"SecretParam": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"StringArrayParam": {
"type": "array",
"items": {
"type": "string"
}
}
},
"definitions": {
"ComplexType": {
"type": "object",
Expand Down Expand Up @@ -186,5 +126,71 @@
}
}
},
"$ref": "#/definitions/NukeBuild"
}
"allOf": [
{
"properties": {
"BooleanParam": {
"type": "boolean"
},
"ComplexTypeArrayParam": {
"type": "array",
"items": {
"$ref": "#/definitions/ComplexType"
}
},
"ComplexTypeParam": {
"$ref": "#/definitions/ComplexType"
},
"ComponentInheritedParam": {
"type": "string"
},
"CustomEnumerationArrayParam": {
"type": "array",
"items": {
"type": "string",
"enum": [
"Debug",
"Release"
]
}
},
"CustomEnumerationParam": {
"type": "string",
"enum": [
"Debug",
"Release"
]
},
"IntegerArrayParam": {
"type": "array",
"items": {
"type": "integer",
"format": "int32"
}
},
"NullableBooleanParam": {
"type": [
"boolean",
"null"
]
},
"RegularParam": {
"type": "string"
},
"SecretParam": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"StringArrayParam": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
{
"$ref": "#/definitions/NukeBuild"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,10 @@
}
}
},
"$ref": "#/definitions/NukeBuild"
"allOf": [
{},
{
"$ref": "#/definitions/NukeBuild"
}
]
}
Loading

0 comments on commit f36586e

Please sign in to comment.