@devup-api/generator
Advanced tools
+3
-3
| { | ||
| "name": "@devup-api/generator", | ||
| "version": "0.1.2", | ||
| "version": "0.1.3", | ||
| "license": "Apache-2.0", | ||
@@ -23,4 +23,4 @@ "type": "module", | ||
| "dependencies": { | ||
| "@devup-api/core": "0.1.2", | ||
| "@devup-api/utils": "0.1.2" | ||
| "@devup-api/core": "0.1.3", | ||
| "@devup-api/utils": "0.1.3" | ||
| }, | ||
@@ -27,0 +27,0 @@ "devDependencies": { |
+50
-12
| # @devup-api/generator | ||
| devup API Type Generator | ||
| TypeScript interface generator from OpenAPI schemas. | ||
| Type generation package that generates TypeScript types from schemas. | ||
| ## Installation | ||
@@ -13,15 +11,55 @@ | ||
| ## Exports | ||
| - `generateInterface(schema: OpenAPIV3_1.Document, options?: DevupApiTypeGeneratorOptions): string` - Generate TypeScript interface definitions from OpenAPI schema | ||
| - `createUrlMap(schema: OpenAPIV3_1.Document, options?: DevupApiTypeGeneratorOptions): Record<string, UrlMapValue>` - Create URL map from OpenAPI schema | ||
| ## Usage | ||
| ```typescript | ||
| import { generateTypes, generateTypeFromSchema } from '@devup-api/generator'; | ||
| ### Generate TypeScript Interfaces | ||
| // Generate types | ||
| await generateTypes({ | ||
| outputPath: './types', | ||
| format: 'typescript', | ||
| }); | ||
| ```ts | ||
| import { generateInterface } from '@devup-api/generator' | ||
| import { readOpenapiAsync } from '@devup-api/utils' | ||
| // Generate type from schema | ||
| const typeString = generateTypeFromSchema(schema); | ||
| const schema = await readOpenapiAsync('openapi.json') | ||
| const interfaceCode = generateInterface(schema, { | ||
| convertCase: 'camel', | ||
| responseDefaultNonNullable: true | ||
| }) | ||
| // Write to file | ||
| await writeFile('api.d.ts', interfaceCode) | ||
| ``` | ||
| ### Create URL Map | ||
| ```ts | ||
| import { createUrlMap } from '@devup-api/generator' | ||
| import { readOpenapiAsync } from '@devup-api/utils' | ||
| const schema = await readOpenapiAsync('openapi.json') | ||
| const urlMap = createUrlMap(schema, { | ||
| convertCase: 'camel' | ||
| }) | ||
| // urlMap will contain entries like: | ||
| // { | ||
| // 'getUsers': { method: 'GET', url: '/users' }, | ||
| // '/users': { method: 'GET', url: '/users' } | ||
| // } | ||
| ``` | ||
| ## Options | ||
| ```ts | ||
| interface DevupApiTypeGeneratorOptions { | ||
| convertCase?: 'snake' | 'camel' | 'pascal' | 'maintain' | ||
| requestDefaultNonNullable?: boolean | ||
| responseDefaultNonNullable?: boolean | ||
| } | ||
| ``` | ||
| ## License | ||
| Apache 2.0 |
29832
3.56%65
140.74%+ Added
+ Added
- Removed
- Removed
Updated
Updated