public List <OperationTemplateRepresentation> CreateRepresentations(IDictionary <string, OpenApiMediaType> content)
        {
            List <OperationTemplateRepresentation> representations = new List <OperationTemplateRepresentation>();

            foreach (KeyValuePair <string, OpenApiMediaType> pair in content)
            {
                // use representation examples to create values and default value
                OpenApiParameterHeaderIntersection param = new OpenApiParameterHeaderIntersection()
                {
                    Example  = pair.Value.Example,
                    Examples = pair.Value.Examples
                };
                OperationTemplateRepresentation representation = new OperationTemplateRepresentation()
                {
                    contentType = pair.Key,
                    sample      = JsonConvert.SerializeObject(CreateParameterDefaultValue(param)),
                    // schema has not yet been created, id is null
                    schemaId       = null,
                    typeName       = pair.Value.Schema != null ? pair.Value.Schema.Type : null,
                    formParameters = null
                };
                // if content type is neither application/x-www-form-urlencoded or multipart/form-data form parameters are null
                if (pair.Value.Schema != null && (pair.Key == "application/x-www-form-urlencoded" || pair.Key == "multipart/form-data"))
                {
                    representation.formParameters = CreateFormParameters(pair.Value.Schema).ToArray();
                }
                ;
                representations.Add(representation);
            }
            return(representations);
        }
        public List <OperationTemplateParameter> CreateTemplateParameters(IList <OpenApiParameter> parameters)
        {
            List <OperationTemplateParameter> templateParameters = new List <OperationTemplateParameter>();

            foreach (OpenApiParameter parameter in parameters)
            {
                // use parameter examples to create values and default value
                OpenApiParameterHeaderIntersection param = new OpenApiParameterHeaderIntersection()
                {
                    Example  = parameter.Example,
                    Examples = parameter.Examples
                };
                OperationTemplateParameter templateParameter = new OperationTemplateParameter()
                {
                    name         = parameter.Name,
                    description  = parameter.Description,
                    type         = parameter.Schema.Type,
                    required     = parameter.Required,
                    values       = CreateParameterValues(param).ToArray(),
                    defaultValue = CreateParameterDefaultValue(param)
                };
                templateParameters.Add(templateParameter);
            }
            return(templateParameters);
        }
        public List <OperationTemplateParameter> CreateResponseHeaders(IDictionary <string, OpenApiHeader> headerPairs)
        {
            List <OperationTemplateParameter> headers = new List <OperationTemplateParameter>();

            foreach (KeyValuePair <string, OpenApiHeader> pair in headerPairs)
            {
                // use header examples to create values and default value
                OpenApiParameterHeaderIntersection param = new OpenApiParameterHeaderIntersection()
                {
                    Example  = pair.Value.Example,
                    Examples = pair.Value.Examples
                };
                OperationTemplateParameter headerTemplate = new OperationTemplateParameter()
                {
                    name         = pair.Key,
                    description  = pair.Value.Description,
                    type         = pair.Value.Schema.Type,
                    required     = pair.Value.Required,
                    values       = CreateParameterValues(param).ToArray(),
                    defaultValue = CreateParameterDefaultValue(param)
                };
                headers.Add(headerTemplate);
            }
            ;
            return(headers);
        }
        public List <string> CreateParameterValues(OpenApiParameterHeaderIntersection parameter)
        {
            List <string> values = new List <string>();

            if (parameter.Example != null)
            {
                // add example property to values
                values.Add(JsonConvert.SerializeObject(parameter.Example));
            }
            foreach (KeyValuePair <string, OpenApiExample> example in parameter.Examples)
            {
                // add each example in examples list property to values
                values.Add(JsonConvert.SerializeObject(example.Value));
            }
            return(values);
        }
 public string CreateParameterDefaultValue(OpenApiParameterHeaderIntersection parameter)
 {
     if (parameter.Example != null)
     {
         // use example property for default value if given
         return(JsonConvert.SerializeObject(parameter.Example));
     }
     else if (parameter.Examples != null)
     {
         // use first example in examples list property for default value if example property is not given
         return(JsonConvert.SerializeObject(parameter.Examples.SingleOrDefault().Value));
     }
     else
     {
         return(null);
     }
 }