Skip to content

Commit

Permalink
feat(schema evaluation): expose the json schema evaluation options to…
Browse files Browse the repository at this point in the history
… be able to customize how schemas are evaluated
  • Loading branch information
Fresa committed Nov 13, 2023
1 parent ea6a9e9 commit a33f16e
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/OpenAPI.Evaluation/Specification/OpenAPI.cs
Expand Up @@ -19,7 +19,8 @@ public sealed class OpenAPI
private OpenAPI(
JsonNode document,
Uri? baseUri = null,
IParameterValueParser[]? parameterValueParsers = null)
IParameterValueParser[]? parameterValueParsers = null,
EvaluationOptions? jsonSchemaEvaluationOptions = null)
{
_reader = new JsonNodeReader(document, JsonPointer.Empty);
OpenApi = _reader.Read("openapi").GetValue<string>();
Expand All @@ -34,11 +35,10 @@ public sealed class OpenAPI

var baseDocument = new JsonNodeBaseDocument(document, baseUri);

var jsonSchemaEvaluationOptions = new Json.Schema.EvaluationOptions
{
OutputFormat = OutputFormat.Hierarchical,
EvaluateAs = SpecVersion.Draft202012
};
jsonSchemaEvaluationOptions ??= new EvaluationOptions();
jsonSchemaEvaluationOptions.OutputFormat = OutputFormat.Hierarchical;
jsonSchemaEvaluationOptions.EvaluateAs = SpecVersion.Draft202012;

Json.Schema.OpenApi.Vocabularies.Register(jsonSchemaEvaluationOptions.VocabularyRegistry, jsonSchemaEvaluationOptions.SchemaRegistry);
jsonSchemaEvaluationOptions.SchemaRegistry.Register(baseDocument);
_evaluationOptions = new OpenApiEvaluationOptions
Expand Down Expand Up @@ -70,11 +70,14 @@ private void EnsureSupportedOpenApiVersion()
/// If not specified the first url in the specification's server node will be used.
/// Must be an absolute URL</param>
/// <param name="parameterValueParsers">A list of parameter value parsers that can override the default logic of parsing parameter values to json objects</param>
/// <param name="jsonSchemaEvaluationOptions">Json Schema evaluation options</param>
/// <returns>The parsed OpenAPI specification</returns>
public static OpenAPI Parse(
JsonNode document,
Uri? baseUri = null,
IParameterValueParser[]? parameterValueParsers = null) => new(document, baseUri, parameterValueParsers);
IParameterValueParser[]? parameterValueParsers = null,
EvaluationOptions? jsonSchemaEvaluationOptions = null) =>
new(document, baseUri, parameterValueParsers, jsonSchemaEvaluationOptions);

public Uri BaseUri => _evaluationOptions.Document.BaseUri;
public string OpenApi { get; }
Expand Down

0 comments on commit a33f16e

Please sign in to comment.