Skip to content

Commit

Permalink
Merge pull request #47 from lifeomic/open-api-v3
Browse files Browse the repository at this point in the history
fix: generate OpenAPI v3.0.0 specs
  • Loading branch information
swain authored Aug 2, 2022
2 parents f122b9e + 22e4612 commit 465afae
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ const program = yargs(process.argv.slice(2))
);

const openAPISpec = toOpenAPISpec(spec, {
info: { version: argv.apiTitle, title: argv.apiTitle },
info: { version: argv.apiVersion, title: argv.apiTitle },
});

const output =
Expand Down
4 changes: 2 additions & 2 deletions src/openapi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ describe('toOpenAPISpec', () => {

// Ensure result is a valid OpenAPI spec
const { errors } = new OpenAPIValidator({
version: '3.1.0',
version: '3.0.0',
}).validate(result);

expect(errors).toHaveLength(0);

// Assert on specific response.
expect(result).toStrictEqual({
openapi: '3.1.0',
openapi: '3.0.0',
info: { title: 'test title', version: '1.2.3' },
components: {
schemas: {
Expand Down
28 changes: 14 additions & 14 deletions src/openapi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { OpenAPIV3_1 } from 'openapi-types';
import type { OpenAPIV3 } from 'openapi-types';
import type { OneSchemaDefinition } from './types';
import { deepCopy } from './generate-endpoints';
import { validateSchema } from './meta-schema';
Expand All @@ -21,14 +21,14 @@ const getPathParameters = (koaPath: string) =>
export const toOpenAPISpec = (
schema: OneSchemaDefinition,
config: {
info: OpenAPIV3_1.InfoObject;
info: OpenAPIV3.InfoObject;
},
): OpenAPIV3_1.Document => {
): OpenAPIV3.Document => {
validateSchema(schema);

// 1. Declare the document. We'll build it as we go.
const openAPIDocument: OpenAPIV3_1.Document = {
openapi: '3.1.0',
const openAPIDocument: OpenAPIV3.Document = {
openapi: '3.0.0',
info: config.info,
components: {},
paths: {},
Expand All @@ -52,7 +52,7 @@ export const toOpenAPISpec = (
] of Object.entries(Endpoints)) {
const [method, path] = endpoint.split(' ');

const operation: OpenAPIV3_1.OperationObject = {
const operation: OpenAPIV3.OperationObject = {
operationId: Name,
responses: {
'200': {
Expand All @@ -69,14 +69,14 @@ export const toOpenAPISpec = (
},
};

const parameters: OpenAPIV3_1.ParameterObject[] = getPathParameters(
path,
).map((name) => ({
name,
in: 'path',
schema: { type: 'string' },
required: true,
}));
const parameters: OpenAPIV3.ParameterObject[] = getPathParameters(path).map(
(name) => ({
name,
in: 'path',
schema: { type: 'string' },
required: true,
}),
);

if (Request) {
if (['GET', 'DELETE'].includes(method)) {
Expand Down

0 comments on commit 465afae

Please sign in to comment.