Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe('Command Runner Builder', () => {
let context: (dir: string) => ExecutorContext;
let schema: GenerateApiLibSourcesExecutorSchema;
let dockerSchema: GenerateApiLibSourcesExecutorSchema;
let dockerAltSchema: GenerateApiLibSourcesExecutorSchema;

beforeEach(async () => {
schema = {
Expand All @@ -24,6 +25,12 @@ describe('Command Runner Builder', () => {
sourceSpecPathOrUrl: 'open-api-spec.yml',
useDockerBuild: true,
};
dockerAltSchema = {
generator: 'typescript-fetch',
dockerImage: 'alt/openapi-generator-cli:not-the-latest',
sourceSpecPathOrUrl: 'open-api-spec.yml',
useDockerBuild: true,
};

context = (dir: string) => ({
root: '/root',
Expand Down Expand Up @@ -70,7 +77,7 @@ describe('Command Runner Builder', () => {
'--rm',
...['-v', `${process.cwd()}:/local`],
...['-w', '/local'],
'openapitools/openapi-generator-cli',
'openapitools/openapi-generator-cli:latest',
'generate',
...['-i', 'open-api-spec.yml'],
...['-g', 'typescript-fetch'],
Expand All @@ -82,4 +89,25 @@ describe('Command Runner Builder', () => {
expect(success).toBe(true);
allSpawned();
});

it('can run in docker with alt image', async () => {
const allSpawned = mockSpawn({
command: 'docker',
args: [
'run',
'--rm',
...['-v', `${process.cwd()}:/local`],
...['-w', '/local'],
'alt/openapi-generator-cli:not-the-latest',
'generate',
...['-i', 'open-api-spec.yml'],
...['-g', 'typescript-fetch'],
...['-o', './tmp/src/dockeralt'],
],
exitCode: 0,
});
const { success } = await executor(dockerAltSchema, context('dockeralt'));
expect(success).toBe(true);
allSpawned();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default async function runExecutor(

await generateSources(
options.useDockerBuild ?? false,
options.dockerImage ?? 'openapitools/openapi-generator-cli:latest',
options.sourceSpecPathOrUrl,
options.sourceSpecUrlAuthorizationHeaders,
options.generator,
Expand All @@ -33,6 +34,7 @@ export default async function runExecutor(

async function generateSources(
useDockerBuild: boolean,
dockerImage: string,
apiSpecPathOrUrl: string,
apiSpecAuthorizationHeaders: string,
generator: string,
Expand All @@ -47,7 +49,7 @@ async function generateSources(
const { command, args } = useDockerBuild
? {
command: 'docker',
args: ['run', '--rm', '-v', `${process.cwd()}:/local`, '-w', '/local', 'openapitools/openapi-generator-cli'],
args: ['run', '--rm', '-v', `${process.cwd()}:/local`, '-w', '/local', dockerImage],
}
: { command: 'npx', args: ['openapi-generator-cli'] };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export interface GenerateApiLibSourcesExecutorSchema {
generator: string;
sourceSpecPathOrUrl: string;
useDockerBuild?: boolean;
dockerImage?: string;
sourceSpecUrlAuthorizationHeaders?: string;
additionalProperties?: string;
globalProperties?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
"description": "Should the build occur inside of a docker container",
"default": false
},
"dockerImage": {
"type": "string",
"description": "Which docker image should be used for the build?",
"default": "openapitools/openapi-generator-cli:latest"
},
"generator": {
"type": "string",
"description": "The OpenAPITools generator you want to use",
Expand Down
16 changes: 10 additions & 6 deletions packages/nx-plugin-openapi/src/generators/api-lib/generator.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
// Nrwl
import {
addProjectConfiguration, formatFiles, generateFiles, GeneratorCallback,
addProjectConfiguration,
formatFiles,
generateFiles,
GeneratorCallback,
getWorkspaceLayout,
joinPathFragments, names,
joinPathFragments,
names,
offsetFromRoot,
ProjectType,
readWorkspaceConfiguration, Tree, updateJson
readWorkspaceConfiguration,
Tree,
updateJson,
} from '@nrwl/devkit';
import { runTasksInSerial } from '@nrwl/workspace/src/utilities/run-tasks-in-serial';
// Third Parties
Expand All @@ -16,9 +22,6 @@ import init from '../init/generator';
// Schemas
import { ApiLibGeneratorSchema } from './schema';




const projectType: ProjectType = 'library';

interface NormalizedSchema extends ApiLibGeneratorSchema {
Expand Down Expand Up @@ -82,6 +85,7 @@ function normalizeOptions(host: Tree, options: ApiLibGeneratorSchema): Normalize
const getExecutorOptions = (options: NormalizedSchema): GenerateApiLibSourcesExecutorSchema => {
const executorOptions: GenerateApiLibSourcesExecutorSchema = {
useDockerBuild: options.useDockerBuild,
dockerImage: options.dockerImage,
generator: options.generator,
sourceSpecPathOrUrl: options.isRemoteSpec
? options.sourceSpecUrl
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export interface ApiLibGeneratorSchema {
name: string;
useDockerBuild?: boolean;
dockerImage?: string;
generator?: string;
tags?: string;
directory?: string;
Expand Down
6 changes: 6 additions & 0 deletions packages/nx-plugin-openapi/src/generators/api-lib/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
"default": false,
"x-prompt": "Should the build occur inside of a docker container?"
},
"dockerImage": {
"type": "string",
"description": "Which docker image should be used for the build",
"default": "openapitools/openapi-generator-cli:latest",
"x-prompt": "Which docker image should be used for the build?"
},
"generator": {
"type": "string",
"description": "The generator this lib will use to build an API SDK (e.g.: typescript-fetch)",
Expand Down