Ejemplo n.º 1
0
        public IEnumerable <ICSharpType> Generate(EntryEndpoint endpoint)
        {
            var types = new List <ICSharpType>();

            types.AddRange(Generate("entry", endpoint).types);
            return(types);
        }
        /// <summary>
        /// Generates an <see cref="EntryEndpoint"/> with children by matching patterns in the OpenAPI Spec document.
        /// </summary>
        /// <param name="document">The document to check for patterns.</param>
        /// <param name="patterns">An ordered list of all known <see cref="IPattern"/>s; leave <c>null</c> for default.</param>
        public static EntryEndpoint MatchTypedRestPatterns(this OpenApiDocument document, PatternRegistry?patterns = null)
        {
            var matcher = new PatternMatcher(patterns ?? PatternRegistry.Default);

            var entryEndpoint = new EntryEndpoint();

            entryEndpoint.Children.AddRange(matcher.GetEndpoints(PathTree.From(document.Paths ?? new OpenApiPaths())));

            return(entryEndpoint);
        }
        /// <summary>
        /// Registers the TypedRest OpenAPI extension parser.
        /// </summary>
        /// <param name="settings">The settings to register the extension parser in.</param>
        /// <param name="endpointRegistry">A list of all known <see cref="IEndpoint"/> kinds; leave <c>null</c> for default.</param>
        /// <seealso cref="OpenApiDocumentExtensions.GetTypedRest"/>
        public static OpenApiReaderSettings AddTypedRest(this OpenApiReaderSettings settings, EndpointRegistry?endpointRegistry = null)
        {
            var parser = new EndpointParser(endpointRegistry ?? EndpointRegistry.Default);

            settings.ExtensionParsers.Add(OpenApiDocumentExtensions.TypedRestKey, (data, _) =>
            {
                if (!(data is OpenApiObject objData))
                {
                    throw new FormatException($"{OpenApiDocumentExtensions.TypedRestKey} is not an object.");
                }

                var entryEndpoint = new EntryEndpoint();
                entryEndpoint.Parse(objData, parser);
                return(entryEndpoint);
            });
 /// <summary>
 /// Adds the <paramref name="endpoint"/> as a TypedRest extension to the OpenAPI Spec <paramref name="document"/>.
 /// </summary>
 public static OpenApiDocument SetTypedRest(this OpenApiDocument document, EntryEndpoint endpoint)
 {
     document.Extensions[TypedRestKey] = endpoint;
     return(document);
 }