コード例 #1
0
        public void GenerateOperationSpecWithDifferentRequestContentTypeThanCodeModel()
        {
            CodeModelTS codeModel = Models.CodeModel();

            Models.Method(codeModel: codeModel, requestContentType: "application/json");
            MethodTS method = Models.Method(codeModel: codeModel, requestContentType: "blah");

            Assert.AreNotEqual(method.RequestContentType, codeModel.RequestContentType);

            TSBuilder builder = GenerateOperationSpec(method);

            AssertEx.EqualLines(
                new[]
            {
                "{",
                "  httpMethod: \"GET\",",
                "  contentType: \"blah\",",
                "  responses: {",
                "    default: {}",
                "  },",
                "  serializer",
                "}"
            },
                builder);
        }
コード例 #2
0
        public void GenerateOperationSpecWithFormDataParameterAndDifferentRequestContentTypeThanCodeModel()
        {
            CodeModelTS codeModel = Models.CodeModel();

            Models.Method(codeModel: codeModel, requestContentType: "application/json");
            MethodTS method = Models.Method(
                codeModel: codeModel,
                requestContentType: "fake-content-type",
                parameters: new[] { Models.Parameter(name: "fakeParameterName", location: ParameterLocation.FormData) });

            TSBuilder builder = GenerateOperationSpec(method);

            AssertEx.EqualLines(
                new[]
            {
                "{",
                "  httpMethod: \"GET\",",
                "  formDataParameters: [",
                "    Parameters.fakeParameterName",
                "  ],",
                "  contentType: \"fake-content-type\",",
                "  responses: {",
                "    default: {}",
                "  },",
                "  serializer",
                "}"
            },
                builder);
        }
コード例 #3
0
        public void GenerateOperationSpecWithHeaderParameter()
        {
            CodeModelTS codeModel = Models.CodeModel();
            MethodTS    method    = Models.Method(
                codeModel: codeModel,
                requestContentType: "fake-content-type",
                parameters: new[] { Models.Parameter(name: "fakeParameterName", location: ParameterLocation.Header) });

            TSBuilder builder = GenerateOperationSpec(method);

            AssertEx.EqualLines(
                new[]
            {
                "{",
                "  httpMethod: \"GET\",",
                "  headerParameters: [",
                "    Parameters.fakeParameterName",
                "  ],",
                "  responses: {",
                "    default: {}",
                "  },",
                "  serializer",
                "}"
            },
                builder);
        }
コード例 #4
0
        private static TSBuilder GenerateOperationSpec(MethodTS method)
        {
            TSBuilder builder = new TSBuilder();

            builder.Object(tsObject =>
            {
                method.GenerateOperationSpec(tsObject);
            });
            return(builder);
        }
コード例 #5
0
        public void GenerateOperationSpecWithMinimalPostMethod()
        {
            MethodTS method = Models.Method(httpMethod: HttpMethod.Post);

            TSBuilder builder = GenerateOperationSpec(method);

            AssertEx.EqualLines(
                new[]
            {
                "{",
                "  httpMethod: \"POST\",",
                "  responses: {",
                "    default: {}",
                "  },",
                "  serializer",
                "}"
            },
                builder);
        }
コード例 #6
0
        public ParameterTransformations(IEnumerable <ParameterTransformation> transformations)
        {
            inputParametersInOptions     = new HashSet <string>();
            unflattenedParameterMappings = new Dictionary <string, IDictionary <string, string> >();
            ungroupedParameterMappings   = new Dictionary <string, string[]>();

            foreach (ParameterTransformation transformation in transformations)
            {
                string outputParameterName = transformation.OutputParameter.Name;

                foreach (ParameterMapping mapping in transformation.ParameterMappings)
                {
                    Parameter inputParameter     = mapping.InputParameter;
                    string    inputParameterName = inputParameter.Name;
                    if (MethodTS.IsInOptionsParameter(inputParameter))
                    {
                        inputParametersInOptions.Add(inputParameterName);
                    }

                    if (!string.IsNullOrEmpty(mapping.OutputParameterProperty))
                    {
                        if (!unflattenedParameterMappings.ContainsKey(outputParameterName))
                        {
                            unflattenedParameterMappings.Add(outputParameterName, new Dictionary <string, string>());
                        }
                        IDictionary <string, string> unflattenedParameterPropertyMappings = unflattenedParameterMappings[outputParameterName];

                        unflattenedParameterPropertyMappings.Add(mapping.OutputParameterProperty, inputParameterName);
                    }
                    else
                    {
                        ungroupedParameterMappings.Add(outputParameterName, new string[] { inputParameterName, mapping.InputParameterProperty });
                    }
                }
            }
        }