Skip to content

fix: use map instead of array for examples to align OpenAPI Spec #9

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
9 changes: 4 additions & 5 deletions src/DefinitionGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export class DefinitionGenerator {

if (parameter.example) {
parameterConfig.example = parameter.example;
} else if (parameter.examples && Array.isArray(parameter.examples)) {
} else if (parameter.examples) {
parameterConfig.examples = parameter.examples;
}

Expand Down Expand Up @@ -273,9 +273,8 @@ export class DefinitionGenerator {
if (requestModel) {
const reqModelConfig = {
schema: {
$ref: `#/components/schemas/${
documentationConfig.requestModels[requestModelType]
}`
$ref: `#/components/schemas/${documentationConfig.requestModels[requestModelType]
}`
}
};

Expand Down Expand Up @@ -304,7 +303,7 @@ export class DefinitionGenerator {
}

private attachExamples(target, config) {
if (target.examples && Array.isArray(target.examples)) {
if (target.examples) {
_.merge(config, { examples: _.cloneDeep(target.examples) });
} else if (target.example) {
_.merge(config, { example: _.cloneDeep(target.example) });
Expand Down
6 changes: 6 additions & 0 deletions src/ServerlessOpenApiDocumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,20 @@ export class ServerlessOpenApiDocumentation {
options: {
output: {
usage: "Output file location [default: openapi.yml|json]",
type: "string",
required: false,
shortcut: "o"
},
format: {
usage: "OpenAPI file format (yml|json) [default: yml]",
type: "string",
required: false,
shortcut: "f"
},
indent: {
usage: "File indentation in spaces [default: 2]",
type: "string",
required: false,
shortcut: "i"
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface Model {
description: string;
contentType: string;
schema: string | JSONSchema7;
examples: Array<any>;
examples: Map<string, any>;
example: object;
}

Expand Down Expand Up @@ -72,7 +72,7 @@ export interface ParameterConfig {
explode?: boolean;
allowReserved?: boolean;
example?: any;
examples?: Array<any>;
examples?: Map<string, any>;
content?: Map<string, any>;
}

Expand Down