@tim-smart/openapi-gen 0.4.0 → 0.4.2
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/main.js +50 -11
- package/package.json +1 -1
package/main.js
CHANGED
|
@@ -34907,9 +34907,10 @@ var make64 = gen2(function* () {
|
|
|
34907
34907
|
filterMap2(([key, schema2]) => {
|
|
34908
34908
|
const fullSchema = getSchema(schema2);
|
|
34909
34909
|
const isOptional = !required2.includes(key);
|
|
34910
|
+
const [enumNullable, filteredSchema] = filterNullable(fullSchema);
|
|
34910
34911
|
return toSource(
|
|
34911
34912
|
importName,
|
|
34912
|
-
schema2,
|
|
34913
|
+
enumNullable ? filteredSchema : schema2,
|
|
34913
34914
|
currentIdentifier + identifier2(key)
|
|
34914
34915
|
).pipe(
|
|
34915
34916
|
map2(
|
|
@@ -34919,7 +34920,8 @@ var make64 = gen2(function* () {
|
|
|
34919
34920
|
key,
|
|
34920
34921
|
source,
|
|
34921
34922
|
isOptional,
|
|
34922
|
-
isNullable: "nullable" in fullSchema && fullSchema.nullable === true || "default" in fullSchema && fullSchema.default === null
|
|
34923
|
+
isNullable: enumNullable || "nullable" in fullSchema && fullSchema.nullable === true || "default" in fullSchema && fullSchema.default === null,
|
|
34924
|
+
default: fullSchema.default
|
|
34923
34925
|
})
|
|
34924
34926
|
)
|
|
34925
34927
|
);
|
|
@@ -34984,8 +34986,21 @@ var make64 = gen2(function* () {
|
|
|
34984
34986
|
topLevel
|
|
34985
34987
|
);
|
|
34986
34988
|
} else if ("anyOf" in schema || "oneOf" in schema) {
|
|
34989
|
+
let itemSchemas = "anyOf" in schema ? schema.anyOf : schema.oneOf;
|
|
34990
|
+
let typePrimitives = 0;
|
|
34991
|
+
const constItems = empty2();
|
|
34992
|
+
for (const item of itemSchemas) {
|
|
34993
|
+
if ("type" in item && item.type !== "null") {
|
|
34994
|
+
typePrimitives++;
|
|
34995
|
+
} else if ("const" in item) {
|
|
34996
|
+
constItems.push(item);
|
|
34997
|
+
}
|
|
34998
|
+
}
|
|
34999
|
+
if (typePrimitives <= 1 && constItems.length > 0 && constItems.length + typePrimitives === itemSchemas.length) {
|
|
35000
|
+
itemSchemas = constItems;
|
|
35001
|
+
}
|
|
34987
35002
|
const items = pipe(
|
|
34988
|
-
|
|
35003
|
+
itemSchemas,
|
|
34989
35004
|
filterMap2(
|
|
34990
35005
|
(_) => toSource(importName, _, currentIdentifier + "Enum").pipe(
|
|
34991
35006
|
map2(
|
|
@@ -35098,12 +35113,12 @@ var layerTransformerSchema = sync6(JsonSchemaTransformer, () => {
|
|
|
35098
35113
|
supportsTopLevel({ isClass, isEnum }) {
|
|
35099
35114
|
return isClass || isEnum;
|
|
35100
35115
|
},
|
|
35101
|
-
onTopLevel({ importName, schema, name: name2, source, isClass }) {
|
|
35116
|
+
onTopLevel({ importName, schema, name: name2, source, isClass, description }) {
|
|
35102
35117
|
const isObject2 = "properties" in schema;
|
|
35103
35118
|
if (!isObject2 || !isClass) {
|
|
35104
|
-
return
|
|
35119
|
+
return `${toComment(description)}export class ${name2} extends ${source} {}`;
|
|
35105
35120
|
}
|
|
35106
|
-
return
|
|
35121
|
+
return `${toComment(description)}export class ${name2} extends ${importName}.Class<${name2}>("${name2}")(${source}) {}`;
|
|
35107
35122
|
},
|
|
35108
35123
|
propertySeparator: ",\n ",
|
|
35109
35124
|
onProperty: (options3) => {
|
|
@@ -35111,7 +35126,7 @@ var layerTransformerSchema = sync6(JsonSchemaTransformer, () => {
|
|
|
35111
35126
|
options3.importName,
|
|
35112
35127
|
options3
|
|
35113
35128
|
)(options3.source);
|
|
35114
|
-
return
|
|
35129
|
+
return `${toComment(options3.description)}"${options3.key}": ${source}`;
|
|
35115
35130
|
},
|
|
35116
35131
|
onRef({ name: name2 }) {
|
|
35117
35132
|
return name2;
|
|
@@ -35162,12 +35177,12 @@ var layerTransformerSchema = sync6(JsonSchemaTransformer, () => {
|
|
|
35162
35177
|
const modifiers = [];
|
|
35163
35178
|
if (minimum !== void 0) {
|
|
35164
35179
|
modifiers.push(
|
|
35165
|
-
`${importName}.greaterThan${exclusiveMinimum ? "" : "OrEqualTo"}(${
|
|
35180
|
+
`${importName}.greaterThan${exclusiveMinimum ? "" : "OrEqualTo"}(${minimum})`
|
|
35166
35181
|
);
|
|
35167
35182
|
}
|
|
35168
35183
|
if (maximum !== void 0) {
|
|
35169
35184
|
modifiers.push(
|
|
35170
|
-
`${importName}.lessThan${exclusiveMaximum ? "" : "OrEqualTo"}(${
|
|
35185
|
+
`${importName}.lessThan${exclusiveMaximum ? "" : "OrEqualTo"}(${maximum})`
|
|
35171
35186
|
);
|
|
35172
35187
|
}
|
|
35173
35188
|
return `${importName}.${schema.type === "integer" ? "Int" : "Number"}${pipeSource(modifiers)}`;
|
|
@@ -35183,7 +35198,7 @@ var layerTransformerSchema = sync6(JsonSchemaTransformer, () => {
|
|
|
35183
35198
|
return `${importName}.${nonEmpty ? "NonEmpty" : ""}Array(${item})${pipeSource(modifiers)}`;
|
|
35184
35199
|
},
|
|
35185
35200
|
onUnion({ importName, items }) {
|
|
35186
|
-
return `${importName}.Union(${items.map((_) => _.source).join("
|
|
35201
|
+
return `${importName}.Union(${items.map((_) => `${toComment(_.description)}${_.source}`).join(",\n")})`;
|
|
35187
35202
|
}
|
|
35188
35203
|
});
|
|
35189
35204
|
});
|
|
@@ -35246,7 +35261,9 @@ export type ${name2} = (typeof ${name2})[keyof typeof ${name2}];` : `${toComment
|
|
|
35246
35261
|
);
|
|
35247
35262
|
var toComment = match2({
|
|
35248
35263
|
onNone: () => "",
|
|
35249
|
-
onSome: (description) => `/**
|
|
35264
|
+
onSome: (description) => `/**
|
|
35265
|
+
* ${description.split("\n").join("\n* ")}
|
|
35266
|
+
*/
|
|
35250
35267
|
`
|
|
35251
35268
|
});
|
|
35252
35269
|
function mergeSchemas(self, other) {
|
|
@@ -35310,6 +35327,28 @@ function resolveRef(schema, context7, recursive = false) {
|
|
|
35310
35327
|
}
|
|
35311
35328
|
return { name: name2, schema: resolveAllOf(current, context7, recursive) };
|
|
35312
35329
|
}
|
|
35330
|
+
function filterNullable(schema) {
|
|
35331
|
+
if ("oneOf" in schema || "anyOf" in schema) {
|
|
35332
|
+
const items = schema.oneOf ?? schema.anyOf;
|
|
35333
|
+
const prop = "oneOf" in schema ? "oneOf" : "anyOf";
|
|
35334
|
+
let isNullable2 = false;
|
|
35335
|
+
let otherItems = empty2();
|
|
35336
|
+
for (const item of items) {
|
|
35337
|
+
if ("type" in item && item.type === "null") {
|
|
35338
|
+
isNullable2 = true;
|
|
35339
|
+
} else if ("const" in item && item.const === null) {
|
|
35340
|
+
isNullable2 = true;
|
|
35341
|
+
} else {
|
|
35342
|
+
otherItems.push(item);
|
|
35343
|
+
}
|
|
35344
|
+
}
|
|
35345
|
+
return [
|
|
35346
|
+
isNullable2,
|
|
35347
|
+
{ ...schema, [prop]: otherItems }
|
|
35348
|
+
];
|
|
35349
|
+
}
|
|
35350
|
+
return [false, schema];
|
|
35351
|
+
}
|
|
35313
35352
|
|
|
35314
35353
|
// src/OpenApi.ts
|
|
35315
35354
|
var import_swagger2openapi = __toESM(require_swagger2openapi());
|