Skip to content

Commit 3784cf4

Browse files
committed
update types
1 parent 4935d85 commit 3784cf4

File tree

10 files changed

+20551
-14251
lines changed

10 files changed

+20551
-14251
lines changed

specification/src/domain.d.ts

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,43 @@ declare module Domain {
4848
required: boolean;
4949
constructor(data: any);
5050
}
51+
class Documentation {
52+
description: string;
53+
url: string;
54+
constructor(data: any);
55+
}
56+
enum Stability {
57+
stable = 0,
58+
beta = 1,
59+
experimental = 2,
60+
}
61+
class Deprecation {
62+
version: string;
63+
description: string;
64+
constructor(data: any);
65+
}
5166
class Endpoint {
5267
name: string;
53-
documentation: string;
54-
bodyDocumentation: BodyDocumentation;
55-
methods: string[];
56-
url: Route;
5768
typeMapping: RestSpecMapping;
69+
documentation: Documentation;
70+
stability: Stability;
71+
body: BodyDocumentation;
72+
url: Url;
73+
queryStringParameters: QueryStringParameter[];
74+
deprecated: Deprecation;
5875
constructor(file: string, restSpecMapping: {
5976
[p: string]: RestSpecMapping;
6077
});
6178
}
62-
class Route {
79+
class UrlPath {
6380
path: string;
64-
paths: string[];
81+
methods: string[];
6582
parts: RoutePart[];
66-
queryStringParameters: QueryStringParameter[];
83+
deprecated: Deprecation;
84+
constructor(data: any);
85+
}
86+
class Url {
87+
paths: UrlPath[];
6788
constructor(data: any);
6889
}
6990
class RestSpecTypeConverter {

specification/src/domain.ts

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {RestSpecMapping} from "./specification/rest-spec-mapping";
22
import * as _ from "lodash";
3+
import { BreakpointResolver } from "ntypescript";
34

45
module Domain {
56
import Any = ts.formatting.Shared.TokenRange.Any;
@@ -55,42 +56,81 @@ module Domain {
5556
this.required = !!data.required;
5657
}
5758
}
59+
export class Documentation {
60+
description: string;
61+
url: string;
62+
constructor(data: any) {
63+
this.description = data.description;
64+
this.url = data.url;
65+
}
66+
}
67+
export enum Stability { stable, beta, experimental }
68+
69+
export class Deprecation {
70+
version: string;
71+
description: string;
72+
constructor(data: any) {
73+
this.version = data.version;
74+
this.description = data.description;
75+
}
76+
}
5877

5978
export class Endpoint {
6079
name: string;
61-
documentation: string;
62-
bodyDocumentation: BodyDocumentation;
63-
methods: string[];
64-
url: Route;
6580
typeMapping: RestSpecMapping;
6681

82+
documentation: Documentation;
83+
stability: Stability;
84+
body: BodyDocumentation;
85+
url: Url;
86+
queryStringParameters: QueryStringParameter[] = [];
87+
deprecated: Deprecation;
88+
6789
constructor(file: string, restSpecMapping: { [p: string]: RestSpecMapping }) {
6890
const json = require(file);
6991

7092
this.name = _(json).keys().first();
7193
this.typeMapping = restSpecMapping[this.name];
7294
const data = json[this.name];
7395

74-
this.documentation = data.documentation;
75-
this.methods = data.methods;
76-
if (data.body)
77-
this.bodyDocumentation = new BodyDocumentation(data.body);
96+
this.documentation = new Documentation(data.documentation);
97+
this.queryStringParameters = _(data.params).map((v, k) => new QueryStringParameter(k, v)).value();
7898

79-
this.url = new Route(data.url);
99+
if (data.body)
100+
this.body = new BodyDocumentation(data.body);
101+
if (data.deprecated)
102+
this.deprecated = new Deprecation(data.deprecated);
103+
104+
switch(data.stability)
105+
{
106+
case "stable": this.stability = Stability.stable; break;
107+
case "beta": this.stability = Stability.stable; break;
108+
case "experimental": this.stability = Stability.stable; break;
109+
};
110+
111+
this.url = new Url(data.url);
80112
}
81113
}
82-
83-
export class Route {
114+
export class UrlPath {
84115
path: string;
85-
paths: string[];
116+
methods: string[];
86117
parts: RoutePart[];
87-
queryStringParameters: QueryStringParameter[] = [];
88-
118+
deprecated: Deprecation;
89119
constructor(data: any) {
90120
this.path = data.path;
91-
this.paths = data.paths;
121+
this.methods = data.methods;
92122
this.parts = _(data.parts).map((v, k) => new RoutePart(k, v)).value();
93-
this.queryStringParameters = _(data.params).map((v, k) => new QueryStringParameter(k, v)).value();
123+
if (data.deprecated)
124+
this.deprecated = new Deprecation(data.deprecated);
125+
}
126+
}
127+
128+
export class Url {
129+
paths: UrlPath[];
130+
131+
132+
constructor(data: any) {
133+
this.paths = _(data.paths).map(p => new UrlPath(p)).value();
94134
}
95135
}
96136
export class RestSpecTypeConverter {

swagger-generator/src/swagger-enpoint-builder.js

Lines changed: 8 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swagger-generator/src/swagger-enpoint-builder.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {Specification} from "../../specification/src/api-specification";
22
import {Path, Schema, Operation, Response, Parameter} from "swagger-schema-official";
3-
import {Endpoint, QueryStringParameter, RoutePart} from "../../specification/src/domain";
3+
import {Endpoint, QueryStringParameter, RoutePart, UrlPath} from "../../specification/src/domain";
44

55
export type Paths = { [p: string]: Path};
66

@@ -12,43 +12,42 @@ export class SwaggerEndpointBuilder {
1212
return this.specification.endpoints
1313
.map(e => e.url.paths.map(p => ({ endpoint: e, path: p})))
1414
.reduce((a, paths) => a.concat(paths), [])
15-
.reduce((o, e) => ({...o, [e.path]: SwaggerEndpointBuilder.createPath(e.endpoint, e.path)}), {});
15+
.reduce((o, e) => ({...o, [e.path.path]: SwaggerEndpointBuilder.createPath(e.endpoint, e.path)}), {});
1616
}
1717

18-
private static createPath(e: Endpoint, url: string): Path {
18+
private static createPath(e: Endpoint, url: UrlPath): Path {
1919
const path: Path = {
20-
parameters: e.url.queryStringParameters
20+
parameters: e.queryStringParameters
2121
.map(SwaggerEndpointBuilder.urlQueryStringToParameter)
2222
};
2323

24-
if (e.bodyDocumentation)
24+
if (e.body)
2525
path.parameters.push(SwaggerEndpointBuilder.urlBodyToParameter(e));
2626

27-
return e.methods
27+
return url.methods
2828
.map(m => m.toLowerCase())
2929
.reduce((o, m) => ({...o, [m]: SwaggerEndpointBuilder.createOperation(e, url)}), path);
3030
}
3131

32-
private static createOperation(endpoint: Endpoint, url: string): Operation {
32+
private static createOperation(endpoint: Endpoint, url: UrlPath): Operation {
3333
const defaultContentTypes = ["application/json"];
3434
return {
3535
responses: SwaggerEndpointBuilder.getResponses(endpoint),
3636
tags: [endpoint.name],
3737
consumes: defaultContentTypes,
3838
produces: defaultContentTypes,
39-
parameters: endpoint.url.parts
40-
.filter(p => url.match(new RegExp("\{" + p.name + "\}")))
39+
parameters: url.parts
4140
.map(SwaggerEndpointBuilder.urlPartToParameter),
42-
externalDocs: endpoint.documentation ? {url: endpoint.documentation} : null
41+
externalDocs: endpoint.documentation ? {url: endpoint.documentation.url || ""} : null
4342
};
4443
}
4544

4645
private static urlBodyToParameter(e: Endpoint) {
4746
return {
4847
in: "body",
4948
name: "request",
50-
description: e.bodyDocumentation ? e.bodyDocumentation.description : null,
51-
required: e.bodyDocumentation ? e.bodyDocumentation.required : false,
49+
description: e.body ? e.body.description : null,
50+
required: e.body ? e.body.required : false,
5251
schema: {$ref: "#/definitions/" + e.typeMapping.request }
5352
};
5453
}

swagger-generator/src/swagger-generator.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swagger-generator/src/swagger-generator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class SwaggerGenerator {
1919
definitions: new JsonSchemaBuilder(this.specification).build()
2020
};
2121

22-
const swaggerRoot = Yaml.safeDump(swag, { noRefs: true, lineWidth: 400 });
22+
const swaggerRoot = Yaml.safeDump(swag, { noRefs: true, lineWidth: 400, skipInvalid: true });
2323
const f = __dirname + "/" + folder;
2424

2525
fs.writeFileSync( f + "/index.yml", swaggerRoot);

swagger-generator/swagger-output/index.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)