Skip to content

Commit

Permalink
feat: add internal to http-spec (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaylachun authored Jul 21, 2022
1 parent 75874a1 commit 4717721
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"dependencies": {
"@stoplight/json": "^3.18.1",
"@stoplight/json-schema-generator": "1.0.1",
"@stoplight/types": "^13.5.0",
"@stoplight/types": "^13.6.0",
"@types/json-schema": "7.0.11",
"@types/swagger-schema-official": "~2.0.22",
"@types/type-is": "^1.6.3",
Expand Down
9 changes: 8 additions & 1 deletion src/oas/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import pickBy = require('lodash.pickby');
import { OpenAPIObject } from 'openapi3-ts';
import { Spec } from 'swagger-schema-official';

import { isNonNullable, isString } from '../guards';
import { isBoolean, isNonNullable, isString } from '../guards';
import { TranslateFunction } from '../types';
import { hasXLogo } from './guards';
import { translateTagDefinition } from './tags';
Expand Down Expand Up @@ -37,6 +37,13 @@ export const transformOasService: TranslateFunction<DeepPartial<OpenAPIObject> |
},
isPlainObject,
),

...pickBy(
{
internal: document['x-internal'],
},
isBoolean,
),
};

if (isPlainObject(document.info) && hasXLogo(document.info)) {
Expand Down
22 changes: 22 additions & 0 deletions src/oas2/__tests__/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,28 @@ describe('oas2 service', () => {
const transformed = transformOas2Service({ document });
expect(transformed).toHaveProperty(['security', 0, 'flows', 'implicit', 'scopes'], { scope_1: '' });
});

it('should handle x-internal property', () => {
const document: Partial<Spec> & Fragment & { 'x-internal': boolean } = {
'x-stoplight': { id: 'abc' },
info: {
title: '',
version: '1.0',
},
'x-internal': true,
};

expect(
transformOas2Service({
document,
}),
).toStrictEqual({
id: 'abc',
name: '',
version: '1.0',
internal: true,
});
});
describe('x-logo support', () => {
it('should support x-logo', () => {
const document: Partial<OpenAPIObject> = {
Expand Down
17 changes: 17 additions & 0 deletions src/oas3/__tests__/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,23 @@ describe('oas3 service', () => {
});
});

it('should handle x-internal property', () => {
const document: Partial<OpenAPIObject> & { 'x-internal': boolean } = {
info: {
title: '',
version: '1.0',
},
'x-internal': true,
};

expect(transformOas3Service({ document })).toStrictEqual({
id: 'abc',
internal: true,
name: '',
version: '1.0',
});
});

it('should filter out scopes', () => {
const document: Partial<OpenAPIObject> = {
openapi: '3.0.0',
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1491,10 +1491,10 @@
"@types/json-schema" "^7.0.4"
utility-types "^3.10.0"

"@stoplight/types@^13.5.0":
version "13.5.0"
resolved "https://registry.yarnpkg.com/@stoplight/types/-/types-13.5.0.tgz#a17990ab4ff3fc60325dc64d758c4670b872ac8b"
integrity sha512-8UFgYj4Y/vcc3a2ZuJJ+ltiJlFsXa7/huZkmjhaHq+jPHIR2Va+aFaExENV/cWtxUVTXE15KSzPOX/ikucUFbw==
"@stoplight/types@^13.6.0":
version "13.6.0"
resolved "https://registry.yarnpkg.com/@stoplight/types/-/types-13.6.0.tgz#96c6aaae05858b36f589821cd52c95aa9b205ce7"
integrity sha512-dzyuzvUjv3m1wmhPfq82lCVYGcXG0xUYgqnWfCq3PCVR4BKFhjdkHrnJ+jIDoMKvXb05AZP/ObQF6+NpDo29IQ==
dependencies:
"@types/json-schema" "^7.0.4"
utility-types "^3.10.0"
Expand Down

0 comments on commit 4717721

Please sign in to comment.