Skip to content

Commit

Permalink
feat(cli): Add support for in-lined path parameters (#5231)
Browse files Browse the repository at this point in the history
  • Loading branch information
amckinney authored Nov 21, 2024
1 parent 8f00632 commit e49cbf3
Show file tree
Hide file tree
Showing 861 changed files with 36,905 additions and 122 deletions.
Binary file removed .package.json.swp
Binary file not shown.
13 changes: 13 additions & 0 deletions fern.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1874,6 +1874,19 @@
}
]
},
"path-parameters": {
"oneOf": [
{
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/service.HttpPathParameterSchema"
}
},
{
"type": "null"
}
]
},
"query-parameters": {
"oneOf": [
{
Expand Down
3 changes: 2 additions & 1 deletion fern/apis/fern-definition/definition/service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ types:
- commons.WithDocsSchema
properties:
content-type: optional<string>
path-parameters: optional<map<string, HttpPathParameterSchema>>
query-parameters: optional<map<string, HttpQueryParameterSchema>>
headers: optional<map<string, HttpHeaderSchema>>
body: optional<HttpRequestBodySchema>
Expand Down Expand Up @@ -191,4 +192,4 @@ types:
extends:
- commons.WithDocsSchema
properties:
error: string
error: string
6 changes: 6 additions & 0 deletions fern/apis/generators-yml/definition/generators.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ types:
only-include-referenced-schemas:
type: optional<boolean>
docs: Whether to only include schemas referenced by endpoints in the generated SDK (i.e. a form of tree-shaking). Defaults to false.
inline-path-parameters:
type: optional<boolean>
docs: Whether to include path parameters within the generated in-lined request. Defaults to false.

UnionSettingsSchema:
enum:
Expand Down Expand Up @@ -228,6 +231,9 @@ types:
only-include-referenced-schemas:
type: optional<boolean>
docs: Whether to only include schemas referenced by endpoints in the generated SDK (i.e. a form of tree-shaking). Defaults to false.
inline-path-parameters:
type: optional<boolean>
docs: Whether to include path parameters within the generated in-lined request. Defaults to false.

OpenAPISpecSchema:
properties:
Expand Down
20 changes: 20 additions & 0 deletions generators-yml.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,16 @@
"type": "null"
}
]
},
"inline-path-parameters": {
"oneOf": [
{
"type": "boolean"
},
{
"type": "null"
}
]
}
},
"additionalProperties": false
Expand Down Expand Up @@ -1324,6 +1334,16 @@
"type": "null"
}
]
},
"inline-path-parameters": {
"oneOf": [
{
"type": "boolean"
},
{
"type": "null"
}
]
}
},
"additionalProperties": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4773,6 +4773,63 @@ func do() {
"
`;
exports[`test definitions > path-parameters 1`] = `
"package example
import (
context "context"
client "github.com/acme/acme-go/client"
)
func do() {
client := client.NewClient()
client.User.GetOrganization(
context.TODO(),
"organizationId",
)
}
------------------------
package example
import (
context "context"
acme "github.com/acme/acme-go"
client "github.com/acme/acme-go/client"
)
func do() {
client := client.NewClient()
client.User.GetUser(
context.TODO(),
"userId",
&acme.GetUsersRequest{},
)
}
------------------------
package example
import (
context "context"
acme "github.com/acme/acme-go"
client "github.com/acme/acme-go/client"
)
func do() {
client := client.NewClient()
client.User.GetOrganizationUser(
context.TODO(),
"organizationId",
"userId",
&acme.GetOrganizationUserRequest{},
)
}
"
`;
exports[`test definitions > plain-text 1`] = `"<none>"`;
exports[`test definitions > query-parameters 1`] = `"<none>"`;
Expand Down
13 changes: 13 additions & 0 deletions package-yml.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1894,6 +1894,19 @@
}
]
},
"path-parameters": {
"oneOf": [
{
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/service.HttpPathParameterSchema"
}
},
{
"type": "null"
}
]
},
"query-parameters": {
"oneOf": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { getExamplesFromExtension } from "../../extensions/getExamplesFromExtens
import { getFernAvailability } from "../../extensions/getFernAvailability";
import { OperationContext } from "../contexts";
import { convertServer } from "../convertServer";
import { convertParameters } from "../endpoint/convertParameters";
import { ConvertedParameters, convertParameters } from "../endpoint/convertParameters";
import { convertRequest } from "../endpoint/convertRequest";
import { convertResponse } from "../endpoint/convertResponse";

Expand Down Expand Up @@ -65,7 +65,7 @@ export function convertHttpOperation({

// if request has query params or headers and body is not an object, then use `Body`
if (
(convertedParameters.queryParameters.length > 0 || convertedParameters.headers.length > 0) &&
endpointHasNonRequestBodyParameters({ context, convertedParameters }) &&
convertedRequest != null &&
convertedRequest.type === "json" &&
convertedRequest.schema.type !== "object" &&
Expand Down Expand Up @@ -149,3 +149,17 @@ function isEndpointAuthed(operation: OpenAPIV3.OperationObject, document: OpenAP
}
return false;
}

function endpointHasNonRequestBodyParameters({
context,
convertedParameters
}: {
context: AbstractOpenAPIV3ParserContext;
convertedParameters: ConvertedParameters;
}): boolean {
return (
(context.options.inlinePathParameters && convertedParameters.pathParameters.length > 0) ||
convertedParameters.queryParameters.length > 0 ||
convertedParameters.headers.length > 0
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export interface ParseOpenAPIOptions {
respectReadonlySchemas: boolean;
/* Whether or not to only include endpoint referenced schemas */
onlyIncludeReferencedSchemas: boolean;
/* Whether or not to include path parameters in the in-lined request */
inlinePathParameters: boolean;
}

export const DEFAULT_PARSE_OPENAPI_SETTINGS: ParseOpenAPIOptions = {
Expand All @@ -27,5 +29,6 @@ export const DEFAULT_PARSE_OPENAPI_SETTINGS: ParseOpenAPIOptions = {
optionalAdditionalProperties: true,
cooerceEnumsToLiterals: true,
respectReadonlySchemas: false,
onlyIncludeReferencedSchemas: false
onlyIncludeReferencedSchemas: false,
inlinePathParameters: false
};
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface SpecImportSettings {
objectQueryParameters: boolean;
respectReadonlySchemas: boolean;
onlyIncludeReferencedSchemas: boolean;
inlinePathParameters: boolean;
}

export type Source = AsyncAPISource | OpenAPISource | ProtobufSource;
Expand Down Expand Up @@ -201,7 +202,11 @@ function getParseOptions({
onlyIncludeReferencedSchemas:
overrides?.onlyIncludeReferencedSchemas ??
specSettings?.onlyIncludeReferencedSchemas ??
DEFAULT_PARSE_OPENAPI_SETTINGS.onlyIncludeReferencedSchemas
DEFAULT_PARSE_OPENAPI_SETTINGS.onlyIncludeReferencedSchemas,
inlinePathParameters:
overrides?.inlinePathParameters ??
specSettings?.inlinePathParameters ??
DEFAULT_PARSE_OPENAPI_SETTINGS.inlinePathParameters
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"content-type": "application/json",
"headers": undefined,
"name": "Request",
"path-parameters": undefined,
"query-parameters": undefined,
},
"response": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14850,6 +14850,7 @@ The authenticated user must have the `account.allows.manageJointOwners` permissi
"content-type": "application/json",
"headers": undefined,
"name": "NewJointOwnerInvitation",
"path-parameters": undefined,
"query-parameters": undefined,
},
"response": {
Expand Down Expand Up @@ -15121,6 +15122,7 @@ The user must have the `allows.manageOverdraftAccounts` permission on the accoun
"content-type": "application/json",
"headers": undefined,
"name": "OverdraftProtectionPatch",
"path-parameters": undefined,
"query-parameters": undefined,
},
"response": {
Expand Down Expand Up @@ -15987,6 +15989,7 @@ Note: This operation requires an identity challenge if the financial institution
},
},
"name": "NewTransfer",
"path-parameters": undefined,
"query-parameters": undefined,
},
"response": {
Expand Down Expand Up @@ -16330,6 +16333,7 @@ Note: This operation requires an identity challenge if the financial institution
},
},
"name": "TransferPatch",
"path-parameters": undefined,
"query-parameters": undefined,
},
"response": {
Expand Down
Loading

0 comments on commit e49cbf3

Please sign in to comment.