Skip to content
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

Improve types for parameter location/style, paths, and schemas #20

Merged
merged 2 commits into from
Apr 20, 2018
Merged
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
54 changes: 48 additions & 6 deletions src/model/OpenApi.ts
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ export interface OpenAPIObject extends ISpecificationExtension {
openapi: string;
info: InfoObject;
servers?: ServerObject[];
paths: PathObject;
paths: PathsObject;
components?: ComponentsObject;
security?: SecurityRequirementObject[];
tags?: TagObject[];
@@ -63,15 +63,27 @@ export interface ComponentsObject extends ISpecificationExtension {
links?: { [link: string]: LinkObject };
callbacks?: { [callback: string]: CallbackObject };
}
export interface PathObject extends ISpecificationExtension {

/**
* Rename it to Paths Object to be consistent with the spec
* See https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#pathsObject
*/
export interface PathsObject extends ISpecificationExtension {
// [path: string]: PathItemObject;
[path: string]: PathItemObject | any; // Hack for allowing ISpecificationExtension
}
export function getPath(pathObject: PathObject, path: string): PathItemObject {

/**
* @deprecated
* Create a type alias for backward compatibility
*/
export type PathObject = PathsObject;

export function getPath(pathsObject: PathsObject, path: string): PathItemObject {
if (SpecificationExtension.isValidExtension(path)) {
return undefined;
}
return pathObject[path] as PathItemObject;
return pathsObject[path] as PathItemObject;
}

export interface PathItemObject extends ISpecificationExtension {
@@ -107,15 +119,40 @@ export interface ExternalDocumentationObject extends ISpecificationExtension {
description?: string;
url: string;
}

/**
* The location of a parameter.
* Possible values are "query", "header", "path" or "cookie".
* Specification:
* https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#parameter-locations
*/
export type ParameterLocation = 'query' | 'header' | 'path' | 'cookie';

/**
* The style of a parameter.
* Describes how the parameter value will be serialized.
* (serialization is not implemented yet)
* Specification:
* https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#style-values
*/
export type ParameterStyle =
| 'matrix'
| 'label'
| 'form'
| 'simple'
| 'spaceDelimited'
| 'pipeDelimited'
| 'deepObject';

export interface ParameterObject extends ISpecificationExtension {
name: string;
in: string; // "query" | "header" | "path" | "cookie";
in: ParameterLocation; // "query" | "header" | "path" | "cookie";
description?: string;
required?: boolean;
deprecated?: boolean;
allowEmptyValue?: boolean;

style?: string; // "matrix" | "label" | "form" | "simple" | "spaceDelimited" | "pipeDelimited" | "deepObject";
style?: ParameterStyle; // "matrix" | "label" | "form" | "simple" | "spaceDelimited" | "pipeDelimited" | "deepObject";
explode?: boolean;
allowReserved?: boolean;
schema?: SchemaObject | ReferenceObject;
@@ -248,6 +285,11 @@ export interface SchemaObject extends ISpecificationExtension {
required?: string[];
enum?: any[];
}

export interface SchemasObject {
[schema: string]: SchemaObject;
}

export interface DiscriminatorObject {
propertyName: string;
mapping?: {[key: string]: string };