@mittwald/api-code-generator 0.0.0-development-04b7288-20240610 → 0.0.0-development-74e1fd1-20240611
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/dist/esm/commands/generate/index.js +70 -0
- package/dist/esm/commands/validate/index.js +21 -0
- package/dist/esm/generation/asyncStringJoin.js +4 -0
- package/dist/esm/generation/asyncStringJoin.test.js +5 -0
- package/dist/esm/generation/compileJsonSchema.js +10 -0
- package/dist/esm/generation/format.js +17 -0
- package/dist/esm/generation/model/CodeGenerationModel.js +43 -0
- package/dist/esm/generation/model/components/Components.js +61 -0
- package/dist/esm/generation/model/components/Parameters.js +30 -0
- package/dist/esm/generation/model/components/RequestBodies.js +25 -0
- package/dist/esm/generation/model/components/Response.js +27 -0
- package/dist/esm/generation/model/components/ResponseContent.js +12 -0
- package/dist/esm/generation/model/components/Responses.js +29 -0
- package/dist/esm/generation/model/components/Schemas.js +25 -0
- package/dist/esm/generation/model/components/SecurityScheme.js +21 -0
- package/dist/esm/generation/model/components/SecuritySchemes.js +43 -0
- package/dist/esm/generation/model/global/JSONSchema.js +44 -0
- package/dist/esm/generation/model/global/Name.js +20 -0
- package/dist/esm/generation/model/global/Name.test.js +10 -0
- package/dist/esm/generation/model/paths/Path.js +35 -0
- package/dist/esm/generation/model/paths/Paths.js +192 -0
- package/dist/esm/generation/model/paths/operation/Operation.js +108 -0
- package/dist/esm/generation/model/paths/operation/RequestParameters.js +98 -0
- package/dist/esm/generation/model/paths/operation/responses/Response.js +25 -0
- package/dist/esm/generation/model/paths/operation/responses/ResponseContent.js +31 -0
- package/dist/esm/generation/model/paths/operation/responses/ResponseContentTypes.js +47 -0
- package/dist/esm/generation/model/paths/operation/responses/Responses.js +31 -0
- package/dist/esm/generation/model/tags/Tag.js +12 -0
- package/dist/esm/generation/prepareTypeScriptOutput.js +10 -0
- package/dist/esm/generation/refs/assertNoRefs.js +6 -0
- package/dist/esm/generation/refs/componentRefsToCustomTypes.js +33 -0
- package/dist/esm/generation/refs/componentRefsToCustomTypes.test.js +44 -0
- package/dist/esm/generation/refs/extractComponentRefName.js +8 -0
- package/dist/esm/generation/refs/isRef.js +3 -0
- package/dist/esm/generation/refs/refNameToTSName.js +3 -0
- package/dist/esm/generation/refs/refNameToTSName.test.js +9 -0
- package/dist/esm/generation/refs/splitRefNamespaces.js +1 -0
- package/dist/esm/generation/refs/splitRefNamespaces.test.js +10 -0
- package/dist/esm/generation/tsNamespaceName.js +2 -0
- package/dist/esm/generation/tsTypeName.js +6 -0
- package/dist/esm/generation/tsTypeName.test.js +12 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/lib/makeError.js +7 -0
- package/dist/esm/lib/relativePath.js +3 -0
- package/dist/esm/lib/writeIfChangedAsync.js +8 -0
- package/dist/esm/loading/UniversalContentLoader.js +65 -0
- package/dist/esm/loading/UniversalContentLoader.test.js +40 -0
- package/dist/esm/loading/UniversalFileLoader.js +42 -0
- package/dist/esm/loading/types.js +1 -0
- package/dist/esm/openapi/OpenAPISchemaValidationError.js +17 -0
- package/dist/esm/openapi/OpenApiSpec.js +44 -0
- package/dist/types/commands/generate/index.d.ts +18 -0
- package/dist/types/commands/validate/index.d.ts +8 -0
- package/dist/types/generation/asyncStringJoin.d.ts +1 -0
- package/dist/types/generation/asyncStringJoin.test.d.ts +1 -0
- package/dist/types/generation/compileJsonSchema.d.ts +2 -0
- package/dist/types/generation/format.d.ts +1 -0
- package/dist/types/generation/model/CodeGenerationModel.d.ts +19 -0
- package/dist/types/generation/model/components/Components.d.ts +24 -0
- package/dist/types/generation/model/components/Parameters.d.ts +11 -0
- package/dist/types/generation/model/components/RequestBodies.d.ts +13 -0
- package/dist/types/generation/model/components/Response.d.ts +12 -0
- package/dist/types/generation/model/components/ResponseContent.d.ts +10 -0
- package/dist/types/generation/model/components/Responses.d.ts +13 -0
- package/dist/types/generation/model/components/Schemas.d.ts +13 -0
- package/dist/types/generation/model/components/SecurityScheme.d.ts +10 -0
- package/dist/types/generation/model/components/SecuritySchemes.d.ts +14 -0
- package/dist/types/generation/model/global/JSONSchema.d.ts +13 -0
- package/dist/types/generation/model/global/Name.d.ts +8 -0
- package/dist/types/generation/model/global/Name.test.d.ts +1 -0
- package/dist/types/generation/model/paths/Path.d.ts +13 -0
- package/dist/types/generation/model/paths/Paths.d.ts +25 -0
- package/dist/types/generation/model/paths/operation/Operation.d.ts +24 -0
- package/dist/types/generation/model/paths/operation/RequestParameters.d.ts +17 -0
- package/dist/types/generation/model/paths/operation/responses/Response.d.ts +16 -0
- package/dist/types/generation/model/paths/operation/responses/ResponseContent.d.ts +12 -0
- package/dist/types/generation/model/paths/operation/responses/ResponseContentTypes.d.ts +16 -0
- package/dist/types/generation/model/paths/operation/responses/Responses.d.ts +14 -0
- package/dist/types/generation/model/tags/Tag.d.ts +8 -0
- package/dist/types/generation/prepareTypeScriptOutput.d.ts +1 -0
- package/dist/types/generation/refs/assertNoRefs.d.ts +2 -0
- package/dist/types/generation/refs/componentRefsToCustomTypes.d.ts +1 -0
- package/dist/types/generation/refs/componentRefsToCustomTypes.test.d.ts +1 -0
- package/dist/types/generation/refs/extractComponentRefName.d.ts +2 -0
- package/dist/types/generation/refs/isRef.d.ts +2 -0
- package/dist/types/generation/refs/refNameToTSName.d.ts +1 -0
- package/dist/types/generation/refs/refNameToTSName.test.d.ts +1 -0
- package/dist/types/generation/refs/splitRefNamespaces.d.ts +1 -0
- package/dist/types/generation/refs/splitRefNamespaces.test.d.ts +1 -0
- package/dist/types/generation/tsNamespaceName.d.ts +1 -0
- package/dist/types/generation/tsTypeName.d.ts +1 -0
- package/dist/types/generation/tsTypeName.test.d.ts +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/lib/makeError.d.ts +1 -0
- package/dist/types/lib/relativePath.d.ts +1 -0
- package/dist/types/lib/writeIfChangedAsync.d.ts +1 -0
- package/dist/types/loading/UniversalContentLoader.d.ts +10 -0
- package/dist/types/loading/UniversalContentLoader.test.d.ts +1 -0
- package/dist/types/loading/UniversalFileLoader.d.ts +9 -0
- package/dist/types/loading/types.d.ts +4 -0
- package/dist/types/openapi/OpenAPISchemaValidationError.d.ts +7 -0
- package/dist/types/openapi/OpenApiSpec.d.ts +11 -0
- package/package.json +2 -2
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { splitRefNamespaces } from "./splitRefNamespaces.js";
|
|
2
|
+
test.each([
|
|
3
|
+
["#/foo/bar", ["foo", "bar"]],
|
|
4
|
+
["foo", ["foo"]],
|
|
5
|
+
["#/", []],
|
|
6
|
+
])("splitRefNamespaces works for test %#", (input, expected) => {
|
|
7
|
+
const result = splitRefNamespaces(input);
|
|
8
|
+
expect(result).toEqual(expect.arrayContaining(expected));
|
|
9
|
+
expect(result.length).toEqual(expected.length);
|
|
10
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { toSafeString } from "json-schema-to-typescript/dist/src/utils.js";
|
|
2
|
+
export const tsTypeName = (name) => {
|
|
3
|
+
const nameStartsWithNumber = /^\d/.test(name);
|
|
4
|
+
const almostSafeString = nameStartsWithNumber ? `$${name}` : name;
|
|
5
|
+
return toSafeString(almostSafeString);
|
|
6
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { tsTypeName } from "./tsTypeName.js";
|
|
2
|
+
test.each([
|
|
3
|
+
["123Foo_Bar", "$123Foo_Bar"],
|
|
4
|
+
["123-foo-bar", "$123FooBar"],
|
|
5
|
+
["1-foo-2-3-bar", "$1Foo23Bar"],
|
|
6
|
+
["Foo_Bar", "Foo_Bar"],
|
|
7
|
+
["fooBar", "FooBar"],
|
|
8
|
+
["foo-bar", "FooBar"],
|
|
9
|
+
])("tsTypeName works for test %#", (input, expected) => {
|
|
10
|
+
const result = tsTypeName(input);
|
|
11
|
+
expect(result).toEqual(expected);
|
|
12
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from "./loading/UniversalContentLoader.js";
|
|
2
|
+
export * from "./loading/UniversalFileLoader.js";
|
|
3
|
+
export * from "./openapi/OpenApiSpec.js";
|
|
4
|
+
export * from "./generation/model/CodeGenerationModel.js";
|
|
5
|
+
export * from "./generation/prepareTypeScriptOutput.js";
|
|
6
|
+
export * from "./loading/UniversalFileLoader.js";
|
|
7
|
+
export * from "./lib/writeIfChangedAsync.js";
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { load } from "js-yaml";
|
|
2
|
+
import { parseAsync } from "yieldable-json";
|
|
3
|
+
import VError from "verror";
|
|
4
|
+
import { makeError } from "../lib/makeError.js";
|
|
5
|
+
export class UniversalContentLoader {
|
|
6
|
+
fileLoader;
|
|
7
|
+
constructor(fileLoader) {
|
|
8
|
+
this.fileLoader = fileLoader;
|
|
9
|
+
}
|
|
10
|
+
async load() {
|
|
11
|
+
try {
|
|
12
|
+
const format = UniversalContentLoader.detectSourceFormat(this.fileLoader.source);
|
|
13
|
+
const fileContent = await this.fileLoader.load();
|
|
14
|
+
switch (format) {
|
|
15
|
+
case "yaml":
|
|
16
|
+
return await UniversalContentLoader.parseYaml(fileContent);
|
|
17
|
+
case "json":
|
|
18
|
+
return await UniversalContentLoader.parseJson(fileContent);
|
|
19
|
+
default:
|
|
20
|
+
return await UniversalContentLoader.tryParseUnknown(fileContent);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
throw new VError({
|
|
25
|
+
cause: makeError(error),
|
|
26
|
+
name: "ContentLoaderError",
|
|
27
|
+
}, "Failed loading content");
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
static detectSourceFormat(source) {
|
|
31
|
+
return source.endsWith(".json")
|
|
32
|
+
? "json"
|
|
33
|
+
: source.endsWith(".yaml")
|
|
34
|
+
? "yaml"
|
|
35
|
+
: source.endsWith(".yml")
|
|
36
|
+
? "yaml"
|
|
37
|
+
: undefined;
|
|
38
|
+
}
|
|
39
|
+
static async tryParseUnknown(content) {
|
|
40
|
+
try {
|
|
41
|
+
return await UniversalContentLoader.parseJson(content);
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
try {
|
|
45
|
+
return await UniversalContentLoader.parseYaml(content);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
throw new Error("Content is not of supported format JSON/YAML.");
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
static async parseYaml(yaml) {
|
|
53
|
+
return load(yaml);
|
|
54
|
+
}
|
|
55
|
+
static parseJson(json) {
|
|
56
|
+
return new Promise((res, rej) => parseAsync(json, (err, data) => {
|
|
57
|
+
if (err) {
|
|
58
|
+
rej(err);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
res(data);
|
|
62
|
+
}
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { UniversalContentLoader } from "./UniversalContentLoader.js";
|
|
2
|
+
class TestFileLoader {
|
|
3
|
+
source;
|
|
4
|
+
content;
|
|
5
|
+
constructor(source, content) {
|
|
6
|
+
this.source = source;
|
|
7
|
+
this.content = content;
|
|
8
|
+
}
|
|
9
|
+
load() {
|
|
10
|
+
return Promise.resolve(this.content);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
describe(".load()", () => {
|
|
14
|
+
test("Throws parser-error error when trying to parse known content", async () => {
|
|
15
|
+
const fileLoader = new TestFileLoader("test.json", "{some invalid");
|
|
16
|
+
const contentLoader = new UniversalContentLoader(fileLoader);
|
|
17
|
+
expect(() => contentLoader.load()).rejects.toThrow("Failed loading content: Bad object");
|
|
18
|
+
});
|
|
19
|
+
test("Throws 'Not supported format' error when trying to parse unknown content", async () => {
|
|
20
|
+
const fileLoader = new TestFileLoader("test.foo", "{some invalid");
|
|
21
|
+
const contentLoader = new UniversalContentLoader(fileLoader);
|
|
22
|
+
expect(() => contentLoader.load()).rejects.toThrow("Failed loading content: Content is not of supported format JSON/YAML.");
|
|
23
|
+
});
|
|
24
|
+
test("Can load JSON file content", async () => {
|
|
25
|
+
const fileLoader = new TestFileLoader("test.json", '{"foo": "bar"}');
|
|
26
|
+
const contentLoader = new UniversalContentLoader(fileLoader);
|
|
27
|
+
const content = await contentLoader.load();
|
|
28
|
+
expect(content).toMatchObject({
|
|
29
|
+
foo: "bar",
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
test("Can load unknown JSON file content", async () => {
|
|
33
|
+
const fileLoader = new TestFileLoader("unknown", '{"foo": "bar"}');
|
|
34
|
+
const contentLoader = new UniversalContentLoader(fileLoader);
|
|
35
|
+
const content = await contentLoader.load();
|
|
36
|
+
expect(content).toMatchObject({
|
|
37
|
+
foo: "bar",
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import jetpack from "fs-jetpack";
|
|
3
|
+
import VError from "verror";
|
|
4
|
+
import { makeError } from "../lib/makeError.js";
|
|
5
|
+
import getStdin from "get-stdin";
|
|
6
|
+
export class UniversalFileLoader {
|
|
7
|
+
source;
|
|
8
|
+
constructor(source) {
|
|
9
|
+
this.source = source;
|
|
10
|
+
}
|
|
11
|
+
load() {
|
|
12
|
+
try {
|
|
13
|
+
if (this.source.startsWith("http")) {
|
|
14
|
+
return UniversalFileLoader.loadFromUrl(this.source);
|
|
15
|
+
}
|
|
16
|
+
if (this.source === "/dev/stdin" || this.source === "-") {
|
|
17
|
+
return UniversalFileLoader.loadFromStdin();
|
|
18
|
+
}
|
|
19
|
+
return UniversalFileLoader.loadFromFile(this.source);
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
throw new VError({ cause: makeError(error), name: "FileLoaderError" }, "Failed loading file from %s", this.source);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
static loadFromStdin() {
|
|
26
|
+
return getStdin();
|
|
27
|
+
}
|
|
28
|
+
static async loadFromUrl(url) {
|
|
29
|
+
const response = await axios.get(url, {
|
|
30
|
+
responseType: "text",
|
|
31
|
+
validateStatus: (status) => status === 200,
|
|
32
|
+
});
|
|
33
|
+
return response.data;
|
|
34
|
+
}
|
|
35
|
+
static async loadFromFile(filename) {
|
|
36
|
+
const file = await jetpack.readAsync(filename);
|
|
37
|
+
if (file === undefined) {
|
|
38
|
+
throw new Error(`File not found: ${filename}`);
|
|
39
|
+
}
|
|
40
|
+
return file;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { dump } from "js-yaml";
|
|
2
|
+
export class OpenAPISchemaValidationError extends Error {
|
|
3
|
+
constructor(errors) {
|
|
4
|
+
const mergedMessage = OpenAPISchemaValidationError.mergeErrorMessage(errors);
|
|
5
|
+
super(`OpenAPI is invalid: ${mergedMessage}`);
|
|
6
|
+
Object.setPrototypeOf(this, OpenAPISchemaValidationError.prototype);
|
|
7
|
+
this.name = "OpenAPISchemaValidationError";
|
|
8
|
+
}
|
|
9
|
+
static mergeErrorMessage(errors) {
|
|
10
|
+
return errors
|
|
11
|
+
.map((error, index) => `
|
|
12
|
+
#${index + 1}
|
|
13
|
+
${dump(error)}
|
|
14
|
+
`)
|
|
15
|
+
.join("");
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { OpenAPISchemaValidationError } from "./OpenAPISchemaValidationError.js";
|
|
2
|
+
import VError from "verror";
|
|
3
|
+
import { makeError } from "../lib/makeError.js";
|
|
4
|
+
import OpenAPISchemaValidator from "openapi-schema-validator";
|
|
5
|
+
import { convert } from "swagger2openapi";
|
|
6
|
+
import { ux } from "@oclif/core";
|
|
7
|
+
const validator = new OpenAPISchemaValidator.default({
|
|
8
|
+
version: 3,
|
|
9
|
+
});
|
|
10
|
+
export class OpenApiSpec {
|
|
11
|
+
document;
|
|
12
|
+
constructor(document) {
|
|
13
|
+
this.document = document;
|
|
14
|
+
}
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
|
+
static async convertToOpenApi(doc) {
|
|
17
|
+
const version = doc.openapi ?? doc.swagger;
|
|
18
|
+
if (version.startsWith("3")) {
|
|
19
|
+
return doc;
|
|
20
|
+
}
|
|
21
|
+
ux.action.start("Converting doc to OpenAPI v3");
|
|
22
|
+
const spec = await convert(doc, {
|
|
23
|
+
patch: true,
|
|
24
|
+
});
|
|
25
|
+
ux.action.stop();
|
|
26
|
+
return spec.openapi;
|
|
27
|
+
}
|
|
28
|
+
static async parse(
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
|
+
doc, opts = {}) {
|
|
31
|
+
try {
|
|
32
|
+
const { skipValidation = false } = opts;
|
|
33
|
+
doc = await OpenApiSpec.convertToOpenApi(doc);
|
|
34
|
+
const validationResult = await validator.validate(doc);
|
|
35
|
+
if (validationResult.errors.length > 0 && !skipValidation) {
|
|
36
|
+
throw new OpenAPISchemaValidationError(validationResult.errors);
|
|
37
|
+
}
|
|
38
|
+
return new OpenApiSpec(doc);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
throw new VError({ cause: makeError(error), name: "OpenAPIParserError" }, "Failed parsing OpenAPISpec");
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Command } from "@oclif/core";
|
|
2
|
+
export default class Generate extends Command {
|
|
3
|
+
static description: string;
|
|
4
|
+
static flags: {
|
|
5
|
+
skipValidation: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
|
|
6
|
+
name: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
7
|
+
optionalHeader: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
8
|
+
};
|
|
9
|
+
static args: {
|
|
10
|
+
input: import("@oclif/core/lib/interfaces/parser.js").Arg<string, {
|
|
11
|
+
exists?: boolean | undefined;
|
|
12
|
+
}>;
|
|
13
|
+
output: import("@oclif/core/lib/interfaces/parser.js").Arg<string, {
|
|
14
|
+
exists?: boolean | undefined;
|
|
15
|
+
}>;
|
|
16
|
+
};
|
|
17
|
+
run(): Promise<void>;
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const asyncStringJoin: <T>(items: T[], contentGenerator: (item: T) => string | Promise<string>, separator?: string) => Promise<string>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const format: (ts: string) => Promise<string>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Name } from "./global/Name.js";
|
|
2
|
+
import { Components } from "./components/Components.js";
|
|
3
|
+
import { Paths } from "./paths/Paths.js";
|
|
4
|
+
import { Tag } from "./tags/Tag.js";
|
|
5
|
+
import { OpenAPIV3 } from "openapi-types";
|
|
6
|
+
export interface TypeCompilationOptions {
|
|
7
|
+
optionalHeaders?: string[];
|
|
8
|
+
rootNamespace: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class CodeGenerationModel {
|
|
11
|
+
readonly rootNamespace: Name;
|
|
12
|
+
readonly paths: Paths;
|
|
13
|
+
readonly components: Components;
|
|
14
|
+
readonly tags: Tag[];
|
|
15
|
+
readonly doc: OpenAPIV3.Document;
|
|
16
|
+
private constructor();
|
|
17
|
+
static fromDoc(rootNamespace: string, doc: OpenAPIV3.Document): CodeGenerationModel;
|
|
18
|
+
compileTypes(opts: TypeCompilationOptions): Promise<string>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { CodeGenerationModel, TypeCompilationOptions } from "../CodeGenerationModel.js";
|
|
2
|
+
import { Name } from "../global/Name.js";
|
|
3
|
+
import { Schemas } from "./Schemas.js";
|
|
4
|
+
import { Parameters } from "./Parameters.js";
|
|
5
|
+
import { RequestBodies } from "./RequestBodies.js";
|
|
6
|
+
import { Responses } from "./Responses.js";
|
|
7
|
+
import { SecuritySchemes } from "./SecuritySchemes.js";
|
|
8
|
+
import { OpenAPIV3 } from "openapi-types";
|
|
9
|
+
export type ComponentTypeName = keyof OpenAPIV3.ComponentsObject;
|
|
10
|
+
export type ComponentType<T extends ComponentTypeName> = Required<OpenAPIV3.ComponentsObject>[T][string];
|
|
11
|
+
export type ResolvedComponentType<T extends ComponentTypeName> = Exclude<ComponentType<T>, OpenAPIV3.ReferenceObject>;
|
|
12
|
+
export declare class Components {
|
|
13
|
+
static readonly ns = "Components";
|
|
14
|
+
name: Name;
|
|
15
|
+
schemas: Schemas;
|
|
16
|
+
securitySchemes: SecuritySchemes;
|
|
17
|
+
parameters: Parameters;
|
|
18
|
+
requestBodies: RequestBodies;
|
|
19
|
+
responses: Responses;
|
|
20
|
+
model: CodeGenerationModel;
|
|
21
|
+
constructor(model: CodeGenerationModel);
|
|
22
|
+
compileTypes(opts: TypeCompilationOptions): Promise<string>;
|
|
23
|
+
resolveRef<T extends ComponentTypeName>(componentType: T, obj: ComponentType<T>): ResolvedComponentType<T>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Name } from "../global/Name.js";
|
|
2
|
+
import { Components, ComponentType } from "./Components.js";
|
|
3
|
+
import { TypeCompilationOptions } from "../CodeGenerationModel.js";
|
|
4
|
+
export declare class Parameters {
|
|
5
|
+
static readonly ns = "Parameters";
|
|
6
|
+
readonly components: Components;
|
|
7
|
+
readonly name: Name;
|
|
8
|
+
readonly parameters: Record<string, ComponentType<"parameters">>;
|
|
9
|
+
constructor(components: Components, parametersObject: Record<string, ComponentType<"parameters">>);
|
|
10
|
+
compileTypes(opts: TypeCompilationOptions): Promise<string>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { JSONSchema } from "../global/JSONSchema.js";
|
|
2
|
+
import { Name } from "../global/Name.js";
|
|
3
|
+
import { Components } from "./Components.js";
|
|
4
|
+
import { TypeCompilationOptions } from "../CodeGenerationModel.js";
|
|
5
|
+
import { OpenAPIV3 } from "openapi-types";
|
|
6
|
+
export declare class RequestBodies {
|
|
7
|
+
static readonly ns = "RequestBodies";
|
|
8
|
+
readonly schemas: JSONSchema[];
|
|
9
|
+
readonly components: Components;
|
|
10
|
+
readonly name: Name;
|
|
11
|
+
constructor(components: Components, schemas: OpenAPIV3.ComponentsObject["requestBodies"]);
|
|
12
|
+
compileTypes(opts: TypeCompilationOptions): Promise<string>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Name } from "../global/Name.js";
|
|
2
|
+
import { ResponseContent } from "./ResponseContent.js";
|
|
3
|
+
import { Responses } from "./Responses.js";
|
|
4
|
+
import { TypeCompilationOptions } from "../CodeGenerationModel.js";
|
|
5
|
+
import { OpenAPIV3 } from "openapi-types";
|
|
6
|
+
export declare class Response {
|
|
7
|
+
readonly name: Name;
|
|
8
|
+
readonly responses: Responses;
|
|
9
|
+
readonly contents: ResponseContent[];
|
|
10
|
+
constructor(name: Name, responses: Responses, mediaTypesDoc: Record<string, OpenAPIV3.MediaTypeObject>);
|
|
11
|
+
compileTypes(opts: TypeCompilationOptions): Promise<string>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { JSONSchema as JSONSchemaType } from "json-schema-to-typescript";
|
|
2
|
+
import { Name } from "../global/Name.js";
|
|
3
|
+
import { Response } from "./Response.js";
|
|
4
|
+
import { JSONSchema } from "../global/JSONSchema.js";
|
|
5
|
+
export declare class ResponseContent {
|
|
6
|
+
readonly mediaType: Name;
|
|
7
|
+
readonly schema: JSONSchema;
|
|
8
|
+
readonly response: Response;
|
|
9
|
+
constructor(response: Response, mediaType: string, schema: JSONSchemaType);
|
|
10
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Name } from "../global/Name.js";
|
|
2
|
+
import { Components } from "./Components.js";
|
|
3
|
+
import { Response } from "./Response.js";
|
|
4
|
+
import { TypeCompilationOptions } from "../CodeGenerationModel.js";
|
|
5
|
+
import { OpenAPIV3 } from "openapi-types";
|
|
6
|
+
export declare class Responses {
|
|
7
|
+
static readonly ns = "Responses";
|
|
8
|
+
readonly responses: Response[];
|
|
9
|
+
readonly components: Components;
|
|
10
|
+
readonly name: Name;
|
|
11
|
+
constructor(components: Components, responses?: OpenAPIV3.ComponentsObject["responses"]);
|
|
12
|
+
compileTypes(opts: TypeCompilationOptions): Promise<string>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { JSONSchema } from "../global/JSONSchema.js";
|
|
2
|
+
import { Name } from "../global/Name.js";
|
|
3
|
+
import { Components } from "./Components.js";
|
|
4
|
+
import { TypeCompilationOptions } from "../CodeGenerationModel.js";
|
|
5
|
+
import { OpenAPIV3 } from "openapi-types";
|
|
6
|
+
export declare class Schemas {
|
|
7
|
+
static readonly ns = "Schemas";
|
|
8
|
+
readonly schemas: JSONSchema[];
|
|
9
|
+
readonly components: Components;
|
|
10
|
+
readonly name: Name;
|
|
11
|
+
constructor(components: Components, schemas: OpenAPIV3.ComponentsObject["schemas"]);
|
|
12
|
+
compileTypes(opts: TypeCompilationOptions): Promise<string>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { OpenAPIV3 } from "openapi-types";
|
|
2
|
+
import { Name } from "../global/Name.js";
|
|
3
|
+
import { SecuritySchemes } from "./SecuritySchemes.js";
|
|
4
|
+
import { JSONSchema } from "../global/JSONSchema.js";
|
|
5
|
+
export declare class SecurityScheme {
|
|
6
|
+
readonly in: string;
|
|
7
|
+
readonly name: Name;
|
|
8
|
+
readonly jsonSchema: JSONSchema;
|
|
9
|
+
constructor(schemes: SecuritySchemes, name: string, doc: OpenAPIV3.ApiKeySecurityScheme);
|
|
10
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Name } from "../global/Name.js";
|
|
2
|
+
import { Components } from "./Components.js";
|
|
3
|
+
import { OpenAPIV3 } from "openapi-types";
|
|
4
|
+
import { SecurityScheme } from "./SecurityScheme.js";
|
|
5
|
+
import { TypeCompilationOptions } from "../CodeGenerationModel.js";
|
|
6
|
+
export declare class SecuritySchemes {
|
|
7
|
+
static readonly ns = "SecuritySchemes";
|
|
8
|
+
readonly schemes: SecurityScheme[];
|
|
9
|
+
readonly components: Components;
|
|
10
|
+
readonly name: Name;
|
|
11
|
+
constructor(components: Components, doc?: OpenAPIV3.ComponentsObject["securitySchemes"]);
|
|
12
|
+
requireScheme(name: string): SecurityScheme;
|
|
13
|
+
compileTypes(opts: TypeCompilationOptions): Promise<string>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { JSONSchema as JSONSchemaObject } from "json-schema-to-typescript";
|
|
2
|
+
import { Name } from "./Name.js";
|
|
3
|
+
import { TypeCompilationOptions } from "../CodeGenerationModel.js";
|
|
4
|
+
export declare class JSONSchema {
|
|
5
|
+
readonly schemaObject: JSONSchemaObject;
|
|
6
|
+
readonly name: Name;
|
|
7
|
+
constructor(name: Name, data?: JSONSchemaObject);
|
|
8
|
+
compile(opts: TypeCompilationOptions): Promise<string>;
|
|
9
|
+
clone(): JSONSchema;
|
|
10
|
+
cloneWithOptionalProperties(optionalProperties: string[]): JSONSchema;
|
|
11
|
+
private setOptionalPropertiesInSchema;
|
|
12
|
+
asCustomTypeRef(): JSONSchemaObject;
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Operation } from "./operation/Operation.js";
|
|
2
|
+
import { Name } from "../global/Name.js";
|
|
3
|
+
import { Paths } from "./Paths.js";
|
|
4
|
+
import { TypeCompilationOptions } from "../CodeGenerationModel.js";
|
|
5
|
+
import { OpenAPIV3 } from "openapi-types";
|
|
6
|
+
export declare class Path {
|
|
7
|
+
readonly paths: Paths;
|
|
8
|
+
readonly name: Name;
|
|
9
|
+
readonly operations: Operation[];
|
|
10
|
+
private constructor();
|
|
11
|
+
static fromDoc(paths: Paths, name: string, operationsDoc: OpenAPIV3.PathItemObject): Path;
|
|
12
|
+
compileTypes(options: TypeCompilationOptions): Promise<string>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Name } from "../global/Name.js";
|
|
2
|
+
import { CodeGenerationModel, TypeCompilationOptions } from "../CodeGenerationModel.js";
|
|
3
|
+
import { Path } from "./Path.js";
|
|
4
|
+
import { Operation } from "./operation/Operation.js";
|
|
5
|
+
import { Tag } from "../tags/Tag.js";
|
|
6
|
+
import { OpenAPIV3 } from "openapi-types";
|
|
7
|
+
export declare class Paths {
|
|
8
|
+
static readonly ns = "Paths";
|
|
9
|
+
readonly paths: Path[];
|
|
10
|
+
readonly model: CodeGenerationModel;
|
|
11
|
+
readonly name: Name;
|
|
12
|
+
constructor(model: CodeGenerationModel, paths: OpenAPIV3.PathsObject);
|
|
13
|
+
compileTypes(opts: TypeCompilationOptions): Promise<string>;
|
|
14
|
+
compileOperationTypes(): Promise<string>;
|
|
15
|
+
compileDescriptors(): string;
|
|
16
|
+
getFlattenedOperations(httpMethod?: string): Operation[];
|
|
17
|
+
getGroupedOperationsByTag(httpMethod?: string): Array<[Tag, Operation[]]>;
|
|
18
|
+
private compileClientMethodsOfTag;
|
|
19
|
+
compileClient(): string;
|
|
20
|
+
private compileReactClientApiName;
|
|
21
|
+
private compileReactClientApiBuilderOfTag;
|
|
22
|
+
private compileReactClientPropertyInitializer;
|
|
23
|
+
private compileReactClientProperties;
|
|
24
|
+
compileReactClient(): string;
|
|
25
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { RequestParameters } from "./RequestParameters.js";
|
|
2
|
+
import { Path } from "../Path.js";
|
|
3
|
+
import { Name } from "../../global/Name.js";
|
|
4
|
+
import { Responses } from "./responses/Responses.js";
|
|
5
|
+
import { Tag } from "../../tags/Tag.js";
|
|
6
|
+
import { TypeCompilationOptions } from "../../CodeGenerationModel.js";
|
|
7
|
+
import { OpenAPIV3 } from "openapi-types";
|
|
8
|
+
export declare class Operation {
|
|
9
|
+
readonly path: Path;
|
|
10
|
+
readonly id: Name;
|
|
11
|
+
readonly httpMethod: Name;
|
|
12
|
+
readonly parameters: RequestParameters;
|
|
13
|
+
readonly responses: Responses;
|
|
14
|
+
readonly summary?: string;
|
|
15
|
+
readonly tags: Tag[];
|
|
16
|
+
private constructor();
|
|
17
|
+
static fromDoc(path: Path, httpMethod: string, doc: OpenAPIV3.OperationObject): Operation;
|
|
18
|
+
compileTypes(options: TypeCompilationOptions): Promise<string>;
|
|
19
|
+
compileDescriptor(): string;
|
|
20
|
+
compileRequestResponseTypes(): string;
|
|
21
|
+
private getMethodName;
|
|
22
|
+
compileClientMethod(tag: Tag): string;
|
|
23
|
+
compileReactClientMethod(tag: Tag): string;
|
|
24
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { JSONSchema } from "../../global/JSONSchema.js";
|
|
2
|
+
import { Operation } from "./Operation.js";
|
|
3
|
+
import { TypeCompilationOptions } from "../../CodeGenerationModel.js";
|
|
4
|
+
import { OpenAPIV3 } from "openapi-types";
|
|
5
|
+
export declare class RequestParameters {
|
|
6
|
+
static readonly ns = "Parameters";
|
|
7
|
+
readonly path?: JSONSchema;
|
|
8
|
+
readonly query?: JSONSchema;
|
|
9
|
+
readonly header?: JSONSchema;
|
|
10
|
+
readonly body?: JSONSchema;
|
|
11
|
+
readonly operation: Operation;
|
|
12
|
+
private constructor();
|
|
13
|
+
private static constructParametersSchema;
|
|
14
|
+
static fromDoc(operation: Operation, doc: OpenAPIV3.OperationObject): RequestParameters;
|
|
15
|
+
compileTypes(opts: TypeCompilationOptions): Promise<string>;
|
|
16
|
+
compileDescriptorRequestType(): string;
|
|
17
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Name } from "../../../global/Name.js";
|
|
2
|
+
import { ResponseContentTypes } from "./ResponseContentTypes.js";
|
|
3
|
+
import { Responses } from "./Responses.js";
|
|
4
|
+
import { TypeCompilationOptions } from "../../../CodeGenerationModel.js";
|
|
5
|
+
import { OpenAPIV3 } from "openapi-types";
|
|
6
|
+
import { ValueOf } from "type-fest";
|
|
7
|
+
type DocType = ValueOf<OpenAPIV3.ResponsesObject>;
|
|
8
|
+
export declare class Response {
|
|
9
|
+
readonly responses: Responses;
|
|
10
|
+
readonly contentTypes: ResponseContentTypes;
|
|
11
|
+
readonly httpStatus: Name;
|
|
12
|
+
private constructor();
|
|
13
|
+
static fromDoc(responses: Responses, httpStatus: Name, doc: DocType): Response;
|
|
14
|
+
compileContentTypes(opts: TypeCompilationOptions): Promise<string>;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { JSONSchema as JSONSchemaType } from "json-schema-to-typescript";
|
|
2
|
+
import { JSONSchema } from "../../../global/JSONSchema.js";
|
|
3
|
+
import { Name } from "../../../global/Name.js";
|
|
4
|
+
import { ResponseContentTypes } from "./ResponseContentTypes.js";
|
|
5
|
+
export declare class ResponseContent {
|
|
6
|
+
readonly mediaType: Name;
|
|
7
|
+
readonly schema: JSONSchema;
|
|
8
|
+
readonly contentTypes: ResponseContentTypes;
|
|
9
|
+
constructor(contentTypes: ResponseContentTypes, mediaType: string, schema?: JSONSchemaType);
|
|
10
|
+
static buildEmpty(contentTypes: ResponseContentTypes): ResponseContent;
|
|
11
|
+
compileDescriptorsResponseContentType(): string;
|
|
12
|
+
}
|