Skip to content

Commit

Permalink
fix(type-safe-api): add missing imports for parameter models
Browse files Browse the repository at this point in the history
Parameter models were not being imported in the API client in the typescript runtime.

References #841
  • Loading branch information
cogwirrel committed Oct 7, 2024
1 parent 345eb6f commit 9f06ae4
Show file tree
Hide file tree
Showing 3 changed files with 1,383 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,8 @@ const buildData = (inSpec: OpenAPIV3.Document, metadata: any) => {
// Augment operations with additional data
data.services.forEach((service) => {

// Keep track of the response models we need the service (ie api client) to import
// Keep track of the request and response models we need the service (ie api client) to import
const requestModelImports: string[] = [];
const responseModelImports: string[] = [];

service.operations.forEach((op) => {
Expand Down Expand Up @@ -486,8 +487,12 @@ const buildData = (inSpec: OpenAPIV3.Document, metadata: any) => {

// Loop through the parameters
op.parameters.forEach((parameter) => {
const specParameter = specParametersByName[parameter.prop];
// Add the request model import
if (parameter.export === "reference") {
requestModelImports.push(parameter.type);
}

const specParameter = specParametersByName[parameter.prop];
const specParameterSchema = resolveIfRef(spec, specParameter?.schema);

if (specParameterSchema) {
Expand Down Expand Up @@ -541,7 +546,7 @@ const buildData = (inSpec: OpenAPIV3.Document, metadata: any) => {
service.operations = _orderBy(service.operations, (op) => op.name);

// Add the models to import
(service as any).modelImports = _orderBy(_uniq([...service.imports, ...responseModelImports]));
(service as any).modelImports = _orderBy(_uniq([...service.imports, ...requestModelImports, ...responseModelImports]));

// Add the service class name
(service as any).className = `${service.name}Api`;
Expand Down
Loading

0 comments on commit 9f06ae4

Please sign in to comment.