gtx-cli 2.5.20 → 2.5.22
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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# gtx-cli
|
|
2
2
|
|
|
3
|
+
## 2.5.22
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#870](https://github.com/generaltranslation/gt/pull/870) [`4291258`](https://github.com/generaltranslation/gt/commit/42912587a51da045c0b578ac71699fda4a8fcc26) Thanks [@fernando-aviles](https://github.com/fernando-aviles)! - Persist style of YAML frontmatter when applying Mintlify OpenAPI postprocessing
|
|
8
|
+
|
|
9
|
+
## 2.5.21
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#868](https://github.com/generaltranslation/gt/pull/868) [`34499ce`](https://github.com/generaltranslation/gt/commit/34499ce8407d4b96dea1b4db7a92225e8118fc56) Thanks [@fernando-aviles](https://github.com/fernando-aviles)! - Removing `"openapi"` top level config, adding as option under `"options.mintlify.openapi"`. Also adding a `jsonSchema` preset for `openapi`.
|
|
14
|
+
|
|
3
15
|
## 2.5.20
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -132,23 +132,6 @@ export async function generateSettings(flags, cwd = process.cwd()) {
|
|
|
132
132
|
};
|
|
133
133
|
// Add additional options if provided
|
|
134
134
|
if (mergedOptions.options) {
|
|
135
|
-
// Auto-add jsonSchema include paths for configured OpenAPI specs (Mintlify)
|
|
136
|
-
if (mergedOptions.openapi?.framework === 'mintlify' &&
|
|
137
|
-
Array.isArray(mergedOptions.openapi.files) &&
|
|
138
|
-
mergedOptions.openapi.files.length) {
|
|
139
|
-
const translateFields = mergedOptions.openapi.translateFields?.length &&
|
|
140
|
-
mergedOptions.openapi.translateFields.length > 0
|
|
141
|
-
? mergedOptions.openapi.translateFields
|
|
142
|
-
: ['$..summary', '$..description'];
|
|
143
|
-
mergedOptions.options.jsonSchema = mergedOptions.options.jsonSchema || {};
|
|
144
|
-
for (const specFile of mergedOptions.openapi.files) {
|
|
145
|
-
if (!mergedOptions.options.jsonSchema[specFile]) {
|
|
146
|
-
mergedOptions.options.jsonSchema[specFile] = {
|
|
147
|
-
include: translateFields,
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
135
|
if (mergedOptions.options.jsonSchema) {
|
|
153
136
|
for (const fileGlob of Object.keys(mergedOptions.options.jsonSchema)) {
|
|
154
137
|
const jsonSchema = mergedOptions.options.jsonSchema[fileGlob];
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { JsonSchema, YamlSchema } from '../types/index.js';
|
|
2
|
-
export declare function generatePreset(preset:
|
|
2
|
+
export declare function generatePreset(preset: JsonSchema['preset'], type: 'json'): JsonSchema;
|
|
3
|
+
export declare function generatePreset(preset: YamlSchema['preset'], type: 'yaml'): YamlSchema;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -31,10 +31,12 @@ export type Options = {
|
|
|
31
31
|
}>;
|
|
32
32
|
};
|
|
33
33
|
export type OpenApiConfig = {
|
|
34
|
-
framework: 'mintlify';
|
|
35
34
|
files: string[];
|
|
36
35
|
translateFields?: string[];
|
|
37
36
|
};
|
|
37
|
+
export type MintlifyOptions = {
|
|
38
|
+
openapi?: OpenApiConfig;
|
|
39
|
+
};
|
|
38
40
|
export type TranslateFlags = {
|
|
39
41
|
config?: string;
|
|
40
42
|
apiKey?: string;
|
|
@@ -149,7 +151,6 @@ export type Settings = {
|
|
|
149
151
|
parsingOptions: ParsingConfigOptions;
|
|
150
152
|
branchOptions: BranchOptions;
|
|
151
153
|
sharedStaticAssets?: SharedStaticAssetsConfig;
|
|
152
|
-
openapi?: OpenApiConfig;
|
|
153
154
|
};
|
|
154
155
|
export type BranchOptions = {
|
|
155
156
|
currentBranch?: string;
|
|
@@ -164,6 +165,7 @@ export type AdditionalOptions = {
|
|
|
164
165
|
yamlSchema?: {
|
|
165
166
|
[fileGlob: string]: YamlSchema;
|
|
166
167
|
};
|
|
168
|
+
mintlify?: MintlifyOptions;
|
|
167
169
|
docsUrlPattern?: string;
|
|
168
170
|
docsImportPattern?: string;
|
|
169
171
|
excludeStaticUrls?: string[];
|
|
@@ -189,7 +191,7 @@ export type SharedStaticAssetsConfig = {
|
|
|
189
191
|
publicPath?: string;
|
|
190
192
|
};
|
|
191
193
|
export type JsonSchema = {
|
|
192
|
-
preset?: 'mintlify';
|
|
194
|
+
preset?: 'mintlify' | 'openapi';
|
|
193
195
|
include?: string[];
|
|
194
196
|
composite?: {
|
|
195
197
|
[sourceObjectPath: string]: SourceObjectOptions;
|
|
@@ -3,7 +3,7 @@ import path from 'node:path';
|
|
|
3
3
|
import { unified } from 'unified';
|
|
4
4
|
import remarkParse from 'remark-parse';
|
|
5
5
|
import remarkFrontmatter from 'remark-frontmatter';
|
|
6
|
-
import YAML from 'yaml';
|
|
6
|
+
import YAML, { isMap, isScalar } from 'yaml';
|
|
7
7
|
import { logger } from '../console/logger.js';
|
|
8
8
|
import { createFileMapping } from '../formats/files/fileMapping.js';
|
|
9
9
|
const HTTP_METHODS = new Set([
|
|
@@ -23,14 +23,13 @@ const HTTP_METHODS = new Set([
|
|
|
23
23
|
* - Warns on missing/ambiguous references but keeps behavior deterministic.
|
|
24
24
|
*/
|
|
25
25
|
export default async function processOpenApi(settings, includeFiles) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (!settings.openapi.files?.length)
|
|
26
|
+
const openapiConfig = settings.options?.mintlify?.openapi;
|
|
27
|
+
if (!openapiConfig || !openapiConfig.files?.length)
|
|
29
28
|
return;
|
|
30
29
|
if (!settings.files)
|
|
31
30
|
return;
|
|
32
31
|
const configDir = path.dirname(settings.config);
|
|
33
|
-
const specAnalyses = buildSpecAnalyses(
|
|
32
|
+
const specAnalyses = buildSpecAnalyses(openapiConfig.files, configDir);
|
|
34
33
|
if (!specAnalyses.length)
|
|
35
34
|
return;
|
|
36
35
|
const warnings = new Set();
|
|
@@ -185,18 +184,18 @@ function rewriteFrontmatter(content, filePath, locale, specs, fileMapping, warni
|
|
|
185
184
|
const start = yamlNode.position.start.offset;
|
|
186
185
|
const end = yamlNode.position.end.offset;
|
|
187
186
|
const frontmatterRaw = yamlNode.value || '';
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
}
|
|
192
|
-
|
|
187
|
+
const doc = YAML.parseDocument(frontmatterRaw, {
|
|
188
|
+
prettyErrors: false,
|
|
189
|
+
keepSourceTokens: true,
|
|
190
|
+
});
|
|
191
|
+
if (doc.errors?.length)
|
|
193
192
|
return null;
|
|
194
|
-
|
|
195
|
-
if (!parsed || typeof parsed !== 'object')
|
|
193
|
+
if (!isMap(doc.contents))
|
|
196
194
|
return null;
|
|
197
195
|
let changed = false;
|
|
198
|
-
|
|
199
|
-
|
|
196
|
+
const openapiNode = doc.get('openapi', true);
|
|
197
|
+
if (isScalar(openapiNode) && typeof openapiNode.value === 'string') {
|
|
198
|
+
const parsedValue = parseOpenApiValue(openapiNode.value);
|
|
200
199
|
if (parsedValue) {
|
|
201
200
|
const matchKey = parsedValue.kind === 'operation'
|
|
202
201
|
? {
|
|
@@ -209,22 +208,23 @@ function rewriteFrontmatter(content, filePath, locale, specs, fileMapping, warni
|
|
|
209
208
|
const descriptor = formatOpenApiDescriptor(parsedValue);
|
|
210
209
|
const localizedSpecPath = resolveLocalizedSpecPath(spec, locale, fileMapping, configDir, parsedValue.specPath || spec.configPath);
|
|
211
210
|
const newValue = `${localizedSpecPath} ${descriptor}`.trim();
|
|
212
|
-
if (newValue !==
|
|
213
|
-
|
|
211
|
+
if (newValue !== openapiNode.value) {
|
|
212
|
+
doc.set('openapi', newValue);
|
|
214
213
|
changed = true;
|
|
215
214
|
}
|
|
216
215
|
}
|
|
217
216
|
}
|
|
218
217
|
}
|
|
219
|
-
|
|
220
|
-
|
|
218
|
+
const schemaNode = doc.get('openapi-schema', true);
|
|
219
|
+
if (isScalar(schemaNode) && typeof schemaNode.value === 'string') {
|
|
220
|
+
const parsedValue = parseSchemaValue(schemaNode.value);
|
|
221
221
|
if (parsedValue) {
|
|
222
222
|
const spec = resolveSpec(parsedValue.specPath, specs, filePath, configDir, warnings, `schema "${parsedValue.schemaName}"`, { type: 'schema', key: parsedValue.schemaName });
|
|
223
223
|
if (spec) {
|
|
224
224
|
const localizedSpecPath = resolveLocalizedSpecPath(spec, locale, fileMapping, configDir, parsedValue.specPath || spec.configPath);
|
|
225
225
|
const newValue = `${localizedSpecPath} ${parsedValue.schemaName}`.trim();
|
|
226
|
-
if (newValue !==
|
|
227
|
-
|
|
226
|
+
if (newValue !== schemaNode.value) {
|
|
227
|
+
doc.set('openapi-schema', newValue);
|
|
228
228
|
changed = true;
|
|
229
229
|
}
|
|
230
230
|
}
|
|
@@ -232,7 +232,7 @@ function rewriteFrontmatter(content, filePath, locale, specs, fileMapping, warni
|
|
|
232
232
|
}
|
|
233
233
|
if (!changed)
|
|
234
234
|
return null;
|
|
235
|
-
const fmString =
|
|
235
|
+
const fmString = doc.toString().trimEnd();
|
|
236
236
|
const rebuilt = `${content.slice(0, start)}---\n${fmString}\n---${content.slice(end)}`;
|
|
237
237
|
return { changed, content: rebuilt };
|
|
238
238
|
}
|