Skip to content
This repository was archived by the owner on Dec 10, 2021. It is now read-only.
Merged
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
15 changes: 12 additions & 3 deletions src/DefinitionGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,28 @@ export class DefinitionGenerator {
title = "",
description = "",
version = uuid.v4(),
models
models,
security,
securitySchemes
} = this.config;

_.merge(this.definition, {
openapi: this.version,
info: { title, description, version },
paths: {},
components: {
schemas: {},
securitySchemes: {}
schemas: {}
}
});

if (security) {
this.definition.security = security;
}

if (securitySchemes) {
this.definition.components.securitySchemes = securitySchemes;
}

this.definition.components.schemas = await parseModels(models, this.root);

return this;
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/DefinitionGenerator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ describe("OpenAPI Documentation Generator", () => {
docGen.readFunctions(funcConfigs);

// get the parameters from the `/create POST' endpoint
const actual = docGen.definition.paths["/create"].post.parameters;
const actual =
docGen.definition.paths["/create/{username}"].post.parameters;
const expected = [
{
description: "The username for a user to create",
Expand Down
3 changes: 3 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { JSONSchema7 } from "json-schema";
import { OpenAPIV3 } from "openapi-types";

export interface Model {
name: string;
Expand All @@ -13,6 +14,8 @@ export interface DefinitionConfig {
title: string;
description: string;
version?: string;
securitySchemes: OpenAPIV3.SecuritySchemeObject;
security: Array<OpenAPIV3.SecurityRequirementObject>;
models: Array<Model>;
}

Expand Down
19 changes: 16 additions & 3 deletions test/project/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,22 @@ components:
properties:
data:
$ref: '#/components/schemas/data'
securitySchemes: {}
securitySchemes:
bearerAuth:
type: oauth2
flows:
implicit:
authorizationUrl: 'https://example.com/oauth/authorize'
scopes:
read: Grants read access
write: Grants write access
admin: Grants access to admin operations
info:
title: ''
description: ''
version: 96d3d004-1a24-4384-9df7-1e7416393223
version: 6e48be1a-d9be-41ef-95eb-41ffad58eac3
paths:
/create:
'/create/{username}':
post:
operationId: createUser
summary: Create User
Expand Down Expand Up @@ -239,3 +248,7 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
security:
- bearerAuth:
- read
- write
15 changes: 15 additions & 0 deletions test/project/serverless.doc.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
documentation:
components:
securitySchemes:
bearerAuth:
type: oauth2
flows:
implicit:
authorizationUrl: https://example.com/oauth/authorize
scopes:
read: Grants read access
write: Grants write access
admin: Grants access to admin operations
security:
- bearerAuth:
- read
- write
models:
- name: ErrorResponse
description: This is an error
Expand Down
2 changes: 1 addition & 1 deletion test/project/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ functions:
handler: handler.create
events:
- http:
path: create
path: create/{username}
method: post
documentation:
summary: Create User
Expand Down