index.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. const header = document.querySelector("header");
  2. const container = document.getElementById("container");
  3. const createHeaderItem =(type, title, id)=>{
  4. const anc = document.createElement("a");
  5. anc.href = `#${id}`;
  6. anc.textContent = title;
  7. switch(type){
  8. case "object": anc.classList.add("headMain"); break;
  9. case "route": anc.classList.add("headSub"); break;
  10. }
  11. return anc;
  12. }
  13. const createItem = (data)=>{
  14. const article = document.createElement("article");
  15. article.id = data.id;
  16. const title = document.createElement("h1");
  17. title.textContent = data.title;
  18. article.appendChild(title);
  19. if(data.type === "route"){
  20. const route = document.createElement("p");
  21. route.classList.add("url");
  22. route.textContent = data.url;
  23. article.appendChild(route);
  24. }
  25. if(data.auth){
  26. const auth = document.createElement("p");
  27. auth.textContent = "Auth required";
  28. article.appendChild(auth);
  29. }
  30. const description = document.createElement("p");
  31. description.classList.add("description");
  32. description.textContent = data.description;
  33. article.appendChild(description);
  34. if(data.properties){
  35. const subTitle = document.createElement("h3");
  36. subTitle.textContent = "Properties";
  37. article.appendChild(subTitle);
  38. for(let i = 0; i < data.properties.length; i++){
  39. article.appendChild(createProp(data.properties[i]));
  40. }
  41. }
  42. if(data.requestBody){
  43. const subTitle = document.createElement("h3");
  44. subTitle.textContent = "Request Body";
  45. article.appendChild(subTitle);
  46. for(let i = 0; i < data.requestBody.length; i++){
  47. article.appendChild(createProp(data.requestBody[i]))
  48. }
  49. }
  50. if(data.responseBody){
  51. const subTitle = document.createElement("h3");
  52. subTitle.textContent = "Response Body";
  53. article.appendChild(subTitle);
  54. for(let i = 0; i < data.responseBody.length; i++){
  55. article.appendChild(createProp(data.responseBody[i]))
  56. }
  57. }
  58. if(data.queries){
  59. const subTitle = document.createElement("h3");
  60. subTitle.textContent = "Query Parameters";
  61. article.appendChild(subTitle);
  62. for(let i = 0; i < data.queries.length; i++){
  63. article.appendChild(createProp(data.queries[i]))
  64. }
  65. }
  66. return article;
  67. }
  68. const createProp = (propData)=>{
  69. const propContainer = document.createElement("div");
  70. propContainer.classList.add("prop");
  71. const name = document.createElement("p");
  72. name.classList.add("name");
  73. name.textContent = propData.name;
  74. propContainer.appendChild(name);
  75. const type = document.createElement("p");
  76. type.classList.add("type");
  77. type.textContent = propData.type;
  78. propContainer.appendChild(type);
  79. const desc = document.createElement("p");
  80. desc.classList.add("propDesc");
  81. desc.textContent = propData.desc;
  82. propContainer.appendChild(desc);
  83. if(propData.options){
  84. const ul = document.createElement("ul");
  85. propContainer.appendChild(ul);
  86. const title = document.createElement("li");
  87. title.textContent = "Options";
  88. title.classList.add("ulTitle");
  89. ul.appendChild(title)
  90. for(let i = 0; i < propData.options.length; i++){
  91. const li = document.createElement("li");
  92. li.textContent = propData.options[i];
  93. ul.appendChild(li);
  94. }
  95. }
  96. return propContainer;
  97. }
  98. for(let i = 0; i < data.length; i++){
  99. header.appendChild(createHeaderItem(data[i].type, data[i].title, data[i].id));
  100. container.appendChild(createItem(data[i]));
  101. }