MCPcopy
hub / github.com/nestjs/swagger / createAdditionalPropertiesValueSchema

Function createAdditionalPropertiesValueSchema

lib/plugin/utils/plugin-utils.ts:150–218  ·  view source on GitHub ↗
(
  valueType: ts.Type,
  typeChecker: ts.TypeChecker,
  factory: ts.NodeFactory
)

Source from the content-addressed store, hash-verified

148}
149
150export function createAdditionalPropertiesValueSchema(
151 valueType: ts.Type,
152 typeChecker: ts.TypeChecker,
153 factory: ts.NodeFactory
154): ts.Expression {
155 const text = getText(valueType, typeChecker);
156 const objType = (t: string) =>
157 factory.createObjectLiteralExpression(
158 [
159 factory.createPropertyAssignment('type', factory.createStringLiteral(t))
160 ],
161 false
162 );
163
164 if (
165 isString(valueType) ||
166 isStringLiteral(valueType) ||
167 isStringMapping(valueType)
168 ) {
169 return objType('string');
170 }
171 if (isNumber(valueType) || isBigInt(valueType)) {
172 return objType('number');
173 }
174 if (isBoolean(valueType)) {
175 return objType('boolean');
176 }
177 if (text === 'any' || text === 'unknown' || text === 'object') {
178 return factory.createTrue();
179 }
180
181 const nested = getRecordValueType(valueType, typeChecker);
182 if (nested) {
183 return factory.createObjectLiteralExpression(
184 [
185 factory.createPropertyAssignment(
186 'type',
187 factory.createStringLiteral('object')
188 ),
189 factory.createPropertyAssignment(
190 'additionalProperties',
191 createAdditionalPropertiesValueSchema(nested, typeChecker, factory)
192 )
193 ],
194 false
195 );
196 }
197 if (isArray(valueType)) {
198 const elementType = getTypeArguments(valueType)[0];
199 return factory.createObjectLiteralExpression(
200 [
201 factory.createPropertyAssignment(
202 'type',
203 factory.createStringLiteral('array')
204 ),
205 factory.createPropertyAssignment(
206 'items',
207 createAdditionalPropertiesValueSchema(

Callers 1

Calls 12

getTextFunction · 0.90
isStringFunction · 0.90
isStringLiteralFunction · 0.90
isStringMappingFunction · 0.90
isNumberFunction · 0.90
isBigIntFunction · 0.90
isBooleanFunction · 0.90
isArrayFunction · 0.90
getTypeArgumentsFunction · 0.90
objTypeFunction · 0.85
getRecordValueTypeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…