fern-api 0.30.5 → 0.30.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bundle.cjs +359 -136
  2. package/package.json +1 -1
package/bundle.cjs CHANGED
@@ -352084,6 +352084,12 @@ var init_WebhookHttpMethod = __esm({
352084
352084
  }
352085
352085
  });
352086
352086
 
352087
+ // pnp:/home/circleci/project/packages/ir-sdk/lib/sdk/api/resources/webhooks/types/ExampleWebhookCall.js
352088
+ var init_ExampleWebhookCall = __esm({
352089
+ "pnp:/home/circleci/project/packages/ir-sdk/lib/sdk/api/resources/webhooks/types/ExampleWebhookCall.js"() {
352090
+ }
352091
+ });
352092
+
352087
352093
  // pnp:/home/circleci/project/packages/ir-sdk/lib/sdk/api/resources/webhooks/types/index.js
352088
352094
  var init_types12 = __esm({
352089
352095
  "pnp:/home/circleci/project/packages/ir-sdk/lib/sdk/api/resources/webhooks/types/index.js"() {
@@ -352095,6 +352101,7 @@ var init_types12 = __esm({
352095
352101
  init_InlinedWebhookPayload();
352096
352102
  init_InlinedWebhookPayloadProperty();
352097
352103
  init_WebhookHttpMethod();
352104
+ init_ExampleWebhookCall();
352098
352105
  }
352099
352106
  });
352100
352107
 
@@ -357013,7 +357020,8 @@ var init_Webhook2 = __esm({
357013
357020
  displayName: schemas_exports4.string().optional(),
357014
357021
  method: schemas_exports4.lazy(async () => (await Promise.resolve().then(() => (init_serialization2(), serialization_exports2))).WebhookHttpMethod),
357015
357022
  headers: schemas_exports4.list(schemas_exports4.lazyObject(async () => (await Promise.resolve().then(() => (init_serialization2(), serialization_exports2))).HttpHeader)),
357016
- payload: schemas_exports4.lazy(async () => (await Promise.resolve().then(() => (init_serialization2(), serialization_exports2))).WebhookPayload)
357023
+ payload: schemas_exports4.lazy(async () => (await Promise.resolve().then(() => (init_serialization2(), serialization_exports2))).WebhookPayload),
357024
+ examples: schemas_exports4.list(schemas_exports4.lazyObject(async () => (await Promise.resolve().then(() => (init_serialization2(), serialization_exports2))).ExampleWebhookCall)).optional()
357017
357025
  }).extend(schemas_exports4.lazyObject(async () => (await Promise.resolve().then(() => (init_serialization2(), serialization_exports2))).Declaration));
357018
357026
  }
357019
357027
  });
@@ -357097,6 +357105,18 @@ var init_WebhookHttpMethod2 = __esm({
357097
357105
  }
357098
357106
  });
357099
357107
 
357108
+ // pnp:/home/circleci/project/packages/ir-sdk/lib/sdk/serialization/resources/webhooks/types/ExampleWebhookCall.js
357109
+ var ExampleWebhookCall;
357110
+ var init_ExampleWebhookCall2 = __esm({
357111
+ "pnp:/home/circleci/project/packages/ir-sdk/lib/sdk/serialization/resources/webhooks/types/ExampleWebhookCall.js"() {
357112
+ init_core2();
357113
+ ExampleWebhookCall = schemas_exports4.objectWithoutOptionalProperties({
357114
+ name: schemas_exports4.lazyObject(async () => (await Promise.resolve().then(() => (init_serialization2(), serialization_exports2))).Name).optional(),
357115
+ payload: schemas_exports4.lazyObject(async () => (await Promise.resolve().then(() => (init_serialization2(), serialization_exports2))).ExampleTypeReference)
357116
+ }).extend(schemas_exports4.lazyObject(async () => (await Promise.resolve().then(() => (init_serialization2(), serialization_exports2))).WithDocs));
357117
+ }
357118
+ });
357119
+
357100
357120
  // pnp:/home/circleci/project/packages/ir-sdk/lib/sdk/serialization/resources/webhooks/types/index.js
357101
357121
  var init_types24 = __esm({
357102
357122
  "pnp:/home/circleci/project/packages/ir-sdk/lib/sdk/serialization/resources/webhooks/types/index.js"() {
@@ -357108,12 +357128,14 @@ var init_types24 = __esm({
357108
357128
  init_InlinedWebhookPayload2();
357109
357129
  init_InlinedWebhookPayloadProperty2();
357110
357130
  init_WebhookHttpMethod2();
357131
+ init_ExampleWebhookCall2();
357111
357132
  }
357112
357133
  });
357113
357134
 
357114
357135
  // pnp:/home/circleci/project/packages/ir-sdk/lib/sdk/serialization/resources/webhooks/index.js
357115
357136
  var webhooks_exports2 = {};
357116
357137
  __export(webhooks_exports2, {
357138
+ ExampleWebhookCall: () => ExampleWebhookCall,
357117
357139
  InlinedWebhookPayload: () => InlinedWebhookPayload,
357118
357140
  InlinedWebhookPayloadProperty: () => InlinedWebhookPayloadProperty,
357119
357141
  Webhook: () => Webhook,
@@ -357445,6 +357467,7 @@ __export(serialization_exports2, {
357445
357467
  ExampleWebSocketMessage: () => ExampleWebSocketMessage2,
357446
357468
  ExampleWebSocketMessageBody: () => ExampleWebSocketMessageBody2,
357447
357469
  ExampleWebSocketSession: () => ExampleWebSocketSession2,
357470
+ ExampleWebhookCall: () => ExampleWebhookCall,
357448
357471
  FeatureId: () => FeatureId,
357449
357472
  FernFilepath: () => FernFilepath,
357450
357473
  FileDownloadResponse: () => FileDownloadResponse,
@@ -363877,6 +363900,12 @@ var init_Webhook3 = __esm({
363877
363900
  }
363878
363901
  });
363879
363902
 
363903
+ // pnp:/home/circleci/project/packages/cli/openapi-ir-sdk/lib/sdk/api/resources/finalIr/types/WebhookExampleCall.js
363904
+ var init_WebhookExampleCall = __esm({
363905
+ "pnp:/home/circleci/project/packages/cli/openapi-ir-sdk/lib/sdk/api/resources/finalIr/types/WebhookExampleCall.js"() {
363906
+ }
363907
+ });
363908
+
363880
363909
  // pnp:/home/circleci/project/packages/cli/openapi-ir-sdk/lib/sdk/api/resources/finalIr/types/WebsocketChannel.js
363881
363910
  var init_WebsocketChannel = __esm({
363882
363911
  "pnp:/home/circleci/project/packages/cli/openapi-ir-sdk/lib/sdk/api/resources/finalIr/types/WebsocketChannel.js"() {
@@ -364903,6 +364932,7 @@ var init_types28 = __esm({
364903
364932
  init_Tags();
364904
364933
  init_HttpError();
364905
364934
  init_Webhook3();
364935
+ init_WebhookExampleCall();
364906
364936
  init_WebsocketChannel();
364907
364937
  init_WebsocketHandshake();
364908
364938
  init_WebsocketSessionExample();
@@ -367732,7 +367762,20 @@ var init_Webhook4 = __esm({
367732
367762
  tags: schemas_exports5.list(schemas_exports5.lazy(async () => (await Promise.resolve().then(() => (init_serialization3(), serialization_exports3))).TagId)),
367733
367763
  headers: schemas_exports5.list(schemas_exports5.lazyObject(async () => (await Promise.resolve().then(() => (init_serialization3(), serialization_exports3))).Header)),
367734
367764
  generatedPayloadName: schemas_exports5.string(),
367735
- payload: schemas_exports5.lazy(async () => (await Promise.resolve().then(() => (init_serialization3(), serialization_exports3))).Schema)
367765
+ payload: schemas_exports5.lazy(async () => (await Promise.resolve().then(() => (init_serialization3(), serialization_exports3))).Schema),
367766
+ examples: schemas_exports5.list(schemas_exports5.lazyObject(async () => (await Promise.resolve().then(() => (init_serialization3(), serialization_exports3))).WebhookExampleCall))
367767
+ }).extend(schemas_exports5.lazyObject(async () => (await Promise.resolve().then(() => (init_serialization3(), serialization_exports3))).WithDescription));
367768
+ }
367769
+ });
367770
+
367771
+ // pnp:/home/circleci/project/packages/cli/openapi-ir-sdk/lib/sdk/serialization/resources/finalIr/types/WebhookExampleCall.js
367772
+ var WebhookExampleCall;
367773
+ var init_WebhookExampleCall2 = __esm({
367774
+ "pnp:/home/circleci/project/packages/cli/openapi-ir-sdk/lib/sdk/serialization/resources/finalIr/types/WebhookExampleCall.js"() {
367775
+ init_core3();
367776
+ WebhookExampleCall = schemas_exports5.objectWithoutOptionalProperties({
367777
+ name: schemas_exports5.string().optional(),
367778
+ payload: schemas_exports5.lazy(async () => (await Promise.resolve().then(() => (init_serialization3(), serialization_exports3))).FullExample)
367736
367779
  }).extend(schemas_exports5.lazyObject(async () => (await Promise.resolve().then(() => (init_serialization3(), serialization_exports3))).WithDescription));
367737
367780
  }
367738
367781
  });
@@ -368731,6 +368774,7 @@ var init_types32 = __esm({
368731
368774
  init_Tags2();
368732
368775
  init_HttpError2();
368733
368776
  init_Webhook4();
368777
+ init_WebhookExampleCall2();
368734
368778
  init_WebsocketChannel2();
368735
368779
  init_WebsocketHandshake2();
368736
368780
  init_WebsocketSessionExample2();
@@ -368861,6 +368905,7 @@ __export(finalIr_exports2, {
368861
368905
  TextResponse: () => TextResponse2,
368862
368906
  UnDiscriminatedOneOfSchema: () => UnDiscriminatedOneOfSchema,
368863
368907
  Webhook: () => Webhook2,
368908
+ WebhookExampleCall: () => WebhookExampleCall,
368864
368909
  WebhookHttpMethod: () => WebhookHttpMethod5,
368865
368910
  WebsocketChannel: () => WebsocketChannel,
368866
368911
  WebsocketHandshake: () => WebsocketHandshake,
@@ -369683,6 +369728,7 @@ __export(serialization_exports3, {
369683
369728
  UnDiscriminatedOneOfSchemaWithExample: () => UnDiscriminatedOneOfSchemaWithExample,
369684
369729
  UnknownSchemaWithExample: () => UnknownSchemaWithExample,
369685
369730
  Webhook: () => Webhook2,
369731
+ WebhookExampleCall: () => WebhookExampleCall,
369686
369732
  WebhookHttpMethod: () => WebhookHttpMethod5,
369687
369733
  WebsocketChannel: () => WebsocketChannel,
369688
369734
  WebsocketHandshake: () => WebsocketHandshake,
@@ -1030215,7 +1030261,7 @@ var AccessTokenPosthogManager = class {
1030215
1030261
  properties: {
1030216
1030262
  ...event,
1030217
1030263
  ...event.properties,
1030218
- version: "0.30.5",
1030264
+ version: "0.30.7",
1030219
1030265
  usingAccessToken: true
1030220
1030266
  }
1030221
1030267
  });
@@ -1030277,7 +1030323,7 @@ var UserPosthogManager = class {
1030277
1030323
  distinctId: this.userId ?? await this.getPersistedDistinctId(),
1030278
1030324
  event: "CLI",
1030279
1030325
  properties: {
1030280
- version: "0.30.5",
1030326
+ version: "0.30.7",
1030281
1030327
  ...event,
1030282
1030328
  ...event.properties
1030283
1030329
  }
@@ -1040928,6 +1040974,7 @@ async function visitWebhooks({ webhook, visitor, nodePathForWebhook }) {
1040928
1040974
  await visitObject(webhook, {
1040929
1040975
  "display-name": noop,
1040930
1040976
  method: noop,
1040977
+ examples: noop,
1040931
1040978
  headers: async (headers) => {
1040932
1040979
  await visitHeaders2({
1040933
1040980
  headers,
@@ -1041420,6 +1041467,7 @@ __export(schemas_exports3, {
1041420
1041467
  ExampleTypeSchema: () => ExampleTypeSchema,
1041421
1041468
  ExampleTypeValueSchema: () => ExampleTypeValueSchema,
1041422
1041469
  ExampleWebSocketSession: () => ExampleWebSocketSession,
1041470
+ ExampleWebhookCallSchema: () => ExampleWebhookCallSchema,
1041423
1041471
  HeaderAuthSchemeSchema: () => HeaderAuthSchemeSchema,
1041424
1041472
  HttpEndpointSchema: () => HttpEndpointSchema,
1041425
1041473
  HttpHeaderSchema: () => HttpHeaderSchema,
@@ -1041839,6 +1041887,13 @@ var ExampleEndpointCallSchema = WithNameAndDocsSchema.extend({
1041839
1041887
  });
1041840
1041888
  var ExampleEndpointCallArraySchema = z.array(ExampleEndpointCallSchema);
1041841
1041889
 
1041890
+ // pnp:/home/circleci/project/packages/cli/yaml/yaml-schema/lib/schemas/ExampleWebhookCallSchema.js
1041891
+ var ExampleWebhookCallSchema = WithNameAndDocsSchema.extend({
1041892
+ id: z.optional(z.string()),
1041893
+ payload: z.optional(ExampleTypeReferenceSchema)
1041894
+ });
1041895
+ var ExampleWebhookCallArraySchema = z.array(ExampleWebhookCallSchema);
1041896
+
1041842
1041897
  // pnp:/home/circleci/project/packages/cli/yaml/yaml-schema/lib/schemas/ExampleWebSocketMessage.js
1041843
1041898
  var ExampleWebSocketMessage = z.object({
1041844
1041899
  type: z.string(),
@@ -1042030,7 +1042085,8 @@ var WebhookSchema = DeclarationSchema.extend({
1042030
1042085
  method: z.enum(["GET", "POST"]),
1042031
1042086
  "display-name": z.optional(z.string()),
1042032
1042087
  headers: z.optional(z.record(HttpHeaderSchema)),
1042033
- payload: WebhookPayloadSchema
1042088
+ payload: WebhookPayloadSchema,
1042089
+ examples: z.optional(z.array(ExampleWebhookCallSchema))
1042034
1042090
  });
1042035
1042091
 
1042036
1042092
  // pnp:/home/circleci/project/packages/cli/yaml/yaml-schema/lib/schemas/WebSocketChannelInlinedMessageSchema.js
@@ -1045937,6 +1045993,12 @@ function convertToFullExample(value) {
1045937
1045993
  return FullExample.primitive(PrimitiveExample.double(value));
1045938
1045994
  } else if (typeof value === "boolean") {
1045939
1045995
  return FullExample.primitive(PrimitiveExample.boolean(value));
1045996
+ } else if (Array.isArray(value)) {
1045997
+ const examples = value.map((example) => convertToFullExample(example));
1045998
+ if (examples.length === 0) {
1045999
+ return void 0;
1046000
+ }
1046001
+ return FullExample.array(examples.filter((example) => example != null));
1045940
1046002
  } else if (value != null && typeof value === "object" && Object.keys(value).every((key2) => typeof key2 === "string")) {
1045941
1046003
  const kvs = [];
1045942
1046004
  for (const [property5, propertyValue] of Object.entries(value)) {
@@ -1047846,7 +1047908,7 @@ function getReferenceOccurrencesHelper({ obj, occurrences, breadcrumbs }) {
1047846
1047908
  function removeApplicationJsonAndMultipartConflictsFromDocument(document6) {
1047847
1047909
  return {
1047848
1047910
  ...document6,
1047849
- paths: Object.fromEntries(Object.entries(document6.paths).map(([path42, pathItem]) => {
1047911
+ paths: Object.fromEntries(Object.entries(document6.paths ?? {}).map(([path42, pathItem]) => {
1047850
1047912
  return [
1047851
1047913
  path42,
1047852
1047914
  {
@@ -1048974,12 +1049036,31 @@ function convertWebhookOperation({ context, operationContext }) {
1048974
1049036
  headers: convertedParameters.headers,
1048975
1049037
  generatedPayloadName: getGeneratedTypeName(payloadBreadcrumbs),
1048976
1049038
  payload: convertedPayload.schema,
1048977
- description: operation.description
1049039
+ description: operation.description,
1049040
+ examples: convertWebhookExamples(convertedPayload.fullExamples)
1048978
1049041
  };
1048979
1049042
  }
1049043
+ function convertWebhookExamples(payloadExamples) {
1049044
+ if (payloadExamples == null) {
1049045
+ return [];
1049046
+ }
1049047
+ const webhookExampleCalls = [];
1049048
+ for (const payloadExample of payloadExamples) {
1049049
+ const fullExample = convertToFullExample(payloadExample.value);
1049050
+ if (fullExample == null) {
1049051
+ continue;
1049052
+ }
1049053
+ webhookExampleCalls.push({
1049054
+ description: payloadExample.description,
1049055
+ name: payloadExample.name,
1049056
+ payload: fullExample
1049057
+ });
1049058
+ }
1049059
+ return webhookExampleCalls;
1049060
+ }
1048980
1049061
 
1048981
1049062
  // pnp:/home/circleci/project/packages/cli/openapi-parser/lib/openapi/v3/converters/operation/convertOperation.js
1048982
- function convertOperation({ context, pathItemContext, operation }) {
1049063
+ function convertOperation({ context, pathItemContext, operation, convertToWebhook }) {
1048983
1049064
  const shouldIgnore = getExtension(operation, FernOpenAPIExtension.IGNORE);
1048984
1049065
  if (shouldIgnore != null && shouldIgnore) {
1048985
1049066
  context.logger.info(`${pathItemContext.method.toUpperCase()} ${pathItemContext.path} is marked with x-fern-ignore. Skipping.`);
@@ -1049000,7 +1049081,7 @@ function convertOperation({ context, pathItemContext, operation }) {
1049000
1049081
  operationParameters: operation.parameters ?? [],
1049001
1049082
  pagination
1049002
1049083
  };
1049003
- if (isWebhook({ operation })) {
1049084
+ if (convertToWebhook) {
1049004
1049085
  const webhook = convertWebhookOperation({
1049005
1049086
  context,
1049006
1049087
  operationContext
@@ -1049040,9 +1049121,6 @@ function convertOperation({ context, pathItemContext, operation }) {
1049040
1049121
  });
1049041
1049122
  return { type: "http", value: convertedHttpOperation };
1049042
1049123
  }
1049043
- function isWebhook({ operation }) {
1049044
- return getExtension(operation, [FernOpenAPIExtension.WEBHOOK]) ?? false;
1049045
- }
1049046
1049124
  function getSdkGroupAndMethod(operation) {
1049047
1049125
  const sdkMethodName = getExtension(operation, FernOpenAPIExtension.SDK_METHOD_NAME);
1049048
1049126
  const sdkGroupName = getExtension(operation, FernOpenAPIExtension.SDK_GROUP_NAME) ?? [];
@@ -1049083,13 +1049161,40 @@ function convertPathItem(path42, pathItemObject, document6, context) {
1049083
1049161
  pathItemParameters: pathItemObject.parameters ?? []
1049084
1049162
  };
1049085
1049163
  for (const operation of operations) {
1049164
+ const convertToWebhook = isWebhook({ operation: operation.operation });
1049086
1049165
  const convertedOperation = convertOperation({
1049087
1049166
  context,
1049088
1049167
  pathItemContext: {
1049089
1049168
  ...basePathItemContext,
1049090
1049169
  method: operation.method
1049091
1049170
  },
1049092
- operation: operation.operation
1049171
+ operation: operation.operation,
1049172
+ convertToWebhook
1049173
+ });
1049174
+ if (convertedOperation != null) {
1049175
+ result2.push(convertedOperation);
1049176
+ }
1049177
+ }
1049178
+ return result2;
1049179
+ }
1049180
+ function convertPathItemToWebhooks(path42, pathItemObject, document6, context) {
1049181
+ const result2 = [];
1049182
+ const operations = getOperationObjectsFromPathItem(pathItemObject);
1049183
+ const basePathItemContext = {
1049184
+ document: document6,
1049185
+ pathItem: pathItemObject,
1049186
+ path: path42,
1049187
+ pathItemParameters: pathItemObject.parameters ?? []
1049188
+ };
1049189
+ for (const operation of operations) {
1049190
+ const convertedOperation = convertOperation({
1049191
+ context,
1049192
+ pathItemContext: {
1049193
+ ...basePathItemContext,
1049194
+ method: operation.method
1049195
+ },
1049196
+ operation: operation.operation,
1049197
+ convertToWebhook: true
1049093
1049198
  });
1049094
1049199
  if (convertedOperation != null) {
1049095
1049200
  result2.push(convertedOperation);
@@ -1049131,6 +1049236,9 @@ function getOperationObjectsFromPathItem(pathItemObject) {
1049131
1049236
  }
1049132
1049237
  return operations;
1049133
1049238
  }
1049239
+ function isWebhook({ operation }) {
1049240
+ return getExtension(operation, [FernOpenAPIExtension.WEBHOOK]) ?? false;
1049241
+ }
1049134
1049242
 
1049135
1049243
  // pnp:/home/circleci/project/packages/cli/openapi-parser/lib/openapi/v3/extensions/getBasicSecuritySchemeNames.js
1049136
1049244
  function getBasicSecuritySchemeNames(securityScheme) {
@@ -1049304,6 +1049412,12 @@ function getVariableDefinitions(document6) {
1049304
1049412
  }));
1049305
1049413
  }
1049306
1049414
 
1049415
+ // pnp:/home/circleci/project/packages/cli/openapi-parser/lib/openapi/v3/getWebhookPathsObject.js
1049416
+ var WEBHOOKS = "webhooks";
1049417
+ function getWebhooksPathsObject(document6) {
1049418
+ return getExtension(document6, WEBHOOKS) ?? {};
1049419
+ }
1049420
+
1049307
1049421
  // pnp:/home/circleci/project/packages/cli/openapi-parser/lib/openapi/v3/OpenAPIV3ParserContext.js
1049308
1049422
  var OpenAPIV3ParserContext = class extends AbstractOpenAPIV3ParserContext {
1049309
1049423
  nonRequestReferencedSchemas = /* @__PURE__ */ new Set();
@@ -1049488,7 +1049602,7 @@ function generateIr({ openApi, taskContext, disableExamples, audiences, shouldUs
1049488
1049602
  const idempotencyHeaders = getIdempotencyHeaders(openApi);
1049489
1049603
  const endpointsWithExample = [];
1049490
1049604
  const webhooks = [];
1049491
- Object.entries(openApi.paths).forEach(([path42, pathItem]) => {
1049605
+ Object.entries(openApi.paths ?? {}).forEach(([path42, pathItem]) => {
1049492
1049606
  if (pathItem == null) {
1049493
1049607
  return;
1049494
1049608
  }
@@ -1049521,6 +1049635,20 @@ function generateIr({ openApi, taskContext, disableExamples, audiences, shouldUs
1049521
1049635
  }
1049522
1049636
  }
1049523
1049637
  });
1049638
+ Object.entries(getWebhooksPathsObject(openApi)).forEach(([path42, pathItem]) => {
1049639
+ if (pathItem == null) {
1049640
+ return;
1049641
+ }
1049642
+ taskContext.logger.debug(`Converting path ${path42}`);
1049643
+ const convertedWebhooks = convertPathItemToWebhooks(path42, pathItem, openApi, context);
1049644
+ for (const webhook of convertedWebhooks) {
1049645
+ const webhookAudiences = getAudiences({ operation: webhook });
1049646
+ if (audiences.length > 0 && !audiences.some((audience) => webhookAudiences.includes(audience))) {
1049647
+ continue;
1049648
+ }
1049649
+ webhooks.push(webhook.value);
1049650
+ }
1049651
+ });
1049524
1049652
  const schemasWithExample = Object.fromEntries(Object.entries(((_b4 = openApi.components) == null ? void 0 : _b4.schemas) ?? {}).map(([key2, schema2]) => {
1049525
1049653
  if (!isReferenceObject(schema2)) {
1049526
1049654
  const ignoreSchema = getExtension(schema2, FernOpenAPIExtension.IGNORE);
@@ -1050621,88 +1050749,7 @@ function buildIdempotencyHeaders(context) {
1050621
1050749
  }
1050622
1050750
  }
1050623
1050751
 
1050624
- // pnp:/home/circleci/project/packages/cli/openapi-ir-to-fern/lib/buildEndpointExample.js
1050625
- function buildEndpointExample({ endpointExample, context }) {
1050626
- const example = {};
1050627
- if (endpointExample.type !== "full") {
1050628
- return endpointExample.value;
1050629
- }
1050630
- if (endpointExample.name != null) {
1050631
- example.name = endpointExample.name;
1050632
- }
1050633
- if (endpointExample.description != null) {
1050634
- example.docs = endpointExample.description;
1050635
- }
1050636
- if (endpointExample.pathParameters != null && endpointExample.pathParameters.length > 0) {
1050637
- example["path-parameters"] = convertNamedFullExamples(endpointExample.pathParameters);
1050638
- }
1050639
- if (endpointExample.queryParameters != null && endpointExample.queryParameters.length > 0) {
1050640
- example["query-parameters"] = convertQueryParameterExample2(endpointExample.queryParameters);
1050641
- }
1050642
- if (endpointExample.headers != null && endpointExample.headers.length > 0) {
1050643
- example.headers = convertHeaderExamples2({ context, namedFullExamples: endpointExample.headers });
1050644
- }
1050645
- if (endpointExample.request != null) {
1050646
- example.request = convertFullExample2(endpointExample.request);
1050647
- }
1050648
- if (endpointExample.response != null) {
1050649
- example.response = { body: convertFullExample2(endpointExample.response) };
1050650
- }
1050651
- if (endpointExample.response != null) {
1050652
- example.response = { body: convertFullExample2(endpointExample.response) };
1050653
- }
1050654
- if (endpointExample.codeSamples != null && endpointExample.codeSamples.length > 0) {
1050655
- example["code-samples"] = endpointExample.codeSamples.map((codeSample) => {
1050656
- if (codeSample.type === "language") {
1050657
- return {
1050658
- name: codeSample.name ?? void 0,
1050659
- docs: codeSample.description ?? void 0,
1050660
- language: codeSample.language,
1050661
- code: codeSample.code,
1050662
- install: codeSample.install ?? void 0
1050663
- };
1050664
- } else {
1050665
- return {
1050666
- name: codeSample.name ?? void 0,
1050667
- docs: codeSample.description ?? void 0,
1050668
- sdk: codeSample.sdk,
1050669
- code: codeSample.code
1050670
- };
1050671
- }
1050672
- }).filter(isNonNullish);
1050673
- }
1050674
- return example;
1050675
- }
1050676
- function convertNamedFullExamples(namedFullExamples) {
1050677
- const result2 = {};
1050678
- namedFullExamples.map((namedFullExample) => result2[namedFullExample.name] = convertFullExample2(namedFullExample.value));
1050679
- return result2;
1050680
- }
1050681
- function convertQueryParameterExample2(namedFullExamples) {
1050682
- const result2 = {};
1050683
- namedFullExamples.forEach((namedFullExample) => {
1050684
- const convertedExample = convertFullExample2(namedFullExample.value);
1050685
- if (Array.isArray(convertedExample)) {
1050686
- result2[namedFullExample.name] = convertedExample[0];
1050687
- } else if (convertedExample != null) {
1050688
- result2[namedFullExample.name] = convertedExample;
1050689
- }
1050690
- });
1050691
- return result2;
1050692
- }
1050693
- function convertHeaderExamples2({ context, namedFullExamples }) {
1050694
- const globalHeaderNames = context.builder.getGlobalHeaderNames();
1050695
- const result2 = {};
1050696
- namedFullExamples.forEach((namedFullExample) => {
1050697
- const convertedExample = convertFullExample2(namedFullExample.value);
1050698
- if (globalHeaderNames.has(namedFullExample.name)) {
1050699
- return;
1050700
- } else if (convertedExample != null) {
1050701
- result2[namedFullExample.name] = convertedExample;
1050702
- }
1050703
- });
1050704
- return result2;
1050705
- }
1050752
+ // pnp:/home/circleci/project/packages/cli/openapi-ir-to-fern/lib/utils/convertFullExample.js
1050706
1050753
  function convertFullExample2(fullExample) {
1050707
1050754
  switch (fullExample.type) {
1050708
1050755
  case "primitive":
@@ -1050788,6 +1050835,89 @@ function convertLiteralExample2(literal2) {
1050788
1050835
  }
1050789
1050836
  }
1050790
1050837
 
1050838
+ // pnp:/home/circleci/project/packages/cli/openapi-ir-to-fern/lib/buildEndpointExample.js
1050839
+ function buildEndpointExample({ endpointExample, context }) {
1050840
+ const example = {};
1050841
+ if (endpointExample.type !== "full") {
1050842
+ return endpointExample.value;
1050843
+ }
1050844
+ if (endpointExample.name != null) {
1050845
+ example.name = endpointExample.name;
1050846
+ }
1050847
+ if (endpointExample.description != null) {
1050848
+ example.docs = endpointExample.description;
1050849
+ }
1050850
+ if (endpointExample.pathParameters != null && endpointExample.pathParameters.length > 0) {
1050851
+ example["path-parameters"] = convertNamedFullExamples(endpointExample.pathParameters);
1050852
+ }
1050853
+ if (endpointExample.queryParameters != null && endpointExample.queryParameters.length > 0) {
1050854
+ example["query-parameters"] = convertQueryParameterExample2(endpointExample.queryParameters);
1050855
+ }
1050856
+ if (endpointExample.headers != null && endpointExample.headers.length > 0) {
1050857
+ example.headers = convertHeaderExamples2({ context, namedFullExamples: endpointExample.headers });
1050858
+ }
1050859
+ if (endpointExample.request != null) {
1050860
+ example.request = convertFullExample2(endpointExample.request);
1050861
+ }
1050862
+ if (endpointExample.response != null) {
1050863
+ example.response = { body: convertFullExample2(endpointExample.response) };
1050864
+ }
1050865
+ if (endpointExample.response != null) {
1050866
+ example.response = { body: convertFullExample2(endpointExample.response) };
1050867
+ }
1050868
+ if (endpointExample.codeSamples != null && endpointExample.codeSamples.length > 0) {
1050869
+ example["code-samples"] = endpointExample.codeSamples.map((codeSample) => {
1050870
+ if (codeSample.type === "language") {
1050871
+ return {
1050872
+ name: codeSample.name ?? void 0,
1050873
+ docs: codeSample.description ?? void 0,
1050874
+ language: codeSample.language,
1050875
+ code: codeSample.code,
1050876
+ install: codeSample.install ?? void 0
1050877
+ };
1050878
+ } else {
1050879
+ return {
1050880
+ name: codeSample.name ?? void 0,
1050881
+ docs: codeSample.description ?? void 0,
1050882
+ sdk: codeSample.sdk,
1050883
+ code: codeSample.code
1050884
+ };
1050885
+ }
1050886
+ }).filter(isNonNullish);
1050887
+ }
1050888
+ return example;
1050889
+ }
1050890
+ function convertNamedFullExamples(namedFullExamples) {
1050891
+ const result2 = {};
1050892
+ namedFullExamples.map((namedFullExample) => result2[namedFullExample.name] = convertFullExample2(namedFullExample.value));
1050893
+ return result2;
1050894
+ }
1050895
+ function convertQueryParameterExample2(namedFullExamples) {
1050896
+ const result2 = {};
1050897
+ namedFullExamples.forEach((namedFullExample) => {
1050898
+ const convertedExample = convertFullExample2(namedFullExample.value);
1050899
+ if (Array.isArray(convertedExample)) {
1050900
+ result2[namedFullExample.name] = convertedExample[0];
1050901
+ } else if (convertedExample != null) {
1050902
+ result2[namedFullExample.name] = convertedExample;
1050903
+ }
1050904
+ });
1050905
+ return result2;
1050906
+ }
1050907
+ function convertHeaderExamples2({ context, namedFullExamples }) {
1050908
+ const globalHeaderNames = context.builder.getGlobalHeaderNames();
1050909
+ const result2 = {};
1050910
+ namedFullExamples.forEach((namedFullExample) => {
1050911
+ const convertedExample = convertFullExample2(namedFullExample.value);
1050912
+ if (globalHeaderNames.has(namedFullExample.name)) {
1050913
+ return;
1050914
+ } else if (convertedExample != null) {
1050915
+ result2[namedFullExample.name] = convertedExample;
1050916
+ }
1050917
+ });
1050918
+ return result2;
1050919
+ }
1050920
+
1050791
1050921
  // pnp:/home/circleci/project/packages/cli/openapi-ir-to-fern/lib/utils/convertToHttpMethod.js
1050792
1050922
  function convertToHttpMethod(httpMethod) {
1050793
1050923
  return HttpMethod6._visit(httpMethod, {
@@ -1051376,7 +1051506,14 @@ function buildWebhooks(context) {
1051376
1051506
  schema: webhook.payload,
1051377
1051507
  context,
1051378
1051508
  fileContainingReference: webhookLocation.file
1051379
- })
1051509
+ }),
1051510
+ examples: webhook.examples != null ? webhook.examples.map((exampleWebhookCall) => {
1051511
+ return {
1051512
+ docs: exampleWebhookCall.description,
1051513
+ name: exampleWebhookCall.name,
1051514
+ payload: convertFullExample2(exampleWebhookCall.payload)
1051515
+ };
1051516
+ }) : void 0
1051380
1051517
  };
1051381
1051518
  context.builder.addWebhook(webhookLocation.file, {
1051382
1051519
  name: webhookLocation.endpointId,
@@ -1056126,10 +1056263,10 @@ var CliContext = class {
1056126
1056263
  return "fern-api";
1056127
1056264
  }
1056128
1056265
  getPackageVersion() {
1056129
- if ("0.30.5" == null) {
1056266
+ if ("0.30.7" == null) {
1056130
1056267
  this.logger.error("CLI_VERSION is not defined");
1056131
1056268
  }
1056132
- return "0.30.5";
1056269
+ return "0.30.7";
1056133
1056270
  }
1056134
1056271
  getCliName() {
1056135
1056272
  if ("fern" == null) {
@@ -1060637,7 +1060774,7 @@ function getReadmeEndpointObject({ endpoint }) {
1060637
1060774
  }
1060638
1060775
 
1060639
1060776
  // pnp:/home/circleci/project/packages/cli/generation/ir-generator/lib/converters/convertWebhookGroup.js
1060640
- async function convertWebhookGroup({ webhooks, file }) {
1060777
+ async function convertWebhookGroup({ webhooks, file, typeResolver, exampleResolver, workspace }) {
1060641
1060778
  const webhookGroup = [];
1060642
1060779
  for (const [webhookId, webhook] of Object.entries(webhooks)) {
1060643
1060780
  webhookGroup.push({
@@ -1060647,7 +1060784,15 @@ async function convertWebhookGroup({ webhooks, file }) {
1060647
1060784
  method: webhook.method,
1060648
1060785
  name: file.casingsGenerator.generateName(webhookId),
1060649
1060786
  headers: webhook.headers != null ? await Promise.all(Object.entries(webhook.headers).map(([headerKey, header]) => convertHttpHeader({ headerKey, header, file }))) : [],
1060650
- payload: convertWebhookPayloadSchema({ payload: webhook.payload, file })
1060787
+ payload: convertWebhookPayloadSchema({ payload: webhook.payload, file }),
1060788
+ examples: webhook.examples != null ? convertWebhookExamples2({
1060789
+ webhook,
1060790
+ examples: webhook.examples,
1060791
+ file,
1060792
+ typeResolver,
1060793
+ exampleResolver,
1060794
+ workspace
1060795
+ }) : void 0
1060651
1060796
  });
1060652
1060797
  }
1060653
1060798
  return webhookGroup;
@@ -1060686,6 +1060831,40 @@ function convertInlinedRequestProperty2({ propertyKey, propertyDefinition, docs,
1060686
1060831
  valueType: file.parseTypeReference(propertyDefinition)
1060687
1060832
  };
1060688
1060833
  }
1060834
+ function convertWebhookExamples2({ webhook, examples, file, typeResolver, exampleResolver, workspace }) {
1060835
+ const typeName = typeof webhook.payload === "string" ? webhook.payload : isReferencedWebhookPayloadSchema2(webhook.payload) ? webhook.payload.type : void 0;
1060836
+ if (typeName != null) {
1060837
+ return examples.map((example) => ({
1060838
+ docs: webhook.docs,
1060839
+ name: example.name != null ? file.casingsGenerator.generateName(example.name) : void 0,
1060840
+ payload: convertTypeReferenceExample({
1060841
+ example: example.payload,
1060842
+ rawTypeBeingExemplified: typeName,
1060843
+ fileContainingRawTypeReference: file,
1060844
+ fileContainingExample: file,
1060845
+ typeResolver,
1060846
+ exampleResolver,
1060847
+ workspace
1060848
+ })
1060849
+ }));
1060850
+ }
1060851
+ if (!isPlainObject(webhook.payload)) {
1060852
+ throw new Error(`Example webhook payload is not an object. Got: ${JSON.stringify(webhook.payload)}`);
1060853
+ }
1060854
+ return examples.map((example) => ({
1060855
+ docs: webhook.docs,
1060856
+ name: example.name != null ? file.casingsGenerator.generateName(example.name) : void 0,
1060857
+ payload: convertTypeReferenceExample({
1060858
+ example: example.payload,
1060859
+ rawTypeBeingExemplified: "map<string, unknown>",
1060860
+ fileContainingRawTypeReference: file,
1060861
+ fileContainingExample: file,
1060862
+ typeResolver,
1060863
+ exampleResolver,
1060864
+ workspace
1060865
+ })
1060866
+ }));
1060867
+ }
1060689
1060868
  function isReferencedWebhookPayloadSchema2(payload) {
1060690
1060869
  return payload.type != null;
1060691
1060870
  }
@@ -1063156,7 +1063335,13 @@ async function generateIntermediateRepresentation({ workspace, generationLanguag
1063156
1063335
  return;
1063157
1063336
  }
1063158
1063337
  const webhookGroupId = IdGenerator.generateWebhookGroupId(file.fernFilepath);
1063159
- const convertedWebhookGroup = await convertWebhookGroup({ webhooks, file });
1063338
+ const convertedWebhookGroup = await convertWebhookGroup({
1063339
+ webhooks,
1063340
+ file,
1063341
+ typeResolver,
1063342
+ exampleResolver,
1063343
+ workspace
1063344
+ });
1063160
1063345
  intermediateRepresentation.webhookGroups[webhookGroupId] = convertedWebhookGroup;
1063161
1063346
  packageTreeGenerator.addWebhookGroup(webhookGroupId, file.fernFilepath);
1063162
1063347
  },
@@ -1072827,7 +1073012,10 @@ function isExternalUrl(url) {
1072827
1073012
  function replaceImagePathsAndUrls(markdown, fileIdsMap, markdownFilesToPathName, metadata, context) {
1072828
1073013
  const { content: content5, data: data2 } = (0, import_gray_matter.default)(markdown);
1072829
1073014
  let replacedContent = content5;
1072830
- const tree = fromMarkdown(content5);
1073015
+ const tree = fromMarkdown(content5, {
1073016
+ extensions: [mdx()],
1073017
+ mdastExtensions: [mdxFromMarkdown()]
1073018
+ });
1072831
1073019
  let offset2 = 0;
1072832
1073020
  visit2(tree, (node3) => {
1072833
1073021
  if (node3.position == null) {
@@ -1072836,8 +1073024,7 @@ function replaceImagePathsAndUrls(markdown, fileIdsMap, markdownFilesToPathName,
1072836
1073024
  const { start: start4, length } = getPosition(content5, node3.position);
1072837
1073025
  const original = replacedContent.slice(start4 + offset2, start4 + offset2 + length);
1072838
1073026
  let replaced = original;
1072839
- if (node3.type === "image") {
1072840
- const src = trimAnchor(node3.url);
1073027
+ function replaceSrc(src) {
1072841
1073028
  if (src != null && !isExternalUrl(src)) {
1072842
1073029
  try {
1072843
1073030
  const fileId = fileIdsMap.get(AbsoluteFilePath.of(src));
@@ -1072848,25 +1073035,11 @@ function replaceImagePathsAndUrls(markdown, fileIdsMap, markdownFilesToPathName,
1072848
1073035
  }
1072849
1073036
  }
1072850
1073037
  }
1072851
- if (node3.type === "html" || node3.type === "text") {
1072852
- const srcRegex = /src={?['"]([^'"]+)['"](?! \+)}?/g;
1072853
- let match;
1072854
- while ((match = srcRegex.exec(node3.value)) != null) {
1072855
- const pathToImage = trimAnchor(match[1]);
1072856
- if (pathToImage != null && !isExternalUrl(pathToImage)) {
1072857
- try {
1072858
- const fileId = fileIdsMap.get(AbsoluteFilePath.of(pathToImage));
1072859
- if (fileId != null) {
1072860
- replaced = replaced.replaceAll(pathToImage, `file:${fileId}`);
1072861
- }
1072862
- } catch (e) {
1072863
- }
1072864
- }
1073038
+ function replaceHref(href) {
1073039
+ if (href == null) {
1073040
+ return;
1072865
1073041
  }
1072866
- }
1072867
- if (node3.type === "link") {
1072868
- const href = trimAnchor(node3.url);
1072869
- if (href != null && (href.endsWith(".md") || href.endsWith(".mdx"))) {
1073042
+ if (href.endsWith(".md") || href.endsWith(".mdx")) {
1072870
1073043
  const absoluteFilePath = resolvePath(href, metadata);
1072871
1073044
  if (absoluteFilePath != null) {
1072872
1073045
  const pathName = markdownFilesToPathName.get(absoluteFilePath);
@@ -1072878,24 +1073051,70 @@ function replaceImagePathsAndUrls(markdown, fileIdsMap, markdownFilesToPathName,
1072878
1073051
  }
1072879
1073052
  }
1072880
1073053
  }
1072881
- if (node3.type === "html" || node3.type === "text") {
1072882
- const hrefRegex = /href={?['"]([^'"]+)['"](?! \+)}?/g;
1073054
+ if (node3.type === "image") {
1073055
+ const src = trimAnchor(node3.url);
1073056
+ replaceSrc(src);
1073057
+ }
1073058
+ if (node3.type === "mdxJsxFlowElement" || node3.type === "mdxJsxTextElement") {
1073059
+ if (node3.name && MEDIA_NODE_NAMES.includes(node3.name)) {
1073060
+ const srcAttr = node3.attributes.find((attr) => attr.type === "mdxJsxAttribute" && attr.name === "src");
1073061
+ if (srcAttr == null ? void 0 : srcAttr.value) {
1073062
+ let srcValue = srcAttr.value;
1073063
+ if (typeof srcValue !== "string") {
1073064
+ const match = srcValue.value.match(STR_REGEX);
1073065
+ if (match == null ? void 0 : match[1]) {
1073066
+ srcValue = match[1];
1073067
+ }
1073068
+ }
1073069
+ const pathToImage = trimAnchor(srcValue);
1073070
+ replaceSrc(pathToImage);
1073071
+ }
1073072
+ } else {
1073073
+ node3.attributes.forEach((attr) => {
1073074
+ if (attr.type === "mdxJsxAttribute" && attr.value && typeof attr.value !== "string") {
1073075
+ const match = SRC_REGEX.exec(attr.value.value);
1073076
+ if (match == null ? void 0 : match[1]) {
1073077
+ const pathToImage = trimAnchor(match[1]);
1073078
+ replaceSrc(pathToImage);
1073079
+ }
1073080
+ }
1073081
+ });
1073082
+ }
1073083
+ }
1073084
+ if (node3.type === "html" || node3.type === "text" || node3.type === "mdxTextExpression") {
1073085
+ const srcRegex = /src={?['"]([^'"]+)['"](?! \+)}?/g;
1072883
1073086
  let match;
1072884
- while ((match = hrefRegex.exec(node3.value)) != null) {
1072885
- const href = trimAnchor(match[1]);
1072886
- if (href != null && (href.endsWith(".md") || href.endsWith(".mdx"))) {
1072887
- const absoluteFilePath = resolvePath(href, metadata);
1072888
- if (absoluteFilePath != null) {
1072889
- const pathName = markdownFilesToPathName.get(absoluteFilePath);
1072890
- if (pathName != null) {
1072891
- replaced = replaced.replaceAll(href, pathName);
1072892
- } else {
1072893
- context.logger.error(`${relative(metadata.absolutePathToFernFolder, absoluteFilePath)} has no slug defined but is referenced by ${relative(metadata.absolutePathToFernFolder, metadata.absolutePathToMdx)}`);
1073087
+ while ((match = srcRegex.exec(node3.value)) != null) {
1073088
+ const pathToImage = trimAnchor(match[1]);
1073089
+ replaceSrc(pathToImage);
1073090
+ }
1073091
+ }
1073092
+ if (node3.type === "link") {
1073093
+ replaceHref(trimAnchor(node3.url));
1073094
+ }
1073095
+ if (node3.type === "mdxJsxFlowElement" || node3.type === "mdxJsxTextElement") {
1073096
+ if (node3.name === "a") {
1073097
+ const hrefAttr = node3.attributes.find((attr) => attr.type === "mdxJsxAttribute" && attr.name === "href");
1073098
+ if (hrefAttr == null ? void 0 : hrefAttr.value) {
1073099
+ let href = hrefAttr.value;
1073100
+ if (typeof href !== "string") {
1073101
+ const match = href.value.match(STR_REGEX);
1073102
+ if (match == null ? void 0 : match[1]) {
1073103
+ href = match[1];
1072894
1073104
  }
1072895
1073105
  }
1073106
+ replaceHref(trimAnchor(href));
1072896
1073107
  }
1072897
1073108
  }
1072898
1073109
  }
1073110
+ if (node3.type === "html" || node3.type === "text" || node3.type === "mdxTextExpression") {
1073111
+ const hrefRegex = /href={?['"]([^'"]+)['"](?! \+)}?/g;
1073112
+ let match;
1073113
+ while ((match = hrefRegex.exec(node3.value)) != null) {
1073114
+ const href = trimAnchor(match[1]);
1073115
+ replaceHref(href);
1073116
+ }
1073117
+ }
1072899
1073118
  if (replaced === original) {
1072900
1073119
  return;
1072901
1073120
  }
@@ -1075457,7 +1075676,11 @@ function convertWebhookGroup2(webhookGroup) {
1075457
1075676
  type: convertTypeReference(header.valueType)
1075458
1075677
  })),
1075459
1075678
  payload: convertWebhookPayload(webhook.payload),
1075460
- examples: []
1075679
+ examples: webhook.examples != null ? webhook.examples.map((example) => {
1075680
+ return {
1075681
+ payload: example.payload.jsonExample
1075682
+ };
1075683
+ }) : []
1075461
1075684
  };
1075462
1075685
  });
1075463
1075686
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fern-api",
3
- "version": "0.30.5",
3
+ "version": "0.30.7",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/fern-api/fern.git",