swaggular 0.6.1 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # Swaggular
2
2
 
3
3
  A powerful tool to generate Angular services and models from Swagger/OpenAPI specifications.
4
- Note: Currently, it does not detects generic types or common interfaces. If you want a more
5
- customized version, please download the project in github and modify the templates folder.
4
+
5
+ You can create a configuration file to customize the generation process.
6
+
7
+ If you want a more customized version, you are invited to download the project in github and modify the project.
6
8
 
7
9
  ## Features
8
10
 
@@ -40,15 +42,71 @@ Run the generator by providing the path to your Swagger/OpenAPI file:
40
42
  swaggular --input=path/to/your/swagger.json
41
43
  ```
42
44
 
43
- #### Options
45
+ ## Configuration
46
+
47
+ You can configure Swaggular using CLI arguments or a configuration file (e.g., `swaggular.config.json`).
48
+
49
+ ### CLI Arguments (`ArgsVariables`)
50
+
51
+ | Argument | Description | Default |
52
+ | :--- | :--- | :--- |
53
+ | `--input`, `-i` | Path to the Swagger/OpenAPI file or URL. | `swagger.json` |
54
+ | `--output`, `-o` | Output directory for generated files. | `results` |
55
+ | `--mode` | Grouping mode for services: `tags` or `path`. | `path` |
56
+ | `--ignore-segments` | Comma-separated list of URL segments to ignore when generating service names. | `api` |
57
+ | `--no-generate` | Parse the Swagger file but do not generate any output files. useful for testing. | `false` |
58
+ | `--config` | Path to a configuration file. | `swaggular.config.json` (if exists) |
59
+
60
+ ### Configuration File (`SwaggularConfig`)
61
+
62
+ You can create a `swaggular.config.json` file in your project root to define advanced configurations, such as custom templates, base classes for DTOs, or generic types.
63
+
64
+ #### Example `swaggular.config.json`
65
+
66
+ ```json
67
+ {
68
+ "input": "swagger.json",
69
+ "output": "src/app/api",
70
+ "groupingMode": "tags",
71
+ "segmentsToIgnore": ["api", "v1"],
72
+ "types": {
73
+ "extendsFrom": [
74
+ {
75
+ "name": "PagedRequestDto",
76
+ "type": "interface",
77
+ "properties": [
78
+ { "name": "skipCount", "type": "number", "optional": true, "comments": "" },
79
+ { "name": "maxResultCount", "type": "number", "optional": true, "comments": "" }
80
+ ],
81
+ "imports": []
82
+ }
83
+ ],
84
+ "generic": [
85
+ {
86
+ "name": "PagedResultDto",
87
+ "type": "interface",
88
+ "properties": [
89
+ { "name": "items", "type": "T[]", "optional": true, "comments": "" },
90
+ { "name": "totalCount", "type": "number", "optional": true, "comments": "" }
91
+ ],
92
+ "imports": []
93
+ }
94
+ ]
95
+ },
96
+ "templates": {
97
+ "service": {
98
+ "httpParamsHandlerImport": "import { HttpHelper } from '@shared/utils/http-helper';",
99
+ "httpParamsHandler": "const params = HttpHelper.toHttpParams(${params} || {});"
100
+ }
101
+ }
102
+ }
103
+ ```
44
104
 
45
- - `--input`: Path to the swagger.json file (required).
46
- - `--ignore-segments`: Path segments to ignore when generating service names. (comma separated)
47
- - `--mode`: Grouping mode. (tags or path) Default: path
48
- - `--no-generate`: Parse the file but don't generate the output. (For testing purposes)
49
- - `--output`: Path to the output folder. Default: results
105
+ This configuration allows you to:
50
106
 
51
- The generated files will be available in the `results` folder.
107
+ 1. **extendsFrom**: Automatically make generated DTOs extend a base class (e.g., `PagedRequestDto`) if they share the same properties.
108
+ 2. **generic**: Automatically detect and use generic types (e.g., `PagedResultDto<T>`) instead of generating duplicate classes like `PagedResultDtoOfUser`.
109
+ 3. **templates.service.options**: Customize how HTTP parameters are handled in generated services, allowing you to use your own helper functions.
52
110
 
53
111
  ## Development
54
112
 
@@ -68,8 +126,8 @@ Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduc
68
126
  ### 🚀 Roadmap
69
127
 
70
128
  - [ ] Add TSDoc comments
71
- - [ ] Add function to identify common properties and generate interfaces
72
- - [ ] Add function to generate interfaces and services for just one path
129
+ - [ ] Add function to identify common properties and generate interfaces without any configuration
130
+ - [ ] Add function to generate interfaces and services for just one specific path
73
131
 
74
132
  ## License
75
133
 
@@ -9,10 +9,6 @@ export interface SwaggularConfig {
9
9
  service?: {
10
10
  path: string;
11
11
  options?: Partial<ServiceTemplateParams>;
12
- transform?: (options: ServiceTemplateParams) => string;
13
- content?: string;
14
- httpParamsHandler?: string;
15
- httpParamsHandlerImport?: string;
16
12
  };
17
13
  };
18
14
  input?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swaggular",
3
- "version": "0.6.1",
3
+ "version": "1.0.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "bin": {