@mini2/core 1.1.0 β†’ 1.1.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
@@ -756,15 +756,84 @@ const result = sum(5, 3); // 8
756
756
 
757
757
  ### πŸ“– Swagger Integration
758
758
 
759
- Automatic API documentation is generated based on your decorators and DTOs.
759
+ @mini2/core automatically generates comprehensive API documentation using Swagger/OpenAPI 3.0 specification based on your decorators and DTOs.
760
+
761
+ #### **πŸ“ API Documentation Endpoints**
762
+
763
+ When your application starts, Swagger documentation is automatically available at:
764
+
765
+ ```typescript
766
+ // Interactive Swagger UI - Test your API directly in browser
767
+ http://localhost:3000/api-docs
768
+
769
+ // Raw OpenAPI JSON specification - For tools, imports, etc.
770
+ http://localhost:3000/api-docs.json
771
+ ```
772
+
773
+ #### **πŸ”§ Automatic Documentation Features**
774
+
775
+ - **Route Discovery**: All `@controller` and HTTP method decorators are automatically documented
776
+ - **Request/Response Schemas**: DTO classes with `class-validator` decorators generate JSON schemas
777
+ - **Security Requirements**: `@authenticated` and `@authorized` decorators add security info
778
+ - **Parameter Documentation**: Path parameters, query parameters, and request bodies are documented
779
+ - **HTTP Status Codes**: Response codes from `ResponseBuilder` and exceptions are included
780
+
781
+ #### **πŸ“‹ Example Generated Documentation**
782
+
783
+ For this controller:
784
+
785
+ ```typescript
786
+ @controller('/api/users')
787
+ export class UserController {
788
+ @get('/:id')
789
+ @authenticated()
790
+ @authorized(['user:read'])
791
+ @validate({ params: UserParamsDto })
792
+ async getUser(@req() req: Request) {
793
+ const id = req.params.id;
794
+ const user = await this.userService.findById(id);
795
+ return new ResponseBuilder().ok(user);
796
+ }
797
+
798
+ @post('/')
799
+ @validate({ body: CreateUserDto })
800
+ async createUser(@req() req: Request) {
801
+ const userData = req.body;
802
+ const user = await this.userService.create(userData);
803
+ return new ResponseBuilder().created(user);
804
+ }
805
+ }
806
+ ```
807
+
808
+ Swagger will automatically generate:
809
+
810
+ - **GET /api/users/{id}** - Requires authentication and authorization
811
+ - **POST /api/users** - With CreateUserDto schema for request body
812
+ - Parameter definitions, security requirements, and response schemas
813
+
814
+ #### **🎯 DTO-Based Schema Generation**
815
+
816
+ Class-validator decorators automatically create OpenAPI schemas:
760
817
 
761
818
  ```typescript
762
- // Swagger documentation available at:
763
- // http://localhost:3000/api-docs - Swagger UI
764
- // http://localhost:3000/api-docs.json - OpenAPI JSON spec
819
+ export class CreateUserDto {
820
+ @IsEmail()
821
+ email: string;
822
+
823
+ @IsString()
824
+ @MinLength(2)
825
+ name: string;
826
+
827
+ @IsOptional()
828
+ @IsNumber()
829
+ @Min(0)
830
+ age?: number;
831
+ }
765
832
  ```
766
833
 
767
- **Swagger Configuration:**
834
+ #### **βš™οΈ Swagger Configuration**
835
+
836
+ Default configuration is applied automatically, but you can customize it:
768
837
 
769
838
  ```typescript
770
839
  const swaggerOptions = {
@@ -772,11 +841,63 @@ const swaggerOptions = {
772
841
  description: `API documentation for ${config.applicationName}`,
773
842
  version: '1.0.0',
774
843
  servers: [{ url: `http://${config.host}:${config.port}` }],
775
- docsPath: '/api-docs',
776
- jsonPath: '/api-docs.json',
844
+ docsPath: '/api-docs', // Swagger UI endpoint
845
+ jsonPath: '/api-docs.json', // OpenAPI JSON endpoint
846
+ components: {
847
+ securitySchemes: {
848
+ bearerAuth: {
849
+ type: 'http',
850
+ scheme: 'bearer',
851
+ bearerFormat: 'JWT',
852
+ },
853
+ },
854
+ },
777
855
  };
778
856
  ```
779
857
 
858
+ #### **πŸ” Security Documentation**
859
+
860
+ Security decorators automatically add authentication requirements:
861
+
862
+ ```typescript
863
+ @get('/profile')
864
+ @authenticated()
865
+ @authorized(['user:profile'])
866
+ async getProfile(@req() req: Request) {
867
+ // Swagger will show:
868
+ // - πŸ”’ Authentication required
869
+ // - πŸ›‘οΈ Requires 'user:profile' permission
870
+ // - 401 Unauthorized response possible
871
+ // - 403 Forbidden response possible
872
+ }
873
+ ```
874
+
875
+ #### **πŸ“Š Response Documentation**
876
+
877
+ ResponseBuilder methods automatically document response types:
878
+
879
+ ```typescript
880
+ @post('/users')
881
+ async createUser(@req() req: Request) {
882
+ const user = await this.userService.create(req.body);
883
+
884
+ // Swagger documents:
885
+ // - 201 Created status
886
+ // - User object schema in response body
887
+ // - Location header if set
888
+ return new ResponseBuilder()
889
+ .created(user)
890
+ .setHeader('Location', `/users/${user.id}`);
891
+ }
892
+ ```
893
+
894
+ #### **πŸš€ Production Usage**
895
+
896
+ - Swagger UI is automatically available in all environments
897
+ - For production, consider disabling Swagger UI and keeping only JSON endpoint
898
+ - OpenAPI JSON can be used with external documentation tools
899
+ - All validation errors are automatically documented with examples
900
+
780
901
  ### πŸ“ TypeScript Support
781
902
 
782
903
  Full TypeScript support with type-safe API development:
@@ -1,14 +1,9 @@
1
- export interface TimestampFields {
2
- id: string;
3
- createdAt: Date;
4
- updatedAt: Date;
5
- }
6
1
  export interface IRepository<IdentifierType, ModelType> {
7
- findAll(): Promise<(ModelType & TimestampFields)[]>;
8
- findById(id: IdentifierType): Promise<(ModelType & TimestampFields) | null>;
9
- create(item: ModelType): Promise<ModelType & TimestampFields>;
10
- update(id: IdentifierType, item: Partial<ModelType>): Promise<ModelType & TimestampFields>;
2
+ findAll(): Promise<ModelType[]>;
3
+ findById(id: IdentifierType): Promise<ModelType | null>;
4
+ create(item: ModelType): Promise<ModelType>;
5
+ update(id: IdentifierType, item: Partial<ModelType>): Promise<ModelType>;
11
6
  delete(id: IdentifierType): Promise<void>;
12
- findPaginated(query: Partial<ModelType>, page: number, limit: number): Promise<(ModelType & TimestampFields)[]>;
7
+ findPaginated(query: Partial<ModelType>, page: number, limit: number): Promise<ModelType[]>;
13
8
  }
14
9
  //# sourceMappingURL=repository.interface.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"repository.interface.d.ts","sourceRoot":"","sources":["../../interfaces/repository.interface.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,eAAe;IAC/B,EAAE,EAAE,MA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MAAM,CAAC,EAAE,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1C,aAAa,CACZ,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,EACzB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,GACX,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;CACxB"}
package/package.json CHANGED
@@ -25,7 +25,7 @@
25
25
  "license": "ISC",
26
26
  "description": "Mini Express Framework - Lightweight and modular Express.js framework with TypeScript support",
27
27
  "name": "@mini2/core",
28
- "version": "1.1.0",
28
+ "version": "1.1.1",
29
29
  "author": "Mustafa Γ‡olakoglu <mustafacolakoglu94@gmail.com> (https://github.com/mustafa-colakoglu)",
30
30
  "dependencies": {
31
31
  "class-transformer": "^0.5.1",