Esempio n. 1
0
 private IEnumerable <Parameter> SelectParameterByLocation(OpenApiEndpointModel parentEndpoint,
                                                           ParameterIn paramIn)
 {
     return(parentEndpoint.Parameters?
            .Where(p => p.In == paramIn)
            .Select(p => new Parameter()
     {
         Name = p.Name,
         Required = p.Required,
         Type = _primitiveService.GetType(p.Schema,
                                          parentEndpoint.ShortName + p.Name)
     }));
 }
        public Type GetType(IOpenApiObjectToTypeService objectService,
                            IObjectsProcessingKeyStore objectKeyStore,
                            IOpenApiType openApiType,
                            IDictionary <string, IOpenApiType> definitions,
                            string suggestedObjectName = null)
        {
            if (openApiType is OpenApiPrimitiveType)
            {
                return(_primitiveService.GetType((OpenApiPrimitiveType)openApiType,
                                                 nameIfEnum: suggestedObjectName));
            }

            if (openApiType.Matches <OpenApiReferencedType>())
            {
                return(_referenceService.GetType(objectService,
                                                 typeResolver: this,
                                                 objectKeyStore,
                                                 (OpenApiReferencedType)openApiType,
                                                 definitions));
            }

            if (openApiType.Matches <OpenApiObjectType>())
            {
                return(objectService.GetType((OpenApiObjectType)openApiType,
                                             definitions,
                                             suggestedObjectName,
                                             objectKeyStore));
            }

            if (openApiType.Matches <OpenApiArrayType>())
            {
                var memberType      = ((OpenApiArrayType)openApiType).Items;
                var arrayMemberType = GetType(objectService,
                                              objectKeyStore,
                                              memberType,
                                              definitions,
                                              suggestedObjectName + "Member");

                return(typeof(IEnumerable <>).MakeGenericType(arrayMemberType));
            }

            throw new NotSupportedException($"Unable to convert unsupported " +
                                            $"OpenApi Type {openApiType.GetType()}");
        }