Skip to content

Commit

Permalink
fix: 🐛 Minor bux fix + test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
GerasNyx committed Jan 12, 2024
1 parent 9bf6b89 commit f1da22a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
10 changes: 7 additions & 3 deletions packages/codegen-openapi/__tests__/features/v3/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,22 @@ const expectedOperationTypes = {
FindPetsResponseType: "export type FindPetsResponseType = Paths.FindPets.Responses.$200",
AddPetRequestBody: "export type AddPetRequestBody = Paths.AddPet.RequestBody",
AddPetResponseType: "export type AddPetResponseType = Paths.AddPet.Responses.$200",
AddPetErrorType: "export type AddPetErrorType = Paths.AddPet.Responses.$405",
FindPetByIdPathParams: "export type FindPetByIdPathParams = Paths.FindPetById.PathParameters",
FindPetByIdResponseType: "export type FindPetByIdResponseType = Paths.FindPetById.Responses.$200",
DeletePetPathParams: "export type DeletePetPathParams = Paths.DeletePet.PathParameters",
DeletePetResponseType: "export type DeletePetResponseType = any",
DeletePetErrorType: "export type DeletePetErrorType = Paths.DeletePet.Responses.$400",
UpdatePetRequestBody: "export type UpdatePetRequestBody = Paths.UpdatePet.RequestBody",
UpdatePetResponseType: "export type UpdatePetResponseType = Paths.UpdatePet.Responses.$200",
UpdatePetErrorType:
"export type UpdatePetErrorType = Paths.UpdatePet.Responses.$400 | Paths.UpdatePet.Responses.$404 | Paths.UpdatePet.Responses.$405",
};
const expectedRequests = [
`export const findPets = client.createRequest<FindPetsResponseType, undefined, undefined, FindPetsQueryParams>()({method: "GET", endpoint: "/pets"})`,
`export const addPet = client.createRequest<AddPetResponseType, AddPetRequestBody, undefined, undefined>()({method: "POST", endpoint: "/pet"})`,
`export const deletePet = client.createRequest<DeletePetResponseType, undefined, undefined, undefined>()({method: "DELETE", endpoint: "/pet/:petId"})`,
`export const updatePet = client.createRequest<UpdatePetResponseType, UpdatePetRequestBody, undefined, undefined>()({method: "PUT", endpoint: "/pet"})`,
`export const addPet = client.createRequest<AddPetResponseType, AddPetRequestBody, AddPetErrorType, undefined>()({method: "POST", endpoint: "/pet"})`,
`export const deletePet = client.createRequest<DeletePetResponseType, undefined, DeletePetErrorType, undefined>()({method: "DELETE", endpoint: "/pet/:petId"})`,
`export const updatePet = client.createRequest<UpdatePetResponseType, UpdatePetRequestBody, UpdatePetErrorType, undefined>()({method: "PUT", endpoint: "/pet"})`,
];

describe("Generator", () => {
Expand Down
12 changes: 7 additions & 5 deletions packages/codegen-openapi/src/openapi/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ export class OpenapiRequestGenerator {
const Payload = types[`${createTypeBaseName(id)}RequestBody`]
? `${createTypeBaseName(id)}RequestBody`
: "undefined";
const LocalError = types[`${createTypeBaseName(id)}ErrorType`]
? `${createTypeBaseName(id)}ErrorType`
: "undefined";
const LocalError = types[`${createTypeBaseName(id)}ErrorType`] ? `${createTypeBaseName(id)}ErrorType` : "undefined";
const QueryParams = types[`${createTypeBaseName(id)}QueryParams`]
? `${createTypeBaseName(id)}QueryParams`
: "undefined";
Expand Down Expand Up @@ -122,7 +120,7 @@ export class OpenapiRequestGenerator {
types[`${typeName}RequestBody`] = `export type ${typeName}RequestBody = ${requestBodyType}`;
}
if (errorType) {
types[`${typeName}ErrorType`] = `export type ${typeName}ErrorType = ${responseType}`;
types[`${typeName}ErrorType`] = `export type ${typeName}ErrorType = ${errorType}`;
}
if (responseType) {
types[`${typeName}ResponseType`] = `export type ${typeName}ResponseType = ${responseType}`;
Expand All @@ -145,7 +143,11 @@ export class OpenapiRequestGenerator {
.map(({ path }) => path)
.value();
const errorTypePaths = chain(exportTypes)
.filter(({ schemaRef }) => schemaRef.startsWith(`#/paths/${normalizedOperationId}/responses/4`) || schemaRef.startsWith(`#/paths/${normalizedOperationId}/responses/5`))
.filter(
({ schemaRef }) =>
schemaRef.startsWith(`#/paths/${normalizedOperationId}/responses/4`) ||
schemaRef.startsWith(`#/paths/${normalizedOperationId}/responses/5`),
)
.map(({ path }) => path)
.value();

Expand Down

0 comments on commit f1da22a

Please sign in to comment.