Skip to content

Commit

Permalink
Merge pull request #21 from lifeomic/remove-publishing
Browse files Browse the repository at this point in the history
fix!: remove schema + client publishing utils
  • Loading branch information
swain authored Jun 1, 2022
2 parents 167a25a + 840b94f commit 0c29222
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 411 deletions.
71 changes: 0 additions & 71 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,77 +187,6 @@ const server = new Koa()
.listen();
```

### Distributing Schemas

Use the `generate-publishable-schema` command in concert with the `Meta.PackageJSON` entry to generate a ready-to-publish NPM artifact containing the schema.

```yaml
# schema.yml
Meta:
PackageJSON:
name: desired-package-name
description: A description of the package
# ... any other desired package.json values
# ...
```

```bash
one-schema generate-publishable-schema \
--schema schema.yml \
--output output-directory
```

The `output-directory` will have this file structure:

```
output-directory/
package.json
schema.json
schema.yaml
```

### Distributing Clients

Use the `generate-publishable-client` command in concert with the `Meta.PackageJSON` entry to generate a ready-to-publish NPM artifact containing a ready-to-use client.

```yaml
# schema.yml
Meta:
PackageJSON:
name: desired-package-name
description: A description of the package
# ... any other desired package.json values
# ...
```

```bash
one-schema generate-publishable-client \
--schema schema.yml \
--output output-directory
```

The `output-directory` will have this file structure:

```
output-directory/
package.json
schema.json
schema.yaml
index.js
index.d.ts
```

The generated client code is identical to the output of `generate-axios-client`:

```typescript
import axios from 'axios';
import { Client } from './output-directory';

const client = new Client(axios.create(...))

// use the client
```

### OpenAPI Spec generation

Use the `generate-open-api-spec` command to generate an OpenAPI spec from a simple schema, which may be useful for interfacing with common OpenAPI tooling.
Expand Down
28 changes: 12 additions & 16 deletions src/bin/__snapshots__/cli.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ exports[`input validation snapshots bogus command name 1`] = `
"cli.ts <command>
Commands:
cli.ts generate-axios-client Generates an Axios client using the
specified schema and options.
cli.ts generate-api-types Generates API types using the specified
schema and options.
cli.ts generate-open-api-spec Generates an OpenAPI v3.1.0 spec using the
specified schema and options.
cli.ts generate-publishable-schema Generates a publishable schema artifact.
cli.ts generate-publishable-client Generates a publishable client artifact.
cli.ts generate-axios-client Generates an Axios client using the specified
schema and options.
cli.ts generate-api-types Generates API types using the specified schema
and options.
cli.ts generate-open-api-spec Generates an OpenAPI v3.1.0 spec using the
specified schema and options.
Options:
--help Show help [boolean]
Expand All @@ -24,14 +22,12 @@ exports[`input validation snapshots empty input 1`] = `
"cli.ts <command>
Commands:
cli.ts generate-axios-client Generates an Axios client using the
specified schema and options.
cli.ts generate-api-types Generates API types using the specified
schema and options.
cli.ts generate-open-api-spec Generates an OpenAPI v3.1.0 spec using the
specified schema and options.
cli.ts generate-publishable-schema Generates a publishable schema artifact.
cli.ts generate-publishable-client Generates a publishable client artifact.
cli.ts generate-axios-client Generates an Axios client using the specified
schema and options.
cli.ts generate-api-types Generates API types using the specified schema
and options.
cli.ts generate-open-api-spec Generates an OpenAPI v3.1.0 spec using the
specified schema and options.
Options:
--help Show help [boolean]
Expand Down
48 changes: 0 additions & 48 deletions src/bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import { generateAxiosClient } from '../generate-axios-client';
import { generateAPITypes } from '../generate-api-types';
import { loadSchemaFromFile, SchemaAssumptions } from '../meta-schema';
import { toOpenAPISpec } from '../openapi';
import { generatePublishableSchema } from '../generate-publishable-schema';
import { generatePublishableClient } from '../generate-publishable-client';

const getPrettierParser = (outputFilename: string): BuiltInParserName => {
const extension = path.extname(outputFilename).replace('.', '');
Expand Down Expand Up @@ -186,52 +184,6 @@ const program = yargs(process.argv.slice(2))
writeGeneratedFile(argv.output, output, { format: argv.format });
},
)
.command(
'generate-publishable-schema',
'Generates a publishable schema artifact.',
getCommonOptions,
(argv) => {
const spec = loadSchemaFromFile(
argv.schema,
parseAssumptions(argv.assumptions),
);

const { files } = generatePublishableSchema({ spec });

for (const [filename, content] of Object.entries(files)) {
writeGeneratedFile(path.resolve(argv.output, filename), content, {
format: argv.format,
});
}
},
)
.command(
'generate-publishable-client',
'Generates a publishable client artifact.',
(y) =>
getCommonOptions(y).option('className', {
type: 'string',
description: 'The name of the generated client class.',
default: 'Client',
}),
async (argv) => {
const spec = loadSchemaFromFile(
argv.schema,
parseAssumptions(argv.assumptions),
);

const { files } = await generatePublishableClient({
spec,
outputClass: argv.className,
});

for (const [filename, content] of Object.entries(files)) {
writeGeneratedFile(path.resolve(argv.output, filename), content, {
format: argv.format,
});
}
},
)
.demandCommand()
.strict();

Expand Down
85 changes: 0 additions & 85 deletions src/generate-publishable-client.test.ts

This file was deleted.

49 changes: 0 additions & 49 deletions src/generate-publishable-client.ts

This file was deleted.

Loading

0 comments on commit 0c29222

Please sign in to comment.