Skip to content

Commit bd2136e

Browse files
authored
feat: add readme
feat: add readme
2 parents 0c66571 + 0ce7c4e commit bd2136e

3 files changed

Lines changed: 105 additions & 8 deletions

File tree

packages/generators-v2/README.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# OpenAPI JSON Schema Generator
2+
3+
This application generates OpenAPI JSON schemas based on configuration data from a single input file.
4+
5+
## 🚀 To Run the Generator
6+
7+
```
8+
npm run generate --prefix packages/generators-v2
9+
```
10+
11+
The script will process data from the json_for-docs_generation.json file and produce schema files accordingly.
12+
13+
## Input File Structure
14+
15+
The generator reads configuration from a JSON file named json_for-docs_generation.json, which should follow this structure:
16+
17+
```json
18+
[
19+
{
20+
"name": "modelName",
21+
"url": "https://ai.aimlapi.com/docs-json?endpoint=openai/chat-completions&model=o1-pro&source=openai",
22+
"alias": "alias",
23+
"category": "text-models-llm",
24+
"vendor": "OpenAI",
25+
"codeSamples": "chat-completion",
26+
"customUrlApi": "https://api.aimlapi.com/v1/images/generations",
27+
"customParams": {
28+
"text_param": "text",
29+
"object_param": {
30+
"name": "object",
31+
"type": "string"
32+
},
33+
"array_param": ["param1", 212],
34+
"object_array_param": [
35+
{
36+
"name": "object1",
37+
"type": "string"
38+
},
39+
{
40+
"name": 21212,
41+
"type": "string"
42+
}
43+
]
44+
},
45+
"hideTryItPanel": true
46+
}
47+
]
48+
```
49+
50+
### Field Descriptions
51+
52+
| Field | Type | Required | Description |
53+
| ------------------ | --------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
54+
| **name** | `string` || Model name (required if using a ready-made code sample). |
55+
| **url** | `string` || URL to the JSON documentation endpoint. |
56+
| **alias** | `string` || The output filename (used when saving the generated schema). |
57+
| **category** | `string` || The category under which the schema is grouped (e.g. `text-models-llm`). |
58+
| **vendor** | `string` || Model vendor name (e.g. `OpenAI`). |
59+
| **codeSamples** | `string` || Optional. Determines which predefined code samples to include. Options: <br>• `chat-completion` <br>• `chat-completion-audio` <br>• `text-to-image` <br>• `image-to-image` <br>• `gpt-image-edit` <br>• `hide` (if your want hide codeSample) <br>• `custom` (requires `customUrlApi` and `customParams`) |
60+
| **customUrlApi** | `string` || Used when `codeSamples` is set to `"custom"`. Specifies a custom API endpoint. |
61+
| **customParams** | `object` || Custom parameters for the API request. Supports simple, object, array, and object-array formats. |
62+
| **hideTryItPanel** | `boolean` || If set to true, hides the “Try It” panel in the generated documentation. Useful for endpoints that are not meant to be interactive. |
63+
## Example Usage
64+
### Example 1 — Ready-made code sample
65+
```json
66+
{
67+
"name": "gpt-4o",
68+
"url": "https://ai.aimlapi.com/docs-json?endpoint=openai/chat-completions&model=gpt-4o&source=openai",
69+
"alias": "gpt-4o",
70+
"category": "text-models-llm",
71+
"vendor": "OpenAI",
72+
"codeSamples": "chat-completion",
73+
"hideTryItPanel": true
74+
}
75+
```
76+
### Example 2 — Custom API configuration
77+
```json
78+
{
79+
"name": "flux/dev",
80+
"url": "https://ai.aimlapi.com/docs-json?endpoint=internal/image-generations&model=flux/dev&source=falai",
81+
"alias": "flux-dev",
82+
"category": "image-models",
83+
"vendor": "Black-Forest-Labs",
84+
"codeSamples": "custom",
85+
"customUrlApi": "https://api.aimlapi.com/v1/images/generations",
86+
"customParams": {
87+
"prompt": "text",
88+
"style": "string",
89+
"size": ["512x512", "1024x1024"]
90+
},
91+
"hideTryItPanel": false
92+
}
93+
```
94+
## Output
95+
96+
Each schema is generated and saved under a filename based on its category, vendor and alias (e.g., category/vendor/alias.json) inside /docs/api-references.

packages/generators-v2/src/saver.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
66

77
export async function saveSchema(schema, options) {
88
const rootPath = path.join(__dirname, '../../../docs/api-references');
9-
console.log(__dirname);
109
const categoryPath = path.join(
1110
rootPath,
1211
options.category,

packages/generators-v2/src/transformer.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export function transformSchema(schema, options) {
1111
}
1212
});
1313
}
14-
if (options.codeSamples === undefined) {
14+
if (options.codeSamples === 'hide') {
1515
Object.entries(updatedSchema.paths).map(([path, operation]) => {
1616
for (const method of ['get', 'post']) {
1717
if (operation[method]) {
@@ -20,7 +20,7 @@ export function transformSchema(schema, options) {
2020
}
2121
});
2222
}
23-
let codeSample = [];
23+
let codeSample;
2424
if (options.codeSamples === 'chat-completion') {
2525
codeSample = codeSamples.chatCompletionSample(options);
2626
} else if (options.codeSamples === 'chat-completion-audio') {
@@ -35,11 +35,13 @@ export function transformSchema(schema, options) {
3535
codeSample = codeSamples.customSample(options);
3636
}
3737

38-
Object.entries(updatedSchema.paths).map(([path, operation]) => {
39-
if (operation.post) {
40-
updatedSchema.paths[path].post['x-codeSamples'] = codeSample;
41-
}
42-
});
38+
if (codeSample) {
39+
Object.entries(updatedSchema.paths).map(([path, operation]) => {
40+
if (operation.post) {
41+
updatedSchema.paths[path].post['x-codeSamples'] = codeSample;
42+
}
43+
});
44+
}
4345

4446
return updatedSchema;
4547
}

0 commit comments

Comments
 (0)