Skip to content

Commit

Permalink
fix componentRef import statements
Browse files Browse the repository at this point in the history
  • Loading branch information
inkognitro committed Apr 21, 2024
1 parent 49bb323 commit daed546
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
18 changes: 10 additions & 8 deletions src/oas3/codegen/ts/generate.petstore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import {generateOas3ToTs} from './generate';
const petStoreSpecification = require('./generate.petstore.test.specs.json');

test('can generate files from petstore specification', () => {
generateOas3ToTs({
getSpecification: () => {
return new Promise<object>(resolve => {
resolve(petStoreSpecification);
});
},
outputFolderPath: './generated-files-petstore',
});
expect(() => {
generateOas3ToTs({
getSpecification: () => {
return new Promise<object>(resolve => {
resolve(petStoreSpecification);
});
},
outputFolderPath: './generated-files-petstore',
});
}).not.toThrow();
});
37 changes: 32 additions & 5 deletions src/oas3/codegen/ts/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,13 +512,40 @@ export class DefaultCodeGenerator implements CodeGenerator {
if (!requiredOutput) {
return;
}
if (this.isSameOutputFile(requiredOutput.path, output.path)) {

if (
output.type !== OutputType.COMPONENT_REF &&
this.isSameOutputFile(requiredOutput.path, output.path)
) {
return;
}
const importAsset: ImportAsset = {
name: requiredOutput.createName(requiredOutput.path),
importAsName: requiredOutput.createName(output.path),
};

if (output.type === OutputType.COMPONENT_REF) {
const componentOutputPath = this.createOutputPathByComponentRef(
output.componentRef
);
requiredOutput = availableOutputs.find(o =>
areOutputPathsEqual(o.path, componentOutputPath)
);
if (!requiredOutput) {
return;
}
if (this.isSameOutputFile(requiredOutput.path, output.path)) {
return;
}
}

const importAsset: ImportAsset =
output.type === OutputType.COMPONENT_REF
? {
name: output.createName(requiredOutput.path),
importAsName: output.createName(output.path),
}
: {
name: requiredOutput.createName(requiredOutput.path),
importAsName: requiredOutput.createName(output.path),
};

const importPath = this.createImportPath(
requiredOutput.path,
output.path,
Expand Down

0 comments on commit daed546

Please sign in to comment.