public void CreateCodeDom(OpenApiComponents components) { if (components == null) { return; } ComponentsSchemas = components.Schemas; //.OrderBy(d => d.Value.Reference != null).OrderBy(k => k.Value.Properties.Count > 0).OrderBy(g => g.Value.AllOf.Count > 0).OrderBy(d => d.Value.Type != "array"); //so simple complex types will be handled first to be referenced by more complex ones. var classNamespaceNames = NameFunc.FindNamespacesInClassNames(ComponentsSchemas.Keys); if (classNamespaceNames.Length > 0) { var groupedComponentsSchemas = ComponentsSchemas .GroupBy(d => NameFunc.GetNamespaceOfClassName(d.Key)) .OrderBy(k => k.Key); var namespacesOfTypes = groupedComponentsSchemas.Select(d => d.Key).ToArray(); foreach (var groupedTypes in groupedComponentsSchemas) { var classNamespaceText = groupedTypes.Key; var classNamespace = new CodeNamespace(classNamespaceText); codeCompileUnit.Namespaces.Add(classNamespace); ClassNamespaces.Add(classNamespace); foreach (var kv in groupedTypes.OrderBy(t => t.Key)) { var existingType = ComponentsHelper.FindTypeDeclarationInNamespace(NameFunc.RefineTypeName(kv.Key, classNamespaceText), classNamespace); if (existingType == null) { AddTypeToCodeDom(kv); } } } } else { foreach (KeyValuePair <string, OpenApiSchema> item in ComponentsSchemas) { var existingType = FindTypeDeclarationInNamespaces(NameFunc.RefineTypeName(item.Key, null), null); if (existingType == null) { AddTypeToCodeDom(item); } } } }
public override CodeTypeDeclaration AddTypeToClassNamespace(string typeName, string ns) { if (String.IsNullOrEmpty(ns)) { return(PodGenHelper.CreatePodClientInterface(ClientNamespace, typeName)); } else { var foundNamespace = ClassNamespaces.Find(d => d.Name == ns); if (foundNamespace == null) { foundNamespace = new CodeNamespace(ns); codeCompileUnit.Namespaces.Add(foundNamespace); ClassNamespaces.Add(foundNamespace); } return(PodGenHelper.CreatePodClientInterface(foundNamespace, typeName)); } }