Skip to content

Commit

Permalink
Merge branch 'main' into ajiang/trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
abvthecity committed Oct 30, 2024
2 parents 30c3c35 + 350ca16 commit 768faae
Show file tree
Hide file tree
Showing 41 changed files with 1,190 additions and 617 deletions.
3 changes: 1 addition & 2 deletions packages/cdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@
"synth:dev2": "cdk synth local-preview-bundle2-dev2"
},
"dependencies": {
"@fern-fern/fern-cloud-sdk": "^0.0.257",
"@fern-fern/fern-cloud-sdk": "^0.0.305",
"archiver": "^7.0.1",
"aws-cdk-lib": "^2.122.0",
"axios": "^1.7.4",
"constructs": "^10.3.0",
"tsx": "^4.7.1"
},
Expand Down
5 changes: 2 additions & 3 deletions packages/cdk/src/cdk.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env node
import { Environments, EnvironmentType } from "@fern-fern/fern-cloud-sdk/api/index";
import * as cdk from "aws-cdk-lib";
import axios from "axios";
import { DocsFeStack } from "./docs-fe-stack";

void main();
Expand All @@ -27,7 +26,7 @@ async function main() {
}

async function getEnvironments(): Promise<Environments> {
const response = await axios(
const response = await fetch(
"https://raw.githubusercontent.com/fern-api/fern-cloud/main/env-scoped-resources/environments.json",
{
method: "GET",
Expand All @@ -36,5 +35,5 @@ async function getEnvironments(): Promise<Environments> {
},
},
);
return response.data as Environments;
return (await response.json()) as any as Environments;
}
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,11 @@ class ApiDefinitionTransformationContext {
}

private getHost(url: string) {
const parsedBaseUrl = new URL(url);
return parsedBaseUrl.host;
try {
const parsedBaseUrl = new URL(url);
return parsedBaseUrl.host;
} catch (err) {
return "";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import * as ApiDefinition from "@fern-api/fdr-sdk/api-definition";
import { unwrapReference } from "@fern-api/fdr-sdk/api-definition";
import { ReactElement, useMemo } from "react";
import { PlaygroundObjectForm } from "../form/PlaygroundObjectForm";
import { PlaygroundTypeReferenceForm } from "../form/PlaygroundTypeReferenceForm";
import { PlaygroundEndpointFormSection } from "./PlaygroundEndpointFormSection";

interface PlaygroundEndpointAliasFormProps {
alias: ApiDefinition.HttpRequestBodyShape.Alias;
types: Record<ApiDefinition.TypeId, ApiDefinition.TypeDefinition>;
ignoreHeaders: boolean;
setBodyJson: (value: unknown) => void;
value: unknown;
}

export function PlaygroundEndpointAliasForm({
alias,
types,
ignoreHeaders,
setBodyJson,
value,
}: PlaygroundEndpointAliasFormProps): ReactElement {
const { shape, isOptional } = useMemo(() => unwrapReference(alias.value, types), [alias.value, types]);

if (shape.type === "object" && !isOptional) {
return (
<PlaygroundEndpointFormSection ignoreHeaders={ignoreHeaders} title="Body Parameters">
<PlaygroundObjectForm id="body" shape={shape} onChange={setBodyJson} value={value} types={types} />
</PlaygroundEndpointFormSection>
);
}
return (
<PlaygroundEndpointFormSection ignoreHeaders={ignoreHeaders} title={isOptional ? "Optional Body" : "Body"}>
<PlaygroundTypeReferenceForm id="body" shape={shape} onChange={setBodyJson} value={value} types={types} />
</PlaygroundEndpointFormSection>
);
}
46 changes: 11 additions & 35 deletions packages/ui/app/src/playground/endpoint/PlaygroundEndpointForm.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { EndpointContext } from "@fern-api/fdr-sdk/api-definition";
import { unwrapObjectType, unwrapReference } from "@fern-api/fdr-sdk/api-definition";
import { EMPTY_ARRAY, visitDiscriminatedUnion } from "@fern-api/ui-core-utils";
import { Dispatch, FC, SetStateAction, useCallback, useMemo } from "react";
import { PlaygroundFileUploadForm } from "../form/PlaygroundFileUploadForm";
import { PlaygroundObjectForm } from "../form/PlaygroundObjectForm";
import { PlaygroundObjectPropertiesForm } from "../form/PlaygroundObjectPropertyForm";
import { PlaygroundTypeReferenceForm } from "../form/PlaygroundTypeReferenceForm";
import { PlaygroundEndpointRequestFormState, PlaygroundFormStateBody } from "../types";
import { PlaygroundEndpointAliasForm } from "./PlaygroundEndpointAliasForm";
import { PlaygroundEndpointFormSection } from "./PlaygroundEndpointFormSection";
import { PlaygroundEndpointMultipartForm } from "./PlaygroundEndpointMultipartForm";

Expand Down Expand Up @@ -169,13 +169,11 @@ export const PlaygroundEndpointForm: FC<PlaygroundEndpointFormProps> = ({
</PlaygroundEndpointFormSection>
),
object: (value) => {
const unwrappedObjectType = unwrapObjectType(value, types);
return (
<PlaygroundEndpointFormSection ignoreHeaders={ignoreHeaders} title="Body Parameters">
<PlaygroundObjectPropertiesForm
<PlaygroundObjectForm
id="body"
properties={unwrappedObjectType.properties}
extraProperties={unwrappedObjectType.extraProperties}
shape={value}
onChange={setBodyJson}
value={formState?.body?.value}
types={types}
Expand All @@ -184,36 +182,14 @@ export const PlaygroundEndpointForm: FC<PlaygroundEndpointFormProps> = ({
);
},
alias: (alias) => {
const { shape, isOptional } = unwrapReference(alias.value, types);

if (shape.type === "object" && !isOptional) {
const unwrappedObjectType = unwrapObjectType(shape, types);
return (
<PlaygroundEndpointFormSection ignoreHeaders={ignoreHeaders} title="Body Parameters">
<PlaygroundObjectPropertiesForm
id="body"
properties={unwrappedObjectType.properties}
extraProperties={unwrappedObjectType.extraProperties}
onChange={setBodyJson}
value={formState?.body?.value}
types={types}
/>
</PlaygroundEndpointFormSection>
);
}
return (
<PlaygroundEndpointFormSection
ignoreHeaders={ignoreHeaders}
title={isOptional ? "Optional Body" : "Body"}
>
<PlaygroundTypeReferenceForm
id="body"
shape={shape}
onChange={setBodyJson}
value={formState?.body?.value}
types={types}
/>
</PlaygroundEndpointFormSection>
<PlaygroundEndpointAliasForm
alias={alias}
types={types}
ignoreHeaders={ignoreHeaders ?? false}
setBodyJson={setBodyJson}
value={formState?.body?.value}
/>
);
},
})}
Expand Down
129 changes: 129 additions & 0 deletions packages/ui/app/src/playground/form/PlaygroundAdditionalProperties.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
// import { Property, TypeIdKey, TypeId } from "@fern-api/fdr-sdk/navigation";
import * as ApiDefinition from "@fern-api/fdr-sdk/api-definition";
import clsx from "clsx";
import { ReactElement, useCallback, useMemo } from "react";
import { noop } from "ts-essentials";
import { WithLabel } from "../WithLabel";
import { castToRecord } from "../utils";
import { PlaygroundMapForm } from "./PlaygroundMapForm";

const ADDITIONAL_PROPERTIES_KEY_SHAPE = {
type: "primitive",
value: {
type: "string",
regex: undefined,
minLength: undefined,
maxLength: undefined,
default: undefined,
},
} as const;

const ADDITIONAL_PROPERTIES_VALUE_SHAPE = {
type: "primitive",
value: {
type: "string",
regex: undefined,
minLength: undefined,
maxLength: undefined,
default: undefined,
},
} as const;

// TODO: This is hardcoded for now, but change to dynamic type references, by setting value
const ADDITIONAL_PROPERTIES_DEFAULT_SHAPE = {
type: "alias",
value: {
type: "optional",
shape: {
type: "alias",
value: {
type: "map",
keyShape: {
type: "alias",
value: ADDITIONAL_PROPERTIES_KEY_SHAPE,
},
valueShape: {
type: "alias",
value: ADDITIONAL_PROPERTIES_VALUE_SHAPE,
},
},
},
default: undefined,
},
} as const;

interface PlaygroundAdditionalPropertiesProps {
onChange: (dispatch: unknown) => void;
properties: readonly ApiDefinition.ObjectProperty[];
extraProperties: ApiDefinition.TypeReference;
value: unknown;
types: Record<ApiDefinition.TypeId, ApiDefinition.TypeDefinition>;
}

export function PlaygroundAdditionalProperties({
onChange,
properties,
// TODO: this should be used:
// extraProperties,
value,
types,
}: PlaygroundAdditionalPropertiesProps): ReactElement {
const additionalProperties = useMemo(() => {
// remove property keys from value
const valueAsRecord = castToRecord(value);

const additionalPropertiesOnly: Record<string, unknown> = {};

Object.keys(valueAsRecord).forEach((key) => {
if (!properties.some((p) => p.key === key)) {
additionalPropertiesOnly[key] = valueAsRecord[key];
}
});

return additionalPropertiesOnly;
}, [properties, value]);

const handleChange = useCallback(
(dispatch: unknown) => {
onChange((prev: unknown) => {
const castedPrev = castToRecord(prev);
const newValue = typeof dispatch === "function" ? dispatch(prev) : dispatch;

// spread in the properties that are not in the extraProperties
const obj = { ...newValue };
Object.keys(castedPrev).forEach((key) => {
if (properties.find((p) => p.key === key)) {
obj[key] = castedPrev[key];
}
});
return obj;
});
},
[onChange, properties],
);

return (
<div className={clsx("flex-1 shrink min-w-0 mt-8")}>
<WithLabel
property={{
key: ApiDefinition.PropertyKey("Optional Extra Properties"),
valueShape: ADDITIONAL_PROPERTIES_DEFAULT_SHAPE,
description: undefined,
availability: undefined,
}}
value={"Optional Extra Properties"}
onRemove={noop}
types={types}
>
<PlaygroundMapForm
id="extraProperties"
keyShape={ADDITIONAL_PROPERTIES_KEY_SHAPE}
valueShape={ADDITIONAL_PROPERTIES_VALUE_SHAPE}
onChange={handleChange}
value={additionalProperties}
types={types}
/>
</WithLabel>
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ export const PlaygroundDiscriminatedUnionForm = memo<PlaygroundDiscriminatedUnio
(variant) => variant.discriminantValue === selectedVariantKey,
);

const properties = selectedVariant != null ? unwrapObjectType(selectedVariant, types).properties : [];
const properties = useMemo(
() => (selectedVariant != null ? unwrapObjectType(selectedVariant, types).properties : []),
[selectedVariant, types],
);

return (
<div className="w-full">
Expand Down
Loading

0 comments on commit 768faae

Please sign in to comment.