-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OAI2-> OAI3: Fail if there is no produces provided for a path and the…
… response has a schema/body (#144)
- Loading branch information
1 parent
5fabda5
commit 4a39dcc
Showing
14 changed files
with
202 additions
and
61 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
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { OpenAPI2Operation } from "./oai2"; | ||
|
||
/** | ||
* Resolve the list of content types produced by an operation. | ||
* @param operationProduces: List of content type produces by the operation. | ||
* @param globalProduces: List of default content type produced by the API. | ||
* @returns list of produced content types. Array will have at least one entry. | ||
*/ | ||
export const resolveOperationProduces = ( | ||
operation: OpenAPI2Operation, | ||
globalProduces: string[], | ||
): string[] => { | ||
const operationProduces = operation.produces; | ||
const produces = operationProduces | ||
? operationProduces.indexOf("application/json") !== -1 | ||
? operationProduces | ||
: [...new Set([...operationProduces])] | ||
: globalProduces; | ||
|
||
// default | ||
if (produces.length === 0) { | ||
produces.push("*/*"); | ||
} | ||
|
||
return produces; | ||
}; | ||
|
||
/** | ||
* Resolve the list of content types consumed by an operation. | ||
* @param operationConsumes: List of content type consumed by the operation. | ||
* @param globalConsumes: List of default content type consumed by the API. | ||
*/ | ||
export const resolveOperationConsumes = (operation: OpenAPI2Operation, globalConsumes: string[]): string[] => { | ||
const operationConsumes = operation.consumes; | ||
return operationConsumes | ||
? operationConsumes.indexOf("application/octet-stream") !== -1 | ||
? operationConsumes | ||
: [...new Set([...operationConsumes])] | ||
: globalConsumes; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
export interface OpenAPI2Definition { | ||
[key: string]: unknown; | ||
|
||
additionalProperties?: OpenAPI2Definition | OpenAPI2Reference | boolean; | ||
allOf?: OpenAPI2Definition[]; | ||
description?: string; | ||
enum?: string[]; | ||
format?: string; | ||
items?: OpenAPI2Definition | OpenAPI2Reference; | ||
oneOf?: (OpenAPI2Definition | OpenAPI2Reference)[]; | ||
properties?: { [index: string]: OpenAPI2Definition | OpenAPI2Reference }; | ||
required?: string[]; | ||
title?: string; | ||
type?: OpenAPI2Type; // allow this to be optional to cover cases when this is missing | ||
} | ||
|
||
export interface OpenAPI2Reference { | ||
$ref: string; | ||
} | ||
|
||
export type OpenAPI2Type = | ||
| "array" | ||
| "boolean" | ||
| "byte" | ||
| "date" | ||
| "dateTime" | ||
| "double" | ||
| "float" | ||
| "integer" | ||
| "long" | ||
| "number" | ||
| "object" | ||
| "string"; |
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,19 @@ | ||
import { OpenAPI2Definition } from "./definition"; | ||
import { OpenAPI2Path } from "./paths"; | ||
|
||
export interface OpenAPI2Document { | ||
swagger: "2.0"; | ||
produces?: string[]; | ||
consumes?: string[]; | ||
schemes?: string[]; | ||
host?: string; | ||
basePath?: string; | ||
paths: { [path: string]: OpenAPI2Path }; | ||
definitions: { [name: string]: OpenAPI2Definition }; | ||
} | ||
|
||
export interface OpenAPI2DocumentInfo { | ||
title: string; | ||
description: string; | ||
version: string; | ||
} |
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,3 @@ | ||
export * from "./document"; | ||
export * from "./paths"; | ||
export * from "./definition"; |
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,42 @@ | ||
import { OpenAPI2Definition, OpenAPI2Reference } from "./definition"; | ||
|
||
/** | ||
* Custom http method verb for autorest. | ||
*/ | ||
export type HttpMethodCustom = "x-trace"; | ||
|
||
export type HttpMethod = "get" | "post" | "patch" | "put" | "delete" | "options" | "head" | "trace"; | ||
|
||
export type OpenAPI2Path = { | ||
[method in HttpMethod]: OpenAPI2Path; | ||
} & { | ||
parameters: any[]; | ||
}; | ||
|
||
export interface OpenAPI2Operation { | ||
operationId: string; | ||
description: string; | ||
responses: OpenAPI2OperationResponses; | ||
parameters?: any[]; | ||
produces?: string[]; | ||
consumes?: string[]; | ||
} | ||
|
||
export type OpenAPI2OperationResponses = { [statusCode: string]: OpenAPI2OperationResponse }; | ||
|
||
export interface OpenAPI2OperationResponse { | ||
description: string; | ||
schema?: OpenAPI2Definition; | ||
examples?: { [exampleName: string]: unknown }; | ||
headers?: { [headerName: string]: OpenAPI2Header }; | ||
} | ||
|
||
export type OpenAPI2Header = OpenAPI2Reference & OpenAPI2HeaderDefinition; | ||
|
||
export interface OpenAPI2HeaderDefinition { | ||
type: "string" | "number" | "integer" | "boolean" | "array"; | ||
schema: OpenAPI2Reference & OpenAPI2Definition; | ||
description: string; | ||
items: any; | ||
collectionFormat: "csv" | "ssv" | "tsv" | "pipes" | "multi"; | ||
} |
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.