Skip to content

Commit 1868ec8

Browse files
committed
Spec now includes if a property is marked as a request parameter or not in the typescript source.
Flight recorder ommits this now from generation on body
1 parent 815ddb3 commit 1868ec8

File tree

5 files changed

+30
-16
lines changed

5 files changed

+30
-16
lines changed

flight-recorder-generator/flight-recorder-json-generator.js

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

flight-recorder-generator/flight-recorder-json-generator.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ export class FlightRecorderJsonGenerator {
1212
fs.mkdirSync(f);
1313
this.specification.endpoints.forEach(api => {
1414
const pathPrefix = path.join(f, api.name);
15+
const body =this.createRequestResponse(api.typeMapping.request);
16+
const args = api.queryStringParameters.reduce((o, p) => ({...o, [p.name]: p.type}), {});
17+
// @ts-ignore
18+
args.body = body;
19+
1520
const request = {
1621
api: api.name,
17-
args: {
18-
body: this.createRequestResponse(api.typeMapping.request)
19-
}
22+
args
2023
};
2124
fs.writeFileSync(pathPrefix + "_request.json", JSON.stringify(request, null, 2));
2225
const response = {
@@ -44,7 +47,9 @@ export class FlightRecorderJsonGenerator {
4447
const valueType = FlightRecorderJsonGenerator.createValueType(i.name);
4548
if (valueType !== null) return valueType;
4649

47-
return i.properties.reduce((o, p) => ({...o, [p.name]: this.createInterfaceProperty(p, seenTypes)}), {});
50+
return i.properties
51+
.filter(p => !p.isRequestParameter)
52+
.reduce((o, p) => ({...o, [p.name]: this.createInterfaceProperty(p, seenTypes)}), {});
4853
}
4954

5055
private static createValueType(typeName) {
@@ -91,23 +96,24 @@ export class FlightRecorderJsonGenerator {
9196
return i;
9297
}
9398

94-
private createTypeSchema(type: Domain.Type, seenTypes) {
99+
private createTypeSchema(type: Domain.Type, seenTypes: Set<string>) {
95100
const valueType = FlightRecorderJsonGenerator.createValueType(type.name);
96101
if (valueType !== null) return valueType;
97102

98103
if (seenTypes.has(type.name)) return { $type: `Circular reference to: ${type.name}`};
99104
seenTypes.add(type.name);
100105

101106
const i = this.lookupType(type.name);
102-
return this.toSchema(i, seenTypes, type.name);
107+
const schema = this.toSchema(i, seenTypes, type.name);
108+
seenTypes.delete(type.name);
109+
return schema;
103110
}
104111

105112
private createArraySchema(arr: Domain.ArrayOf, seenTypes) {
106113
return [this.dispatchInstanceOf(arr.of, seenTypes)];
107114
}
108115

109116
private createDictionarySchema(dict: Domain.Dictionary, seenTypes: Set<string>) {
110-
// todo handle additionalProperties and find out how we can type the key.
111117
return { __name__ : this.dispatchInstanceOf(dict.value, seenTypes) };
112118
}
113119

@@ -116,7 +122,6 @@ export class FlightRecorderJsonGenerator {
116122
}
117123

118124
private createUnionOfSchema(union: Domain.UnionOf, seenTypes: Set<string>) {
119-
// union should be oneOf but open api does not support the full json-schema draft 4
120125
return { __anyOf__ : [
121126
union.items.map(i => this.dispatchInstanceOf(i, seenTypes))
122127
] };

specification/src/domain.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ declare namespace Domain {
3030
}
3131
class InterfaceProperty {
3232
name: string;
33-
constructor(name: string);
33+
isRequestParameter: boolean;
34+
constructor(name: string, isRequestParameter: boolean);
3435
type: InstanceOf;
3536
}
3637
class Enum extends TypeDeclaration {

specification/src/domain.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace Domain {
3434
}
3535

3636
export class InterfaceProperty {
37-
constructor(public name: string) {}
37+
constructor(public name: string, public isRequestParameter: boolean) {}
3838
type: InstanceOf;
3939
}
4040

specification/src/specification/type-reader.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ class InterfaceVisitor extends Visitor {
8787
const name = this.symbolName(p.name);
8888
const returnType = this.visitTypeNode(p.type);
8989

90-
const prop = new Domain.InterfaceProperty(name);
90+
const decorator = _(p.decorators || [])
91+
.map(d => d.expression.getText())
92+
.find(d => d.startsWith("request_parameter"));
93+
const prop = new Domain.InterfaceProperty(name, !!decorator);
9194
prop.type = returnType;
9295
parent.properties.push(prop);
9396
}

0 commit comments

Comments
 (0)