Skip to content

Commit fbf5ae2

Browse files
committed
feat: migrate to version 1.0.0 with TypeScript support and improved module structure
- Refactored codebase to use TypeScript, enhancing type safety and developer experience. - Updated package version from 0.15.0 to 1.0.0 in package.json and package-lock.json. - Introduced new entry points and exports in package.json for better module resolution. - Added migration guide (MIGRATION.md) detailing changes from v0.15.0 to v1.0.0. - Created src/index.ts and src/openapi-to-har.ts files to encapsulate core functionality. - Updated webpack configuration to point to the compiled TypeScript output. - Included TypeScript configuration (tsconfig.json) for project compilation settings. - Enhanced dependency management by updating devDependencies and ensuring compatibility.
1 parent b43a4f3 commit fbf5ae2

File tree

7 files changed

+1222
-23
lines changed

7 files changed

+1222
-23
lines changed

MIGRATION.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Migration vers v1.0.0
2+
3+
## Changements principaux
4+
5+
La version 1.0.0 de `@sctg/openapi-snippet` a été refactorisée pour une meilleure utilisation :
6+
7+
### ✅ Avant (v0.15.0)
8+
```javascript
9+
import '@sctg/openapi-snippet/dist/openapisnippet.js';
10+
const snippets = (window as any).OpenAPISnippets.getEndpointSnippets(data, path, method, targets);
11+
```
12+
13+
### ✅ Après (v1.0.0)
14+
```typescript
15+
import { getEndpointSnippets } from '@sctg/openapi-snippet';
16+
const snippets = getEndpointSnippets(data, path, method, targets);
17+
```
18+
19+
## Améliorations
20+
21+
1. **TypeScript natif** - Le module est écrit en TypeScript pur avec types générés automatiquement
22+
2. **Exports corrects** - Les exports ES6 sont correctement configurés dans `package.json`
23+
3. **Pas de build dans les projets consommateurs** - Plus besoin de faire `npm run build` ou d'accéder à `node_modules`
24+
4. **Utilisation directe** - Simple import des fonctions nécessaires
25+
26+
## Structure du projet
27+
28+
```
29+
src/
30+
├── index.ts # Point d'entrée principal
31+
└── openapi-to-har.ts # Conversion OpenAPI vers HAR
32+
33+
dist/
34+
├── index.js # ES Module compilé
35+
├── index.d.ts # Fichier de types TypeScript
36+
├── openapi-to-har.js
37+
├── openapi-to-har.d.ts
38+
├── openapisnippet.js # UMD pour le navigateur (non-minifié)
39+
└── openapisnippet.min.js # UMD pour le navigateur (minifié)
40+
```
41+
42+
## Utilisation en Node.js
43+
44+
```typescript
45+
import { getSnippets, getEndpointSnippets } from '@sctg/openapi-snippet';
46+
47+
// Obtenir tous les snippets
48+
const allSnippets = getSnippets(openApiDocument, ['shell_curl', 'javascript_fetch']);
49+
50+
// Obtenir les snippets pour un endpoint spécifique
51+
const endpointSnippets = getEndpointSnippets(
52+
openApiDocument,
53+
'/pets',
54+
'get',
55+
['shell_curl', 'javascript_fetch']
56+
);
57+
```
58+
59+
## Utilisation en navigateur
60+
61+
Pour le navigateur, incluez le fichier UMD et utilisez la variable globale `OpenAPISnippets` :
62+
63+
```html
64+
<script src="node_modules/@sctg/openapi-snippet/dist/openapisnippet.min.js"></script>
65+
<script>
66+
const snippets = OpenAPISnippets.getEndpointSnippets(data, path, method, targets);
67+
</script>
68+
```
69+
70+
## Types TypeScript
71+
72+
Les types sont inclus automatiquement :
73+
74+
```typescript
75+
interface SnippetItem {
76+
id: string;
77+
mimeType?: string;
78+
title: string;
79+
content: string;
80+
}
81+
82+
interface EndpointSnippetResult {
83+
method: string;
84+
url: string;
85+
description?: string;
86+
resource?: string;
87+
snippets: SnippetItem[];
88+
}
89+
90+
function getEndpointSnippets(
91+
openApi: any,
92+
path: string,
93+
method: string,
94+
targets: string[],
95+
values?: Record<string, any>
96+
): EndpointSnippetResult;
97+
98+
function getSnippets(
99+
openApi: any,
100+
targets: string[]
101+
): EndpointSnippetResult[];
102+
```
103+
104+
## Build
105+
106+
```bash
107+
npm install
108+
npm run build
109+
```
110+
111+
## Tests
112+
113+
```bash
114+
npm test
115+
```

package-lock.json

Lines changed: 38 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sctg/openapi-snippet",
3-
"version": "0.15.0",
3+
"version": "1.0.0",
44
"description": "Generates code snippets from Open API (previously Swagger) documents.",
55
"type": "module",
66
"repository": {
@@ -15,10 +15,17 @@
1515
],
1616
"author": "Erik Wittern",
1717
"license": "MIT",
18-
"main": "index.js",
18+
"main": "./dist/index.js",
19+
"types": "./dist/index.d.ts",
20+
"exports": {
21+
".": {
22+
"types": "./dist/index.d.ts",
23+
"import": "./dist/index.js"
24+
}
25+
},
1926
"scripts": {
2027
"test": "node test/test.js | tap-spec",
21-
"build": "webpack"
28+
"build": "tsc && webpack --config webpack.config.mjs"
2229
},
2330
"dependencies": {
2431
"@sctg/httpsnippet": "^3.0.12",
@@ -33,6 +40,7 @@
3340
},
3441
"devDependencies": {
3542
"@babel/preset-env": "^7.25.8",
43+
"@types/node": "^20.0.0",
3644
"babel-loader": "^10.0.0",
3745
"process": "^0.11.10",
3846
"stream-browserify": "^3.0.0",
@@ -41,6 +49,7 @@
4149
"vm-browserify": "^1.1.0",
4250
"tap-spec": "^5.0.0",
4351
"tape": "^5.9.0",
52+
"typescript": "^5.0.0",
4453
"uglifyify": "^5.0.0",
4554
"webpack": "^5.95.0",
4655
"webpack-cli": "^6.0.1"

0 commit comments

Comments
 (0)