Skip to content

Commit

Permalink
(feature): OpenAPI importer attempts to use tag order to render endpo…
Browse files Browse the repository at this point in the history
…ints if possible (#3048)

ordered tag ids
  • Loading branch information
dsinghvi authored Feb 23, 2024
1 parent e0683f3 commit 0a60759
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
4 changes: 4 additions & 0 deletions fern/apis/public-api/definition/__package__.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
navigation:
- snippets
- transactions

6 changes: 6 additions & 0 deletions packages/cli/openapi-ir-to-fern/src/FernDefnitionBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { camelCase } from "lodash-es";
import { basename, extname } from "path";

export interface FernDefinitionBuilder {
addNavigation({ navigation }: { navigation: string[] }): void;

addAuthScheme({ name, schema }: { name: string; schema: RawSchemas.AuthSchemeDeclarationSchema }): void;

setAuth(name: string): void;
Expand Down Expand Up @@ -82,6 +84,10 @@ export class FernDefinitionBuilderImpl implements FernDefinitionBuilder {
}
}

public addNavigation({ navigation }: { navigation: string[] }): void {
this.packageMarkerFile.navigation = navigation;
}

setServiceInfo(
file: RelativeFilePath,
{ displayName, docs }: { displayName?: string | undefined; docs?: string | undefined }
Expand Down
13 changes: 12 additions & 1 deletion packages/cli/openapi-ir-to-fern/src/buildFernDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function buildFernDefinition(context: OpenApiIrConverterContext): FernDef
if (context.ir.hasEndpointsMarkedInternal) {
context.builder.addAudience(EXTERNAL_AUDIENCE);
}
const { schemaIdsToExclude } = buildServices(context);
const { schemaIdsToExclude, sdkGroups } = buildServices(context);
buildWebhooks(context);

// Add Channels
Expand Down Expand Up @@ -79,5 +79,16 @@ export function buildFernDefinition(context: OpenApiIrConverterContext): FernDef
});
}

if (context.ir.tags.orderedTagIds != null && context.ir.tags.orderedTagIds.length > 0) {
const containsValidTagIds = context.ir.tags.orderedTagIds.every((tagId) => {
return sdkGroups.has(tagId);
});
if (containsValidTagIds) {
context.builder.addNavigation({
navigation: context.ir.tags.orderedTagIds
});
}
}

return context.builder.build();
}
12 changes: 10 additions & 2 deletions packages/cli/openapi-ir-to-fern/src/buildServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@ import { buildEndpoint } from "./buildEndpoint";
import { OpenApiIrConverterContext } from "./OpenApiIrConverterContext";
import { getEndpointLocation } from "./utils/getEndpointLocation";

export function buildServices(context: OpenApiIrConverterContext): { schemaIdsToExclude: string[] } {
export function buildServices(context: OpenApiIrConverterContext): {
schemaIdsToExclude: string[];
sdkGroups: Set<string>;
} {
const sdkGroups = new Set<string>();
const { endpoints, tags } = context.ir;
let schemaIdsToExclude: string[] = [];
for (const endpoint of endpoints) {
const { endpointId, file, tag } = getEndpointLocation(endpoint);
const sdkGroup = file.split(".")[0];
if (sdkGroup != null) {
sdkGroups.add(sdkGroup);
}
const irTag = tag == null ? undefined : tags.tagsById[tag];
const convertedEndpoint = buildEndpoint({
context,
Expand All @@ -23,5 +31,5 @@ export function buildServices(context: OpenApiIrConverterContext): { schemaIdsTo
docs: irTag?.description ?? undefined
});
}
return { schemaIdsToExclude };
return { schemaIdsToExclude, sdkGroups };
}

0 comments on commit 0a60759

Please sign in to comment.