File tree 4 files changed +14
-25
lines changed
4 files changed +14
-25
lines changed Original file line number Diff line number Diff line change 5
5
6
6
import * as assert from 'assert' ;
7
7
import {
8
- ExtensionValue ,
9
8
OpenApiSpec ,
10
9
OperationObject ,
11
10
ResponseObject ,
12
11
ParameterObject ,
13
12
createEmptyApiSpec ,
14
13
RequestBodyObject ,
14
+ ISpecificationExtension ,
15
15
} from '@loopback/openapi-v3-types' ;
16
16
17
17
/**
@@ -30,11 +30,7 @@ export function anOperationSpec() {
30
30
return new OperationSpecBuilder ( ) ;
31
31
}
32
32
33
- export interface Extendable {
34
- [ extension : string ] : ExtensionValue ;
35
- }
36
-
37
- export class BuilderBase < T extends Extendable > {
33
+ export class BuilderBase < T extends ISpecificationExtension > {
38
34
protected _spec : T ;
39
35
40
36
constructor ( initialSpec : T ) {
@@ -47,7 +43,11 @@ export class BuilderBase<T extends Extendable> {
47
43
* @param key The property name starting with "x-".
48
44
* @param value The property value.
49
45
*/
50
- withExtension ( key : string , value : ExtensionValue ) : this {
46
+ withExtension (
47
+ key : string ,
48
+ // tslint:disable-next-line:no-any
49
+ value : any ,
50
+ ) : this {
51
51
assert (
52
52
key . startsWith ( 'x-' ) ,
53
53
`Invalid extension ${ key } , extension keys must be prefixed with "x-"` ,
Original file line number Diff line number Diff line change @@ -12,12 +12,6 @@ import {OpenAPIObject} from 'openapi3-ts';
12
12
export * from 'openapi3-ts' ;
13
13
14
14
export type OpenApiSpec = OpenAPIObject ;
15
- /**
16
- * Custom extensions can use arbitrary type as the value,
17
- * e.g. a string, an object or an array.
18
- */
19
- // tslint:disable-next-line:no-any
20
- export type ExtensionValue = any ;
21
15
22
16
/**
23
17
* Create an empty OpenApiSpec object that's still a valid openapi document.
Original file line number Diff line number Diff line change 3
3
// This file is licensed under the MIT License.
4
4
// License text available at https://opensource.org/licenses/MIT
5
5
6
- import {
7
- SchemaObject ,
8
- ReferenceObject ,
9
- ExtensionValue ,
10
- } from './openapi-v3-spec-types' ;
6
+ import { SchemaObject , ReferenceObject } from './openapi-v3-spec-types' ;
11
7
12
8
/**
13
9
* Type guard for OpenAPI 3.0.0 schema object
@@ -20,6 +16,6 @@ export function isSchemaObject(
20
16
return ! schema . hasOwnProperty ( '$ref' ) ;
21
17
}
22
18
23
- export function isReferenceObject ( obj : ExtensionValue ) : obj is ReferenceObject {
19
+ export function isReferenceObject ( obj : object ) : obj is ReferenceObject {
24
20
return obj . hasOwnProperty ( '$ref' ) ;
25
21
}
Original file line number Diff line number Diff line change 4
4
// License text available at https://opensource.org/licenses/MIT
5
5
6
6
import { JsonDefinition } from '@loopback/repository-json-schema' ;
7
- import { SchemaObject , ExtensionValue } from '@loopback/openapi-v3-types' ;
7
+ import { SchemaObject } from '@loopback/openapi-v3-types' ;
8
8
import * as _ from 'lodash' ;
9
9
10
- export function jsonToSchemaObject ( jsonDef : JsonDefinition ) : SchemaObject {
11
- const json = jsonDef as { [ name : string ] : ExtensionValue } ; // gets around index signature error
10
+ export function jsonToSchemaObject ( json : JsonDefinition ) : SchemaObject {
12
11
const result : SchemaObject = { } ;
13
12
const propsToIgnore = [
14
13
'anyOf' ,
@@ -63,7 +62,7 @@ export function jsonToSchemaObject(jsonDef: JsonDefinition): SchemaObject {
63
62
case 'enum' : {
64
63
const newEnum = [ ] ;
65
64
const primitives = [ 'string' , 'number' , 'boolean' ] ;
66
- for ( const element of json . enum ) {
65
+ for ( const element of json . enum ! ) {
67
66
if ( primitives . includes ( typeof element ) || element === null ) {
68
67
newEnum . push ( element ) ;
69
68
} else {
@@ -76,14 +75,14 @@ export function jsonToSchemaObject(jsonDef: JsonDefinition): SchemaObject {
76
75
break ;
77
76
}
78
77
case '$ref' : {
79
- result . $ref = json . $ref . replace (
78
+ result . $ref = json . $ref ! . replace (
80
79
'#/definitions' ,
81
80
'#/components/schemas' ,
82
81
) ;
83
82
break ;
84
83
}
85
84
default : {
86
- result [ property ] = json [ property ] ;
85
+ result [ property ] = json [ property as keyof JsonDefinition ] ;
87
86
break ;
88
87
}
89
88
}
You can’t perform that action at this time.
0 commit comments