-
Notifications
You must be signed in to change notification settings - Fork 352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: STOP-243 - create prism instance with full spec #2501
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
acd7526
wip
brendarearden ab2059c
STOP-243 add fake IncomingMessage class so we can reuse existing Pris…
EdVinyard ff6a770
create callable prism instance
brendarearden 004c6e9
remove mock changes
brendarearden f6621c3
fix import
brendarearden 4051d46
refactor to resolve pr review; add operations export; update tests;
brendarearden fb17e3e
add export for new function and types
brendarearden 794b321
update dependencies
brendarearden File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,2 @@ | ||
import { transformOas3Operations } from '@stoplight/http-spec/oas3/operation'; | ||
import { transformOas2Operations } from '@stoplight/http-spec/oas2/operation'; | ||
import { transformPostmanCollectionOperations } from '@stoplight/http-spec/postman/operation'; | ||
import * as $RefParser from '@stoplight/json-schema-ref-parser'; | ||
import { HTTPResolverOptions } from '@stoplight/json-schema-ref-parser'; | ||
import { bundleTarget, decycle } from '@stoplight/json'; | ||
import { IHttpOperation } from '@stoplight/types'; | ||
import { get } from 'lodash'; | ||
import * as os from 'os'; | ||
import type { Spec } from 'swagger-schema-official'; | ||
import type { OpenAPIObject } from 'openapi3-ts'; | ||
import type { CollectionDefinition } from 'postman-collection'; | ||
|
||
export async function getHttpOperationsFromSpec(specFilePathOrObject: string | object): Promise<IHttpOperation[]> { | ||
const prismVersion = require('../package.json').version; | ||
const httpResolverOpts: HTTPResolverOptions = { | ||
headers: { | ||
'User-Agent': `PrismMockServer/${prismVersion} (${os.type()} ${os.arch()} ${os.release()})`, | ||
}, | ||
}; | ||
const result = decycle( | ||
await new $RefParser().dereference(specFilePathOrObject, { resolve: { http: httpResolverOpts } }) | ||
); | ||
|
||
let operations: IHttpOperation[] = []; | ||
if (isOpenAPI2(result)) operations = transformOas2Operations(result); | ||
else if (isOpenAPI3(result)) operations = transformOas3Operations(result); | ||
else if (isPostmanCollection(result)) operations = transformPostmanCollectionOperations(result); | ||
else throw new Error('Unsupported document format'); | ||
|
||
operations.forEach((op, i, ops) => { | ||
ops[i] = bundleTarget({ | ||
document: { | ||
...result, | ||
__target__: op, | ||
}, | ||
path: '#/__target__', | ||
cloneDocument: false, | ||
}); | ||
}); | ||
|
||
return operations; | ||
} | ||
|
||
function isOpenAPI2(document: unknown): document is Spec { | ||
return get(document, 'swagger') !== undefined; | ||
} | ||
|
||
function isOpenAPI3(document: unknown): document is OpenAPIObject { | ||
return get(document, 'openapi') !== undefined; | ||
} | ||
|
||
function isPostmanCollection(document: unknown): document is CollectionDefinition { | ||
return Array.isArray(get(document, 'item')) && get(document, 'info.name') !== undefined; | ||
} | ||
// add to keep this from being a breaking change. | ||
export { getHttpOperationsFromSpec } from '@stoplight/prism-http'; |
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
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
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was checking a 413, so I updated the title to match.
the rest of the changes in this file are formatting changes