Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow grpc and http endpoints in a single service #5071

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions fern.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2656,6 +2656,26 @@
"type": "null"
}
]
},
"transport": {
"oneOf": [
{
"$ref": "#/definitions/service.ServiceTransport"
},
{
"type": "null"
}
]
},
"source": {
"oneOf": [
{
"$ref": "#/definitions/source.SourceSchema"
},
{
"type": "null"
}
]
}
},
"required": [
Expand Down
162 changes: 82 additions & 80 deletions fern/apis/fern-definition/definition/service.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
imports:
imports:
commons: commons.yml
types: types.yml
examples: examples.yml
pagination: pagination.yml
source: source.yml
variables: variables.yml

types:
HttpServiceSchema:
extends:
types:
HttpServiceSchema:
extends:
- commons.DeclarationWithoutDocsSchema
- commons.WithDisplayName
properties:
properties:
auth: boolean
url: optional<string>
base-path: string
path-parameters: optional<map<string, string>>
idempotent: optional<boolean>
headers: optional<map<string, types.TypeReferenceSchema>>
transport: optional<ServiceTransport>
transport: optional<ServiceTransport>
source: optional<source.SourceSchema>
endpoints: map<string, HttpEndpointSchema>

ServiceTransport:
properties:
grpc: optional<GrpcTransport>
GrpcTransport:
properties:
service-name:
ServiceTransport:
properties:
grpc: optional<GrpcTransport>

GrpcTransport:
properties:
service-name:
type: string
docs: "The name of the gRPC service."
HttpEndpointSchema:
extends:

HttpEndpointSchema:
extends:
- commons.WithDisplayName
- commons.DeclarationSchema
properties:
properties:
method: optional<HttpMethodSchema>
base-path: optional<string>
path: string
Expand All @@ -51,142 +51,144 @@ types:
errors: optional<ResponseErrorsSchema>
examples: optional<list<examples.ExampleEndpointCallSchema>>
pagination: optional<Pagination>

HttpMethodSchema:
enum:
transport: optional<ServiceTransport>
source: optional<source.SourceSchema>

HttpMethodSchema:
enum:
- GET
- POST
- PUT
- PATCH
- DELETE
HttpRequest:

HttpRequest:
discriminated: false
union:
union:
- string
- HttpRequestSchema

HttpRequestSchema:
extends:
extends:
- commons.WithName
- commons.WithDocsSchema
properties:
properties:
content-type: optional<string>
query-parameters: optional<map<string, HttpQueryParameterSchema>>
headers: optional<map<string, HttpHeaderSchema>>
body: optional<HttpRequestBodySchema>

TypeReferenceDeclarationWithEnvOverride:
discriminated: false
union:
union:
- string
- TypeReferenceDeclarationWithEnvOverrideSchema

TypeReferenceDeclarationWithEnvOverrideSchema:
TypeReferenceDeclarationWithEnvOverrideSchema:
extends: types.TypeReferenceDeclarationWithName
properties:
properties:
env: optional<string>

HttpHeaderSchema: TypeReferenceDeclarationWithEnvOverride
HttpRequestBodySchema:

HttpRequestBodySchema:
discriminated: false
union:
union:
- string
- HttpReferencedRequestBodySchema
- HttpInlineRequestBodySchema
HttpReferencedRequestBodySchema:
extends:

HttpReferencedRequestBodySchema:
extends:
- commons.WithDocsSchema
properties:
type: string

HttpInlineRequestBodySchema:
properties:
HttpInlineRequestBodySchema:
properties:
extends: optional<types.ObjectExtendsSchema>
extra-properties: optional<boolean>
properties: optional<map<string, HttpInlineRequestBodyPropertySchema>>
HttpInlineRequestBodyPropertySchema:

HttpInlineRequestBodyPropertySchema:
discriminated: false
union:
union:
- string
- TypeReferenceDeclarationWithContentTypeSchema
TypeReferenceDeclarationWithContentTypeSchema:

TypeReferenceDeclarationWithContentTypeSchema:
extends: types.TypeReferenceDeclarationWithName
properties:
properties:
content-type: optional<string>
HttpQueryParameterSchema:

HttpQueryParameterSchema:
discriminated: false
union:
union:
- string
- QueryParameterTypeReferenceDetailed
QueryParameterTypeReferenceDetailed:
extends:

QueryParameterTypeReferenceDetailed:
extends:
- types.TypeReferenceDeclarationWithName
properties:
properties:
allow-multiple: optional<boolean>
HttpResponseSchema:

HttpResponseSchema:
discriminated: false
union:
union:
- string
- HttpResponseSchemaDetailed
HttpResponseSchemaDetailed:
extends:

HttpResponseSchemaDetailed:
extends:
- commons.WithDocsSchema
properties:
properties:
type: string
property: optional<string>
status-code: optional<integer>

HttpResponseStreamSchema:
HttpResponseStreamSchema:
discriminated: false
union:
union:
- string
- HttpResponseStreamSchemaDetailed
HttpResponseStreamSchemaDetailed:
extends:

HttpResponseStreamSchemaDetailed:
extends:
- commons.WithDocsSchema
properties:
properties:
type: string
format: optional<StreamFormat>
terminator: optional<string>

StreamFormat:
enum:
StreamFormat:
enum:
- sse
- json
HttpPathParameterSchema:

HttpPathParameterSchema:
discriminated: false
union:
union:
- types.TypeReferenceSchema
- variables.VariableReferenceSchema
Pagination:

Pagination:
discriminated: false
union:
union:
- pagination.PaginationSchema
- boolean
ResponseErrorsSchema:

ResponseErrorsSchema:
type: list<ResponseError>

ResponseError:
ResponseError:
discriminated: false
union:
union:
- string
- ResponseErrorWithDocsSchema
ResponseErrorWithDocsSchema:
extends:

ResponseErrorWithDocsSchema:
extends:
- commons.WithDocsSchema
properties:
error: string
properties:
error: string
20 changes: 20 additions & 0 deletions package-yml.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2676,6 +2676,26 @@
"type": "null"
}
]
},
"transport": {
"oneOf": [
{
"$ref": "#/definitions/service.ServiceTransport"
},
{
"type": "null"
}
]
},
"source": {
"oneOf": [
{
"$ref": "#/definitions/source.SourceSchema"
},
{
"type": "null"
}
]
}
},
"required": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { convertToHttpMethod } from "./utils/convertToHttpMethod";
import { getDocsFromTypeReference, getTypeFromTypeReference } from "./utils/getTypeFromTypeReference";
import { getEndpointNamespace } from "./utils/getNamespaceFromGroup";
import { resolveLocationWithNamespace } from "./utils/convertSdkGroupName";
import { convertToSourceSchema } from "./utils/convertToSourceSchema";

export interface ConvertedEndpoint {
value: RawSchemas.HttpEndpointSchema;
Expand Down Expand Up @@ -94,7 +95,8 @@ export function buildEndpoint({
method: convertToHttpMethod(endpoint.method),
auth: endpoint.authed,
docs: endpoint.description ?? undefined,
pagination
pagination,
source: endpoint.source != null ? convertToSourceSchema(endpoint.source) : undefined
};

if (Object.keys(pathParameters).length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ export interface HttpEndpointSchema extends FernDefinition.WithDisplayName, Fern
errors?: FernDefinition.ResponseErrorsSchema;
examples?: FernDefinition.ExampleEndpointCallSchema[];
pagination?: FernDefinition.Pagination;
transport?: FernDefinition.ServiceTransport;
source?: FernDefinition.SourceSchema;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { HttpResponseStreamSchema } from "./HttpResponseStreamSchema";
import { ResponseErrorsSchema } from "./ResponseErrorsSchema";
import { ExampleEndpointCallSchema } from "../../examples/types/ExampleEndpointCallSchema";
import { Pagination } from "./Pagination";
import { ServiceTransport } from "./ServiceTransport";
import { SourceSchema } from "../../source/types/SourceSchema";
import { WithDisplayName } from "../../commons/types/WithDisplayName";
import { DeclarationSchema } from "../../commons/types/DeclarationSchema";
import { ResponseError } from "./ResponseError";
Expand All @@ -36,6 +38,8 @@ export const HttpEndpointSchema: core.serialization.ObjectSchema<
errors: ResponseErrorsSchema.optional(),
examples: core.serialization.list(ExampleEndpointCallSchema).optional(),
pagination: Pagination.optional(),
transport: ServiceTransport.optional(),
source: SourceSchema.optional(),
})
.extend(WithDisplayName)
.extend(DeclarationSchema);
Expand All @@ -56,5 +60,7 @@ export declare namespace HttpEndpointSchema {
errors?: ResponseErrorsSchema.Raw | null;
examples?: ExampleEndpointCallSchema.Raw[] | null;
pagination?: Pagination.Raw | null;
transport?: ServiceTransport.Raw | null;
source?: SourceSchema.Raw | null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,8 @@ async function visitEndpoint({
});
}
},
pagination: noop
pagination: noop,
source: noop
});
}

Expand Down
Loading
Loading