Пример #1
0
        /// <summary>
        /// Creates a new swagger parameter
        /// </summary>
        public SwaggerParameter(MethodInfo method, ParameterInfo parameter, RestInvokeAttribute operation)
        {
            this.Name        = parameter.Name;
            this.Location    = operation.UriTemplate.Contains($"{{{parameter.Name}}}") ? SwaggerParameterLocation.path : SwaggerParameterLocation.body;
            this.Description = MetadataComposerUtil.GetElementDocumentation(method, parameter);

            SwaggerSchemaElementType type = SwaggerSchemaElementType.@string;

            if (parameter.ParameterType.StripNullable().IsEnum)
            {
                this.Enum = parameter.ParameterType.StripNullable().GetFields().Select(f => f.GetCustomAttributes <XmlEnumAttribute>().FirstOrDefault()?.Name).Where(o => !string.IsNullOrEmpty(o)).ToList();
                this.Type = SwaggerSchemaElementType.@string;
            }
            else if (!m_typeMap.TryGetValue(parameter.ParameterType, out type))
            {
                this.Schema = new SwaggerSchemaDefinition()
                {
                    Reference = $"#/definitions/{MetadataComposerUtil.CreateSchemaReference(parameter.ParameterType)}",
                    NetType   = parameter.ParameterType
                };
            }
            else
            {
                this.Type = type;
            }
        }
Пример #2
0
 /// <summary>
 /// Operation description
 /// </summary>
 public OperationDescription(ContractDescription contract, MethodInfo operationMethod, RestInvokeAttribute restAttribute)
 {
     this.m_traceSource.TraceEvent(TraceEventType.Verbose, 0, "Enter OperationDescription CTOR ({0})", operationMethod);
     this.InvokeMethod = operationMethod;
     this.Method       = restAttribute.Method;
     this.UriTemplate  = restAttribute.UriTemplate;
     this.Contract     = contract;
 }