@g1cloud/api-gen 1.0.0
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/.claude/settings.local.json +22 -0
- package/CLAUDE.md +63 -0
- package/README.md +379 -0
- package/dist/analyzer/controllerAnalyzer.d.ts +20 -0
- package/dist/analyzer/controllerAnalyzer.d.ts.map +1 -0
- package/dist/analyzer/controllerAnalyzer.js +101 -0
- package/dist/analyzer/controllerAnalyzer.js.map +1 -0
- package/dist/analyzer/parameterAnalyzer.d.ts +19 -0
- package/dist/analyzer/parameterAnalyzer.d.ts.map +1 -0
- package/dist/analyzer/parameterAnalyzer.js +207 -0
- package/dist/analyzer/parameterAnalyzer.js.map +1 -0
- package/dist/analyzer/responseAnalyzer.d.ts +12 -0
- package/dist/analyzer/responseAnalyzer.d.ts.map +1 -0
- package/dist/analyzer/responseAnalyzer.js +116 -0
- package/dist/analyzer/responseAnalyzer.js.map +1 -0
- package/dist/analyzer/schemaGenerator.d.ts +6 -0
- package/dist/analyzer/schemaGenerator.d.ts.map +1 -0
- package/dist/analyzer/schemaGenerator.js +347 -0
- package/dist/analyzer/schemaGenerator.js.map +1 -0
- package/dist/analyzer/securityAnalyzer.d.ts +6 -0
- package/dist/analyzer/securityAnalyzer.d.ts.map +1 -0
- package/dist/analyzer/securityAnalyzer.js +177 -0
- package/dist/analyzer/securityAnalyzer.js.map +1 -0
- package/dist/generator/openapiGenerator.d.ts +14 -0
- package/dist/generator/openapiGenerator.d.ts.map +1 -0
- package/dist/generator/openapiGenerator.js +340 -0
- package/dist/generator/openapiGenerator.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +218 -0
- package/dist/index.js.map +1 -0
- package/dist/lib.d.ts +61 -0
- package/dist/lib.d.ts.map +1 -0
- package/dist/lib.js +199 -0
- package/dist/lib.js.map +1 -0
- package/dist/mcp-server.d.ts +9 -0
- package/dist/mcp-server.d.ts.map +1 -0
- package/dist/mcp-server.js +257 -0
- package/dist/mcp-server.js.map +1 -0
- package/dist/mcp-server.mjs +45586 -0
- package/dist/parser/astAnalyzer.d.ts +87 -0
- package/dist/parser/astAnalyzer.d.ts.map +1 -0
- package/dist/parser/astAnalyzer.js +321 -0
- package/dist/parser/astAnalyzer.js.map +1 -0
- package/dist/parser/javaParser.d.ts +10 -0
- package/dist/parser/javaParser.d.ts.map +1 -0
- package/dist/parser/javaParser.js +805 -0
- package/dist/parser/javaParser.js.map +1 -0
- package/dist/types/index.d.ts +217 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/examples/CreateUserRequest.java +80 -0
- package/examples/DepartmentDTO.java +45 -0
- package/examples/Filter.java +39 -0
- package/examples/PaginatedList.java +71 -0
- package/examples/ProductController.java +136 -0
- package/examples/ProductDTO.java +129 -0
- package/examples/RoleDTO.java +47 -0
- package/examples/SearchParam.java +55 -0
- package/examples/Sort.java +70 -0
- package/examples/UpdateUserRequest.java +74 -0
- package/examples/UserController.java +98 -0
- package/examples/UserDTO.java +119 -0
- package/package.json +51 -0
- package/prompt/01_Initial.md +358 -0
- package/prompt/02_/354/266/224/352/260/200.md +31 -0
- package/src/analyzer/controllerAnalyzer.ts +125 -0
- package/src/analyzer/parameterAnalyzer.ts +259 -0
- package/src/analyzer/responseAnalyzer.ts +142 -0
- package/src/analyzer/schemaGenerator.ts +412 -0
- package/src/analyzer/securityAnalyzer.ts +200 -0
- package/src/generator/openapiGenerator.ts +378 -0
- package/src/index.ts +212 -0
- package/src/lib.ts +240 -0
- package/src/mcp-server.ts +310 -0
- package/src/parser/astAnalyzer.ts +373 -0
- package/src/parser/javaParser.ts +901 -0
- package/src/types/index.ts +238 -0
- package/test-boolean.yaml +607 -0
- package/test-filter.yaml +576 -0
- package/test-inner.ts +59 -0
- package/test-output.yaml +650 -0
- package/test-paginated.yaml +585 -0
- package/tsconfig.json +20 -0
- package/tsup.config.ts +30 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.analyzeParameters = analyzeParameters;
|
|
4
|
+
exports.createSchemaForType = createSchemaForType;
|
|
5
|
+
const astAnalyzer_1 = require("../parser/astAnalyzer");
|
|
6
|
+
/**
|
|
7
|
+
* Analyze method parameters and extract OpenAPI parameter/request body info
|
|
8
|
+
* @param method The Java method to analyze
|
|
9
|
+
* @param context Processing context
|
|
10
|
+
* @param paramDescriptions Javadoc @param descriptions (param name -> description)
|
|
11
|
+
*/
|
|
12
|
+
function analyzeParameters(method, context, paramDescriptions = {}) {
|
|
13
|
+
const parameters = [];
|
|
14
|
+
let requestBody;
|
|
15
|
+
let hasSearchParam = false;
|
|
16
|
+
for (const param of method.parameters) {
|
|
17
|
+
// Check if it's a SearchParam
|
|
18
|
+
if (astAnalyzer_1.ASTAnalyzer.isSearchParam(param.type)) {
|
|
19
|
+
hasSearchParam = true;
|
|
20
|
+
// Add SearchParam query parameters
|
|
21
|
+
parameters.push(...getSearchParamParameters());
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
// Get parameter type from annotations
|
|
25
|
+
const paramType = astAnalyzer_1.ASTAnalyzer.getParameterType(param.annotations);
|
|
26
|
+
// Get @param description from javadoc
|
|
27
|
+
const javadocDescription = paramDescriptions[param.name];
|
|
28
|
+
if (paramType === 'body') {
|
|
29
|
+
requestBody = createRequestBody(param, context, javadocDescription);
|
|
30
|
+
}
|
|
31
|
+
else if (paramType) {
|
|
32
|
+
const paramInfo = createParameterInfo(param, paramType, javadocDescription);
|
|
33
|
+
if (paramInfo) {
|
|
34
|
+
parameters.push(paramInfo);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// Parameters without REST annotations are typically handled by Spring automatically
|
|
38
|
+
// but we skip them as they're not part of the API contract
|
|
39
|
+
}
|
|
40
|
+
return { parameters, requestBody, hasSearchParam };
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Get SearchParam query parameters
|
|
44
|
+
*/
|
|
45
|
+
function getSearchParamParameters() {
|
|
46
|
+
return [
|
|
47
|
+
{
|
|
48
|
+
name: 'offset',
|
|
49
|
+
in: 'query',
|
|
50
|
+
required: false,
|
|
51
|
+
type: 'integer',
|
|
52
|
+
description: 'Pagination offset',
|
|
53
|
+
schema: { type: 'integer' },
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
name: 'limit',
|
|
57
|
+
in: 'query',
|
|
58
|
+
required: false,
|
|
59
|
+
type: 'integer',
|
|
60
|
+
description: 'Pagination limit',
|
|
61
|
+
schema: { type: 'integer' },
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: 'filter',
|
|
65
|
+
in: 'query',
|
|
66
|
+
required: false,
|
|
67
|
+
type: 'object',
|
|
68
|
+
description: 'Filter conditions',
|
|
69
|
+
schema: { $ref: '#/components/schemas/Filter' },
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
name: 'sort',
|
|
73
|
+
in: 'query',
|
|
74
|
+
required: false,
|
|
75
|
+
type: 'object',
|
|
76
|
+
description: 'Sort conditions',
|
|
77
|
+
schema: { $ref: '#/components/schemas/Sort' },
|
|
78
|
+
},
|
|
79
|
+
];
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Create ParameterInfo from a Java parameter
|
|
83
|
+
*/
|
|
84
|
+
function createParameterInfo(param, paramType, javadocDescription) {
|
|
85
|
+
// Find the relevant annotation
|
|
86
|
+
const annotation = param.annotations.find((a) => a.name === 'RequestParam' || a.name === 'PathVariable' || a.name === 'RequestHeader');
|
|
87
|
+
if (!annotation) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
// Get parameter name (from annotation or Java parameter name)
|
|
91
|
+
const paramName = getAnnotationStringValue(annotation, 'value') ||
|
|
92
|
+
getAnnotationStringValue(annotation, 'name') ||
|
|
93
|
+
param.name;
|
|
94
|
+
// Determine if required
|
|
95
|
+
let required = paramType === 'path'; // Path variables are always required
|
|
96
|
+
if (paramType !== 'path') {
|
|
97
|
+
const requiredValue = annotation.values['required'];
|
|
98
|
+
if (requiredValue !== undefined) {
|
|
99
|
+
required = requiredValue === 'true' || requiredValue === true;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
// Default is true for @RequestParam
|
|
103
|
+
required = paramType === 'query';
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// Get default value
|
|
107
|
+
const defaultValue = getAnnotationStringValue(annotation, 'defaultValue');
|
|
108
|
+
if (defaultValue) {
|
|
109
|
+
required = false; // If there's a default value, it's not required
|
|
110
|
+
}
|
|
111
|
+
// Convert Java type to OpenAPI type
|
|
112
|
+
const openApiType = astAnalyzer_1.ASTAnalyzer.javaTypeToOpenAPI(param.type);
|
|
113
|
+
return {
|
|
114
|
+
name: paramName,
|
|
115
|
+
in: paramType,
|
|
116
|
+
required,
|
|
117
|
+
type: openApiType.type,
|
|
118
|
+
description: javadocDescription,
|
|
119
|
+
defaultValue,
|
|
120
|
+
schema: {
|
|
121
|
+
type: openApiType.type,
|
|
122
|
+
format: openApiType.format,
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Create RequestBodyInfo from a Java parameter
|
|
128
|
+
*/
|
|
129
|
+
function createRequestBody(param, context, javadocDescription) {
|
|
130
|
+
// Find @RequestBody annotation
|
|
131
|
+
const annotation = param.annotations.find((a) => a.name === 'RequestBody');
|
|
132
|
+
// Determine if required
|
|
133
|
+
let required = true;
|
|
134
|
+
if (annotation) {
|
|
135
|
+
const requiredValue = annotation.values['required'];
|
|
136
|
+
if (requiredValue !== undefined) {
|
|
137
|
+
required = requiredValue === 'true' || requiredValue === true;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// Create schema reference
|
|
141
|
+
const schema = createSchemaForType(param.type, param.genericType, context);
|
|
142
|
+
return {
|
|
143
|
+
required,
|
|
144
|
+
contentType: 'application/json',
|
|
145
|
+
schema,
|
|
146
|
+
description: javadocDescription,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Create a schema for a Java type
|
|
151
|
+
*/
|
|
152
|
+
function createSchemaForType(javaType, genericType, context) {
|
|
153
|
+
// Check if it's a primitive or wrapper type
|
|
154
|
+
if (astAnalyzer_1.ASTAnalyzer.isPrimitiveOrWrapper(javaType)) {
|
|
155
|
+
return astAnalyzer_1.ASTAnalyzer.javaTypeToOpenAPI(javaType);
|
|
156
|
+
}
|
|
157
|
+
// Check if it's an array
|
|
158
|
+
if (javaType.endsWith('[]')) {
|
|
159
|
+
const elementType = javaType.slice(0, -2);
|
|
160
|
+
return {
|
|
161
|
+
type: 'array',
|
|
162
|
+
items: createSchemaForType(elementType, undefined, context),
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
// Check if it's a collection type
|
|
166
|
+
if (astAnalyzer_1.ASTAnalyzer.isCollectionType(javaType)) {
|
|
167
|
+
const itemType = genericType ? astAnalyzer_1.ASTAnalyzer.extractGenericType(genericType) : 'Object';
|
|
168
|
+
return {
|
|
169
|
+
type: 'array',
|
|
170
|
+
items: itemType ? createSchemaForType(itemType, undefined, context) : { type: 'object' },
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
// Check if it's a Map type
|
|
174
|
+
if (astAnalyzer_1.ASTAnalyzer.isMapType(javaType)) {
|
|
175
|
+
return {
|
|
176
|
+
type: 'object',
|
|
177
|
+
additionalProperties: true,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
// Check if it's ResponseEntity - extract the generic type
|
|
181
|
+
if (astAnalyzer_1.ASTAnalyzer.isResponseEntity(javaType) && genericType) {
|
|
182
|
+
return createSchemaForType(genericType, undefined, context);
|
|
183
|
+
}
|
|
184
|
+
// It's a custom type (DTO) - add to referenced types and return a reference
|
|
185
|
+
const simpleName = javaType.split('.').pop() || javaType;
|
|
186
|
+
context.referencedTypes.add(simpleName);
|
|
187
|
+
return {
|
|
188
|
+
$ref: `#/components/schemas/${simpleName}`,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Get string value from annotation
|
|
193
|
+
*/
|
|
194
|
+
function getAnnotationStringValue(annotation, key) {
|
|
195
|
+
const value = annotation.values[key];
|
|
196
|
+
if (value === undefined) {
|
|
197
|
+
return undefined;
|
|
198
|
+
}
|
|
199
|
+
if (Array.isArray(value)) {
|
|
200
|
+
return value[0];
|
|
201
|
+
}
|
|
202
|
+
if (typeof value === 'string') {
|
|
203
|
+
return value;
|
|
204
|
+
}
|
|
205
|
+
return String(value);
|
|
206
|
+
}
|
|
207
|
+
//# sourceMappingURL=parameterAnalyzer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parameterAnalyzer.js","sourceRoot":"","sources":["../../src/analyzer/parameterAnalyzer.ts"],"names":[],"mappings":";;AAuBA,8CAqCC;AAqID,kDAgDC;AAxOD,uDAAoD;AAQpD;;;;;GAKG;AACH,SAAgB,iBAAiB,CAC/B,MAAkB,EAClB,OAA0B,EAC1B,oBAA4C,EAAE;IAE9C,MAAM,UAAU,GAAoB,EAAE,CAAC;IACvC,IAAI,WAAwC,CAAC;IAC7C,IAAI,cAAc,GAAG,KAAK,CAAC;IAE3B,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;QACtC,8BAA8B;QAC9B,IAAI,yBAAW,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;YAC1C,cAAc,GAAG,IAAI,CAAC;YACtB,mCAAmC;YACnC,UAAU,CAAC,IAAI,CAAC,GAAG,wBAAwB,EAAE,CAAC,CAAC;YAC/C,SAAS;QACX,CAAC;QAED,sCAAsC;QACtC,MAAM,SAAS,GAAG,yBAAW,CAAC,gBAAgB,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QAElE,sCAAsC;QACtC,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C,CAAC;IAExC,OAAO;QACL,IAAI,EAAE,wBAAwB,UAAU,EAAE;KAC3C,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,wBAAwB,CAAC,UAA0B,EAAE,GAAW;IACvE,MAAM,KAAK,GAAG,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACrC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { JavaMethod, ResponseInfo, ProcessingContext } from '../types';
|
|
2
|
+
interface ResponseAnalysisResult {
|
|
3
|
+
responses: ResponseInfo[];
|
|
4
|
+
hasPaginatedList: boolean;
|
|
5
|
+
paginatedListItemType?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Analyze method return type and extract response information
|
|
9
|
+
*/
|
|
10
|
+
export declare function analyzeResponse(method: JavaMethod, context: ProcessingContext): ResponseAnalysisResult;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=responseAnalyzer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"responseAnalyzer.d.ts","sourceRoot":"","sources":["../../src/analyzer/responseAnalyzer.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,YAAY,EACZ,iBAAiB,EAGlB,MAAM,UAAU,CAAC;AAIlB,UAAU,sBAAsB;IAC9B,SAAS,EAAE,YAAY,EAAE,CAAC;IAC1B,gBAAgB,EAAE,OAAO,CAAC;IAC1B,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,iBAAiB,GACzB,sBAAsB,CA6CxB"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.analyzeResponse = analyzeResponse;
|
|
4
|
+
const astAnalyzer_1 = require("../parser/astAnalyzer");
|
|
5
|
+
const parameterAnalyzer_1 = require("./parameterAnalyzer");
|
|
6
|
+
/**
|
|
7
|
+
* Analyze method return type and extract response information
|
|
8
|
+
*/
|
|
9
|
+
function analyzeResponse(method, context) {
|
|
10
|
+
const responses = [];
|
|
11
|
+
let hasPaginatedList = false;
|
|
12
|
+
let paginatedListItemType;
|
|
13
|
+
let returnType = method.returnType;
|
|
14
|
+
let genericType = method.returnGenericType;
|
|
15
|
+
// Handle ResponseEntity<T>
|
|
16
|
+
if (astAnalyzer_1.ASTAnalyzer.isResponseEntity(returnType)) {
|
|
17
|
+
// Extract the generic type from ResponseEntity
|
|
18
|
+
if (genericType) {
|
|
19
|
+
returnType = extractMainType(genericType);
|
|
20
|
+
genericType = extractNestedGenericType(genericType);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
returnType = 'Object';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
// Check for PaginatedList
|
|
27
|
+
if (astAnalyzer_1.ASTAnalyzer.isPaginatedList(returnType)) {
|
|
28
|
+
hasPaginatedList = true;
|
|
29
|
+
paginatedListItemType = genericType ? extractMainType(genericType) : undefined;
|
|
30
|
+
// Create PaginatedList response with headers
|
|
31
|
+
const response = createPaginatedListResponse(returnType, genericType, context);
|
|
32
|
+
responses.push(response);
|
|
33
|
+
}
|
|
34
|
+
else if (returnType === 'void' || returnType === 'Void') {
|
|
35
|
+
// Void response
|
|
36
|
+
responses.push({
|
|
37
|
+
statusCode: '200',
|
|
38
|
+
description: 'Successful response',
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
// Regular response
|
|
43
|
+
const schema = (0, parameterAnalyzer_1.createSchemaForType)(returnType, genericType, context);
|
|
44
|
+
responses.push({
|
|
45
|
+
statusCode: '200',
|
|
46
|
+
description: 'Successful response',
|
|
47
|
+
contentType: 'application/json',
|
|
48
|
+
schema,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return { responses, hasPaginatedList, paginatedListItemType };
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Create response for PaginatedList type
|
|
55
|
+
* PaginatedList<T> is treated as an array of T, with pagination info in headers
|
|
56
|
+
*/
|
|
57
|
+
function createPaginatedListResponse(returnType, genericType, context) {
|
|
58
|
+
const itemType = genericType ? extractMainType(genericType) : 'Object';
|
|
59
|
+
// Add the item type to referenced types
|
|
60
|
+
if (itemType !== 'Object' && !astAnalyzer_1.ASTAnalyzer.isPrimitiveOrWrapper(itemType)) {
|
|
61
|
+
context.referencedTypes.add(itemType);
|
|
62
|
+
}
|
|
63
|
+
// Create array schema directly (treat PaginatedList<T> as List<T>)
|
|
64
|
+
const arraySchema = {
|
|
65
|
+
type: 'array',
|
|
66
|
+
items: itemType !== 'Object' && !astAnalyzer_1.ASTAnalyzer.isPrimitiveOrWrapper(itemType)
|
|
67
|
+
? { $ref: `#/components/schemas/${itemType}` }
|
|
68
|
+
: astAnalyzer_1.ASTAnalyzer.javaTypeToOpenAPI(itemType),
|
|
69
|
+
};
|
|
70
|
+
// Create pagination headers (pagination info is passed via headers)
|
|
71
|
+
const headers = {
|
|
72
|
+
'X-Total-Count': {
|
|
73
|
+
schema: { type: 'integer' },
|
|
74
|
+
description: 'Total number of items',
|
|
75
|
+
},
|
|
76
|
+
'X-Offset': {
|
|
77
|
+
schema: { type: 'integer' },
|
|
78
|
+
description: 'Current offset',
|
|
79
|
+
},
|
|
80
|
+
'X-Limit': {
|
|
81
|
+
schema: { type: 'integer' },
|
|
82
|
+
description: 'Current limit',
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
return {
|
|
86
|
+
statusCode: '200',
|
|
87
|
+
description: 'Successful response',
|
|
88
|
+
contentType: 'application/json',
|
|
89
|
+
schema: arraySchema,
|
|
90
|
+
headers,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Extract the main type from a generic type string
|
|
95
|
+
* e.g., "UserDTO" from "UserDTO" or "List<String>" -> "List"
|
|
96
|
+
*/
|
|
97
|
+
function extractMainType(genericType) {
|
|
98
|
+
// Remove any nested generics to get the main type
|
|
99
|
+
const match = genericType.match(/^([^<]+)/);
|
|
100
|
+
if (match) {
|
|
101
|
+
return match[1].trim();
|
|
102
|
+
}
|
|
103
|
+
return genericType;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Extract nested generic type
|
|
107
|
+
* e.g., "List<String>" -> "String", "PaginatedList<UserDTO>" -> "UserDTO"
|
|
108
|
+
*/
|
|
109
|
+
function extractNestedGenericType(genericType) {
|
|
110
|
+
const match = genericType.match(/<(.+)>$/);
|
|
111
|
+
if (match) {
|
|
112
|
+
return match[1].trim();
|
|
113
|
+
}
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=responseAnalyzer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"responseAnalyzer.js","sourceRoot":"","sources":["../../src/analyzer/responseAnalyzer.ts"],"names":[],"mappings":";;AAmBA,0CAgDC;AA5DD,uDAAoD;AACpD,2DAA0D;AAQ1D;;GAEG;AACH,SAAgB,eAAe,CAC7B,MAAkB,EAClB,OAA0B;IAE1B,MAAM,SAAS,GAAmB,EAAE,CAAC;IACrC,IAAI,gBAAgB,GAAG,KAAK,CAAC;IAC7B,IAAI,qBAAyC,CAAC;IAE9C,IAAI,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;IACnC,IAAI,WAAW,GAAG,MAA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