public ClientGeneratorModel BuildModel() { warnings = new Dictionary <string, string>(); classesNames = new Collection <string>(); classes = new Collection <ClassObject>(); classesObjectsRegistry = new Dictionary <string, ClassObject>(); uriParameterObjects = new Dictionary <string, ApiObject>(); schemaRequestObjects = GetRequestObjects(); schemaResponseObjects = GetResponseObjects(); CleanProperties(schemaRequestObjects); CleanProperties(schemaResponseObjects); var parentClass = new ClassObject { Name = rootClassName, Description = "Main class for grouping root resources. Nested resources are defined as properties. The constructor can optionally receive an URL and HttpClient instance to override the default ones." }; classesNames.Add(parentClass.Name); classes.Add(parentClass); classesObjectsRegistry.Add(rootClassName, parentClass); var classObjects = GetClasses(raml.Resources, null, parentClass, null); SetClassesProperties(classesObjectsRegistry[rootClassName]); var apiRequestObjects = apiRequestGenerator.Generate(classObjects); var apiResponseObjects = apiResponseGenerator.Generate(classObjects); return(new ClientGeneratorModel { Namespace = NetNamingMapper.GetNamespace(raml.Title), RequestObjects = schemaRequestObjects, ResponseObjects = schemaResponseObjects, QueryObjects = queryObjects, HeaderObjects = headerObjects, ApiRequestObjects = apiRequestObjects, ApiResponseObjects = apiResponseObjects, ResponseHeaderObjects = responseHeadersObjects, BaseUriParameters = ParametersMapper.Map(raml.BaseUriParameters), BaseUri = raml.BaseUri, Security = SecurityParser.GetSecurity(raml), Version = raml.Version, Warnings = warnings, Classes = classObjects.Where(c => c.Name != rootClassName).ToArray(), Root = classObjects.First(c => c.Name == rootClassName), UriParameterObjects = uriParameterObjects }); }
public void should_map_paremeters() { var dynRaml = new Dictionary <string, object>(); dynRaml.Add("type", "string"); dynRaml.Add("displayName", "ParameterName"); dynRaml.Add("description", "this is the description"); var parameters = new Dictionary <string, Parameter> { { "one", new ParameterBuilder().Build(dynRaml) } }; var generatorParameters = ParametersMapper.Map(parameters); Assert.AreEqual(parameters.Count, generatorParameters.Count()); Assert.AreEqual(parameters.First().Value.Type, generatorParameters.First().Type); Assert.AreEqual("one", generatorParameters.First().Name); Assert.AreEqual(parameters.First().Value.Description, generatorParameters.First().Description); }
public ClientGeneratorModel BuildModel() { warnings = new Dictionary <string, string>(); classesNames = new Collection <string>(); classes = new Collection <ClassObject>(); classesObjectsRegistry = new Dictionary <string, ClassObject>(); uriParameterObjects = new Dictionary <string, ApiObject>(); enums = new Dictionary <string, ApiEnum>(); //new RamlTypeParser(raml.Shapes, schemaObjects, ns, enums, warnings).Parse(); ParseSchemas(); schemaRequestObjects = GetRequestObjects(); schemaResponseObjects = GetResponseObjects(); FixEnumNamesClashing(); //FixTypes(schemaObjects.Values); //FixTypes(schemaRequestObjects.Values); //FixTypes(schemaResponseObjects.Values); ReconstructInheritance(); CleanProperties(schemaObjects); CleanProperties(schemaRequestObjects); CleanProperties(schemaResponseObjects); HandleScalarTypes(); clientMethodsGenerator = new ClientMethodsGenerator(raml, schemaResponseObjects, uriParameterObjects, queryObjects, headerObjects, responseHeadersObjects, schemaRequestObjects, linkKeysWithObjectNames, schemaObjects, enums); var parentClass = new ClassObject { Name = rootClassName, Description = "Main class for grouping root resources. Nested resources are defined as properties. The constructor can optionally receive an URL and HttpClient instance to override the default ones." }; classesNames.Add(parentClass.Name); classes.Add(parentClass); classesObjectsRegistry.Add(rootClassName, parentClass); var classObjects = GetClasses(raml.WebApi.EndPoints, null, parentClass, null, new Dictionary <string, Parameter>()); SetClassesProperties(classesObjectsRegistry[rootClassName]); var apiRequestObjects = apiRequestGenerator.Generate(classObjects); var apiResponseObjects = apiResponseGenerator.Generate(classObjects); //apiObjectsCleaner = new ApiObjectsCleaner(schemaRequestObjects, schemaResponseObjects, schemaObjects); uriParametersGenerator = new UriParametersGenerator(schemaObjects); //CleanNotUsedObjects(classObjects); return(new ClientGeneratorModel { BaseNamespace = baseNamespace, ModelsNamespace = modelsNamespace, SchemaObjects = schemaObjects, RequestObjects = schemaRequestObjects, ResponseObjects = schemaResponseObjects, QueryObjects = queryObjects, HeaderObjects = headerObjects, ApiRequestObjects = apiRequestObjects.ToArray(), ApiResponseObjects = apiResponseObjects.ToArray(), ResponseHeaderObjects = responseHeadersObjects, BaseUriParameters = ParametersMapper.Map(raml.WebApi.BaseUriParameters).ToArray(), BaseUri = raml.WebApi.Servers.Any() ? raml.WebApi.Servers.First() : null, Security = SecurityParser.GetSecurity(raml.WebApi), Version = raml.WebApi.Version, Warnings = warnings, Classes = classObjects.Where(c => c.Name != rootClassName).ToArray(), Root = classObjects.First(c => c.Name == rootClassName), UriParameterObjects = uriParameterObjects, Enums = Enums.ToArray() }); }