Skip to content

Commit

Permalink
fix(cli): conjure importer reads from base-path (#4984)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsinghvi authored Oct 22, 2024
1 parent d3518bb commit f790669
Show file tree
Hide file tree
Showing 7 changed files with 402 additions and 363 deletions.
4 changes: 4 additions & 0 deletions fern/pages/changelogs/cli/2024-10-22.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 0.45.0-rc15
**`(fix):`** The Conjure importer now correctly imports base-path and docs from your conjure definition.


18 changes: 16 additions & 2 deletions packages/cli/api-importers/commons/src/FernDefnitionBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import { camelCase, isEqual } from "lodash-es";
import path, { basename, extname } from "path";
import { FernDefinitionDirectory } from "./utils/FernDefinitionDirectory";

export type HttpServiceInfo = Partial<
Pick<RawSchemas.HttpServiceSchema, "auth" | "base-path" | "display-name"> & { docs?: string }
>;

export interface FernDefinitionBuilder {
setDisplayName({ displayName }: { displayName: string }): void;

Expand Down Expand Up @@ -84,7 +88,10 @@ export interface FernDefinitionBuilder {

addChannelExample(file: RelativeFilePath, { example }: { example: RawSchemas.ExampleWebSocketSession }): void;

setServiceInfo(file: RelativeFilePath, { displayName, docs }: { displayName?: string; docs?: string }): void;
setServiceInfo(
file: RelativeFilePath,
{ auth, "base-path": basePath, "display-name": displayName, docs }: HttpServiceInfo
): void;

addTypeExample(file: RelativeFilePath, name: string, convertedExample: RawSchemas.ExampleTypeSchema): void;

Expand Down Expand Up @@ -125,16 +132,23 @@ export class FernDefinitionBuilderImpl implements FernDefinitionBuilder {

public setServiceInfo(
file: RelativeFilePath,
{ displayName, docs }: { displayName?: string | undefined; docs?: string | undefined }
{ auth, "base-path": basePath, "display-name": displayName, docs }: HttpServiceInfo
): void {
const fernFile = this.getOrCreateFile(file);
if (fernFile.service == null) {
// Set to default values if service is null
fernFile.service = {
auth: false,
"base-path": "",
endpoints: {}
};
}
if (auth != null) {
fernFile.service.auth = auth;
}
if (basePath != null) {
fernFile.service["base-path"] = basePath;
}
if (displayName != null) {
fernFile.service["display-name"] = displayName;
}
Expand Down
7 changes: 6 additions & 1 deletion packages/cli/api-importers/commons/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
export { APIDefinitionImporter } from "./APIDefinitionImporter";
export { type FernDefinitionBuilder, FernDefinitionBuilderImpl, type FernDefinition } from "./FernDefnitionBuilder";
export {
type FernDefinitionBuilder,
FernDefinitionBuilderImpl,
type FernDefinition,
type HttpServiceInfo
} from "./FernDefnitionBuilder";

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AbsoluteFilePath, dirname, join, RelativeFilePath, relativize, getFilename } from "@fern-api/fs-utils";
import { DefinitionFile } from "@fern-api/conjure-sdk";
import { APIDefinitionImporter, FernDefinitionBuilderImpl } from "@fern-api/importer-commons";
import { APIDefinitionImporter, FernDefinitionBuilderImpl, HttpServiceInfo } from "@fern-api/importer-commons";
import { visitConjureTypeDeclaration } from "./utils/visitConjureTypeDeclaration";
import { parseEndpointLocator, removeSuffix } from "@fern-api/core-utils";
import { listConjureFiles } from "./utils/listConjureFiles";
Expand Down Expand Up @@ -100,6 +100,15 @@ export class ConjureImporter extends APIDefinitionImporter<ConjureImporter.Args>
const unsuffixedServiceName = removeSuffix({ value: serviceName, suffix: "Service" });
const fernFilePath = RelativeFilePath.of(`${unsuffixedServiceName}/__package__.yml`);

const httpServiceInfo: HttpServiceInfo = {};
if (serviceDeclaration.basePath != null) {
httpServiceInfo["base-path"] = serviceDeclaration.basePath;
}
if (serviceDeclaration.docs != null) {
httpServiceInfo.docs = serviceDeclaration.docs;
}
this.fernDefinitionBuilder.setServiceInfo(fernFilePath, httpServiceInfo);

this.importAllTypes({ conjureFile: definition, fernFilePath });

for (const [import_, importedFilepath] of Object.entries(definition.types?.conjureImports ?? {})) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function buildServices(context: OpenApiIrConverterContext): {
});
if (irTag?.id != null || irTag?.description != null) {
context.builder.setServiceInfo(file, {
displayName: group?.summary ?? irTag?.id,
"display-name": group?.summary ?? irTag?.id,
docs: group?.description ?? irTag?.description ?? undefined
});
}
Expand Down
7 changes: 7 additions & 0 deletions packages/cli/cli/versions.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
- changelogEntry:
- summary: |
The Conjure importer now correctly imports base-path and docs from your conjure definition.
type: fix
irVersion: 53
version: 0.45.0-rc15

- changelogEntry:
- summary: |
The Fern CLI now uses a longer timeout to make HTTP requests, which should fix some flakyness with the docs registration process.
Expand Down

0 comments on commit f790669

Please sign in to comment.