Skip to content

Commit

Permalink
Merge branch 'main' into ajiang/navigation-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
abvthecity committed May 24, 2024
2 parents d957f38 + 4228b46 commit 7740a03
Show file tree
Hide file tree
Showing 215 changed files with 4,057 additions and 2,034 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
# Chromatic CI config: https://www.chromatic.com/docs/github-actions/
with:
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
workingDir: packages/ui/app
workingDir: packages/ui/components
onlyChanged: true

fern-generate:
Expand Down
14 changes: 9 additions & 5 deletions fern/apis/fdr/definition/snippets-factory.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,30 +69,34 @@ types:
snippets: list<SingleJavaSnippetCreate>

# Single creates
BaseSnippetCreate:
properties:
endpoint: commons.EndpointIdentifier
exampleIdentifier: optional<string>

SingleTypescriptSnippetCreate:
extends: BaseSnippetCreate
properties:
endpoint: commons.EndpointIdentifier
snippet: TypeScriptSnippetCode

SinglePythonSnippetCreate:
extends: BaseSnippetCreate
properties:
endpoint: commons.EndpointIdentifier
snippet: PythonSnippetCode

SingleGoSnippetCreate:
extends: BaseSnippetCreate
properties:
endpoint: commons.EndpointIdentifier
snippet: GoSnippetCode

SingleRubySnippetCreate:
extends: BaseSnippetCreate
properties:
endpoint: commons.EndpointIdentifier
snippet: RubySnippetCode

SingleJavaSnippetCreate:
extends: BaseSnippetCreate
properties:
endpoint: commons.EndpointIdentifier
snippet: JavaSnippetCode

# Snippet Code
Expand Down
5 changes: 5 additions & 0 deletions fern/apis/fdr/definition/snippets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ service:
The SDKs for which to load snippets. If unspecified,
snippets for the latest published SDKs will be returned.
endpoint: commons.EndpointIdentifier
exampleIdentifier:
type: optional<string>
docs: The identifier of the example to fetch the snippet for, this is ignored if a payload is passed in.
# TODO: Nice to have, allow client variable name to be configurable
# clientName:
# type: optional<string>
Expand Down Expand Up @@ -311,6 +314,8 @@ types:
type: map<commons.EndpointMethod, list<Snippet>>

Snippet:
base-properties:
exampleIdentifier: optional<string>
union:
typescript: TypeScriptSnippet
python: PythonSnippet
Expand Down
19 changes: 15 additions & 4 deletions packages/commons/fdr-utils/src/getNavigationRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ function isNavigationNode(n: SidebarNodeRaw.VisitableNode): n is SidebarNodeRaw.

// lower number means higher priority
const PRIORITY_LIST: Record<SidebarNodeRaw.VisitableNode["type"], number> = {
root: 3,
tabGroup: 2,
root: 6,
section: 5,
apiSection: 4,
tabGroup: 3,
versionGroup: 2,
section: 2,
apiSection: 2,
pageGroup: 1,
page: 0,
};
Expand All @@ -54,6 +54,17 @@ export function getNavigationRoot(
});

if (hits[0] == null) {
// match on top-level versions if the slug starts with a version
// ignore the first item, which doesn't contain a version
for (const rootItem of root.items.slice(1)) {
if (rootItem.type === "versionGroup") {
const versionSlug = rootItem.slug.join("/");
if (slugArray.join("/").startsWith(rootItem.slug.join("/"))) {
return { type: "redirect", redirect: `/${versionSlug}` };
}
}
}

return undefined;
}

Expand Down
8 changes: 5 additions & 3 deletions packages/commons/fdr-utils/src/traverser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ function visitPage(
if (matchCurrentNode(currentNode, page)) {
traverseState.curr = page;
traverseState.sectionTitleBreadcrumbs = sectionTitleBreadcrumbs;
} else {
} else if (!page.hidden) {
traverseState.prev = page;
}
} else {
} else if (!page.hidden) {
traverseState.next = page;
}

Expand Down Expand Up @@ -97,7 +97,9 @@ function visitNode(
}
}

const apiSectionBreadcrumbs = [...sectionTitleBreadcrumbs, apiSection.title];
const apiSectionBreadcrumbs = apiSection.isSidebarFlattened
? sectionTitleBreadcrumbs
: [...sectionTitleBreadcrumbs, apiSection.title];

if (apiSection.changelog != null) {
traverseState = visitPage(apiSection.changelog, currentNode, traverseState, apiSectionBreadcrumbs);
Expand Down
2 changes: 1 addition & 1 deletion packages/fdr-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@
"format": "prettier --write --ignore-unknown --ignore-path ../../shared/.prettierignore \"**\"",
"format:check": "prettier --check --ignore-unknown --ignore-path ../../shared/.prettierignore \"**\"",
"lint": "eslint --max-warnings 0 src --ext .ts --resolve-plugins-relative-to ../../",
"test": "vitest --passWithNoTests"
"test": "vitest"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SDKSnippetHolder } from "@fern-api/fdr-sdk";
import { SDKSnippetHolder } from "../converters";

describe("SDK Snippet Holder", () => {
it("Test SDK Snippet Retrieval", () => {
Expand Down Expand Up @@ -45,7 +45,8 @@ describe("SDK Snippet Holder", () => {
const snippet = sdkSnippetHolder.getPythonCodeSnippetForEndpoint({
endpointMethod: "GET",
endpointPath: "/users/v1",
identifierOverride: "endpoint_connectors.list",
endpointId: "endpoint_connectors.list",
exampleId: undefined,
});
expect(snippet?.async_client).toEqual("client = AsyncAcme(api_key='YOUR_API_KEY')");
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export interface GetSnippetRequest {
*/
sdks?: FernRegistry.SdkRequest[];
endpoint: FernRegistry.EndpointIdentifier;
/** The identifier of the example to fetch the snippet for, this is ignored if a payload is passed in. */
exampleIdentifier?: string;
/**
* The JSON payload to be used as the input for the code snippet. This should just be thought of as the
* request body you'd be sending to the endpoint as a cURL. If not specified then the default payload will be used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,27 @@ export type Snippet =
| FernRegistry.Snippet.Ruby;

export declare namespace Snippet {
interface Typescript extends FernRegistry.TypeScriptSnippet {
interface Typescript extends FernRegistry.TypeScriptSnippet, _Base {
type: "typescript";
}

interface Python extends FernRegistry.PythonSnippet {
interface Python extends FernRegistry.PythonSnippet, _Base {
type: "python";
}

interface Java extends FernRegistry.JavaSnippet {
interface Java extends FernRegistry.JavaSnippet, _Base {
type: "java";
}

interface Go extends FernRegistry.GoSnippet {
interface Go extends FernRegistry.GoSnippet, _Base {
type: "go";
}

interface Ruby extends FernRegistry.RubySnippet {
interface Ruby extends FernRegistry.RubySnippet, _Base {
type: "ruby";
}

interface _Base {
exampleIdentifier?: string;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

import * as FernRegistry from "../../..";

export interface BaseSnippetCreate {
endpoint: FernRegistry.EndpointIdentifier;
exampleIdentifier?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import * as FernRegistry from "../../..";

export interface SingleGoSnippetCreate {
endpoint: FernRegistry.EndpointIdentifier;
export interface SingleGoSnippetCreate extends FernRegistry.BaseSnippetCreate {
snippet: FernRegistry.GoSnippetCode;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import * as FernRegistry from "../../..";

export interface SingleJavaSnippetCreate {
endpoint: FernRegistry.EndpointIdentifier;
export interface SingleJavaSnippetCreate extends FernRegistry.BaseSnippetCreate {
snippet: FernRegistry.JavaSnippetCode;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import * as FernRegistry from "../../..";

export interface SinglePythonSnippetCreate {
endpoint: FernRegistry.EndpointIdentifier;
export interface SinglePythonSnippetCreate extends FernRegistry.BaseSnippetCreate {
snippet: FernRegistry.PythonSnippetCode;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import * as FernRegistry from "../../..";

export interface SingleRubySnippetCreate {
endpoint: FernRegistry.EndpointIdentifier;
export interface SingleRubySnippetCreate extends FernRegistry.BaseSnippetCreate {
snippet: FernRegistry.RubySnippetCode;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import * as FernRegistry from "../../..";

export interface SingleTypescriptSnippetCreate {
endpoint: FernRegistry.EndpointIdentifier;
export interface SingleTypescriptSnippetCreate extends FernRegistry.BaseSnippetCreate {
snippet: FernRegistry.TypeScriptSnippetCode;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export * from "./PythonSdkSnippetCreate";
export * from "./GoSdkSnippetsCreate";
export * from "./RubySdkSnippetsCreate";
export * from "./JavaSdkSnippetsCreate";
export * from "./BaseSnippetCreate";
export * from "./SingleTypescriptSnippetCreate";
export * from "./SinglePythonSnippetCreate";
export * from "./SingleGoSnippetCreate";
Expand Down
17 changes: 12 additions & 5 deletions packages/fdr-sdk/src/converters/db/convertAPIDefinitionToDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ function transformEndpoint({
snippetTemplates: snippets.getSnippetTemplateForEndpoint({
endpointPath: getEndpointPathAsString(writeShape),
endpointMethod: writeShape.method,
identifierOverride: writeShape.originalEndpointId,
endpointId: writeShape.originalEndpointId,
}),
};
}
Expand Down Expand Up @@ -473,6 +473,7 @@ export function transformExampleEndpointCall({
codeExamples: transformCodeExamples({
endpointDefinition,
snippets,
exampleId: writeShape.name,
}),
requestBodyV3:
writeShape.requestBodyV3 ??
Expand All @@ -495,31 +496,37 @@ export function transformExampleEndpointCall({
}

function transformCodeExamples({
exampleId,
endpointDefinition,
snippets,
}: {
endpointDefinition: APIV1Write.EndpointDefinition;
snippets: SDKSnippetHolder;
exampleId: string | undefined;
}): FdrAPI.api.v1.read.CodeExamples {
const maybePythonSnippet = snippets.getPythonCodeSnippetForEndpoint({
endpointMethod: endpointDefinition.method,
endpointPath: getEndpointPathAsString(endpointDefinition),
identifierOverride: endpointDefinition.originalEndpointId,
endpointId: endpointDefinition.originalEndpointId,
exampleId,
});
const maybeTypescriptSnippet = snippets.getTypeScriptCodeSnippetForEndpoint({
endpointMethod: endpointDefinition.method,
endpointPath: getEndpointPathAsString(endpointDefinition),
identifierOverride: endpointDefinition.originalEndpointId,
endpointId: endpointDefinition.originalEndpointId,
exampleId,
});
const maybeGoSnippet = snippets.getGoCodeSnippetForEndpoint({
endpointMethod: endpointDefinition.method,
endpointPath: getEndpointPathAsString(endpointDefinition),
identifierOverride: endpointDefinition.originalEndpointId,
endpointId: endpointDefinition.originalEndpointId,
exampleId,
});
const maybeRubySnippet = snippets.getRubyCodeSnippetForEndpoint({
endpointMethod: endpointDefinition.method,
endpointPath: getEndpointPathAsString(endpointDefinition),
identifierOverride: endpointDefinition.originalEndpointId,
endpointId: endpointDefinition.originalEndpointId,
exampleId,
});
return {
nodeAxios: "",
Expand Down
Loading

0 comments on commit 7740a03

Please sign in to comment.