Skip to content

Commit

Permalink
fix: handle null type in openapi web sdk generator
Browse files Browse the repository at this point in the history
  • Loading branch information
yordis committed Nov 20, 2024
1 parent cbd907a commit 1a53ede
Show file tree
Hide file tree
Showing 5 changed files with 486 additions and 394 deletions.
4 changes: 2 additions & 2 deletions packages/@straw-hat/openapi-web-sdk-generator/src/dir.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { deleteAsync } from 'del';
import makeDir from 'make-dir';
import { makeDirectory } from 'make-dir';
import * as fs from 'node:fs/promises';
import * as path from 'node:path';
import { createDebugger, formatCode } from './helpers.js';
Expand Down Expand Up @@ -34,7 +34,7 @@ export class Dir {
createDir(...pathsSegments: string[]) {
const dirPath = this.resolve(...pathsSegments);
this.debug(`Ensure directory ${dirPath}`);
return makeDir(dirPath);
return makeDirectory(dirPath);
}

readFile(relativePath: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@ function integerType(scope: Scope, schema: OpenAPIV3.NonArraySchemaObject) {
return numberType(scope, schema);
}


function nullType(scope: Scope, schema: OpenAPIV3.NonArraySchemaObject) {
return scope.maybeRegisterType(schema, {
name: undefined,
definition: 'null',
docs: createDocs(schema),
});
}


function unknownType(scope: Scope, schema: OpenAPIV3.NonArraySchemaObject) {
return scope.maybeRegisterType(schema, {
name: undefined,
Expand Down Expand Up @@ -267,6 +277,10 @@ export async function addTypeScripType(
case 'integer': {
return integerType(scope, schema);
}
// @ts-expect-error TODO: fix openapi-types to allow null
case 'null': {
return nullType(scope, schema);
}
default: {
return unknownType(scope, schema);
}
Expand Down
Loading

0 comments on commit 1a53ede

Please sign in to comment.