Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions packages/openapi-spec-builder/src/openapi-spec-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

import * as assert from 'assert';
import {
ExtensionValue,
OpenApiSpec,
OperationObject,
ResponseObject,
ParameterObject,
createEmptyApiSpec,
RequestBodyObject,
ISpecificationExtension,
} from '@loopback/openapi-v3-types';

/**
Expand All @@ -30,11 +30,7 @@ export function anOperationSpec() {
return new OperationSpecBuilder();
}

export interface Extendable {
[extension: string]: ExtensionValue;
}

export class BuilderBase<T extends Extendable> {
export class BuilderBase<T extends ISpecificationExtension> {
protected _spec: T;

constructor(initialSpec: T) {
Expand All @@ -47,7 +43,11 @@ export class BuilderBase<T extends Extendable> {
* @param key The property name starting with "x-".
* @param value The property value.
*/
withExtension(key: string, value: ExtensionValue): this {
withExtension(
key: string,
// tslint:disable-next-line:no-any
value: any,
): this {
assert(
key.startsWith('x-'),
`Invalid extension ${key}, extension keys must be prefixed with "x-"`,
Expand Down
6 changes: 0 additions & 6 deletions packages/openapi-v3-types/src/openapi-v3-spec-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ import {OpenAPIObject} from 'openapi3-ts';
export * from 'openapi3-ts';

export type OpenApiSpec = OpenAPIObject;
/**
* Custom extensions can use arbitrary type as the value,
* e.g. a string, an object or an array.
*/
// tslint:disable-next-line:no-any
export type ExtensionValue = any;

/**
* Create an empty OpenApiSpec object that's still a valid openapi document.
Expand Down
8 changes: 2 additions & 6 deletions packages/openapi-v3-types/src/type-guards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {
SchemaObject,
ReferenceObject,
ExtensionValue,
} from './openapi-v3-spec-types';
import {SchemaObject, ReferenceObject} from './openapi-v3-spec-types';

/**
* Type guard for OpenAPI 3.0.0 schema object
Expand All @@ -20,6 +16,6 @@ export function isSchemaObject(
return !schema.hasOwnProperty('$ref');
}

export function isReferenceObject(obj: ExtensionValue): obj is ReferenceObject {
export function isReferenceObject(obj: object): obj is ReferenceObject {
return obj.hasOwnProperty('$ref');
}
11 changes: 5 additions & 6 deletions packages/openapi-v3/src/json-to-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
// License text available at https://opensource.org/licenses/MIT

import {JsonDefinition} from '@loopback/repository-json-schema';
import {SchemaObject, ExtensionValue} from '@loopback/openapi-v3-types';
import {SchemaObject} from '@loopback/openapi-v3-types';
import * as _ from 'lodash';

export function jsonToSchemaObject(jsonDef: JsonDefinition): SchemaObject {
const json = jsonDef as {[name: string]: ExtensionValue}; // gets around index signature error
export function jsonToSchemaObject(json: JsonDefinition): SchemaObject {
const result: SchemaObject = {};
const propsToIgnore = [
'anyOf',
Expand Down Expand Up @@ -63,7 +62,7 @@ export function jsonToSchemaObject(jsonDef: JsonDefinition): SchemaObject {
case 'enum': {
const newEnum = [];
const primitives = ['string', 'number', 'boolean'];
for (const element of json.enum) {
for (const element of json.enum!) {
if (primitives.includes(typeof element) || element === null) {
newEnum.push(element);
} else {
Expand All @@ -76,14 +75,14 @@ export function jsonToSchemaObject(jsonDef: JsonDefinition): SchemaObject {
break;
}
case '$ref': {
result.$ref = json.$ref.replace(
result.$ref = json.$ref!.replace(
'#/definitions',
'#/components/schemas',
);
break;
}
default: {
result[property] = json[property];
result[property] = json[property as keyof JsonDefinition];
break;
}
}
Expand Down