Example #1
0
        private void MapRequestBodies(OpenApiModel.OpenApiModelBuilder openApiModelBuilder,
                                      Dictionary <string, Request> versionedBodies)
        {
            foreach (var(path, requestBody) in versionedBodies)
            {
                var isRequired = requestBody.Required ?? false;
                var schemas    = new Dictionary <string, ISchema>();

                if (requestBody.Content != null)
                {
                    foreach (var(type, mediaType) in requestBody.Content)
                    {
                        var schemaPath = mediaType.Schema.GetRef() ?? $"{path}/content/{type}/schema";
                        var schema     = openApiModelBuilder.GetSchemaForPath(schemaPath);

                        if (schema == null)
                        {
                            throw new ArgumentException(
                                      $"Couldn't create request body - missing schema {schemaPath}. Pleas validate them earlier.");
                        }

                        schemas.Add(type, schema);
                    }
                }

                openApiModelBuilder.AttachRequestBody(path, new RequestBody(schemas, isRequired));
            }
        }