Skip to content

Commit

Permalink
Add return type override, use for val-match-v1.getRecent
Browse files Browse the repository at this point in the history
  • Loading branch information
MingweiSamuel committed Sep 15, 2020
1 parent 997750f commit 612f602
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
11 changes: 11 additions & 0 deletions src/data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ Methods that are reasonably likely to return 404s or 204s.
Method parameters (URL and GET params, currently body is not considered (?))
to be annotated with `x-enum` values.

# `methodReturnOverrides.json`
Override a method's return type:
```json
{
"val-match-v1.getRecent": {
"$ref": "#/components/schemas/val-match-v1.RecentMatchesDto",
"x-type": "RecentMatchesDto"
}
}
```

# `schemaOverrides.json`
These are additional schemas that are included in the output. If any of these
DTOs exist from the scraping these schemas will override those.
Expand Down
6 changes: 6 additions & 0 deletions src/data/methodReturnOverrides.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"val-match-v1.getRecent": {
"$ref": "#/components/schemas/val-match-v1.RecentMatchesDto",
"x-type": "RecentMatchesDto"
}
}
21 changes: 21 additions & 0 deletions src/data/schemaOverrides.json
Original file line number Diff line number Diff line change
Expand Up @@ -726,5 +726,26 @@
"item6",
"item5"
]
},
"val-match-v1.RecentMatchesDto": {
"type": "object",
"title": "RecentMatchesDto",
"properties": {
"currentTime": {
"type": "integer",
"format": "int64",
"x-type": "long",
"description": "Current time in epoch seconds."
},
"matchIds": {
"type": "array",
"items": {
"type": "string",
"x-type": "string"
},
"x-type": "List[string]",
"description": "List of match IDs."
}
}
}
}
13 changes: 7 additions & 6 deletions src/method.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
/// A method is a single REST API url with associated argument, return value,
/// and response code information.

const fs = require("fs-extra");

const platformsAvailableOverrides = require('./data/endpointPlatformsAvailableOverrides');
const methodReturnOverrides = require('./data/methodReturnOverrides');
const routesTable = require('./data/routesTable');
const methodOptional = require('./data/methodOptional');

Expand All @@ -16,7 +15,7 @@ function Method(endpoint, methodEl) {
this.endpoint = endpoint;
this.methodEl = methodEl;
this.name = methodEl.id.substring(1);
this.canonName = this.endpoint.name + '.' + this.name;
this.canonName = `${this.endpoint.name}.${this.name}`;

let heading = methodEl.children[0];
let method = heading.children[0].children[0];
Expand All @@ -31,7 +30,7 @@ function Method(endpoint, methodEl) {

this.bodyType = null;
this.bodyRequired = null;
this.returnType = null;
this.returnType = methodReturnOverrides[this.canonName] || null;
this.dtos = [];
this.params = [];
this.responses = {};
Expand All @@ -46,7 +45,8 @@ function Method(endpoint, methodEl) {

console.log(` ${this.name} - ${this.httpMethod.toUpperCase()}` +
(this.nullable404 ? ' (nullable)' : '') +
(this.deprecated ? ' (DEPRECATED)' : ''));
(this.deprecated ? ' (DEPRECATED)' : '') +
(this.returnType ? ` [return override ${this.returnType['x-type']}]` : ''));

let apiBlocks = this.methodEl.getElementsByClassName('api_block');
Array.from(apiBlocks)
Expand Down Expand Up @@ -170,7 +170,8 @@ Method.prototype._compileApiBlock = function(apiBlockHtml) {
Method.prototype._handleResponseClasses = function(apiBlockHtml) {
// returnType may be null.
const [ returnTypeBlock, ...schemaBlocks ] = apiBlockHtml.querySelectorAll('div.block.response_body');
this.returnType = Schema.readReturnType(returnTypeBlock, this.endpoint.name, this.name);
this.returnType || (this.returnType =
Schema.readReturnType(returnTypeBlock, this.endpoint.name, this.name));
this.dtos.push(...schemaBlocks
.map(el => Schema.fromHtml(el, this.endpoint.name, this.name, { requiredByDefault: true, useDtoOptional: true })));
};
Expand Down

0 comments on commit 612f602

Please sign in to comment.