private void ApplyOpenApiBodyParameterAttribute(OpenApiOperationDescription operationDescription, MethodInfo methodInfo) { dynamic bodyParameterAttribute = methodInfo.GetCustomAttributes() .FirstAssignableToTypeNameOrDefault("OpenApiBodyParameterAttribute", TypeNameStyle.Name); if (bodyParameterAttribute != null) { if (operationDescription.Operation.RequestBody == null) { operationDescription.Operation.RequestBody = new OpenApiRequestBody(); } var mimeTypes = ObjectExtensions.HasProperty(bodyParameterAttribute, "MimeType") ? new string[] { bodyParameterAttribute.MimeType } : bodyParameterAttribute.MimeTypes; foreach (var mimeType in mimeTypes) { operationDescription.Operation.RequestBody.Content[mimeType] = new OpenApiMediaType { Schema = mimeType == "application/json" ? JsonSchema.CreateAnySchema() : new JsonSchema { Type = _settings.SchemaType == SchemaType.Swagger2 ? JsonObjectType.File : JsonObjectType.String, Format = _settings.SchemaType == SchemaType.Swagger2 ? null : JsonFormatStrings.Binary, } }; } } }
public OperationsBuilder Shared() { var dataSchema = RegisterReference("DataDto", _ => { return(JsonSchema.CreateAnySchema()); }); var contentSchema = RegisterReference("ContentDto", _ => { return(ContentJsonSchemaBuilder.BuildSchema(dataSchema, true)); }); var contentsSchema = RegisterReference("ContentResultDto", _ => { return(BuildResult(contentSchema)); }); var path = $"/content/{AppName}"; var builder = new OperationsBuilder { ContentSchema = contentSchema, ContentsSchema = contentsSchema, DataSchema = dataSchema, Path = path, Parent = this, SchemaDisplayName = "__Shared", SchemaName = "__Shared", SchemaTypeName = "__Shared" }; builder.AddTag("API endpoints for operations across all schemas."); return(builder); }
public OperationsBuilder Shared() { var dataSchema = ResolveSchema("DataDto", () => { return(JsonSchema.CreateAnySchema()); }); var contentSchema = ResolveSchema($"ContentDto", () => { return(ContentJsonSchemaBuilder.BuildSchema("Shared", dataSchema, true)); }); var path = $"/content/{AppName}"; var builder = new OperationsBuilder { ContentSchema = contentSchema, DataSchema = dataSchema, Path = path, Parent = this, SchemaDisplayName = "__Shared", SchemaName = "__Shared", SchemaTypeName = "__Shared", }; var description = "API endpoints for operations across all schemas."; Document.Tags.Add(new OpenApiTag { Name = "__Shared", Description = description }); return(builder); }
public string GenerateSchema() { var schema = new JsonSchema(); var context = new GenerationContext(schema); context.SetRoot <RootOptions>(); schema.Id = @"https://www.github.com/dotnet/dotnet-monitor"; schema.Title = "DotnetMonitorConfiguration"; //Allow other properties in the schema. schema.AdditionalPropertiesSchema = JsonSchema.CreateAnySchema(); AddCollectionRuleSchemas(context); AddConsoleLoggerFormatterSubSchemas(context); //TODO Figure out a better way to add object defaults schema.Definitions[nameof(EgressOptions)].Properties[nameof(EgressOptions.AzureBlobStorage)].Default = JsonSchema.CreateAnySchema(); schema.Definitions[nameof(EgressOptions)].Properties[nameof(EgressOptions.FileSystem)].Default = JsonSchema.CreateAnySchema(); schema.Definitions[nameof(EgressOptions)].Properties[nameof(EgressOptions.Properties)].Default = JsonSchema.CreateAnySchema(); schema.Definitions[nameof(LoggingOptions)].Properties[nameof(LoggingOptions.LogLevel)].Default = JsonSchema.CreateAnySchema(); schema.Definitions[nameof(LoggingOptions)].Properties[nameof(LoggingOptions.Console)].Default = JsonSchema.CreateAnySchema(); schema.Definitions[nameof(LoggingOptions)].Properties[nameof(LoggingOptions.EventLog)].Default = JsonSchema.CreateAnySchema(); schema.Definitions[nameof(LoggingOptions)].Properties[nameof(LoggingOptions.Debug)].Default = JsonSchema.CreateAnySchema(); schema.Definitions[nameof(LoggingOptions)].Properties[nameof(LoggingOptions.EventSource)].Default = JsonSchema.CreateAnySchema(); schema.Definitions[nameof(LogLevelOptions)].Properties[nameof(LogLevelOptions.LogLevel)].Default = JsonSchema.CreateAnySchema(); schema.Definitions[nameof(ConsoleLoggerOptions)].Properties[nameof(ConsoleLoggerOptions.FormatterOptions)].Default = JsonSchema.CreateAnySchema(); schema.Definitions[nameof(ConsoleLoggerOptions)].Properties[nameof(ConsoleLoggerOptions.LogLevel)].Default = JsonSchema.CreateAnySchema(); schema.Definitions[nameof(CollectionRuleOptions)].Properties[nameof(CollectionRuleOptions.Limits)].Default = JsonSchema.CreateAnySchema(); //Make the default for each property an empty object. foreach (KeyValuePair <string, JsonSchemaProperty> kvp in schema.Properties) { kvp.Value.Default = JsonSchema.CreateAnySchema(); } string schemaPayload = schema.ToJson(); //Normalize newlines embedded into json schemaPayload = schemaPayload.Replace(@"\r\n", @"\n", StringComparison.Ordinal); return(schemaPayload); }
private void ApplyOpenApiBodyParameterAttribute(OpenApiOperationDescription operationDescription, MethodInfo methodInfo) { dynamic bodyParameterAttribute = methodInfo.GetCustomAttributes() .FirstAssignableToTypeNameOrDefault("OpenApiBodyParameterAttribute", TypeNameStyle.Name); if (bodyParameterAttribute != null) { if (operationDescription.Operation.RequestBody == null) { operationDescription.Operation.RequestBody = new OpenApiRequestBody(); } operationDescription.Operation.RequestBody.Content[bodyParameterAttribute.MimeType] = new OpenApiMediaType { Schema = bodyParameterAttribute.MimeType == "application/json" ? JsonSchema.CreateAnySchema() : new JsonSchema { Type = JsonObjectType.File } }; } }