Beispiel #1
0
        /// <summary>
        /// Field responses in components
        /// The value of responses is a map of Response Objects.
        /// It contains one name/value pair for the standard OData error response
        /// that is referenced from all operations of the service.
        /// </summary>
        /// <param name="context">The OData context.</param>
        /// <returns>The name/value pairs for the standard OData error response.</returns>
        public static IDictionary <string, OpenApiResponse> CreateResponses(this ODataContext context)
        {
            Utils.CheckArgumentNull(context, nameof(context));

            var responses = new Dictionary <string, OpenApiResponse>
            {
                { "error", context.CreateErrorResponse() }
            };

            if (context.Settings.EnableDollarCountPath)
            {
                responses[Constants.DollarCountSchemaName] = CreateCountResponse();
            }

            responses = responses.Concat(context.GetAllCollectionEntityTypes()
                                         .Select(x => new KeyValuePair <string, OpenApiResponse>(
                                                     $"{(x is IEdmEntityType eType ? eType.FullName() : x.FullTypeName())}{Constants.CollectionSchemaSuffix}",
                                                     CreateCollectionResponse(x)))
                                         .Where(x => !responses.ContainsKey(x.Key)))
                        .Concat(context.GetAllCollectionComplexTypes()
                                .Select(x => new KeyValuePair <string, OpenApiResponse>(
                                            $"{x.FullTypeName()}{Constants.CollectionSchemaSuffix}",
                                            CreateCollectionResponse(x)))
                                .Where(x => !responses.ContainsKey(x.Key)))
                        .ToDictionary(x => x.Key, x => x.Value);

            if (context.HasAnyNonContainedCollections())
            {
                responses[$"String{Constants.CollectionSchemaSuffix}"] = CreateCollectionResponse("String");
            }

            return(responses);
        }