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

docs(openapi-spec-builder): update README code snippet to v3 #1203

Merged
merged 1 commit into from
Mar 29, 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
35 changes: 25 additions & 10 deletions packages/openapi-spec-builder/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# @loopback/openapi-spec-builder

Make it easy to create OpenAPI (Swagger) specification documents in your tests
Make it easy to create OpenAPI specification documents in your tests
using the builder pattern.

## Overview

Creating a full OpenAPI spec document in automated tests is rather cumbersome,
long JSON-like objects pollute the test test code and make it difficult for
readers to distinguish between what's important in the test and what's just
shared swagger boilerplate.
shared OpenAPI boilerplate.

OpenApiSpecBuilder utilizes
[Test Data Builder pattern](http://www.natpryce.com/articles/000714.html) to
Expand Down Expand Up @@ -37,31 +37,46 @@ const spec = anOpenApiSpec()
.build();

// which is equivalent to the following longer form

const spec = new OpenApiSpecBuilder()
.withOperation('get', '/hello', {
'x-operation-name': 'greet',
responses: {
'200': {type: 'string'},
'200': {
description: 'The string result.',
content: {
'text/plain': {
schema: {
type: 'string',
},
},
},
},
},
})
.build();

// the spec

const spec = {
basePath: '/',
swagger: '2.0',
openapi: '3.0.0',
info: {title: 'LoopBack Application', version: '1.0.0'},
servers: [
{
url: '/',
},
],
paths: {
'/hello': {
get: {
'x-operation-name': 'greet',
responses: {
'200': {
description: 'The string result.',
schema: {
type: 'string',
content: {
'text/plain': {
schema: {
type: 'string',
},
},
},
},
},
Expand All @@ -74,7 +89,7 @@ const spec = {
## Related resources

See <https://www.openapis.org/> and
[version 2.0](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md)
[version 3.0.0](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md)
of OpenAPI Specification.

## Contributions
Expand Down