Skip to content

Commit

Permalink
add log statements
Browse files Browse the repository at this point in the history
  • Loading branch information
Omar Rida authored and Omar Rida committed Mar 20, 2024
1 parent 223c552 commit 954d44b
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 1 deletion.
62 changes: 62 additions & 0 deletions .github/workflows/test-openapi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
on:
push:
branches:
- omarrida/openapi-test
jobs:
openapi:
runs-on: ubuntu-latest
needs: versions-changed
if: ${{ needs.versions-changed.outputs.openapi == 'true' || inputs.generator == 'openapi' }}
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-node@v3
with:
node-version: 18
cache: "yarn"

- name: Install
run: yarn install

- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: fernapi
password: ${{ secrets.FERN_API_DOCKERHUB_PASSWORD }}

- name: Build CLI
working-directory: ./generators/openapi
run: yarn dist:cli

- name: Print Version
if: ${{ inputs.generator != 'openapi' }}
run: |
projectVersion=$(cat generators/openapi/VERSION)
echo $projectVersion
echo "VERSION=$projectVersion" >> $GITHUB_ENV
- name: Print Version Dev
if: ${{ inputs.generator == 'openapi' }}
run: |
projectVersion=$(cat generators/openapi/VERSION)
commitNumber=$(git log --oneline | wc -l )
sha_short=$(git rev-parse --short HEAD)
echo $projectVersion-$commitNumber-$sha_short
echo "VERSION=$projectVersion-$commitNumber-$sha_short" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: ./generators/openapi
file: ./generators/openapi/Dockerfile
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=min
push: true
tags: fernapi/omarrida-openapi:latest
2 changes: 1 addition & 1 deletion fern/fern.config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"organization": "fern",
"version": "0.19.10"
"version": "0.19.14-rc0"
}
32 changes: 32 additions & 0 deletions generators/openapi/src/writeOpenApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,66 @@ export type Mode = "stoplight" | "openapi";

export async function writeOpenApi(mode: Mode, pathToConfig: string): Promise<void> {
try {
// eslint-disable-next-line no-console
console.log("beginning writeOpenApi");
const configStr = await readFile(pathToConfig);
const config = JSON.parse(configStr.toString()) as GeneratorConfig;
const customConfig = getCustomConfig(config);

// eslint-disable-next-line no-console
console.log("customConfig", customConfig);
const generatorLoggingClient = new GeneratorLoggingWrapper(config);

try {
// eslint-disable-next-line no-console
console.log("sending update");
await generatorLoggingClient.sendUpdate(
GeneratorUpdate.init({
packagesToPublish: []
})
);

// eslint-disable-next-line no-console
console.log("loading ir");
const ir = await loadIntermediateRepresentation(config.irFilepath);
// eslint-disable-next-line no-console
console.log("parsed ir", ir);
const openApiDefinition = convertToOpenApi({
apiName: config.workspaceName,
ir,
mode
});
// eslint-disable-next-line no-console
console.log("openApiDefinition", openApiDefinition);

const openApiDefinitionWithCustomOverrides = merge(customConfig.customOverrides, openApiDefinition);
// eslint-disable-next-line no-console
console.log("openApiDefinitionWithCustomOverrides", openApiDefinitionWithCustomOverrides);

if (customConfig.format === "json") {
// eslint-disable-next-line no-console
console.log("writing json");
await writeFile(
path.join(config.output.path, OPENAPI_JSON_FILENAME),
JSON.stringify(openApiDefinitionWithCustomOverrides, undefined, 2)
);
// eslint-disable-next-line no-console
console.log("wrote json");
} else {
// eslint-disable-next-line no-console
console.log("writing yml");
await writeFile(
path.join(config.output.path, OPENAPI_YML_FILENAME),
yaml.dump(openApiDefinitionWithCustomOverrides)
);
// eslint-disable-next-line no-console
console.log("wrote yml");
}
// eslint-disable-next-line no-console
console.log("sending exit status update");
await generatorLoggingClient.sendUpdate(GeneratorUpdate.exitStatusUpdate(ExitStatusUpdate.successful({})));
// eslint-disable-next-line no-console
console.log("sent exit status update");
} catch (e) {
// eslint-disable-next-line no-console
console.log("Encountered error", e);
Expand All @@ -70,6 +96,12 @@ export async function writeOpenApi(mode: Mode, pathToConfig: string): Promise<vo

async function loadIntermediateRepresentation(pathToFile: string): Promise<IntermediateRepresentation> {
const irString = (await readFile(pathToFile)).toString();
// eslint-disable-next-line no-console
console.log("irString", irString);
const irJson = JSON.parse(irString);
// eslint-disable-next-line no-console
console.log("irJson", irJson);
// eslint-disable-next-line no-console
console.log("parsing ir");
return IrSerialization.IntermediateRepresentation.parseOrThrow(irJson);
}

0 comments on commit 954d44b

Please sign in to comment.