Skip to content

Commit e250a3f

Browse files
committed
Change default behavior to preserve snake_case & bundle with @pika/pack
1 parent 7f1e349 commit e250a3f

14 files changed

+5275
-3264
lines changed

.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module.exports = {
1010
'comma-dangle': 0,
1111
'function-paren-newline': 0, // let Prettier handle it
1212
'implicit-arrow-linebreak': 0, // let Prettier handle it
13+
'import/no-unresolved': 0, // TypeScript can handle it
1314
'import/no-extraneous-dependencies': 0,
1415
'object-curly-newline': 0, // let Prettier handle it
1516
'no-underscore-dangle': 0,

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.cache
22
.DS_Store
3-
dist
3+
pkg
44
node_modules
55
yarn.lock
66
yarn-error.log

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ the [generate.js](./scripts/generate.js) script.
5353
| :---------- | :--------- | :--------------------------------------------------------------------------------------------------- |
5454
| `output` | (stdout) | Where should the output file be saved? |
5555
| `namespace` | `OpenAPI2` | How should the output be namespaced? (namespacing is enforced as there’s a high chance of collision) |
56+
| `camelcase` | `false` | Convert `snake_case` properties to `camelCase` |
5657
| `swagger` | `2` | Which Swagger version to use. Currently only supports `2`. |
5758

5859
[namespace]: https://www.typescriptlang.org/docs/handbook/namespaces.html

bin/cli.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const chalk = require('chalk');
66
const { dirname, resolve } = require('path');
77
const meow = require('meow');
88
const yaml = require('js-yaml');
9-
const swaggerToTS = require('../dist/cjs');
9+
const { default: swaggerToTS } = require('../dist-node');
1010

1111
const cli = meow(
1212
`
@@ -17,10 +17,16 @@ Options
1717
--namespace, -n specify namespace to prefix types
1818
--help display this
1919
--output, -o specify output file
20-
--swagger, -s specify Swagger version (default 2)
20+
--camelcase, -c convert snake_case properties to camelCase (default: off)
21+
--swagger, -s specify Swagger version (default: 2)
2122
`,
2223
{
2324
flags: {
25+
camelcase: {
26+
type: 'boolean',
27+
default: false,
28+
alias: 'c',
29+
},
2430
namespace: {
2531
type: 'string',
2632
alias: 'n',

example/output.ts

+39-39
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,39 @@ namespace OpenAPI2 {
66
body: string;
77
}
88
export interface UpdateProviderBody {
9-
teamId?: string;
9+
team_id?: string;
1010
label?: string;
1111
name?: string;
12-
logoUrl?: string;
13-
supportEmail?: string;
14-
documentationUrl?: string;
12+
logo_url?: string;
13+
support_email?: string;
14+
documentation_url?: string;
1515
}
1616
export interface UpdateProvider {
1717
id: string;
1818
body: UpdateProviderBody;
1919
}
2020
export interface UpdateProductBody {
2121
name?: string;
22-
logoUrl?: string;
22+
logo_url?: string;
2323
listing?: ProductListing;
2424
// 140 character sentence positioning the product.
2525
tagline?: string;
2626
// A list of value propositions of the product.
27-
valueProps?: ValueProp[];
27+
value_props?: ValueProp[];
2828
images?: string[];
29-
supportEmail?: string;
30-
documentationUrl?: string;
29+
support_email?: string;
30+
documentation_url?: string;
3131
// URL to this Product's Terms of Service. If provided is true, then
3232
// a url must be set. Otherwise, provided is false.
33-
termsUrl?: string;
34-
featureTypes?: FeatureType[];
33+
terms_url?: string;
34+
feature_types?: FeatureType[];
3535
integration?: UpdateProductBodyIntegration;
3636
tags?: string[];
3737
}
3838
export interface UpdateProductBodyIntegration {
3939
provisioning?: string;
40-
baseUrl?: string;
41-
ssoUrl?: string;
40+
base_url?: string;
41+
sso_url?: string;
4242
version?: UpdateProductBodyIntegrationVersion;
4343
features?: ProductIntegrationFeatures;
4444
}
@@ -54,16 +54,16 @@ namespace OpenAPI2 {
5454
label?: string;
5555
state?: string;
5656
// Used in conjuction with resizable_to to set or unset the list
57-
hasResizeConstraints?: boolean;
58-
resizableTo?: string[];
57+
has_resize_constraints?: boolean;
58+
resizable_to?: string[];
5959
// Array of Region IDs
6060
regions?: string[];
6161
// Array of Feature Values
6262
features?: FeatureValue[];
6363
// The number of days a user gets as a free trial when subscribing to
6464
// this plan. Trials are valid only once per product; changing plans
6565
// or adding an additional subscription will not start a new trial.
66-
trialDays?: number;
66+
trial_days?: number;
6767
// Dollar value in cents
6868
cost?: number;
6969
}
@@ -90,12 +90,12 @@ namespace OpenAPI2 {
9090
Region = 'region'
9191
}
9292
export interface ProviderBody {
93-
teamId: string;
93+
team_id: string;
9494
label: string;
9595
name: string;
96-
logoUrl?: string;
97-
supportEmail?: string;
98-
documentationUrl?: string;
96+
logo_url?: string;
97+
support_email?: string;
98+
documentation_url?: string;
9999
}
100100
export interface Provider {
101101
id: string;
@@ -143,13 +143,13 @@ namespace OpenAPI2 {
143143
export interface ProductIntegrationFeatures {
144144
// Indicates whether or not this product supports resource transitions to
145145
// manifold by access_code.
146-
accessCode?: boolean;
146+
access_code?: boolean;
147147
// Represents whether or not this product supports Single
148148
// Sign On
149149
sso?: boolean;
150150
// Represents whether or not this product supports changing
151151
// the plan of a resource.
152-
planChange?: boolean;
152+
plan_change?: boolean;
153153
// Describes how the region for a resource is specified, if
154154
// unspecified, then regions have no impact on this
155155
// resource.
@@ -160,32 +160,32 @@ namespace OpenAPI2 {
160160
Unspecified = 'unspecified'
161161
}
162162
export interface ProductBody {
163-
providerId: string;
163+
provider_id: string;
164164
// Product labels are globally unique and contain the provider name.
165165
label: string;
166166
name: string;
167167
state: string;
168168
listing: ProductListing;
169-
logoUrl: string;
169+
logo_url: string;
170170
// 140 character sentence positioning the product.
171171
tagline: string;
172172
// A list of value propositions of the product.
173-
valueProps: ValueProp[];
173+
value_props: ValueProp[];
174174
images: string[];
175-
supportEmail: string;
176-
documentationUrl: string;
175+
support_email: string;
176+
documentation_url: string;
177177
// URL to this Product's Terms of Service. If provided is true, then
178178
// a url must be set. Otherwise, provided is false.
179179
terms: ProductBodyTerms;
180-
featureTypes: FeatureType[];
180+
feature_types: FeatureType[];
181181
billing: ProductBodyBilling;
182182
integration: ProductBodyIntegration;
183183
tags?: string[];
184184
}
185185
export interface ProductBodyIntegration {
186186
provisioning: string;
187-
baseUrl: string;
188-
ssoUrl?: string;
187+
base_url: string;
188+
sso_url?: string;
189189
version: ProductBodyIntegrationVersion;
190190
features: ProductIntegrationFeatures;
191191
}
@@ -222,20 +222,20 @@ namespace OpenAPI2 {
222222
}
223223
export interface PlanResizeList {}
224224
export interface PlanBody {
225-
providerId: string;
226-
productId: string;
225+
provider_id: string;
226+
product_id: string;
227227
name: string;
228228
label: string;
229229
state: string;
230-
resizableTo?: string[];
230+
resizable_to?: string[];
231231
// Array of Region IDs
232232
regions: string[];
233233
// Array of Feature Values
234234
features: FeatureValue[];
235235
// The number of days a user gets as a free trial when subscribing to
236236
// this plan. Trials are valid only once per product; changing plans
237237
// or adding an additional subscription will not start a new trial.
238-
trialDays?: number;
238+
trial_days?: number;
239239
// Dollar value in cents.
240240
cost: number;
241241
}
@@ -262,7 +262,7 @@ namespace OpenAPI2 {
262262
// Price describes the cost of a feature. It should be preferred over
263263
// the `cost` property.
264264
price?: FeatureValueDetailsPrice;
265-
numericDetails?: FeatureNumericDetails;
265+
numeric_details?: FeatureNumericDetails;
266266
}
267267
export interface FeatureValueDetailsPrice {
268268
// Cost is the price in cents that will be added to plan's base cost
@@ -272,7 +272,7 @@ namespace OpenAPI2 {
272272
// When a feature is used to multiply the cost of the plan or of
273273
// another feature, multiply factor is used for calculation.
274274
// A feature cannot have both a cost and a multiply factor.
275-
multiplyFactor?: number;
275+
multiply_factor?: number;
276276
// Price describes how the feature cost should be calculated.
277277
formula?: string;
278278
// Description explains how a feature is calculated to the user.
@@ -314,7 +314,7 @@ namespace OpenAPI2 {
314314
limit?: number;
315315
// An integer in 10,000,000ths of cents, will be multiplied by the
316316
// numeric value set in the feature to determine the cost.
317-
costMultiple?: number;
317+
cost_multiple?: number;
318318
}
319319
export interface FeatureNumericDetails {
320320
// Sets the increment at which numbers can be selected if customizable, by
@@ -330,7 +330,7 @@ namespace OpenAPI2 {
330330
max?: number;
331331
// Applied to the end of the number for display, for example the ‘GB’ in ‘20 GB’.
332332
suffix?: string;
333-
costRanges?: FeatureNumericRange[];
333+
cost_ranges?: FeatureNumericRange[];
334334
}
335335
export interface FeatureMap {
336336
[name: string]: any;
@@ -351,7 +351,7 @@ namespace OpenAPI2 {
351351
}
352352
export interface ExpandedPlanBody extends PlanBody {
353353
// An array of feature definitions for the plan, as defined on the Product.
354-
expandedFeatures?: ExpandedFeature[];
354+
expanded_features?: ExpandedFeature[];
355355
// A boolean flag that indicates if a plan is free or not based on it's cost and features.
356356
free?: boolean;
357357
// Plan cost using its default features plus base cost.
@@ -373,7 +373,7 @@ namespace OpenAPI2 {
373373
}
374374
export interface ExpandedFeature extends FeatureType {
375375
// The string value set for the feature on the plan, this should only be used if the value property is null.
376-
valueString?: string;
376+
value_string?: string;
377377
value?: FeatureValueDetails;
378378
}
379379
export interface Error {

0 commit comments

Comments
 (0)