|
| 1 | +<div align="center"> |
| 2 | +<a href="https://onix-systems.com/"> |
| 3 | + <img alt="refine logo" src="../../../images/banner_top.jpg"> |
| 4 | +</a> |
| 5 | + |
| 6 | +<br/> |
| 7 | +<br/> |
| 8 | +</div> |
| 9 | + |
| 10 | +# Swagger data components generation |
| 11 | + |
| 12 | +Swagger data components generation designed to create a data layer in the Generated project based on the Swagger JSON. |
| 13 | + |
| 14 | +The data layer consist of data models, entities, mappers, sources and repositories. |
| 15 | + |
| 16 | +The data components generation splited into two steps: parsing and generation. |
| 17 | + |
| 18 | +## Parsing |
| 19 | + |
| 20 | +When user enter Swagger URL in the UI and press the Continue button, components will be parsed. |
| 21 | + |
| 22 | +Once Swagger JSON has fetched parsing starts in `swagger_remote_source.dart`. Components will be parsed depending on the Swagger version. |
| 23 | + |
| 24 | +Each data model have corresponding to version parser function. (`fromJsonV2` and `fromJsonV3`). |
| 25 | + |
| 26 | +General parsing flow looks like: |
| 27 | + |
| 28 | +```mermaid |
| 29 | +flowchart TD |
| 30 | +A[Get Swagger JSON] --> B[Parse Swagger version]; |
| 31 | +B --> C{Has tags in JSON?} |
| 32 | +C -->|Yes| D[Parse Swagger Tags] |
| 33 | +C -->|No| ERR[Return Empty Result] |
| 34 | +D --> E{Has Paths in JSON?} |
| 35 | +E -->|Yes| F{Check version} |
| 36 | +E -->|No| ERR[Return Empty Result] |
| 37 | +F -->|V2| G[Parse Paths with V2 parser] |
| 38 | +F -->|V3+| H[Parse Paths with V3 parser] |
| 39 | +F -->|Other version| ERR |
| 40 | +G ----> J{Check version} |
| 41 | +H ----> J |
| 42 | +J -->|V2| K{Has defintions in JSON?} |
| 43 | +J -->|V3| L{Has components in JSON?} |
| 44 | +K -->|Yes| M[Parse definitions with V2 parser] |
| 45 | +K -->|No| ERR |
| 46 | +L -->|Yes| N[Parse coomponents with V3 parser] |
| 47 | +L -->|No| ERR |
| 48 | +M ----> O[Return parsed result] |
| 49 | +N ----> O[Return parsed result] |
| 50 | +``` |
| 51 | + |
| 52 | +Once components are parsed they will be stored in `SwaggerRepository`. |
| 53 | + |
| 54 | +## Generation |
| 55 | + |
| 56 | +Generation step starts if components were parsed sucessfully and stored in `SwaggerRepository `. |
| 57 | + |
| 58 | +Generation process begins in `ComponentGeneratorService` and consist wth 4 main generation steps: |
| 59 | + |
| 60 | +* Create enums |
| 61 | +* Create data objects |
| 62 | +* Create entities |
| 63 | +* Create sources and repositories |
| 64 | + |
| 65 | +```mermaid |
| 66 | +flowchart TD |
| 67 | +A[Begin] --> B[Create enums] |
| 68 | +B ----> C[Get components source item] |
| 69 | +C ----> L[Find data objects used in sources] |
| 70 | +L -----> D[Create data objects] |
| 71 | +D -----> E[Create entities for all created data objects] |
| 72 | +E -----> F[Create source and repo] |
| 73 | +F ----> G{Has next component source?} |
| 74 | +G -->|Yes| C |
| 75 | +G -->|No| J[End] |
| 76 | +``` |
| 77 | + |
| 78 | +### Create enums |
| 79 | + |
| 80 | + |
| 81 | +```mermaid |
| 82 | +flowchart TD |
| 83 | +A[Search for Enums in every component variable] --> B[Add to Enums to generate list]; |
| 84 | +B ----> C[Get Enum item from list] |
| 85 | +C ----> D[Get Enum file path] |
| 86 | +D ----> E[Get Enum file body] |
| 87 | +E --> G{Enum file already exist?} |
| 88 | +G -->|Yes| J{Has next enum item?} |
| 89 | +G -->|No| F[Create Enum file] |
| 90 | +F ----> J |
| 91 | +J -->|Yes| C |
| 92 | +J -->|No| H[End] |
| 93 | +``` |
| 94 | + |
| 95 | +### Create data objects |
| 96 | + |
| 97 | +```mermaid |
| 98 | +flowchart TD |
| 99 | +A[Start with input references] --> CYCLE[Get component reference item] |
| 100 | +CYCLE --> A1[Find reference data object] |
| 101 | +A1 ----> DO{Is data object not null?} |
| 102 | +DO -->|Yes| A2[Get object file path] |
| 103 | +DO -->|No| CYCLEEND |
| 104 | +A2 ----> A3[Create folders] |
| 105 | +A3 ----> A4[Get object file body] |
| 106 | +A4 ----> CF{Is fie exist?} |
| 107 | +CF -->|Yes| A5[Create object file] |
| 108 | +A5 ----> A6[Get Data object inner references] |
| 109 | +A6 ----> A7{Has inner references?} |
| 110 | +A7 -->|Yes| A |
| 111 | +A7 -->|No| CYCLEEND{Has next reference?} |
| 112 | +CF -->|No| CYCLEEND |
| 113 | +CYCLEEND -->|Yes| CYCLE |
| 114 | +CYCLEEND -->|No| END[End] |
| 115 | +``` |
| 116 | + |
| 117 | +### Create entities |
| 118 | + |
| 119 | +```mermaid |
| 120 | +flowchart TD |
| 121 | +A[Start with created data objects] --> CYCLE[Get created object] |
| 122 | +CYCLE --> A1[Get entity folder] |
| 123 | +A1 ----> A2[Create entity folder] |
| 124 | +A2 ----> A3[Get entity file path] |
| 125 | +A3 ----> CF{Entity file exist?} |
| 126 | +CF -->|Yes| A5 |
| 127 | +CF -->|No| A4[Create entity file] |
| 128 | +A4 --> A5[Get entity mapper folder] |
| 129 | +A5 ----> A6[Create entity mapper folder] |
| 130 | +A6 ----> A7[Get entity mapper file path] |
| 131 | +A7 ----> RR{Need mapper for Request or Response?} |
| 132 | +RR -->|Yes| CF2{Entity mapper file exist?} |
| 133 | +CF2 -->|Yes| CYCLEEND{Has next object?} |
| 134 | +CF2 -->|No| A8[Create entity mapper file] |
| 135 | +A8 ----> CYCLEEND |
| 136 | +CYCLEEND -->|Yes| CYCLE |
| 137 | +CYCLEEND -->|No| END[End] |
| 138 | +``` |
| 139 | + |
| 140 | +### Create sources and repositories |
| 141 | + |
| 142 | +```mermaid |
| 143 | +flowchart TD |
| 144 | +A[Begin] --> A1[Get source folder path] |
| 145 | +A1 ----> A2[Create source folder] |
| 146 | +A2 ----> A3[Get source declaration file path] |
| 147 | +A3 ----> CF1{Source declaration file exist?} |
| 148 | +CF1 -->|Yes| A5 |
| 149 | +CF1 -->|No| A4[Create source declaration file] |
| 150 | +A4 ----> A5[Get source impl file path] |
| 151 | +A5 ----> CF2{Source impl file exist?} |
| 152 | +CF2 -->|Yes| A7[Inject sources SL declarations] |
| 153 | +CF2 -->|No| A6[Create source impl file] |
| 154 | +A6 ----> A7 |
| 155 | +A7 ----> A8[Get repo declaration folder] |
| 156 | +A8 ----> A9[Create repo declaration folder] |
| 157 | +A9 ----> A10[Get repo declaration file path] |
| 158 | +A10 ----> CF3{Repo declaration file exist?} |
| 159 | +CF3 -->|Yes| A12[Get repo impl folder] |
| 160 | +CF3 -->|No| A11[Create repo declaration file] |
| 161 | +A11 ----> A12 |
| 162 | +A12 ----> A13[Create repo impl folder] |
| 163 | +A13 ----> A14[Get repo impl file path] |
| 164 | +A14 ----> CF4{Repo impl file exist?} |
| 165 | +CF4 -->|Yes| A16[Inject repos SL declarations] |
| 166 | +CF4 -->|No| A15[Create repo impl file] |
| 167 | +A15 ----> A16 |
| 168 | +A16 ----> A17[End] |
| 169 | +``` |
| 170 | + |
0 commit comments