Skip to content

Commit

Permalink
scaffolding to ship out ruby snippets (#637)
Browse files Browse the repository at this point in the history
  • Loading branch information
armandobelardo authored Apr 11, 2024
1 parent 59878e8 commit 4f17747
Show file tree
Hide file tree
Showing 15 changed files with 458 additions and 28 deletions.
56 changes: 34 additions & 22 deletions fern/apis/fdr/definition/__package__.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ service:
docs: Get snippet by endpoint method and path
display-name: Get snippet for endpoint
availability: pre-release
audiences:
audiences:
- external
- fiddle
method: POST
Expand Down Expand Up @@ -86,7 +86,7 @@ service:
display-name: Load all snippets
method: POST
availability: pre-release
audiences:
audiences:
- external
- fiddle
request:
Expand Down Expand Up @@ -217,6 +217,7 @@ types:
typescript: TypeScriptSDK
python: PythonSDK
go: GoSDK
ruby: RubySDK
java: JavaSDK

TypeScriptSDK:
Expand All @@ -234,6 +235,11 @@ types:
githubRepo: string
version: string

RubySDK:
properties:
gem: string
version: string

JavaSDK:
properties:
group:
Expand All @@ -243,48 +249,54 @@ types:
type: string
docs: The artifact (e.g. `stripe-java`)
version: string

####### Load Snippets #######

SnippetsPage:
properties:
next:
type: optional<integer>
docs: If present, pass this into the `page` query parameter to load the next page.
snippets:
snippets:
type: map<EndpointPath, SnippetsByEndpointMethod>
docs: |
docs: |
The snippets are returned as a map of endpoint path (e.g. `/api/users`)
to a map of endpoint method (e.g. `POST`) to snippets.
SnippetsByEndpointMethod:
to a map of endpoint method (e.g. `POST`) to snippets.
SnippetsByEndpointMethod:
type: map<EndpointMethod, list<Snippet>>

Snippet:
union:
Snippet:
union:
typescript: TypeScriptSnippet
python: PythonSnippet
java: JavaSnippet
go: GoSnippet

TypeScriptSnippet:
properties:
ruby: RubySnippet

TypeScriptSnippet:
properties:
sdk: TypeScriptSDK
client: string
PythonSnippet:
properties:

PythonSnippet:
properties:
sdk: PythonSDK
async_client: string
sync_client: string
GoSnippet:
properties:

GoSnippet:
properties:
sdk: GoSDK
client: string

JavaSnippet:
properties:

RubySnippet:
properties:
sdk: RubySDK
client: string

JavaSnippet:
properties:
sdk: JavaSDK
async_client: string
sync_client: string
Expand Down
18 changes: 14 additions & 4 deletions fern/apis/fdr/definition/api/v1/read/endpoint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,18 @@ types:
type: StreamConditionResponse
docs: |
A response that can either be streaming or REST
FileDownloadResponseBodyShape:
properties:
contentType: optional<string>

StreamResponseV2:
properties:
terminator:
terminator:
type: optional<string>
docs: |
docs: |
The terminator for each message. For example, for OpenAPI
the terminator is [DATA].
the terminator is [DATA].
shape: JsonBodyShape

StreamConditionResponse:
Expand Down Expand Up @@ -197,6 +197,7 @@ types:
pythonSdk: optional<PythonSnippet>
typescriptSdk: optional<TypescriptSnippet>
goSdk: optional<GoSnippet>
rubySdk: optional<RubySnippet>

CustomCodeSample:
docs: Hand-written code samples
Expand Down Expand Up @@ -224,6 +225,7 @@ types:
- typescript
- ts # alias to typescript
- go
- ruby

ExampleEndpointRequest:
union:
Expand Down Expand Up @@ -270,3 +272,11 @@ types:
docs: |
The client code that is generated by the fern compiler
install: optional<string>

RubySnippet:
properties:
client:
type: string
docs: |
The client code that is generated by the fern compiler
install: optional<string>
5 changes: 5 additions & 0 deletions fern/apis/fdr/definition/api/v1/register/__package__.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ types:
pythonSdk: optional<PythonPackage>
goSdk: optional<GoModule>
javaSdk: optional<JavaCoordinate>
rubySdk: optional<RubyGem>

TypescriptPackage:
properties:
Expand All @@ -86,6 +87,10 @@ types:
properties:
coordinate: string

RubyGem:
properties:
gem: string

ApiDefinitionPackage:
properties:
endpoints: list<endpoint.EndpointDefinition>
Expand Down
15 changes: 15 additions & 0 deletions fern/apis/fdr/definition/snippets-factory.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ types:
python: PythonSDKSnippetCreate
go: GoSDKSnippetsCreate
java: JavaSDKSnippetsCreate
ruby: RubySDKSnippetsCreate

TypescriptSDKSnippetsCreate:
properties:
Expand All @@ -57,6 +58,11 @@ types:
sdk: snippets.GoSDK
snippets: list<SingleGoSnippetCreate>

RubySDKSnippetsCreate:
properties:
sdk: snippets.RubySDK
snippets: list<SingleRubySnippetCreate>

JavaSDKSnippetsCreate:
properties:
sdk: snippets.JavaSDK
Expand All @@ -79,6 +85,11 @@ types:
endpoint: snippets.EndpointIdentifier
snippet: GoSnippetCode

SingleRubySnippetCreate:
properties:
endpoint: snippets.EndpointIdentifier
snippet: RubySnippetCode

SingleJavaSnippetCreate:
properties:
endpoint: snippets.EndpointIdentifier
Expand All @@ -99,6 +110,10 @@ types:
properties:
client: string

RubySnippetCode:
properties:
client: string

JavaSnippetCode:
properties:
async_client: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,11 +517,16 @@ function transformCodeExamples({
endpointMethod: endpointDefinition.method,
endpointPath: getEndpointPathAsString(endpointDefinition),
});
const maybeRubySnippet = snippets.getRubyCodeSnippetForEndpoint({
endpointMethod: endpointDefinition.method,
endpointPath: getEndpointPathAsString(endpointDefinition),
});
return {
nodeAxios: "",
pythonSdk: maybePythonSnippet,
typescriptSdk: maybeTypescriptSnippet,
goSdk: maybeGoSnippet,
rubySdk: maybeRubySnippet,
};
}

Expand Down
26 changes: 26 additions & 0 deletions packages/fdr-sdk/src/converters/db/snippets/SDKSnippetHolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface SnippetsConfigWithSdkId {
pythonSdk?: APIV1Write.PythonPackage & { sdkId: string };
goSdk?: APIV1Write.GoModule & { sdkId: string };
javaSdk?: APIV1Write.JavaCoordinate & { sdkId: string };
rubySdk?: APIV1Write.RubyGem & { sdkId: string };
}

export interface SdkSnippetHolderArgs {
Expand Down Expand Up @@ -96,4 +97,29 @@ export class SDKSnippetHolder {
client: snippetsForEndpoint[0]?.client,
};
}

public getRubyCodeSnippetForEndpoint({
endpointPath,
endpointMethod,
}: {
endpointPath: string;
endpointMethod: FdrAPI.EndpointMethod;
}): APIV1Read.RubySnippet | undefined {
if (this.snippetsConfigWithSdkId.rubySdk == null) {
return undefined;
}
const sdkId = this.snippetsConfigWithSdkId.rubySdk.sdkId;
const snippetsForEndpoint = this.snippetsBySdkId[sdkId]?.[endpointPath]?.[endpointMethod];
// if no snippets for this endpoint or multiple snippets just return undefined
if (snippetsForEndpoint == null || snippetsForEndpoint.length > 1) {
return undefined;
}
if (snippetsForEndpoint[0]?.type !== "ruby") {
return undefined;
}
return {
install: undefined, // TODO: add install snippet
client: snippetsForEndpoint[0]?.client,
};
}
}
2 changes: 2 additions & 0 deletions servers/fdr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
"db:migrate:dev": "dotenv -e .env.dev -- prisma migrate deploy",
"db:migrate:local": "dotenv -e .env.local -- prisma migrate dev",
"db:migrate:prod": "dotenv -e .env.prod -- prisma migrate deploy",
"db:up:local": "docker-compose -f docker-compose.local.yml up -d",
"db:down:local": "docker-compose -f docker-compose.local.yml down -d",
"dev": "tsx src/server.ts --watch",
"devjs": "node --experimental-specifier-resolution=node dist/server.js",
"clean": "rm -rf ./dist && tsc --build --clean",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterEnum
ALTER TYPE "Language" ADD VALUE 'RUBY';
1 change: 1 addition & 0 deletions servers/fdr/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,5 @@ enum Language {
PYTHON
GO
JAVA
RUBY
}
Loading

0 comments on commit 4f17747

Please sign in to comment.