@devup-api/generator 0.1.1 → 0.1.3

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,6 @@
1
1
  # @devup-api/generator
2
2
 
3
- devup API Type Generator
4
-
5
- Type generation package that generates TypeScript types from schemas.
3
+ TypeScript interface generator from OpenAPI schemas.
6
4
 
7
5
  ## Installation
8
6
 
@@ -10,17 +8,57 @@ Type generation package that generates TypeScript types from schemas.
10
8
  npm install @devup-api/generator
11
9
  ```
12
10
 
11
+ ## Exports
12
+
13
+ - `generateInterface(schema: OpenAPIV3_1.Document, options?: DevupApiTypeGeneratorOptions): string` - Generate TypeScript interface definitions from OpenAPI schema
14
+ - `createUrlMap(schema: OpenAPIV3_1.Document, options?: DevupApiTypeGeneratorOptions): Record<string, UrlMapValue>` - Create URL map from OpenAPI schema
15
+
13
16
  ## Usage
14
17
 
15
- ```typescript
16
- import { generateTypes, generateTypeFromSchema } from '@devup-api/generator';
18
+ ### Generate TypeScript Interfaces
19
+
20
+ ```ts
21
+ import { generateInterface } from '@devup-api/generator'
22
+ import { readOpenapiAsync } from '@devup-api/utils'
23
+
24
+ const schema = await readOpenapiAsync('openapi.json')
25
+ const interfaceCode = generateInterface(schema, {
26
+ convertCase: 'camel',
27
+ responseDefaultNonNullable: true
28
+ })
29
+
30
+ // Write to file
31
+ await writeFile('api.d.ts', interfaceCode)
32
+ ```
33
+
34
+ ### Create URL Map
35
+
36
+ ```ts
37
+ import { createUrlMap } from '@devup-api/generator'
38
+ import { readOpenapiAsync } from '@devup-api/utils'
17
39
 
18
- // Generate types
19
- await generateTypes({
20
- outputPath: './types',
21
- format: 'typescript',
22
- });
40
+ const schema = await readOpenapiAsync('openapi.json')
41
+ const urlMap = createUrlMap(schema, {
42
+ convertCase: 'camel'
43
+ })
23
44
 
24
- // Generate type from schema
25
- const typeString = generateTypeFromSchema(schema);
45
+ // urlMap will contain entries like:
46
+ // {
47
+ // 'getUsers': { method: 'GET', url: '/users' },
48
+ // '/users': { method: 'GET', url: '/users' }
49
+ // }
26
50
  ```
51
+
52
+ ## Options
53
+
54
+ ```ts
55
+ interface DevupApiTypeGeneratorOptions {
56
+ convertCase?: 'snake' | 'camel' | 'pascal' | 'maintain'
57
+ requestDefaultNonNullable?: boolean
58
+ responseDefaultNonNullable?: boolean
59
+ }
60
+ ```
61
+
62
+ ## License
63
+
64
+ Apache 2.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devup-api/generator",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "exports": {
@@ -20,8 +20,8 @@
20
20
  "access": "public"
21
21
  },
22
22
  "dependencies": {
23
- "@devup-api/core": "0.1.1",
24
- "@devup-api/utils": "0.1.1"
23
+ "@devup-api/core": "0.1.3",
24
+ "@devup-api/utils": "0.1.3"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@types/node": "^24.10",
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=convert-case.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"convert-case.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/convert-case.test.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=create-url-map.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-url-map.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/create-url-map.test.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=index.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/index.test.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=wrap-interface-key-guard.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"wrap-interface-key-guard.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/wrap-interface-key-guard.test.ts"],"names":[],"mappings":""}