massimo-cli 0.5.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/help/help.txt CHANGED
@@ -75,6 +75,5 @@ Options:
75
75
  * `--types-comment` - Add a comment at the beginning of the auto generated `.d.ts` type definition.
76
76
  * `--with-credentials` - Adds "credentials: 'include'" to all fetch requests (only for frontend clients).
77
77
  * `--props-optional` - If `true`, properties will be defined as optional unless they're part of the `required` array. By default this option is `true`.
78
- * `--skip-config-update` - If `true`, it will not update the `platformatic|watt` config found in your repo. By default this option is `true`.
79
78
  * `--retry-timeout-ms` - If passed, the HTTP request to get an Open API schema will be retried (reference: https://undici.nodejs.org/#/docs/api/RetryHandler.md)
80
79
  * `--type-extension` - Force the use of module-specific type extensions (.d.mts for ESM, .d.cts for CJS) instead of the default logic.
package/index.js CHANGED
@@ -681,13 +681,13 @@ export async function command (argv) {
681
681
  'frontend',
682
682
  'validate-response',
683
683
  'props-optional',
684
- 'skip-config-update',
685
684
  'type-extension'
686
685
  ],
687
686
  default: {
688
687
  typescript: false,
689
688
  language: 'js',
690
- full: true
689
+ full: true,
690
+ 'props-optional': true
691
691
  },
692
692
  alias: {
693
693
  n: 'name',
@@ -729,7 +729,7 @@ export async function command (argv) {
729
729
 
730
730
  options.fullRequest = options['full-request']
731
731
  options.fullResponse = options['full-response']
732
- options.propsOptional = options['props-optional'] ?? true
732
+ options.propsOptional = options['props-optional']
733
733
 
734
734
  options.optionalHeaders = options['optional-headers']
735
735
  ? options['optional-headers'].split(',').map((h) => h.trim())
@@ -748,7 +748,6 @@ export async function command (argv) {
748
748
  options.urlAuthHeaders = options['url-auth-headers']
749
749
  options.typesComment = options['types-comment']
750
750
  options.withCredentials = options['with-credentials']
751
- options.skipConfigUpdate = options['skip-config-update'] ?? true
752
751
  options.retryTimeoutMs = options['retry-timeout-ms']
753
752
  options.typeExtension = options['type-extension']
754
753
  options.explicitModuleFormat = !!options.module
package/lib/get-type.js CHANGED
@@ -65,18 +65,22 @@ export function getType (typeDef, methodType, spec) {
65
65
  return `Array<${getType(typeDef.items, methodType, spec)}>${nullable === true ? ' | null' : ''}`
66
66
  }
67
67
  if (typeDef.enum) {
68
+ // Note: null type represented with an enum have no types and single enum element 'null'
69
+ if (typeDef.type === undefined && typeDef.enum.includes('null')) {
70
+ // Ignore `nullable` as it is implied by the enum
71
+ return 'null'
72
+ }
68
73
  const nullable = typeDef.nullable
69
- return (
70
- typeDef.enum
71
- .map(en => {
72
- if (typeDef.type === 'string') {
73
- return `'${en.replace(/'/g, "\\'")}'`
74
- } else {
75
- return en
76
- }
77
- })
78
- .join(' | ') + (nullable === true ? ' | null' : '')
79
- )
74
+ const chainedTypes = typeDef.enum
75
+ .map(en => {
76
+ if (typeDef.type === 'string') {
77
+ return `'${en.replace(/'/g, "\\'")}'`
78
+ } else {
79
+ return en
80
+ }
81
+ })
82
+ .join(' | ')
83
+ return nullable === true ? `${chainedTypes} | null` : chainedTypes
80
84
  }
81
85
  if (typeDef.type === 'object') {
82
86
  const additionalProps = typeDef?.additionalProperties
@@ -137,8 +141,8 @@ function JSONSchemaToTsType ({ type, format, nullable }, methodType) {
137
141
  resultType = 'boolean'
138
142
  break
139
143
  case 'null':
140
- resultType = 'null'
141
- break
144
+ // Remove duplication, no need to make it nullable later, return directly
145
+ return 'null'
142
146
  // TODO what other types should we support here?
143
147
  }
144
148
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "massimo-cli",
3
- "version": "0.5.0",
3
+ "version": "1.1.0",
4
4
  "description": "A client for HTTP services.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -30,7 +30,7 @@
30
30
  "pino-pretty": "^13.0.0",
31
31
  "undici": "^7.0.0",
32
32
  "yaml": "^2.4.1",
33
- "massimo": "0.5.0"
33
+ "massimo": "1.1.0"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@platformatic/composer": "3.0.0-alpha.6",