Skip to content

Commit

Permalink
Fix bug - exceptions should not be thrown when properties are generat…
Browse files Browse the repository at this point in the history
…ed for sibling-hiding keywords
  • Loading branch information
mwadams committed Oct 1, 2024
1 parent e256f9f commit b480cca
Show file tree
Hide file tree
Showing 2 changed files with 241 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Corvus.Json.CodeGeneration.Keywords;
/// The properties keyword.
/// </summary>
public sealed class PropertiesKeyword
: ISubschemaTypeBuilderKeyword,
: ISubschemaTypeBuilderKeyword,
ILocalSubschemaRegistrationKeyword,
IPropertySubchemaProviderKeyword,
IObjectPropertyValidationKeyword
Expand Down Expand Up @@ -78,6 +78,9 @@ public void CollectProperties(TypeDeclaration source, TypeDeclaration target, Ha
JsonReference propertyPath = KeywordPathReference.AppendUnencodedPropertyNameToFragment(propertyName);
if (source.SubschemaTypeDeclarations.TryGetValue(propertyPath, out TypeDeclaration? propertyTypeDeclaration))
{
// If there was no keyword because it was hidden by sibling-hiding keyword
// we will not have been ab le to get the subschema type declaration, so we will
// not come in here, and just skip the property.
target.AddOrUpdatePropertyDeclaration(
new(
target,
Expand All @@ -88,10 +91,6 @@ public void CollectProperties(TypeDeclaration source, TypeDeclaration target, Ha
this,
null));
}
else
{
throw new InvalidOperationException($"The subschema definition for the schema at '{source.LocatedSchema.Location}' with path '{propertyPath}' was not found.");
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
@draft4

Feature: Unable to find property

Scenario: A schema that fails to generate
Given a schema file
"""
{
"$comment": "https://docs.codeclimate.com/docs/advanced-configuration",
"$schema": "http://json-schema.org/draft-04/schema#",
"definitions": {
"enabled": {
"type": "object",
"properties": {
"enabled": {
"title": "Enabled",
"type": "boolean",
"default": true
}
}
},
"config": {
"title": "Config",
"type": "object"
},
"threshold": {
"title": "Threshold",
"type": [
"integer",
"null"
]
}
},
"description": "Configuration file as an alternative for configuring your repository in the settings page.",
"id": "https://json.schemastore.org/codeclimate.json",
"properties": {
"version": {
"title": "Version",
"description": "Required to adjust maintainability checks.",
"type": "string",
"default": "2"
},
"prepare": {
"title": "Prepare",
"type": "array",
"items": {
"type": "object",
"properties": {
"url": {
"title": "URL",
"type": "string",
"format": "uri"
},
"path": {
"title": "Path",
"type": "string"
}
}
}
},
"checks": {
"title": "Checks",
"type": "object",
"properties": {
"argument-count": {
"title": "Argument Count",
"$ref": "#/definitions/enabled",
"properties": {
"config": {
"$ref": "#/definitions/config",
"properties": {
"threshold": {
"$ref": "#/definitions/threshold",
"default": 4
}
}
}
}
},
"complex-logic": {
"title": "Complex Logic",
"$ref": "#/definitions/enabled",
"properties": {
"config": {
"$ref": "#/definitions/config",
"properties": {
"threshold": {
"$ref": "#/definitions/threshold",
"default": 4
}
}
}
}
},
"file-lines": {
"title": "File Lines",
"$ref": "#/definitions/enabled",
"properties": {
"config": {
"$ref": "#/definitions/config",
"properties": {
"threshold": {
"$ref": "#/definitions/threshold",
"default": 250
}
}
}
}
},
"method-complexity": {
"title": "Method Complexity",
"$ref": "#/definitions/enabled",
"properties": {
"config": {
"$ref": "#/definitions/config",
"properties": {
"threshold": {
"$ref": "#/definitions/threshold",
"default": 5
}
}
}
}
},
"method-count": {
"title": "Method Count",
"$ref": "#/definitions/enabled",
"properties": {
"config": {
"$ref": "#/definitions/config",
"properties": {
"threshold": {
"$ref": "#/definitions/threshold",
"default": 20
}
}
}
}
},
"method-lines": {
"title": "Method Lines",
"$ref": "#/definitions/enabled",
"properties": {
"config": {
"$ref": "#/definitions/config",
"properties": {
"threshold": {
"$ref": "#/definitions/threshold",
"default": 25
}
}
}
}
},
"nested-control-flow": {
"title": "Nested Control Flow",
"$ref": "#/definitions/enabled",
"properties": {
"config": {
"$ref": "#/definitions/config",
"properties": {
"threshold": {
"$ref": "#/definitions/threshold",
"default": 4
}
}
}
}
},
"return-statements": {
"title": "Return Statements",
"$ref": "#/definitions/enabled",
"properties": {
"config": {
"$ref": "#/definitions/config",
"properties": {
"threshold": {
"$ref": "#/definitions/threshold",
"default": 4
}
}
}
}
},
"similar-code": {
"title": "Similar Code",
"$ref": "#/definitions/enabled",
"properties": {
"config": {
"$ref": "#/definitions/config",
"properties": {
"threshold": {
"$ref": "#/definitions/threshold"
}
}
}
}
},
"identical-code": {
"title": "Identical Code",
"$ref": "#/definitions/enabled",
"properties": {
"config": {
"$ref": "#/definitions/config",
"properties": {
"threshold": {
"$ref": "#/definitions/threshold"
}
}
}
}
}
}
},
"plugins": {
"title": "Plugins",
"description": "To add a plugin to your analysis. You can find the complete list of available plugins here: https://docs.codeclimate.com/docs/list-of-engines",
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/enabled"
}
},
"exclude_patterns": {
"title": "Exclude Patterns",
"type": "array",
"items": {
"title": "Exclude Pattern",
"type": "string"
}
}
},
"title": "Code Climate Configuration",
"type": "object"
}
"""
When I generate the code for the schema
# We only need to validate that we don't get an exception here, which is fine.

0 comments on commit b480cca

Please sign in to comment.