Skip to content
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
node_modules

coverage
dist
src/openapi

*.tgz

Expand Down
22 changes: 22 additions & 0 deletions _templates/compeller/add/path.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
to: <%= directory %>/openapi/paths/<%= h.inflection.dasherize(h.inflection.underscore( name )) %>.path.ts
---
import { <%= h.inflection.classify( name )%>Schema } from '../components/schemas/<%= h.inflection.dasherize(h.inflection.underscore( name )) %>.schema'

export const path = {
'<%= path %>': {
<%= method %>: {
responses: {
200: {
description: 'Get the current API version',
content: {
'application/json': {
schema: <%= h.inflection.classify( name )%>Schema,
},
},
},
},
},
},
};

21 changes: 21 additions & 0 deletions _templates/compeller/add/prompt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// see types of prompts:
// https://github.com/enquirer/enquirer/tree/master/examples
//
module.exports = [
{
type: 'input',
name: 'directory',
message: 'Where to store the openapi?',
initial: 'src',
},
{
type: 'input',
name: 'path',
message: 'Fully qualified path e.g. /v1/user',
},
{
type: 'select',
name: 'method',
choices: ['get', 'put', 'post', 'delete'],
},
];
10 changes: 10 additions & 0 deletions _templates/compeller/add/schema.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
to: <%= directory %>/openapi/components/schemas/<%= h.inflection.dasherize(h.inflection.underscore( name )) %>.schema.ts
unless_exists: true
---
import { FromSchema } from 'json-schema-to-ts';

export const <%= h.inflection.classify( name )%>Schema = {} as const;

export type <%= h.inflection.classify( name )%> = FromSchema<typeof <%= h.inflection.classify( name )%>Schema>;

17 changes: 2 additions & 15 deletions _templates/compeller/new/spec.ejs.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
to: <%= directory %>/openapi/spec.ts
---
import { VersionSchema } from './schemas/version.schema';
import { versionPath } from './paths/version.path';

export const OpenAPISpecification = {
info: {
Expand All @@ -10,19 +10,6 @@ export const OpenAPISpecification = {
},
openapi: '3.1.0',
paths: {
'v1/version': {
get: {
responses: {
'200': {
description: 'Get the current API version',
content: {
'application/json': {
schema: VersionSchema,
},
},
},
},
},
},
...versionPath
},
};
21 changes: 21 additions & 0 deletions _templates/compeller/new/version-path.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
to: <%= directory %>/openapi/paths/version.path.ts
---
import { VersionSchema } from '../components/schemas/version.schema';

export const versionPath = {
'v1/version': {
get: {
responses: {
'200': {
description: 'Get the current API version',
content: {
'application/json': {
schema: VersionSchema,
},
},
},
},
},
},
}
2 changes: 1 addition & 1 deletion _templates/compeller/new/version.ejs.t
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
to: <%= directory %>/openapi/schemas/version.schema.ts
to: <%= directory %>/openapi/components/schemas/version.schema.ts
---
import { FromSchema } from 'json-schema-to-ts';

Expand Down