Skip to content

Commit

Permalink
Merge pull request #1418 from SimonCropp/use-some-expression-lambdas
Browse files Browse the repository at this point in the history
use some expression lambdas
  • Loading branch information
baywet authored Oct 11, 2023
2 parents 976c9f5 + c5bc8d9 commit 1d1116b
Show file tree
Hide file tree
Showing 43 changed files with 480 additions and 985 deletions.
5 changes: 1 addition & 4 deletions src/Microsoft.OpenApi.Hidi/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ public static ILoggerFactory ConfigureLogger(LogLevel logLevel)
return LoggerFactory.Create((builder) =>
{
builder
.AddSimpleConsole(c =>
{
c.IncludeScopes = true;
})
.AddSimpleConsole(c => c.IncludeScopes = true)
#if DEBUG
.AddDebug()
#endif
Expand Down
18 changes: 6 additions & 12 deletions src/Microsoft.OpenApi.Readers/V2/OpenApiContactDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,16 @@ internal static partial class OpenApiV2Deserializer
private static FixedFieldMap<OpenApiContact> _contactFixedFields = new()
{
{
"name", (o, n) =>
{
o.Name = n.GetScalarValue();
}
"name",
(o, n) => o.Name = n.GetScalarValue()
},
{
"url", (o, n) =>
{
o.Url = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute);
}
"url",
(o, n) => o.Url = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute)
},
{
"email", (o, n) =>
{
o.Email = n.GetScalarValue();
}
"email",
(o, n) => o.Email = n.GetScalarValue()
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ internal static partial class OpenApiV2Deserializer
private static FixedFieldMap<OpenApiDocument> _openApiFixedFields = new()
{
{
"swagger", (_, _) =>
{
} /* Version is valid field but we already parsed it */
"swagger", (_, _) => {}
/* Version is valid field but we already parsed it */
},
{"info", (o, n) => o.Info = LoadInfo(n)},
{"host", (_, n) => n.Context.SetTempStorage("host", n.GetScalarValue())},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,12 @@ internal static partial class OpenApiV2Deserializer
new()
{
{
OpenApiConstants.Description, (o, n) =>
{
o.Description = n.GetScalarValue();
}
OpenApiConstants.Description,
(o, n) => o.Description = n.GetScalarValue()
},
{
OpenApiConstants.Url, (o, n) =>
{
o.Url = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute);
}
OpenApiConstants.Url,
(o, n) => o.Url = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute)
},
};

Expand Down
108 changes: 36 additions & 72 deletions src/Microsoft.OpenApi.Readers/V2/OpenApiHeaderDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,112 +19,76 @@ internal static partial class OpenApiV2Deserializer
private static readonly FixedFieldMap<OpenApiHeader> _headerFixedFields = new()
{
{
"description", (o, n) =>
{
o.Description = n.GetScalarValue();
}
"description",
(o, n) => o.Description = n.GetScalarValue()
},
{
"type", (o, n) =>
{
GetOrCreateSchema(o).Type = n.GetScalarValue();
}
"type",
(o, n) => GetOrCreateSchema(o).Type = n.GetScalarValue()
},
{
"format", (o, n) =>
{
GetOrCreateSchema(o).Format = n.GetScalarValue();
}
"format",
(o, n) => GetOrCreateSchema(o).Format = n.GetScalarValue()
},
{
"items", (o, n) =>
{
GetOrCreateSchema(o).Items = LoadSchema(n);
}
"items",
(o, n) => GetOrCreateSchema(o).Items = LoadSchema(n)
},
{
"collectionFormat", (o, n) =>
{
LoadStyle(o, n.GetScalarValue());
}
"collectionFormat",
(o, n) => LoadStyle(o, n.GetScalarValue())
},
{
"default", (o, n) =>
{
GetOrCreateSchema(o).Default = n.CreateAny();
}
"default",
(o, n) => GetOrCreateSchema(o).Default = n.CreateAny()
},
{
"maximum", (o, n) =>
{
GetOrCreateSchema(o).Maximum = decimal.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture);
}
"maximum",
(o, n) => GetOrCreateSchema(o).Maximum = decimal.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture)
},
{
"exclusiveMaximum", (o, n) =>
{
GetOrCreateSchema(o).ExclusiveMaximum = bool.Parse(n.GetScalarValue());
}
"exclusiveMaximum",
(o, n) => GetOrCreateSchema(o).ExclusiveMaximum = bool.Parse(n.GetScalarValue())
},
{
"minimum", (o, n) =>
{
GetOrCreateSchema(o).Minimum = decimal.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture);
}
"minimum",
(o, n) => GetOrCreateSchema(o).Minimum = decimal.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture)
},
{
"exclusiveMinimum", (o, n) =>
{
GetOrCreateSchema(o).ExclusiveMinimum = bool.Parse(n.GetScalarValue());
}
"exclusiveMinimum",
(o, n) => GetOrCreateSchema(o).ExclusiveMinimum = bool.Parse(n.GetScalarValue())
},
{
"maxLength", (o, n) =>
{
GetOrCreateSchema(o).MaxLength = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture);
}
"maxLength",
(o, n) => GetOrCreateSchema(o).MaxLength = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture)
},
{
"minLength", (o, n) =>
{
GetOrCreateSchema(o).MinLength = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture);
}
"minLength",
(o, n) => GetOrCreateSchema(o).MinLength = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture)
},
{
"pattern", (o, n) =>
{
GetOrCreateSchema(o).Pattern = n.GetScalarValue();
}
"pattern",
(o, n) => GetOrCreateSchema(o).Pattern = n.GetScalarValue()
},
{
"maxItems", (o, n) =>
{
GetOrCreateSchema(o).MaxItems = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture);
}
"maxItems",
(o, n) => GetOrCreateSchema(o).MaxItems = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture)
},
{
"minItems", (o, n) =>
{
GetOrCreateSchema(o).MinItems = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture);
}
"minItems",
(o, n) => GetOrCreateSchema(o).MinItems = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture)
},
{
"uniqueItems", (o, n) =>
{
GetOrCreateSchema(o).UniqueItems = bool.Parse(n.GetScalarValue());
}
"uniqueItems",
(o, n) => GetOrCreateSchema(o).UniqueItems = bool.Parse(n.GetScalarValue())
},
{
"multipleOf", (o, n) =>
{
GetOrCreateSchema(o).MultipleOf = decimal.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture);
}
"multipleOf",
(o, n) => GetOrCreateSchema(o).MultipleOf = decimal.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture)
},
{
"enum", (o, n) =>
{
GetOrCreateSchema(o).Enum = n.CreateListOfAny();
}
"enum",
(o, n) => GetOrCreateSchema(o).Enum = n.CreateListOfAny()
}
};

Expand Down
36 changes: 12 additions & 24 deletions src/Microsoft.OpenApi.Readers/V2/OpenApiInfoDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,28 @@ internal static partial class OpenApiV2Deserializer
private static FixedFieldMap<OpenApiInfo> _infoFixedFields = new()
{
{
"title", (o, n) =>
{
o.Title = n.GetScalarValue();
}
"title",
(o, n) => o.Title = n.GetScalarValue()
},
{
"description", (o, n) =>
{
o.Description = n.GetScalarValue();
}
"description",
(o, n) => o.Description = n.GetScalarValue()
},
{
"termsOfService", (o, n) =>
{
o.TermsOfService = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute);
}
"termsOfService",
(o, n) => o.TermsOfService = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute)
},
{
"contact", (o, n) =>
{
o.Contact = LoadContact(n);
}
"contact",
(o, n) => o.Contact = LoadContact(n)
},
{
"license", (o, n) =>
{
o.License = LoadLicense(n);
}
"license",
(o, n) => o.License = LoadLicense(n)
},
{
"version", (o, n) =>
{
o.Version = n.GetScalarValue();
}
"version",
(o, n) => o.Version = n.GetScalarValue()
}
};

Expand Down
12 changes: 4 additions & 8 deletions src/Microsoft.OpenApi.Readers/V2/OpenApiLicenseDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,12 @@ internal static partial class OpenApiV2Deserializer
private static FixedFieldMap<OpenApiLicense> _licenseFixedFields = new()
{
{
"name", (o, n) =>
{
o.Name = n.GetScalarValue();
}
"name",
(o, n) => o.Name = n.GetScalarValue()
},
{
"url", (o, n) =>
{
o.Url = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute);
}
"url",
(o, n) => o.Url = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute)
},
};

Expand Down
48 changes: 16 additions & 32 deletions src/Microsoft.OpenApi.Readers/V2/OpenApiOperationDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,24 @@ internal static partial class OpenApiV2Deserializer
valueNode.GetScalarValue()))
},
{
"summary", (o, n) =>
{
o.Summary = n.GetScalarValue();
}
"summary",
(o, n) => o.Summary = n.GetScalarValue()
},
{
"description", (o, n) =>
{
o.Description = n.GetScalarValue();
}
"description",
(o, n) => o.Description = n.GetScalarValue()
},
{
"externalDocs", (o, n) =>
{
o.ExternalDocs = LoadExternalDocs(n);
}
"externalDocs",
(o, n) => o.ExternalDocs = LoadExternalDocs(n)
},
{
"operationId", (o, n) =>
{
o.OperationId = n.GetScalarValue();
}
"operationId",
(o, n) => o.OperationId = n.GetScalarValue()
},
{
"parameters", (o, n) =>
{
o.Parameters = n.CreateList(LoadParameter);
}
"parameters",
(o, n) => o.Parameters = n.CreateList(LoadParameter)
},
{
"consumes", (_, n) => {
Expand All @@ -73,22 +63,16 @@ internal static partial class OpenApiV2Deserializer
}
},
{
"responses", (o, n) =>
{
o.Responses = LoadResponses(n);
}
"responses",
(o, n) => o.Responses = LoadResponses(n)
},
{
"deprecated", (o, n) =>
{
o.Deprecated = bool.Parse(n.GetScalarValue());
}
"deprecated",
(o, n) => o.Deprecated = bool.Parse(n.GetScalarValue())
},
{
"security", (o, n) =>
{
o.Security = n.CreateList(LoadSecurityRequirement);
}
"security",
(o, n) => o.Security = n.CreateList(LoadSecurityRequirement)
},
};

Expand Down
Loading

0 comments on commit 1d1116b

Please sign in to comment.