Skip to content

Commit 169b83c

Browse files
authored
Add Binary data type (#703)
1 parent 883c0f4 commit 169b83c

File tree

8 files changed

+98
-4
lines changed

8 files changed

+98
-4
lines changed

compiler/model/utils.ts

+11
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,17 @@ export function modelType (node: Node): model.ValueOf {
216216
return type
217217
}
218218

219+
case 'ArrayBuffer': {
220+
const type: model.InstanceOf = {
221+
kind: 'instance_of',
222+
type: {
223+
name: 'binary',
224+
namespace: 'internal'
225+
}
226+
}
227+
return type
228+
}
229+
219230
case 'Dictionary':
220231
case 'AdditionalProperties': {
221232
assert(node, node.getTypeArguments().length === 2, 'A Dictionary must have two arguments')

docs/modeling-guide.md

+32
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,38 @@ type TimeSpan = string
139139
type DateString = string
140140
```
141141
142+
### Binary
143+
144+
Some APIs return a Binary stream of data instead of JSON.
145+
Create an alias of the `ArrayBuffer` type for the appropriate name.
146+
147+
```ts
148+
export type MapboxVectorTiles = ArrayBuffer
149+
150+
export class Response {
151+
body: MapboxVectorTiles
152+
}
153+
```
154+
155+
In the output schema.json `MapboxVectorTiles` will be defined as:
156+
157+
```json
158+
{
159+
"kind": "type_alias",
160+
"name": {
161+
"name": "MapboxVectorTiles",
162+
"namespace": "_types"
163+
},
164+
"type": {
165+
"kind": "instance_of",
166+
"type": {
167+
"name": "binary",
168+
"namespace": "internal"
169+
}
170+
}
171+
}
172+
```
173+
142174
### Literal values
143175

144176
The compiler supports literal values as well. This can be useful if a

output/schema/schema.json

+19-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

output/schema/validation-errors.json

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

output/typescript/types.ts

+3-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

specification/_global/search_mvt/SearchMvtResponse.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
* under the License.
1818
*/
1919

20-
import { UserDefinedValue } from '@spec_utils/UserDefinedValue'
20+
import { MapboxVectorTiles } from '@_types/Binary'
2121

2222
export class Response {
23-
body: UserDefinedValue
23+
body: MapboxVectorTiles
2424
}

specification/_types/Binary.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
// Vector tile response
21+
export type MapboxVectorTiles = ArrayBuffer

typescript-generator/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ function buildValue (type: M.ValueOf, openGenerics?: string[], origin?: M.TypeNa
115115
}
116116
}
117117

118+
if (type.type.name === 'binary' && type.type.namespace === 'internal') {
119+
return 'ArrayBuffer'
120+
}
121+
118122
return `${createName(type.type)}${buildGenerics(type.generics, openGenerics)}`
119123
case 'array_of':
120124
return type.value.kind === 'union_of' || getShortcutType(type.value) != null

0 commit comments

Comments
 (0)