Skip to content

Commit

Permalink
fix: render void for empty response status codes in experimental parser
Browse files Browse the repository at this point in the history
  • Loading branch information
mrlubos committed Nov 8, 2024
1 parent be27628 commit 9e07675
Show file tree
Hide file tree
Showing 45 changed files with 239 additions and 133 deletions.
5 changes: 5 additions & 0 deletions .changeset/silver-dolphins-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hey-api/openapi-ts': patch
---

fix: render void for empty response status codes in experimental parser
6 changes: 5 additions & 1 deletion packages/openapi-ts/src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ export const createKeywordTypeNode = ({
| 'number'
| 'string'
| 'undefined'
| 'unknown';
| 'unknown'
| 'void';
}) => {
let kind: ts.KeywordTypeSyntaxKind = ts.SyntaxKind.AnyKeyword;
switch (keyword) {
Expand All @@ -277,6 +278,9 @@ export const createKeywordTypeNode = ({
case 'unknown':
kind = ts.SyntaxKind.UnknownKeyword;
break;
case 'void':
kind = ts.SyntaxKind.VoidKeyword;
break;
}
return ts.factory.createKeywordTypeNode(kind);
};
Expand Down
1 change: 1 addition & 0 deletions packages/openapi-ts/src/ir/ir.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export interface IRSchemaObject
| 'object'
| 'string'
| 'tuple'
| 'undefined'
| 'unknown'
| 'void';
}
8 changes: 6 additions & 2 deletions packages/openapi-ts/src/plugins/@hey-api/types/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ const objectTypeToIdentifier = ({

if (hasOptionalProperties) {
indexPropertyItems.push({
type: 'void',
type: 'undefined',
});
}

Expand Down Expand Up @@ -594,13 +594,17 @@ const schemaTypeToIdentifier = ({
namespace,
schema: schema as SchemaWithType<'tuple'>,
});
case 'undefined':
return compiler.keywordTypeNode({
keyword: 'undefined',
});
case 'unknown':
return compiler.keywordTypeNode({
keyword: 'unknown',
});
case 'void':
return compiler.keywordTypeNode({
keyword: 'undefined',
keyword: 'void',
});
}
};
Expand Down
13 changes: 13 additions & 0 deletions packages/openapi-ts/test/3.0.x.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ describe(`OpenAPI ${VERSION}`, () => {
}),
description: 'handles null enums',
},
{
config: createConfig({
input: 'operation-204.json',
output: 'operation-204',
plugins: [
{
name: '@hey-api/types',
tree: true,
},
],
}),
description: 'handles empty response status codes',
},
];

it.each(scenarios)('$description', async ({ config }) => {
Expand Down
13 changes: 13 additions & 0 deletions packages/openapi-ts/test/3.1.x.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,19 @@ describe(`OpenAPI ${VERSION}`, () => {
description:
'sets correct logical operator and brackets on object with properties and oneOf composition',
},
{
config: createConfig({
input: 'operation-204.json',
output: 'operation-204',
plugins: [
{
name: '@hey-api/types',
tree: true,
},
],
}),
description: 'handles empty response status codes',
},
{
config: createConfig({
input: 'required-all-of-ref.json',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// This file is auto-generated by @hey-api/openapi-ts
export * from './types.gen';
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This file is auto-generated by @hey-api/openapi-ts

export type PostFooResponse = string | void;
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ export type PostCallWithOptionalParamData = {
};
};

export type PostCallWithOptionalParamResponse = number | undefined;
export type PostCallWithOptionalParamResponse = number | void;

export type PostApiVbyApiVersionRequestBodyData = {
/**
Expand Down Expand Up @@ -1259,13 +1259,13 @@ export type CallToTestOrderOfParamsData = {
};
};

export type CallWithNoContentResponseResponse = undefined;
export type CallWithNoContentResponseResponse = void;

export type CallWithResponseAndNoContentResponseResponse = number | undefined;
export type CallWithResponseAndNoContentResponseResponse = number | void;

export type DummyAResponse = _400;

export type DummyBResponse = undefined;
export type DummyBResponse = void;

export type CallWithResponseResponse = _import;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ export type PostCallWithOptionalParamData = {
};
};

export type PostCallWithOptionalParamResponse = number | undefined;
export type PostCallWithOptionalParamResponse = number | void;

export type PostApiVbyApiVersionRequestBodyData = {
/**
Expand Down Expand Up @@ -1259,13 +1259,13 @@ export type CallToTestOrderOfParamsData = {
};
};

export type CallWithNoContentResponseResponse = undefined;
export type CallWithNoContentResponseResponse = void;

export type CallWithResponseAndNoContentResponseResponse = number | undefined;
export type CallWithResponseAndNoContentResponseResponse = number | void;

export type DummyAResponse = _400;

export type DummyBResponse = undefined;
export type DummyBResponse = void;

export type CallWithResponseResponse = _import;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ export type PostCallWithOptionalParamData = {
};
};

export type PostCallWithOptionalParamResponse = number | undefined;
export type PostCallWithOptionalParamResponse = number | void;

export type PostApiVbyApiVersionRequestBodyData = {
/**
Expand Down Expand Up @@ -1259,13 +1259,13 @@ export type CallToTestOrderOfParamsData = {
};
};

export type CallWithNoContentResponseResponse = undefined;
export type CallWithNoContentResponseResponse = void;

export type CallWithResponseAndNoContentResponseResponse = number | undefined;
export type CallWithResponseAndNoContentResponseResponse = number | void;

export type DummyAResponse = _400;

export type DummyBResponse = undefined;
export type DummyBResponse = void;

export type CallWithResponseResponse = _import;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ export type PostCallWithOptionalParamData = {
};
};

export type PostCallWithOptionalParamResponse = number | undefined;
export type PostCallWithOptionalParamResponse = number | void;

export type PostApiVbyApiVersionRequestBodyData = {
/**
Expand Down Expand Up @@ -1259,13 +1259,13 @@ export type CallToTestOrderOfParamsData = {
};
};

export type CallWithNoContentResponseResponse = undefined;
export type CallWithNoContentResponseResponse = void;

export type CallWithResponseAndNoContentResponseResponse = number | undefined;
export type CallWithResponseAndNoContentResponseResponse = number | void;

export type DummyAResponse = _400;

export type DummyBResponse = undefined;
export type DummyBResponse = void;

export type CallWithResponseResponse = _import;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ export type PostCallWithOptionalParamData = {
};
};

export type PostCallWithOptionalParamResponse = number | undefined;
export type PostCallWithOptionalParamResponse = number | void;

export type PostApiVbyApiVersionRequestBodyData = {
/**
Expand Down Expand Up @@ -1259,13 +1259,13 @@ export type CallToTestOrderOfParamsData = {
};
};

export type CallWithNoContentResponseResponse = undefined;
export type CallWithNoContentResponseResponse = void;

export type CallWithResponseAndNoContentResponseResponse = number | undefined;
export type CallWithResponseAndNoContentResponseResponse = number | void;

export type DummyAResponse = _400;

export type DummyBResponse = undefined;
export type DummyBResponse = void;

export type CallWithResponseResponse = _import;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ export type PostCallWithOptionalParamData = {
};
};

export type PostCallWithOptionalParamResponse = number | undefined;
export type PostCallWithOptionalParamResponse = number | void;

export type PostApiVbyApiVersionRequestBodyData = {
/**
Expand Down Expand Up @@ -1259,13 +1259,13 @@ export type CallToTestOrderOfParamsData = {
};
};

export type CallWithNoContentResponseResponse = undefined;
export type CallWithNoContentResponseResponse = void;

export type CallWithResponseAndNoContentResponseResponse = number | undefined;
export type CallWithResponseAndNoContentResponseResponse = number | void;

export type DummyAResponse = _400;

export type DummyBResponse = undefined;
export type DummyBResponse = void;

export type CallWithResponseResponse = _import;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ export type PostCallWithOptionalParamData = {
};
};

export type PostCallWithOptionalParamResponse = number | undefined;
export type PostCallWithOptionalParamResponse = number | void;

export type PostApiVbyApiVersionRequestBodyData = {
/**
Expand Down Expand Up @@ -1259,13 +1259,13 @@ export type CallToTestOrderOfParamsData = {
};
};

export type CallWithNoContentResponseResponse = undefined;
export type CallWithNoContentResponseResponse = void;

export type CallWithResponseAndNoContentResponseResponse = number | undefined;
export type CallWithResponseAndNoContentResponseResponse = number | void;

export type DummyAResponse = _400;

export type DummyBResponse = undefined;
export type DummyBResponse = void;

export type CallWithResponseResponse = _import;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ export type PostCallWithOptionalParamData = {
};
};

export type PostCallWithOptionalParamResponse = number | undefined;
export type PostCallWithOptionalParamResponse = number | void;

export type PostApiVbyApiVersionRequestBodyData = {
/**
Expand Down Expand Up @@ -1259,13 +1259,13 @@ export type CallToTestOrderOfParamsData = {
};
};

export type CallWithNoContentResponseResponse = undefined;
export type CallWithNoContentResponseResponse = void;

export type CallWithResponseAndNoContentResponseResponse = number | undefined;
export type CallWithResponseAndNoContentResponseResponse = number | void;

export type DummyAResponse = _400;

export type DummyBResponse = undefined;
export type DummyBResponse = void;

export type CallWithResponseResponse = _import;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ export type PostCallWithOptionalParamData = {
};
};

export type PostCallWithOptionalParamResponse = number | undefined;
export type PostCallWithOptionalParamResponse = number | void;

export type PostApiVbyApiVersionRequestBodyData = {
/**
Expand Down Expand Up @@ -1259,13 +1259,13 @@ export type CallToTestOrderOfParamsData = {
};
};

export type CallWithNoContentResponseResponse = undefined;
export type CallWithNoContentResponseResponse = void;

export type CallWithResponseAndNoContentResponseResponse = number | undefined;
export type CallWithResponseAndNoContentResponseResponse = number | void;

export type DummyAResponse = _400;

export type DummyBResponse = undefined;
export type DummyBResponse = void;

export type CallWithResponseResponse = _import;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ export type PostCallWithOptionalParamData = {
};
};

export type PostCallWithOptionalParamResponse = number | undefined;
export type PostCallWithOptionalParamResponse = number | void;

export type PostApiVbyApiVersionRequestBodyData = {
/**
Expand Down Expand Up @@ -1259,13 +1259,13 @@ export type CallToTestOrderOfParamsData = {
};
};

export type CallWithNoContentResponseResponse = undefined;
export type CallWithNoContentResponseResponse = void;

export type CallWithResponseAndNoContentResponseResponse = number | undefined;
export type CallWithResponseAndNoContentResponseResponse = number | void;

export type DummyAResponse = _400;

export type DummyBResponse = undefined;
export type DummyBResponse = void;

export type CallWithResponseResponse = _import;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ export type PostCallWithOptionalParamData = {
};
};

export type PostCallWithOptionalParamResponse = number | undefined;
export type PostCallWithOptionalParamResponse = number | void;

export type PostApiVbyApiVersionRequestBodyData = {
/**
Expand Down Expand Up @@ -1259,13 +1259,13 @@ export type CallToTestOrderOfParamsData = {
};
};

export type CallWithNoContentResponseResponse = undefined;
export type CallWithNoContentResponseResponse = void;

export type CallWithResponseAndNoContentResponseResponse = number | undefined;
export type CallWithResponseAndNoContentResponseResponse = number | void;

export type DummyAResponse = _400;

export type DummyBResponse = undefined;
export type DummyBResponse = void;

export type CallWithResponseResponse = _import;

Expand Down
Loading

0 comments on commit 9e07675

Please sign in to comment.