-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove random console.log statements
format fix-request-media-type-object-missing-schema fix bug in fix-passthrough-refs fix incorrect ref publish getresponse
- Loading branch information
Showing
34 changed files
with
159,247 additions
and
1,369 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 28 additions & 17 deletions
45
.../konfig-dash/packages/konfig-cli/src/util/fix-request-media-type-object-missing-schema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,32 @@ | ||
import { Spec, getOperations, resolveRef } from 'konfig-lib' | ||
|
||
export async function fixRequestMediaTypeObjectMissingSchema({ | ||
spec, | ||
}: { | ||
spec: Spec | ||
}): Promise<number> { | ||
let numberOfMissingRequestSchemasInMediaTypeObjects = 0 | ||
getOperations({ spec: spec.spec }).forEach(({ operation }) => { | ||
if (operation.requestBody) { | ||
const requestBody = resolveRef({refOrObject: operation.requestBody, $ref: spec.$ref}) | ||
Object.values(requestBody.content).forEach((mediaTypeObject) => { | ||
if (!mediaTypeObject.schema) { | ||
mediaTypeObject.schema = { description: "WARNING: Missing schema in media type object. Missing schema has been filled with this AnyType schema." } | ||
numberOfMissingRequestSchemasInMediaTypeObjects++ | ||
} | ||
}) | ||
spec, | ||
}: { | ||
spec: Spec | ||
}): Promise<number> { | ||
let numberOfMissingRequestSchemasInMediaTypeObjects = 0 | ||
getOperations({ spec: spec.spec }).forEach(({ operation }) => { | ||
if (operation.requestBody) { | ||
const requestBody = resolveRef({ | ||
refOrObject: operation.requestBody, | ||
$ref: spec.$ref, | ||
}) | ||
if (requestBody.content === undefined || requestBody.content === null) { | ||
throw Error( | ||
`Missing content in request body for ${operation.operationId}` | ||
) | ||
} | ||
}) | ||
return numberOfMissingRequestSchemasInMediaTypeObjects; | ||
} | ||
Object.values(requestBody.content).forEach((mediaTypeObject) => { | ||
if (!mediaTypeObject.schema) { | ||
mediaTypeObject.schema = { | ||
description: | ||
'WARNING: Missing schema in media type object. Missing schema has been filled with this AnyType schema.', | ||
} | ||
numberOfMissingRequestSchemasInMediaTypeObjects++ | ||
} | ||
}) | ||
} | ||
}) | ||
return numberOfMissingRequestSchemasInMediaTypeObjects | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...konfig-dash/packages/konfig-cli/test/util/__snapshots__/fix-passthrough-refs.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`fixPassthroughRefs request body shouldn't be shortened 1`] = ` | ||
{ | ||
"components": { | ||
"requestBodies": { | ||
"TestRequestBody": { | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"$ref": "#/components/schemas/PassthroughSchema", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"schemas": { | ||
"PassthroughSchema": { | ||
"properties": { | ||
"test": { | ||
"type": "string", | ||
}, | ||
}, | ||
"type": "object", | ||
}, | ||
}, | ||
}, | ||
"info": { | ||
"title": "Test API", | ||
"version": "1.0.0", | ||
}, | ||
"openapi": "3.0.0", | ||
"paths": { | ||
"/test": { | ||
"post": { | ||
"requestBody": { | ||
"$ref": "#/components/requestBodies/RequestBody", | ||
}, | ||
"responses": { | ||
"200": { | ||
"description": "Successful response", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
`; |
61 changes: 61 additions & 0 deletions
61
generator/konfig-dash/packages/konfig-cli/test/util/fix-passthrough-refs.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { Spec, parseSpec, recurseObject } from 'konfig-lib' | ||
import { fixPassthroughRefs } from '../../src/util/fix-passthrough-refs' | ||
|
||
describe('fixPassthroughRefs', () => { | ||
it(`request body shouldn't be shortened`, async () => { | ||
const openapi: Spec['spec'] = { | ||
openapi: '3.0.0', | ||
info: { | ||
title: 'Test API', | ||
version: '1.0.0', | ||
}, | ||
paths: { | ||
'/test': { | ||
post: { | ||
requestBody: { | ||
$ref: '#/components/requestBodies/RequestBody', | ||
}, | ||
responses: { | ||
'200': { | ||
description: 'Successful response', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
components: { | ||
requestBodies: { | ||
TestRequestBody: { | ||
content: { | ||
'application/json': { | ||
schema: { | ||
$ref: '#/components/schemas/RequestBody', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
schemas: { | ||
RequestBody: { | ||
$ref: '#/components/schemas/PassthroughSchema', | ||
}, | ||
PassthroughSchema: { | ||
type: 'object', | ||
properties: { | ||
test: { | ||
type: 'string', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
const spec = await parseSpec(JSON.stringify(openapi)) | ||
|
||
const fixedSpec = await fixPassthroughRefs({ spec }) | ||
|
||
// snapshot expect | ||
expect(spec.spec).toMatchSnapshot() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.