fern-api 0.18.2 → 0.18.3-rc0
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.
- package/bundle.cjs +1405 -1040
- package/package.json +1 -1
package/bundle.cjs
CHANGED
|
@@ -356225,6 +356225,18 @@ var init_WebsocketHandshake = __esm({
|
|
|
356225
356225
|
}
|
|
356226
356226
|
});
|
|
356227
356227
|
|
|
356228
|
+
// pnp:/home/circleci/project/packages/cli/openapi-ir-sdk/lib/sdk/api/resources/finalIr/types/WebsocketSessionExample.js
|
|
356229
|
+
var init_WebsocketSessionExample = __esm({
|
|
356230
|
+
"pnp:/home/circleci/project/packages/cli/openapi-ir-sdk/lib/sdk/api/resources/finalIr/types/WebsocketSessionExample.js"() {
|
|
356231
|
+
}
|
|
356232
|
+
});
|
|
356233
|
+
|
|
356234
|
+
// pnp:/home/circleci/project/packages/cli/openapi-ir-sdk/lib/sdk/api/resources/finalIr/types/WebsocketMessageExample.js
|
|
356235
|
+
var init_WebsocketMessageExample = __esm({
|
|
356236
|
+
"pnp:/home/circleci/project/packages/cli/openapi-ir-sdk/lib/sdk/api/resources/finalIr/types/WebsocketMessageExample.js"() {
|
|
356237
|
+
}
|
|
356238
|
+
});
|
|
356239
|
+
|
|
356228
356240
|
// pnp:/home/circleci/project/packages/cli/openapi-ir-sdk/lib/sdk/api/resources/finalIr/types/WebhookHttpMethod.js
|
|
356229
356241
|
var init_WebhookHttpMethod3 = __esm({
|
|
356230
356242
|
"pnp:/home/circleci/project/packages/cli/openapi-ir-sdk/lib/sdk/api/resources/finalIr/types/WebhookHttpMethod.js"() {
|
|
@@ -357048,6 +357060,8 @@ var init_types27 = __esm({
|
|
|
357048
357060
|
init_Webhook3();
|
|
357049
357061
|
init_WebsocketChannel();
|
|
357050
357062
|
init_WebsocketHandshake();
|
|
357063
|
+
init_WebsocketSessionExample();
|
|
357064
|
+
init_WebsocketMessageExample();
|
|
357051
357065
|
init_WebhookHttpMethod3();
|
|
357052
357066
|
init_EndpointAvailability();
|
|
357053
357067
|
init_Endpoint();
|
|
@@ -357113,6 +357127,12 @@ var init_NamedFullExample = __esm({
|
|
|
357113
357127
|
}
|
|
357114
357128
|
});
|
|
357115
357129
|
|
|
357130
|
+
// pnp:/home/circleci/project/packages/cli/openapi-ir-sdk/lib/sdk/api/resources/parseIr/types/WebsocketHandshakeWithExample.js
|
|
357131
|
+
var init_WebsocketHandshakeWithExample = __esm({
|
|
357132
|
+
"pnp:/home/circleci/project/packages/cli/openapi-ir-sdk/lib/sdk/api/resources/parseIr/types/WebsocketHandshakeWithExample.js"() {
|
|
357133
|
+
}
|
|
357134
|
+
});
|
|
357135
|
+
|
|
357116
357136
|
// pnp:/home/circleci/project/packages/cli/openapi-ir-sdk/lib/sdk/api/resources/parseIr/types/EndpointWithExample.js
|
|
357117
357137
|
var init_EndpointWithExample = __esm({
|
|
357118
357138
|
"pnp:/home/circleci/project/packages/cli/openapi-ir-sdk/lib/sdk/api/resources/parseIr/types/EndpointWithExample.js"() {
|
|
@@ -357689,6 +357709,7 @@ var init_BooleanWithExample = __esm({
|
|
|
357689
357709
|
var init_types28 = __esm({
|
|
357690
357710
|
"pnp:/home/circleci/project/packages/cli/openapi-ir-sdk/lib/sdk/api/resources/parseIr/types/index.js"() {
|
|
357691
357711
|
init_NamedFullExample();
|
|
357712
|
+
init_WebsocketHandshakeWithExample();
|
|
357692
357713
|
init_EndpointWithExample();
|
|
357693
357714
|
init_RequestWithExample();
|
|
357694
357715
|
init_JsonRequestWithExample();
|
|
@@ -359825,7 +359846,8 @@ var init_WebsocketChannel2 = __esm({
|
|
|
359825
359846
|
summary: schemas_exports3.string().optional(),
|
|
359826
359847
|
handshake: schemas_exports3.lazyObject(async () => (await Promise.resolve().then(() => (init_serialization2(), serialization_exports2))).WebsocketHandshake),
|
|
359827
359848
|
publish: schemas_exports3.lazy(async () => (await Promise.resolve().then(() => (init_serialization2(), serialization_exports2))).Schema).optional(),
|
|
359828
|
-
subscribe: schemas_exports3.lazy(async () => (await Promise.resolve().then(() => (init_serialization2(), serialization_exports2))).Schema).optional()
|
|
359849
|
+
subscribe: schemas_exports3.lazy(async () => (await Promise.resolve().then(() => (init_serialization2(), serialization_exports2))).Schema).optional(),
|
|
359850
|
+
examples: schemas_exports3.list(schemas_exports3.lazyObject(async () => (await Promise.resolve().then(() => (init_serialization2(), serialization_exports2))).WebsocketSessionExample))
|
|
359829
359851
|
}).extend(schemas_exports3.lazyObject(async () => (await Promise.resolve().then(() => (init_serialization2(), serialization_exports2))).WithDescription));
|
|
359830
359852
|
}
|
|
359831
359853
|
});
|
|
@@ -359842,6 +359864,32 @@ var init_WebsocketHandshake2 = __esm({
|
|
|
359842
359864
|
}
|
|
359843
359865
|
});
|
|
359844
359866
|
|
|
359867
|
+
// pnp:/home/circleci/project/packages/cli/openapi-ir-sdk/lib/sdk/serialization/resources/finalIr/types/WebsocketSessionExample.js
|
|
359868
|
+
var WebsocketSessionExample;
|
|
359869
|
+
var init_WebsocketSessionExample2 = __esm({
|
|
359870
|
+
"pnp:/home/circleci/project/packages/cli/openapi-ir-sdk/lib/sdk/serialization/resources/finalIr/types/WebsocketSessionExample.js"() {
|
|
359871
|
+
init_core2();
|
|
359872
|
+
WebsocketSessionExample = schemas_exports3.objectWithoutOptionalProperties({
|
|
359873
|
+
name: schemas_exports3.string().optional(),
|
|
359874
|
+
queryParameters: schemas_exports3.list(schemas_exports3.lazyObject(async () => (await Promise.resolve().then(() => (init_serialization2(), serialization_exports2))).QueryParameterExample)).optional(),
|
|
359875
|
+
headers: schemas_exports3.list(schemas_exports3.lazyObject(async () => (await Promise.resolve().then(() => (init_serialization2(), serialization_exports2))).HeaderExample)).optional(),
|
|
359876
|
+
messages: schemas_exports3.list(schemas_exports3.lazyObject(async () => (await Promise.resolve().then(() => (init_serialization2(), serialization_exports2))).WebsocketMessageExample))
|
|
359877
|
+
}).extend(schemas_exports3.lazyObject(async () => (await Promise.resolve().then(() => (init_serialization2(), serialization_exports2))).WithDescription));
|
|
359878
|
+
}
|
|
359879
|
+
});
|
|
359880
|
+
|
|
359881
|
+
// pnp:/home/circleci/project/packages/cli/openapi-ir-sdk/lib/sdk/serialization/resources/finalIr/types/WebsocketMessageExample.js
|
|
359882
|
+
var WebsocketMessageExample;
|
|
359883
|
+
var init_WebsocketMessageExample2 = __esm({
|
|
359884
|
+
"pnp:/home/circleci/project/packages/cli/openapi-ir-sdk/lib/sdk/serialization/resources/finalIr/types/WebsocketMessageExample.js"() {
|
|
359885
|
+
init_core2();
|
|
359886
|
+
WebsocketMessageExample = schemas_exports3.objectWithoutOptionalProperties({
|
|
359887
|
+
messageType: schemas_exports3.string(),
|
|
359888
|
+
payload: schemas_exports3.lazy(async () => (await Promise.resolve().then(() => (init_serialization2(), serialization_exports2))).FullExample)
|
|
359889
|
+
}).extend(schemas_exports3.lazyObject(async () => (await Promise.resolve().then(() => (init_serialization2(), serialization_exports2))).WithDescription));
|
|
359890
|
+
}
|
|
359891
|
+
});
|
|
359892
|
+
|
|
359845
359893
|
// pnp:/home/circleci/project/packages/cli/openapi-ir-sdk/lib/sdk/serialization/resources/finalIr/types/WebhookHttpMethod.js
|
|
359846
359894
|
var WebhookHttpMethod3;
|
|
359847
359895
|
var init_WebhookHttpMethod4 = __esm({
|
|
@@ -360637,6 +360685,8 @@ var init_types31 = __esm({
|
|
|
360637
360685
|
init_Webhook4();
|
|
360638
360686
|
init_WebsocketChannel2();
|
|
360639
360687
|
init_WebsocketHandshake2();
|
|
360688
|
+
init_WebsocketSessionExample2();
|
|
360689
|
+
init_WebsocketMessageExample2();
|
|
360640
360690
|
init_WebhookHttpMethod4();
|
|
360641
360691
|
init_EndpointAvailability2();
|
|
360642
360692
|
init_Endpoint2();
|
|
@@ -360747,7 +360797,9 @@ __export(finalIr_exports2, {
|
|
|
360747
360797
|
Webhook: () => Webhook2,
|
|
360748
360798
|
WebhookHttpMethod: () => WebhookHttpMethod3,
|
|
360749
360799
|
WebsocketChannel: () => WebsocketChannel,
|
|
360750
|
-
WebsocketHandshake: () => WebsocketHandshake
|
|
360800
|
+
WebsocketHandshake: () => WebsocketHandshake,
|
|
360801
|
+
WebsocketMessageExample: () => WebsocketMessageExample,
|
|
360802
|
+
WebsocketSessionExample: () => WebsocketSessionExample
|
|
360751
360803
|
});
|
|
360752
360804
|
var init_finalIr2 = __esm({
|
|
360753
360805
|
"pnp:/home/circleci/project/packages/cli/openapi-ir-sdk/lib/sdk/serialization/resources/finalIr/index.js"() {
|
|
@@ -360767,6 +360819,18 @@ var init_NamedFullExample2 = __esm({
|
|
|
360767
360819
|
}
|
|
360768
360820
|
});
|
|
360769
360821
|
|
|
360822
|
+
// pnp:/home/circleci/project/packages/cli/openapi-ir-sdk/lib/sdk/serialization/resources/parseIr/types/WebsocketHandshakeWithExample.js
|
|
360823
|
+
var WebsocketHandshakeWithExample;
|
|
360824
|
+
var init_WebsocketHandshakeWithExample2 = __esm({
|
|
360825
|
+
"pnp:/home/circleci/project/packages/cli/openapi-ir-sdk/lib/sdk/serialization/resources/parseIr/types/WebsocketHandshakeWithExample.js"() {
|
|
360826
|
+
init_core2();
|
|
360827
|
+
WebsocketHandshakeWithExample = schemas_exports3.objectWithoutOptionalProperties({
|
|
360828
|
+
queryParameters: schemas_exports3.list(schemas_exports3.lazyObject(async () => (await Promise.resolve().then(() => (init_serialization2(), serialization_exports2))).QueryParameterWithExample)),
|
|
360829
|
+
headers: schemas_exports3.list(schemas_exports3.lazyObject(async () => (await Promise.resolve().then(() => (init_serialization2(), serialization_exports2))).HeaderWithExample))
|
|
360830
|
+
});
|
|
360831
|
+
}
|
|
360832
|
+
});
|
|
360833
|
+
|
|
360770
360834
|
// pnp:/home/circleci/project/packages/cli/openapi-ir-sdk/lib/sdk/serialization/resources/parseIr/types/EndpointWithExample.js
|
|
360771
360835
|
var EndpointWithExample;
|
|
360772
360836
|
var init_EndpointWithExample2 = __esm({
|
|
@@ -361298,6 +361362,7 @@ var init_BooleanWithExample2 = __esm({
|
|
|
361298
361362
|
var init_types32 = __esm({
|
|
361299
361363
|
"pnp:/home/circleci/project/packages/cli/openapi-ir-sdk/lib/sdk/serialization/resources/parseIr/types/index.js"() {
|
|
361300
361364
|
init_NamedFullExample2();
|
|
361365
|
+
init_WebsocketHandshakeWithExample2();
|
|
361301
361366
|
init_EndpointWithExample2();
|
|
361302
361367
|
init_RequestWithExample2();
|
|
361303
361368
|
init_JsonRequestWithExample2();
|
|
@@ -361368,7 +361433,8 @@ __export(parseIr_exports2, {
|
|
|
361368
361433
|
SchemaWithExample: () => SchemaWithExample2,
|
|
361369
361434
|
StringSchemaWithExample: () => StringSchemaWithExample,
|
|
361370
361435
|
UnDiscriminatedOneOfSchemaWithExample: () => UnDiscriminatedOneOfSchemaWithExample,
|
|
361371
|
-
UnknownSchemaWithExample: () => UnknownSchemaWithExample
|
|
361436
|
+
UnknownSchemaWithExample: () => UnknownSchemaWithExample,
|
|
361437
|
+
WebsocketHandshakeWithExample: () => WebsocketHandshakeWithExample
|
|
361372
361438
|
});
|
|
361373
361439
|
var init_parseIr2 = __esm({
|
|
361374
361440
|
"pnp:/home/circleci/project/packages/cli/openapi-ir-sdk/lib/sdk/serialization/resources/parseIr/index.js"() {
|
|
@@ -361502,6 +361568,9 @@ __export(serialization_exports2, {
|
|
|
361502
361568
|
WebhookHttpMethod: () => WebhookHttpMethod3,
|
|
361503
361569
|
WebsocketChannel: () => WebsocketChannel,
|
|
361504
361570
|
WebsocketHandshake: () => WebsocketHandshake,
|
|
361571
|
+
WebsocketHandshakeWithExample: () => WebsocketHandshakeWithExample,
|
|
361572
|
+
WebsocketMessageExample: () => WebsocketMessageExample,
|
|
361573
|
+
WebsocketSessionExample: () => WebsocketSessionExample,
|
|
361505
361574
|
WithDescription: () => WithDescription,
|
|
361506
361575
|
WithName: () => WithName,
|
|
361507
361576
|
WithSdkGroupName: () => WithSdkGroupName,
|
|
@@ -777882,7 +777951,7 @@ var AccessTokenPosthogManager = class {
|
|
|
777882
777951
|
properties: {
|
|
777883
777952
|
...event,
|
|
777884
777953
|
...event.properties,
|
|
777885
|
-
version: "0.18.
|
|
777954
|
+
version: "0.18.3-rc0",
|
|
777886
777955
|
usingAccessToken: true
|
|
777887
777956
|
}
|
|
777888
777957
|
});
|
|
@@ -777944,7 +778013,7 @@ var UserPosthogManager = class {
|
|
|
777944
778013
|
distinctId: this.userId ?? await this.getPersistedDistinctId(),
|
|
777945
778014
|
event: "CLI",
|
|
777946
778015
|
properties: {
|
|
777947
|
-
version: "0.18.
|
|
778016
|
+
version: "0.18.3-rc0",
|
|
777948
778017
|
...event,
|
|
777949
778018
|
...event.properties
|
|
777950
778019
|
}
|
|
@@ -789077,6 +789146,7 @@ __export(schemas_exports, {
|
|
|
789077
789146
|
ExampleTypeReferenceSchema: () => ExampleTypeReferenceSchema,
|
|
789078
789147
|
ExampleTypeSchema: () => ExampleTypeSchema,
|
|
789079
789148
|
ExampleTypeValueSchema: () => ExampleTypeValueSchema,
|
|
789149
|
+
ExampleWebSocketSession: () => ExampleWebSocketSession,
|
|
789080
789150
|
HeaderAuthSchemeSchema: () => HeaderAuthSchemeSchema,
|
|
789081
789151
|
HttpEndpointSchema: () => HttpEndpointSchema,
|
|
789082
789152
|
HttpHeaderSchema: () => HttpHeaderSchema,
|
|
@@ -789379,6 +789449,20 @@ var ExampleEndpointCallSchema = WithNameAndDocsSchema.extend({
|
|
|
789379
789449
|
"code-samples": z.optional(z.array(ExampleCodeSampleSchema))
|
|
789380
789450
|
});
|
|
789381
789451
|
|
|
789452
|
+
// pnp:/home/circleci/project/packages/cli/yaml/yaml-schema/lib/schemas/ExampleWebSocketMessage.js
|
|
789453
|
+
var ExampleWebSocketMessage = z.object({
|
|
789454
|
+
type: z.string(),
|
|
789455
|
+
body: z.unknown()
|
|
789456
|
+
});
|
|
789457
|
+
|
|
789458
|
+
// pnp:/home/circleci/project/packages/cli/yaml/yaml-schema/lib/schemas/ExampleWebSocketSession.js
|
|
789459
|
+
var ExampleWebSocketSession = WithNameAndDocsSchema.extend({
|
|
789460
|
+
"path-parameters": z.optional(z.record(z.string(), ExampleTypeReferenceSchema)),
|
|
789461
|
+
"query-parameters": z.optional(z.record(z.string(), ExampleTypeReferenceSchema)),
|
|
789462
|
+
headers: z.optional(z.record(z.string(), ExampleTypeReferenceSchema)),
|
|
789463
|
+
messages: z.array(ExampleWebSocketMessage)
|
|
789464
|
+
});
|
|
789465
|
+
|
|
789382
789466
|
// pnp:/home/circleci/project/packages/cli/yaml/yaml-schema/lib/schemas/VariableReferenceSchema.js
|
|
789383
789467
|
var VariableReferenceSchema = WithDocsSchema.extend({
|
|
789384
789468
|
variable: z.string()
|
|
@@ -789543,20 +789627,6 @@ var WebhookSchema = DeclarationSchema.extend({
|
|
|
789543
789627
|
payload: WebhookPayloadSchema
|
|
789544
789628
|
});
|
|
789545
789629
|
|
|
789546
|
-
// pnp:/home/circleci/project/packages/cli/yaml/yaml-schema/lib/schemas/ExampleWebSocketMessage.js
|
|
789547
|
-
var ExampleWebSocketMessage = z.object({
|
|
789548
|
-
type: z.string(),
|
|
789549
|
-
body: z.unknown()
|
|
789550
|
-
});
|
|
789551
|
-
|
|
789552
|
-
// pnp:/home/circleci/project/packages/cli/yaml/yaml-schema/lib/schemas/ExampleWebSocketSession.js
|
|
789553
|
-
var ExampleWebSocketSession = WithNameAndDocsSchema.extend({
|
|
789554
|
-
"path-parameters": z.optional(z.record(z.string(), ExampleTypeReferenceSchema)),
|
|
789555
|
-
"query-parameters": z.optional(z.record(z.string(), ExampleTypeReferenceSchema)),
|
|
789556
|
-
headers: z.optional(z.record(z.string(), ExampleTypeReferenceSchema)),
|
|
789557
|
-
messages: z.array(ExampleWebSocketMessage)
|
|
789558
|
-
});
|
|
789559
|
-
|
|
789560
789630
|
// pnp:/home/circleci/project/packages/cli/yaml/yaml-schema/lib/schemas/WebSocketChannelInlinedMessageSchema.js
|
|
789561
789631
|
var WebSocketChannelInlinedMessageSchema = z.union([
|
|
789562
789632
|
z.strictObject({
|
|
@@ -790683,7 +790753,7 @@ function buildHeader({ header, context, fileContainingReference }) {
|
|
|
790683
790753
|
// pnp:/home/circleci/project/packages/cli/openapi-parser/lib/openapi/parse.js
|
|
790684
790754
|
var import_promises23 = require("fs/promises");
|
|
790685
790755
|
|
|
790686
|
-
// pnp:/home/circleci/project/packages/cli/openapi-parser/lib/
|
|
790756
|
+
// pnp:/home/circleci/project/packages/cli/openapi-parser/lib/schema/examples/getExample.js
|
|
790687
790757
|
function getExampleAsNumber(schema2) {
|
|
790688
790758
|
if (schema2.example != null && typeof schema2.example === "number") {
|
|
790689
790759
|
return schema2.example;
|
|
@@ -792693,6 +792763,870 @@ var AsyncAPIV2ParserContext = class extends AbstractAsyncAPIV2ParserContext {
|
|
|
792693
792763
|
}
|
|
792694
792764
|
};
|
|
792695
792765
|
|
|
792766
|
+
// pnp:/home/circleci/project/packages/cli/openapi-parser/lib/schema/examples/convertToFullExample.js
|
|
792767
|
+
function convertToFullExample(value) {
|
|
792768
|
+
if (typeof value === "string") {
|
|
792769
|
+
return FullExample.primitive(PrimitiveExample.string(value));
|
|
792770
|
+
} else if (typeof value === "number") {
|
|
792771
|
+
if (Number.isInteger(value)) {
|
|
792772
|
+
return FullExample.primitive(PrimitiveExample.int(value));
|
|
792773
|
+
}
|
|
792774
|
+
return FullExample.primitive(PrimitiveExample.double(value));
|
|
792775
|
+
} else if (typeof value === "boolean") {
|
|
792776
|
+
return FullExample.primitive(PrimitiveExample.boolean(value));
|
|
792777
|
+
} else if (value != null && typeof value === "object" && Object.keys(value).every((key2) => typeof key2 === "string")) {
|
|
792778
|
+
const kvs = [];
|
|
792779
|
+
for (const [property4, propertyValue] of Object.entries(value)) {
|
|
792780
|
+
const propertyExample = convertToFullExample(propertyValue);
|
|
792781
|
+
if (propertyExample != null) {
|
|
792782
|
+
kvs.push({
|
|
792783
|
+
key: PrimitiveExample.string(property4),
|
|
792784
|
+
value: propertyExample
|
|
792785
|
+
});
|
|
792786
|
+
}
|
|
792787
|
+
}
|
|
792788
|
+
return FullExample.map(kvs);
|
|
792789
|
+
}
|
|
792790
|
+
return void 0;
|
|
792791
|
+
}
|
|
792792
|
+
|
|
792793
|
+
// pnp:/home/circleci/project/packages/cli/openapi-parser/lib/schema/examples/getFullExample.js
|
|
792794
|
+
function getFullExampleAsObject(value) {
|
|
792795
|
+
if (value != null && typeof value === "object" && Object.keys(value).every((key2) => typeof key2 === "string")) {
|
|
792796
|
+
return value;
|
|
792797
|
+
}
|
|
792798
|
+
return void 0;
|
|
792799
|
+
}
|
|
792800
|
+
function getFullExampleAsArray(value) {
|
|
792801
|
+
if (value != null && Array.isArray(value)) {
|
|
792802
|
+
return value;
|
|
792803
|
+
}
|
|
792804
|
+
return void 0;
|
|
792805
|
+
}
|
|
792806
|
+
|
|
792807
|
+
// pnp:/home/circleci/project/packages/cli/openapi-parser/lib/schema/examples/ExampleTypeFactory.js
|
|
792808
|
+
var ExampleTypeFactory = class {
|
|
792809
|
+
schemas;
|
|
792810
|
+
constructor(schemas) {
|
|
792811
|
+
this.schemas = schemas;
|
|
792812
|
+
}
|
|
792813
|
+
buildExample({ schema: schema2, example, options }) {
|
|
792814
|
+
return this.buildExampleHelper({ schema: schema2, visitedSchemaIds: /* @__PURE__ */ new Set(), example, options, depth: 0 });
|
|
792815
|
+
}
|
|
792816
|
+
buildExampleHelper({ example, schema: schema2, depth, visitedSchemaIds, options }) {
|
|
792817
|
+
var _a2, _b2;
|
|
792818
|
+
switch (schema2.type) {
|
|
792819
|
+
case "enum":
|
|
792820
|
+
if (typeof example === "string" && enumContainsValue({ schema: schema2, value: example })) {
|
|
792821
|
+
return FullExample.enum(example);
|
|
792822
|
+
}
|
|
792823
|
+
return schema2.values[0] != null ? FullExample.enum((_a2 = schema2.values[0]) == null ? void 0 : _a2.value) : void 0;
|
|
792824
|
+
case "literal":
|
|
792825
|
+
return FullExample.literal(schema2.value);
|
|
792826
|
+
case "nullable": {
|
|
792827
|
+
if (example == null && !this.hasExample(schema2.value) && (options.ignoreOptionals || this.exceedsMaxDepth(depth, options))) {
|
|
792828
|
+
return void 0;
|
|
792829
|
+
}
|
|
792830
|
+
const result2 = this.buildExampleHelper({
|
|
792831
|
+
schema: schema2.value,
|
|
792832
|
+
visitedSchemaIds,
|
|
792833
|
+
example,
|
|
792834
|
+
depth,
|
|
792835
|
+
options
|
|
792836
|
+
});
|
|
792837
|
+
if (result2 != null && result2.type === "array" && result2.value.length === 0) {
|
|
792838
|
+
return void 0;
|
|
792839
|
+
}
|
|
792840
|
+
if (result2 != null && result2.type === "map" && result2.value.length === 0) {
|
|
792841
|
+
return void 0;
|
|
792842
|
+
}
|
|
792843
|
+
if (result2 != null && result2.type === "object" && Object.keys(result2.properties).length === 0) {
|
|
792844
|
+
return void 0;
|
|
792845
|
+
}
|
|
792846
|
+
return result2;
|
|
792847
|
+
}
|
|
792848
|
+
case "optional": {
|
|
792849
|
+
if (example == null && !this.hasExample(schema2.value) && (options.ignoreOptionals || this.exceedsMaxDepth(depth, options))) {
|
|
792850
|
+
return void 0;
|
|
792851
|
+
}
|
|
792852
|
+
const result2 = this.buildExampleHelper({
|
|
792853
|
+
schema: schema2.value,
|
|
792854
|
+
visitedSchemaIds,
|
|
792855
|
+
example,
|
|
792856
|
+
depth,
|
|
792857
|
+
options
|
|
792858
|
+
});
|
|
792859
|
+
if (result2 != null && result2.type === "array" && result2.value.length === 0) {
|
|
792860
|
+
return void 0;
|
|
792861
|
+
}
|
|
792862
|
+
if (result2 != null && result2.type === "map" && result2.value.length === 0) {
|
|
792863
|
+
return void 0;
|
|
792864
|
+
}
|
|
792865
|
+
if (result2 != null && result2.type === "object" && Object.keys(result2.properties).length === 0) {
|
|
792866
|
+
return void 0;
|
|
792867
|
+
}
|
|
792868
|
+
return result2;
|
|
792869
|
+
}
|
|
792870
|
+
case "primitive": {
|
|
792871
|
+
const primitiveExample = this.buildExampleFromPrimitive({ schema: schema2.schema, example, options });
|
|
792872
|
+
return FullExample.primitive(primitiveExample);
|
|
792873
|
+
}
|
|
792874
|
+
case "reference": {
|
|
792875
|
+
const referencedSchemaWithExample = this.schemas[schema2.schema];
|
|
792876
|
+
if (referencedSchemaWithExample != null && !visitedSchemaIds.has(schema2.schema)) {
|
|
792877
|
+
visitedSchemaIds.add(schema2.schema);
|
|
792878
|
+
const referencedExample = this.buildExampleHelper({
|
|
792879
|
+
example,
|
|
792880
|
+
schema: referencedSchemaWithExample,
|
|
792881
|
+
visitedSchemaIds,
|
|
792882
|
+
depth,
|
|
792883
|
+
options
|
|
792884
|
+
});
|
|
792885
|
+
visitedSchemaIds.delete(schema2.schema);
|
|
792886
|
+
return referencedExample;
|
|
792887
|
+
}
|
|
792888
|
+
return void 0;
|
|
792889
|
+
}
|
|
792890
|
+
case "oneOf":
|
|
792891
|
+
switch (schema2.value.type) {
|
|
792892
|
+
case "discriminated": {
|
|
792893
|
+
const result2 = {};
|
|
792894
|
+
let allProperties = {};
|
|
792895
|
+
let requiredProperties = {};
|
|
792896
|
+
const fullExample = getFullExampleAsObject(example);
|
|
792897
|
+
const exampleDiscriminant = fullExample == null ? void 0 : fullExample[schema2.value.discriminantProperty];
|
|
792898
|
+
const exampleUnionVariantSchema = schema2.value.schemas[exampleDiscriminant];
|
|
792899
|
+
const firstUnionVariant = Object.entries(schema2.value.schemas)[0];
|
|
792900
|
+
if (exampleDiscriminant != null && exampleUnionVariantSchema != null && exampleUnionVariantSchema.type === "object") {
|
|
792901
|
+
allProperties = this.getAllProperties(exampleUnionVariantSchema);
|
|
792902
|
+
requiredProperties = this.getAllRequiredProperties(exampleUnionVariantSchema);
|
|
792903
|
+
result2[schema2.value.discriminantProperty] = FullExample.primitive(PrimitiveExample.string(exampleDiscriminant));
|
|
792904
|
+
} else if (firstUnionVariant != null && firstUnionVariant[1].type === "object") {
|
|
792905
|
+
allProperties = this.getAllProperties(firstUnionVariant[1]);
|
|
792906
|
+
requiredProperties = this.getAllRequiredProperties(firstUnionVariant[1]);
|
|
792907
|
+
result2[schema2.value.discriminantProperty] = FullExample.primitive(PrimitiveExample.string(firstUnionVariant[0]));
|
|
792908
|
+
} else {
|
|
792909
|
+
return void 0;
|
|
792910
|
+
}
|
|
792911
|
+
for (const commonProperty of schema2.value.commonProperties) {
|
|
792912
|
+
allProperties[commonProperty.key] = commonProperty.schema;
|
|
792913
|
+
const resolvedSchema = this.getResolvedSchema(commonProperty.schema);
|
|
792914
|
+
if (resolvedSchema.type !== "optional" && resolvedSchema.type !== "nullable") {
|
|
792915
|
+
requiredProperties[commonProperty.key] = commonProperty.schema;
|
|
792916
|
+
}
|
|
792917
|
+
}
|
|
792918
|
+
for (const [property4, schema3] of Object.entries(allProperties)) {
|
|
792919
|
+
const required = property4 in requiredProperties;
|
|
792920
|
+
if (required && (fullExample == null ? void 0 : fullExample[property4]) != null) {
|
|
792921
|
+
const propertyExample = this.buildExampleHelper({
|
|
792922
|
+
schema: schema3,
|
|
792923
|
+
example: fullExample[property4],
|
|
792924
|
+
visitedSchemaIds,
|
|
792925
|
+
depth: depth + 1,
|
|
792926
|
+
options
|
|
792927
|
+
});
|
|
792928
|
+
if (propertyExample != null) {
|
|
792929
|
+
result2[property4] = propertyExample;
|
|
792930
|
+
} else {
|
|
792931
|
+
return void 0;
|
|
792932
|
+
}
|
|
792933
|
+
} else {
|
|
792934
|
+
const propertyExample = this.buildExampleHelper({
|
|
792935
|
+
schema: schema3,
|
|
792936
|
+
example: fullExample == null ? void 0 : fullExample[property4],
|
|
792937
|
+
visitedSchemaIds,
|
|
792938
|
+
depth: depth + 1,
|
|
792939
|
+
options
|
|
792940
|
+
});
|
|
792941
|
+
if (propertyExample != null) {
|
|
792942
|
+
result2[property4] = propertyExample;
|
|
792943
|
+
} else if (required) {
|
|
792944
|
+
return void 0;
|
|
792945
|
+
}
|
|
792946
|
+
}
|
|
792947
|
+
}
|
|
792948
|
+
return FullExample.oneOf(FullOneOfExample.discriminated(result2));
|
|
792949
|
+
}
|
|
792950
|
+
case "undisciminated": {
|
|
792951
|
+
if (schema2.value.schemas[0] != null) {
|
|
792952
|
+
return this.buildExampleHelper({
|
|
792953
|
+
example,
|
|
792954
|
+
schema: schema2.value.schemas[0],
|
|
792955
|
+
visitedSchemaIds,
|
|
792956
|
+
depth,
|
|
792957
|
+
options
|
|
792958
|
+
});
|
|
792959
|
+
}
|
|
792960
|
+
break;
|
|
792961
|
+
}
|
|
792962
|
+
}
|
|
792963
|
+
return void 0;
|
|
792964
|
+
case "unknown":
|
|
792965
|
+
if (example != null) {
|
|
792966
|
+
const fullExample = convertToFullExample(example);
|
|
792967
|
+
if (fullExample != null) {
|
|
792968
|
+
return FullExample.unknown(fullExample);
|
|
792969
|
+
}
|
|
792970
|
+
}
|
|
792971
|
+
if (options.ignoreOptionals || this.exceedsMaxDepth(depth, options)) {
|
|
792972
|
+
return void 0;
|
|
792973
|
+
}
|
|
792974
|
+
if (options.isParameter) {
|
|
792975
|
+
return FullExample.primitive(PrimitiveExample.string(options.name ?? "string"));
|
|
792976
|
+
}
|
|
792977
|
+
return FullExample.map([
|
|
792978
|
+
{
|
|
792979
|
+
key: PrimitiveExample.string("key"),
|
|
792980
|
+
value: FullExample.primitive(PrimitiveExample.string("value"))
|
|
792981
|
+
}
|
|
792982
|
+
]);
|
|
792983
|
+
case "array": {
|
|
792984
|
+
const fullExample = getFullExampleAsArray(example);
|
|
792985
|
+
const itemExamples = [];
|
|
792986
|
+
if (fullExample != null && fullExample.length > 0) {
|
|
792987
|
+
for (const item of fullExample) {
|
|
792988
|
+
const itemExample2 = this.buildExampleHelper({
|
|
792989
|
+
example: item,
|
|
792990
|
+
schema: schema2.value,
|
|
792991
|
+
depth: depth + 1,
|
|
792992
|
+
visitedSchemaIds,
|
|
792993
|
+
options
|
|
792994
|
+
});
|
|
792995
|
+
if (itemExample2 != null) {
|
|
792996
|
+
itemExamples.push(itemExample2);
|
|
792997
|
+
}
|
|
792998
|
+
}
|
|
792999
|
+
}
|
|
793000
|
+
const itemExample = this.buildExampleHelper({
|
|
793001
|
+
example: void 0,
|
|
793002
|
+
schema: schema2.value,
|
|
793003
|
+
depth: depth + 1,
|
|
793004
|
+
visitedSchemaIds,
|
|
793005
|
+
options
|
|
793006
|
+
});
|
|
793007
|
+
if (itemExample != null) {
|
|
793008
|
+
itemExamples.push(itemExample);
|
|
793009
|
+
}
|
|
793010
|
+
return FullExample.array(itemExamples);
|
|
793011
|
+
}
|
|
793012
|
+
case "map": {
|
|
793013
|
+
const objectExample = getFullExampleAsObject(example);
|
|
793014
|
+
if (objectExample != null && Object.entries(objectExample).length > 0) {
|
|
793015
|
+
const kvs = [];
|
|
793016
|
+
for (const [key2, value] of Object.entries(objectExample)) {
|
|
793017
|
+
const keyExample2 = this.buildExampleFromPrimitive({
|
|
793018
|
+
schema: schema2.key.schema,
|
|
793019
|
+
example: key2,
|
|
793020
|
+
options
|
|
793021
|
+
});
|
|
793022
|
+
const valueExample2 = this.buildExampleHelper({
|
|
793023
|
+
example: value,
|
|
793024
|
+
schema: schema2.value,
|
|
793025
|
+
visitedSchemaIds,
|
|
793026
|
+
depth: depth + 1,
|
|
793027
|
+
options
|
|
793028
|
+
});
|
|
793029
|
+
if (valueExample2 != null) {
|
|
793030
|
+
kvs.push({
|
|
793031
|
+
key: keyExample2,
|
|
793032
|
+
value: valueExample2
|
|
793033
|
+
});
|
|
793034
|
+
}
|
|
793035
|
+
}
|
|
793036
|
+
return FullExample.map(kvs);
|
|
793037
|
+
}
|
|
793038
|
+
const keyExample = this.buildExampleFromPrimitive({
|
|
793039
|
+
schema: schema2.key.schema,
|
|
793040
|
+
example: void 0,
|
|
793041
|
+
options
|
|
793042
|
+
});
|
|
793043
|
+
const valueExample = this.buildExampleHelper({
|
|
793044
|
+
example: void 0,
|
|
793045
|
+
schema: schema2.value,
|
|
793046
|
+
visitedSchemaIds,
|
|
793047
|
+
depth: depth + 1,
|
|
793048
|
+
options
|
|
793049
|
+
});
|
|
793050
|
+
if (valueExample != null) {
|
|
793051
|
+
return FullExample.map([
|
|
793052
|
+
{
|
|
793053
|
+
key: keyExample,
|
|
793054
|
+
value: valueExample
|
|
793055
|
+
}
|
|
793056
|
+
]);
|
|
793057
|
+
}
|
|
793058
|
+
return FullExample.map([]);
|
|
793059
|
+
}
|
|
793060
|
+
case "object": {
|
|
793061
|
+
const result2 = {};
|
|
793062
|
+
const fullExample = getFullExampleAsObject(example) ?? (((_b2 = schema2.fullExamples) == null ? void 0 : _b2[0]) != null ? getFullExampleAsObject(schema2.fullExamples[0].value) : {}) ?? {};
|
|
793063
|
+
const allProperties = this.getAllProperties(schema2);
|
|
793064
|
+
const requiredProperties = this.getAllRequiredProperties(schema2);
|
|
793065
|
+
for (const [property4, schema3] of Object.entries(allProperties)) {
|
|
793066
|
+
const required = property4 in requiredProperties;
|
|
793067
|
+
const propertyExample = this.buildExampleHelper({
|
|
793068
|
+
schema: schema3,
|
|
793069
|
+
example: fullExample[property4],
|
|
793070
|
+
visitedSchemaIds,
|
|
793071
|
+
depth: depth + 1,
|
|
793072
|
+
options: {
|
|
793073
|
+
...options,
|
|
793074
|
+
name: property4
|
|
793075
|
+
}
|
|
793076
|
+
});
|
|
793077
|
+
if (propertyExample != null) {
|
|
793078
|
+
result2[property4] = propertyExample;
|
|
793079
|
+
} else if (required) {
|
|
793080
|
+
const generatedExample = this.buildExampleHelper({
|
|
793081
|
+
schema: schema3,
|
|
793082
|
+
example: fullExample[property4],
|
|
793083
|
+
visitedSchemaIds,
|
|
793084
|
+
depth: depth + 1,
|
|
793085
|
+
options: {
|
|
793086
|
+
...options,
|
|
793087
|
+
name: property4
|
|
793088
|
+
}
|
|
793089
|
+
});
|
|
793090
|
+
if (generatedExample == null) {
|
|
793091
|
+
return void 0;
|
|
793092
|
+
}
|
|
793093
|
+
result2[property4] = generatedExample;
|
|
793094
|
+
}
|
|
793095
|
+
}
|
|
793096
|
+
return FullExample.object({
|
|
793097
|
+
properties: result2
|
|
793098
|
+
});
|
|
793099
|
+
}
|
|
793100
|
+
default:
|
|
793101
|
+
assertNever(schema2);
|
|
793102
|
+
}
|
|
793103
|
+
}
|
|
793104
|
+
hasExample(schema2) {
|
|
793105
|
+
switch (schema2.type) {
|
|
793106
|
+
case "array":
|
|
793107
|
+
return this.hasExample(schema2.value);
|
|
793108
|
+
case "enum":
|
|
793109
|
+
return schema2.example != null;
|
|
793110
|
+
case "literal":
|
|
793111
|
+
return false;
|
|
793112
|
+
case "map":
|
|
793113
|
+
return schema2.key.schema.example != null && this.hasExample(schema2.value);
|
|
793114
|
+
case "object": {
|
|
793115
|
+
const objectExample = schema2.fullExamples != null && schema2.fullExamples.length > 0;
|
|
793116
|
+
if (objectExample) {
|
|
793117
|
+
return true;
|
|
793118
|
+
}
|
|
793119
|
+
for (const property4 of schema2.properties) {
|
|
793120
|
+
if (this.hasExample(property4.schema)) {
|
|
793121
|
+
return true;
|
|
793122
|
+
}
|
|
793123
|
+
}
|
|
793124
|
+
return false;
|
|
793125
|
+
}
|
|
793126
|
+
case "primitive":
|
|
793127
|
+
return schema2.schema.example != null;
|
|
793128
|
+
case "reference": {
|
|
793129
|
+
const resolvedSchema = this.schemas[schema2.schema];
|
|
793130
|
+
if (resolvedSchema != null) {
|
|
793131
|
+
return this.hasExample(resolvedSchema);
|
|
793132
|
+
}
|
|
793133
|
+
return false;
|
|
793134
|
+
}
|
|
793135
|
+
case "unknown":
|
|
793136
|
+
return schema2.example != null;
|
|
793137
|
+
case "oneOf":
|
|
793138
|
+
return Object.values(schema2.value.schemas).some((schema3) => this.hasExample(schema3));
|
|
793139
|
+
default:
|
|
793140
|
+
return false;
|
|
793141
|
+
}
|
|
793142
|
+
}
|
|
793143
|
+
exceedsMaxDepth(depth, options) {
|
|
793144
|
+
return depth > (options.maxDepth ?? 0);
|
|
793145
|
+
}
|
|
793146
|
+
getAllProperties(object3) {
|
|
793147
|
+
let properties = {};
|
|
793148
|
+
for (const property4 of object3.properties) {
|
|
793149
|
+
properties[property4.key] = property4.schema;
|
|
793150
|
+
}
|
|
793151
|
+
for (const allOf of object3.allOf) {
|
|
793152
|
+
const allOfSchema = this.schemas[allOf.schema];
|
|
793153
|
+
if (allOfSchema == null) {
|
|
793154
|
+
continue;
|
|
793155
|
+
}
|
|
793156
|
+
const resolvedAllOfSchema = this.getResolvedSchema(allOfSchema);
|
|
793157
|
+
if (resolvedAllOfSchema.type !== "object") {
|
|
793158
|
+
continue;
|
|
793159
|
+
}
|
|
793160
|
+
properties = {
|
|
793161
|
+
...this.getAllProperties(resolvedAllOfSchema),
|
|
793162
|
+
...properties
|
|
793163
|
+
};
|
|
793164
|
+
}
|
|
793165
|
+
return properties;
|
|
793166
|
+
}
|
|
793167
|
+
getAllRequiredProperties(object3) {
|
|
793168
|
+
let requiredProperties = {};
|
|
793169
|
+
for (const property4 of object3.properties) {
|
|
793170
|
+
const resolvedSchema = this.getResolvedSchema(property4.schema);
|
|
793171
|
+
if (resolvedSchema.type !== "optional" && resolvedSchema.type !== "nullable") {
|
|
793172
|
+
requiredProperties[property4.key] = property4.schema;
|
|
793173
|
+
}
|
|
793174
|
+
}
|
|
793175
|
+
for (const allOf of object3.allOf) {
|
|
793176
|
+
const allOfSchema = this.schemas[allOf.schema];
|
|
793177
|
+
if (allOfSchema == null) {
|
|
793178
|
+
continue;
|
|
793179
|
+
}
|
|
793180
|
+
const resolvedAllOfSchema = this.getResolvedSchema(allOfSchema);
|
|
793181
|
+
if (resolvedAllOfSchema.type !== "object") {
|
|
793182
|
+
continue;
|
|
793183
|
+
}
|
|
793184
|
+
requiredProperties = {
|
|
793185
|
+
...this.getAllRequiredProperties(resolvedAllOfSchema),
|
|
793186
|
+
...requiredProperties
|
|
793187
|
+
};
|
|
793188
|
+
}
|
|
793189
|
+
return requiredProperties;
|
|
793190
|
+
}
|
|
793191
|
+
getResolvedSchema(schema2) {
|
|
793192
|
+
while (schema2.type === "reference") {
|
|
793193
|
+
const resolvedSchema = this.schemas[schema2.schema];
|
|
793194
|
+
if (resolvedSchema == null) {
|
|
793195
|
+
throw new Error(`Unexpected error: Failed to resolve schema reference: ${schema2.schema}`);
|
|
793196
|
+
}
|
|
793197
|
+
schema2 = resolvedSchema;
|
|
793198
|
+
}
|
|
793199
|
+
return schema2;
|
|
793200
|
+
}
|
|
793201
|
+
buildExampleFromPrimitive({ example, schema: schema2, options }) {
|
|
793202
|
+
switch (schema2.type) {
|
|
793203
|
+
case "string":
|
|
793204
|
+
if (example != null && typeof example === "string") {
|
|
793205
|
+
return PrimitiveExample.string(example);
|
|
793206
|
+
} else if (schema2.example != null) {
|
|
793207
|
+
return PrimitiveExample.string(schema2.example);
|
|
793208
|
+
} else {
|
|
793209
|
+
return PrimitiveExample.string(options.name ?? "string");
|
|
793210
|
+
}
|
|
793211
|
+
case "base64":
|
|
793212
|
+
if (example != null && typeof example === "string") {
|
|
793213
|
+
return PrimitiveExample.base64(example);
|
|
793214
|
+
} else if (schema2.example != null) {
|
|
793215
|
+
return PrimitiveExample.base64(schema2.example);
|
|
793216
|
+
} else {
|
|
793217
|
+
return PrimitiveExample.base64("SGVsbG8gd29ybGQh");
|
|
793218
|
+
}
|
|
793219
|
+
case "boolean":
|
|
793220
|
+
if (example != null && typeof example === "boolean") {
|
|
793221
|
+
return PrimitiveExample.boolean(example);
|
|
793222
|
+
} else if (schema2.example != null) {
|
|
793223
|
+
return PrimitiveExample.boolean(schema2.example);
|
|
793224
|
+
} else {
|
|
793225
|
+
return PrimitiveExample.boolean(true);
|
|
793226
|
+
}
|
|
793227
|
+
case "date":
|
|
793228
|
+
if (example != null && typeof example === "string") {
|
|
793229
|
+
return PrimitiveExample.date(example);
|
|
793230
|
+
} else if (schema2.example != null) {
|
|
793231
|
+
return PrimitiveExample.date(schema2.example);
|
|
793232
|
+
} else {
|
|
793233
|
+
return PrimitiveExample.date("2023-01-15");
|
|
793234
|
+
}
|
|
793235
|
+
case "datetime":
|
|
793236
|
+
if (example != null && typeof example === "string") {
|
|
793237
|
+
return PrimitiveExample.datetime(new Date(example));
|
|
793238
|
+
} else if (schema2.example != null) {
|
|
793239
|
+
return PrimitiveExample.datetime(new Date(schema2.example));
|
|
793240
|
+
} else {
|
|
793241
|
+
return PrimitiveExample.datetime(new Date("2024-01-15T09:30:00Z"));
|
|
793242
|
+
}
|
|
793243
|
+
case "double":
|
|
793244
|
+
if (example != null && typeof example === "number") {
|
|
793245
|
+
return PrimitiveExample.double(example);
|
|
793246
|
+
} else if (schema2.example != null) {
|
|
793247
|
+
return PrimitiveExample.double(schema2.example);
|
|
793248
|
+
} else {
|
|
793249
|
+
return PrimitiveExample.double(1.1);
|
|
793250
|
+
}
|
|
793251
|
+
case "float":
|
|
793252
|
+
if (example != null && typeof example === "number") {
|
|
793253
|
+
return PrimitiveExample.float(example);
|
|
793254
|
+
} else if (schema2.example != null) {
|
|
793255
|
+
return PrimitiveExample.float(schema2.example);
|
|
793256
|
+
} else {
|
|
793257
|
+
return PrimitiveExample.float(1.1);
|
|
793258
|
+
}
|
|
793259
|
+
case "int":
|
|
793260
|
+
if (example != null && typeof example === "number") {
|
|
793261
|
+
return PrimitiveExample.int(example);
|
|
793262
|
+
} else if (schema2.example != null) {
|
|
793263
|
+
return PrimitiveExample.int(schema2.example);
|
|
793264
|
+
} else {
|
|
793265
|
+
return PrimitiveExample.int(1);
|
|
793266
|
+
}
|
|
793267
|
+
case "int64":
|
|
793268
|
+
if (example != null && typeof example === "number") {
|
|
793269
|
+
return PrimitiveExample.int64(example);
|
|
793270
|
+
} else if (schema2.example != null) {
|
|
793271
|
+
return PrimitiveExample.int64(schema2.example);
|
|
793272
|
+
} else {
|
|
793273
|
+
return PrimitiveExample.int64(1e6);
|
|
793274
|
+
}
|
|
793275
|
+
default:
|
|
793276
|
+
assertNever(schema2);
|
|
793277
|
+
}
|
|
793278
|
+
}
|
|
793279
|
+
};
|
|
793280
|
+
function enumContainsValue({ schema: schema2, value }) {
|
|
793281
|
+
return schema2.values.map((enumValue) => {
|
|
793282
|
+
return enumValue.value;
|
|
793283
|
+
}).includes(value);
|
|
793284
|
+
}
|
|
793285
|
+
|
|
793286
|
+
// pnp:/home/circleci/project/packages/cli/openapi-parser/lib/schema/utils/isSchemaRequired.js
|
|
793287
|
+
function isSchemaRequired3(schema2) {
|
|
793288
|
+
return schema2.type !== "optional" && schema2.type !== "nullable";
|
|
793289
|
+
}
|
|
793290
|
+
|
|
793291
|
+
// pnp:/home/circleci/project/packages/cli/openapi-parser/lib/openapi/v3/converters/ExampleEndpointFactory.js
|
|
793292
|
+
var ExampleEndpointFactory = class {
|
|
793293
|
+
exampleTypeFactory;
|
|
793294
|
+
logger;
|
|
793295
|
+
schemas;
|
|
793296
|
+
constructor(schemas, logger) {
|
|
793297
|
+
this.schemas = schemas;
|
|
793298
|
+
this.exampleTypeFactory = new ExampleTypeFactory(schemas);
|
|
793299
|
+
this.logger = logger;
|
|
793300
|
+
}
|
|
793301
|
+
buildEndpointExample(endpoint) {
|
|
793302
|
+
var _a2, _b2, _c2;
|
|
793303
|
+
this.logger.debug(`Building endpoint example for ${endpoint.method.toUpperCase()} ${endpoint.path}`);
|
|
793304
|
+
const requestSchemaIdResponse = getRequestSchema(endpoint.request);
|
|
793305
|
+
const responseSchemaIdResponse = getResponseSchema(endpoint.response);
|
|
793306
|
+
if ((requestSchemaIdResponse == null ? void 0 : requestSchemaIdResponse.type) === "unsupported" || (responseSchemaIdResponse == null ? void 0 : responseSchemaIdResponse.type) === "unsupported") {
|
|
793307
|
+
return void 0;
|
|
793308
|
+
}
|
|
793309
|
+
let requestExample = void 0;
|
|
793310
|
+
if (requestSchemaIdResponse != null) {
|
|
793311
|
+
const required = this.isSchemaRequired(requestSchemaIdResponse.schema);
|
|
793312
|
+
requestExample = this.exampleTypeFactory.buildExample({
|
|
793313
|
+
schema: requestSchemaIdResponse.schema,
|
|
793314
|
+
example: (_a2 = requestSchemaIdResponse.example) == null ? void 0 : _a2.value,
|
|
793315
|
+
options: {
|
|
793316
|
+
isParameter: false,
|
|
793317
|
+
ignoreOptionals: true
|
|
793318
|
+
}
|
|
793319
|
+
});
|
|
793320
|
+
if (required && requestExample == null) {
|
|
793321
|
+
return void 0;
|
|
793322
|
+
}
|
|
793323
|
+
}
|
|
793324
|
+
let responseExample = void 0;
|
|
793325
|
+
if (responseSchemaIdResponse != null) {
|
|
793326
|
+
const required = this.isSchemaRequired(responseSchemaIdResponse.schema);
|
|
793327
|
+
responseExample = this.exampleTypeFactory.buildExample({
|
|
793328
|
+
schema: responseSchemaIdResponse.schema,
|
|
793329
|
+
example: (_b2 = responseSchemaIdResponse.example) == null ? void 0 : _b2.value,
|
|
793330
|
+
options: {
|
|
793331
|
+
isParameter: false,
|
|
793332
|
+
ignoreOptionals: false,
|
|
793333
|
+
maxDepth: 3
|
|
793334
|
+
}
|
|
793335
|
+
});
|
|
793336
|
+
if (required && responseExample == null) {
|
|
793337
|
+
return void 0;
|
|
793338
|
+
}
|
|
793339
|
+
}
|
|
793340
|
+
const pathParameters = [];
|
|
793341
|
+
for (const pathParameter of endpoint.pathParameters) {
|
|
793342
|
+
const required = this.isSchemaRequired(pathParameter.schema);
|
|
793343
|
+
let example = this.exampleTypeFactory.buildExample({
|
|
793344
|
+
schema: pathParameter.schema,
|
|
793345
|
+
example: void 0,
|
|
793346
|
+
options: {
|
|
793347
|
+
name: pathParameter.name,
|
|
793348
|
+
isParameter: true,
|
|
793349
|
+
ignoreOptionals: true
|
|
793350
|
+
}
|
|
793351
|
+
});
|
|
793352
|
+
if (example != null && !isExamplePrimitive(example)) {
|
|
793353
|
+
example = void 0;
|
|
793354
|
+
}
|
|
793355
|
+
if (required && example == null) {
|
|
793356
|
+
return void 0;
|
|
793357
|
+
} else if (example != null) {
|
|
793358
|
+
pathParameters.push({
|
|
793359
|
+
name: pathParameter.name,
|
|
793360
|
+
value: example
|
|
793361
|
+
});
|
|
793362
|
+
}
|
|
793363
|
+
}
|
|
793364
|
+
const queryParameters = [];
|
|
793365
|
+
for (const queryParameter of endpoint.queryParameters) {
|
|
793366
|
+
const required = this.isSchemaRequired(queryParameter.schema);
|
|
793367
|
+
let example = this.exampleTypeFactory.buildExample({
|
|
793368
|
+
schema: queryParameter.schema,
|
|
793369
|
+
example: void 0,
|
|
793370
|
+
options: {
|
|
793371
|
+
name: queryParameter.name,
|
|
793372
|
+
isParameter: true,
|
|
793373
|
+
ignoreOptionals: true
|
|
793374
|
+
}
|
|
793375
|
+
});
|
|
793376
|
+
if (example != null && !isExamplePrimitive(example)) {
|
|
793377
|
+
example = void 0;
|
|
793378
|
+
}
|
|
793379
|
+
if (required && example == null) {
|
|
793380
|
+
return void 0;
|
|
793381
|
+
} else if (example != null) {
|
|
793382
|
+
queryParameters.push({
|
|
793383
|
+
name: queryParameter.name,
|
|
793384
|
+
value: example
|
|
793385
|
+
});
|
|
793386
|
+
}
|
|
793387
|
+
}
|
|
793388
|
+
const headers = [];
|
|
793389
|
+
for (const header of endpoint.headers) {
|
|
793390
|
+
const required = this.isSchemaRequired(header.schema);
|
|
793391
|
+
let example = this.exampleTypeFactory.buildExample({
|
|
793392
|
+
schema: header.schema,
|
|
793393
|
+
example: void 0,
|
|
793394
|
+
options: {
|
|
793395
|
+
name: header.name,
|
|
793396
|
+
isParameter: true,
|
|
793397
|
+
ignoreOptionals: true
|
|
793398
|
+
}
|
|
793399
|
+
});
|
|
793400
|
+
if (example != null && !isExamplePrimitive(example)) {
|
|
793401
|
+
example = void 0;
|
|
793402
|
+
}
|
|
793403
|
+
if (required && example == null) {
|
|
793404
|
+
return void 0;
|
|
793405
|
+
} else if (example != null) {
|
|
793406
|
+
headers.push({
|
|
793407
|
+
name: header.name,
|
|
793408
|
+
value: example
|
|
793409
|
+
});
|
|
793410
|
+
}
|
|
793411
|
+
}
|
|
793412
|
+
let exampleName = (_c2 = requestSchemaIdResponse == null ? void 0 : requestSchemaIdResponse.example) == null ? void 0 : _c2.name;
|
|
793413
|
+
if (exampleName == null && (requestSchemaIdResponse == null ? void 0 : requestSchemaIdResponse.schema) != null) {
|
|
793414
|
+
exampleName = getNameFromSchemaWithExample(requestSchemaIdResponse.schema);
|
|
793415
|
+
}
|
|
793416
|
+
return {
|
|
793417
|
+
name: exampleName,
|
|
793418
|
+
description: void 0,
|
|
793419
|
+
pathParameters,
|
|
793420
|
+
queryParameters,
|
|
793421
|
+
headers,
|
|
793422
|
+
request: requestExample,
|
|
793423
|
+
response: responseExample,
|
|
793424
|
+
codeSamples: []
|
|
793425
|
+
};
|
|
793426
|
+
}
|
|
793427
|
+
isSchemaRequired(schema2) {
|
|
793428
|
+
return isSchemaRequired3(this.getResolvedSchema(schema2));
|
|
793429
|
+
}
|
|
793430
|
+
getResolvedSchema(schema2) {
|
|
793431
|
+
while (schema2.type === "reference") {
|
|
793432
|
+
const resolvedSchema = this.schemas[schema2.schema];
|
|
793433
|
+
if (resolvedSchema == null) {
|
|
793434
|
+
throw new Error(`Unexpected error: Failed to resolve schema reference: ${schema2.schema}`);
|
|
793435
|
+
}
|
|
793436
|
+
schema2 = resolvedSchema;
|
|
793437
|
+
}
|
|
793438
|
+
return schema2;
|
|
793439
|
+
}
|
|
793440
|
+
};
|
|
793441
|
+
function getRequestSchema(request) {
|
|
793442
|
+
var _a2;
|
|
793443
|
+
if (request == null) {
|
|
793444
|
+
return void 0;
|
|
793445
|
+
}
|
|
793446
|
+
if (request.type !== "json") {
|
|
793447
|
+
return { type: "unsupported" };
|
|
793448
|
+
}
|
|
793449
|
+
return { type: "present", schema: request.schema, example: ((_a2 = request.fullExamples) == null ? void 0 : _a2[0]) ?? void 0 };
|
|
793450
|
+
}
|
|
793451
|
+
function getResponseSchema(response) {
|
|
793452
|
+
var _a2;
|
|
793453
|
+
if (response == null) {
|
|
793454
|
+
return void 0;
|
|
793455
|
+
}
|
|
793456
|
+
if (response.type !== "json") {
|
|
793457
|
+
return { type: "unsupported" };
|
|
793458
|
+
}
|
|
793459
|
+
return { type: "present", schema: response.schema, example: ((_a2 = response.fullExamples) == null ? void 0 : _a2[0]) ?? void 0 };
|
|
793460
|
+
}
|
|
793461
|
+
function isExamplePrimitive(example) {
|
|
793462
|
+
switch (example.type) {
|
|
793463
|
+
case "primitive":
|
|
793464
|
+
case "enum":
|
|
793465
|
+
case "literal":
|
|
793466
|
+
return true;
|
|
793467
|
+
case "unknown":
|
|
793468
|
+
return isExamplePrimitive(example);
|
|
793469
|
+
case "array":
|
|
793470
|
+
case "object":
|
|
793471
|
+
case "map":
|
|
793472
|
+
return false;
|
|
793473
|
+
case "oneOf":
|
|
793474
|
+
switch (example.value.type) {
|
|
793475
|
+
case "discriminated":
|
|
793476
|
+
return false;
|
|
793477
|
+
case "undisciminated":
|
|
793478
|
+
return isExamplePrimitive(example.value.value);
|
|
793479
|
+
default:
|
|
793480
|
+
return false;
|
|
793481
|
+
}
|
|
793482
|
+
default:
|
|
793483
|
+
assertNever(example);
|
|
793484
|
+
}
|
|
793485
|
+
}
|
|
793486
|
+
function getNameFromSchemaWithExample(schema2) {
|
|
793487
|
+
var _a2, _b2;
|
|
793488
|
+
switch (schema2.type) {
|
|
793489
|
+
case "primitive":
|
|
793490
|
+
case "enum":
|
|
793491
|
+
case "literal":
|
|
793492
|
+
case "unknown":
|
|
793493
|
+
case "array":
|
|
793494
|
+
case "map":
|
|
793495
|
+
case "optional":
|
|
793496
|
+
case "nullable":
|
|
793497
|
+
case "reference":
|
|
793498
|
+
return void 0;
|
|
793499
|
+
case "object":
|
|
793500
|
+
return ((_b2 = (_a2 = schema2.fullExamples) == null ? void 0 : _a2[0]) == null ? void 0 : _b2.name) ?? void 0;
|
|
793501
|
+
case "oneOf":
|
|
793502
|
+
switch (schema2.value.type) {
|
|
793503
|
+
case "discriminated":
|
|
793504
|
+
return void 0;
|
|
793505
|
+
case "undisciminated":
|
|
793506
|
+
return void 0;
|
|
793507
|
+
default:
|
|
793508
|
+
return void 0;
|
|
793509
|
+
}
|
|
793510
|
+
default:
|
|
793511
|
+
assertNever(schema2);
|
|
793512
|
+
}
|
|
793513
|
+
}
|
|
793514
|
+
|
|
793515
|
+
// pnp:/home/circleci/project/packages/cli/openapi-parser/lib/asyncapi/ExampleWebsocketSessionFactory.js
|
|
793516
|
+
var ExampleWebsocketSessionFactory = class {
|
|
793517
|
+
exampleTypeFactory;
|
|
793518
|
+
schemas;
|
|
793519
|
+
constructor(schemas, logger) {
|
|
793520
|
+
this.exampleTypeFactory = new ExampleTypeFactory(schemas);
|
|
793521
|
+
this.schemas = schemas;
|
|
793522
|
+
}
|
|
793523
|
+
buildWebsocketSessionExample({ publish: publish2, subscribe, handshake }) {
|
|
793524
|
+
const example = {
|
|
793525
|
+
name: void 0,
|
|
793526
|
+
queryParameters: [],
|
|
793527
|
+
headers: [],
|
|
793528
|
+
description: void 0,
|
|
793529
|
+
messages: []
|
|
793530
|
+
};
|
|
793531
|
+
const queryParameters = [];
|
|
793532
|
+
for (const queryParameter of handshake.queryParameters) {
|
|
793533
|
+
const required = this.isSchemaRequired(queryParameter.schema);
|
|
793534
|
+
let example2 = this.exampleTypeFactory.buildExample({
|
|
793535
|
+
schema: queryParameter.schema,
|
|
793536
|
+
example: void 0,
|
|
793537
|
+
options: {
|
|
793538
|
+
name: queryParameter.name,
|
|
793539
|
+
isParameter: true,
|
|
793540
|
+
ignoreOptionals: true
|
|
793541
|
+
}
|
|
793542
|
+
});
|
|
793543
|
+
if (example2 != null && !isExamplePrimitive(example2)) {
|
|
793544
|
+
example2 = void 0;
|
|
793545
|
+
}
|
|
793546
|
+
if (required && example2 == null) {
|
|
793547
|
+
return void 0;
|
|
793548
|
+
} else if (example2 != null) {
|
|
793549
|
+
queryParameters.push({
|
|
793550
|
+
name: queryParameter.name,
|
|
793551
|
+
value: example2
|
|
793552
|
+
});
|
|
793553
|
+
}
|
|
793554
|
+
}
|
|
793555
|
+
const headers = [];
|
|
793556
|
+
for (const header of handshake.headers) {
|
|
793557
|
+
const required = this.isSchemaRequired(header.schema);
|
|
793558
|
+
let example2 = this.exampleTypeFactory.buildExample({
|
|
793559
|
+
schema: header.schema,
|
|
793560
|
+
example: void 0,
|
|
793561
|
+
options: {
|
|
793562
|
+
name: header.name,
|
|
793563
|
+
isParameter: true,
|
|
793564
|
+
ignoreOptionals: true
|
|
793565
|
+
}
|
|
793566
|
+
});
|
|
793567
|
+
if (example2 != null && !isExamplePrimitive(example2)) {
|
|
793568
|
+
example2 = void 0;
|
|
793569
|
+
}
|
|
793570
|
+
if (required && example2 == null) {
|
|
793571
|
+
return void 0;
|
|
793572
|
+
} else if (example2 != null) {
|
|
793573
|
+
headers.push({
|
|
793574
|
+
name: header.name,
|
|
793575
|
+
value: example2
|
|
793576
|
+
});
|
|
793577
|
+
}
|
|
793578
|
+
}
|
|
793579
|
+
if (publish2 != null) {
|
|
793580
|
+
const publishMessageExample = this.exampleTypeFactory.buildExample({
|
|
793581
|
+
schema: publish2,
|
|
793582
|
+
example: void 0,
|
|
793583
|
+
options: {
|
|
793584
|
+
isParameter: false,
|
|
793585
|
+
ignoreOptionals: true
|
|
793586
|
+
}
|
|
793587
|
+
});
|
|
793588
|
+
if (publishMessageExample != null) {
|
|
793589
|
+
example.messages.push({
|
|
793590
|
+
messageType: "publish",
|
|
793591
|
+
payload: publishMessageExample,
|
|
793592
|
+
description: void 0
|
|
793593
|
+
});
|
|
793594
|
+
}
|
|
793595
|
+
}
|
|
793596
|
+
if (subscribe != null) {
|
|
793597
|
+
const publishMessageExample = this.exampleTypeFactory.buildExample({
|
|
793598
|
+
schema: subscribe,
|
|
793599
|
+
example: void 0,
|
|
793600
|
+
options: {
|
|
793601
|
+
isParameter: false,
|
|
793602
|
+
ignoreOptionals: true
|
|
793603
|
+
}
|
|
793604
|
+
});
|
|
793605
|
+
if (publishMessageExample != null) {
|
|
793606
|
+
example.messages.push({
|
|
793607
|
+
messageType: "subscribe",
|
|
793608
|
+
payload: publishMessageExample,
|
|
793609
|
+
description: void 0
|
|
793610
|
+
});
|
|
793611
|
+
}
|
|
793612
|
+
}
|
|
793613
|
+
return example;
|
|
793614
|
+
}
|
|
793615
|
+
isSchemaRequired(schema2) {
|
|
793616
|
+
return isSchemaRequired3(this.getResolvedSchema(schema2));
|
|
793617
|
+
}
|
|
793618
|
+
getResolvedSchema(schema2) {
|
|
793619
|
+
while (schema2.type === "reference") {
|
|
793620
|
+
const resolvedSchema = this.schemas[schema2.schema];
|
|
793621
|
+
if (resolvedSchema == null) {
|
|
793622
|
+
throw new Error(`Unexpected error: Failed to resolve schema reference: ${schema2.schema}`);
|
|
793623
|
+
}
|
|
793624
|
+
schema2 = resolvedSchema;
|
|
793625
|
+
}
|
|
793626
|
+
return schema2;
|
|
793627
|
+
}
|
|
793628
|
+
};
|
|
793629
|
+
|
|
792696
793630
|
// pnp:/home/circleci/project/packages/cli/openapi-parser/lib/asyncapi/parse.js
|
|
792697
793631
|
function parseAsyncAPI({ document: document4, taskContext }) {
|
|
792698
793632
|
var _a2, _b2, _c2, _d;
|
|
@@ -792705,8 +793639,13 @@ function parseAsyncAPI({ document: document4, taskContext }) {
|
|
|
792705
793639
|
const context = new AsyncAPIV2ParserContext({ document: document4, taskContext });
|
|
792706
793640
|
const schemas = {};
|
|
792707
793641
|
let parsedChannel = void 0;
|
|
793642
|
+
for (const [schemaId, schema2] of Object.entries(((_b2 = document4.components) == null ? void 0 : _b2.schemas) ?? {})) {
|
|
793643
|
+
const convertedSchema = convertSchema(schema2, false, context, [schemaId]);
|
|
793644
|
+
schemas[schemaId] = convertedSchema;
|
|
793645
|
+
}
|
|
793646
|
+
const exampleFactory = new ExampleWebsocketSessionFactory(schemas, taskContext.logger);
|
|
792708
793647
|
for (const [channelPath, channel] of Object.entries(document4.channels ?? {})) {
|
|
792709
|
-
if (((
|
|
793648
|
+
if (((_c2 = channel.bindings) == null ? void 0 : _c2.ws) == null) {
|
|
792710
793649
|
context.logger.error(`Channel ${channelPath} does not have websocket bindings. Skipping.`);
|
|
792711
793650
|
continue;
|
|
792712
793651
|
}
|
|
@@ -792755,28 +793694,43 @@ function parseAsyncAPI({ document: document4, taskContext }) {
|
|
|
792755
793694
|
});
|
|
792756
793695
|
}
|
|
792757
793696
|
if (headers.length > 0 || queryParameters.length > 0 || publishSchema != null || subscribeSchema != null) {
|
|
792758
|
-
const
|
|
792759
|
-
parsedChannel = {
|
|
793697
|
+
const example = exampleFactory.buildWebsocketSessionExample({
|
|
792760
793698
|
handshake: {
|
|
792761
793699
|
headers,
|
|
792762
793700
|
queryParameters
|
|
792763
793701
|
},
|
|
793702
|
+
publish: publishSchema,
|
|
793703
|
+
subscribe: subscribeSchema
|
|
793704
|
+
});
|
|
793705
|
+
const tag = (_d = document4.tags) == null ? void 0 : _d[0];
|
|
793706
|
+
parsedChannel = {
|
|
793707
|
+
handshake: {
|
|
793708
|
+
headers: headers.map((header) => {
|
|
793709
|
+
return {
|
|
793710
|
+
...header,
|
|
793711
|
+
schema: convertSchemaWithExampleToSchema(header.schema)
|
|
793712
|
+
};
|
|
793713
|
+
}),
|
|
793714
|
+
queryParameters: queryParameters.map((param) => {
|
|
793715
|
+
return {
|
|
793716
|
+
...param,
|
|
793717
|
+
schema: convertSchemaWithExampleToSchema(param.schema)
|
|
793718
|
+
};
|
|
793719
|
+
})
|
|
793720
|
+
},
|
|
792764
793721
|
groupName: (tag == null ? void 0 : tag.name) != null ? [tag.name] : ["Websocket"],
|
|
792765
793722
|
publish: publishSchema != null ? convertSchemaWithExampleToSchema(publishSchema) : publishSchema,
|
|
792766
793723
|
subscribe: subscribeSchema != null ? convertSchemaWithExampleToSchema(subscribeSchema) : subscribeSchema,
|
|
792767
793724
|
summary: void 0,
|
|
792768
793725
|
path: channelPath,
|
|
792769
|
-
description: void 0
|
|
793726
|
+
description: void 0,
|
|
793727
|
+
examples: example != null ? [example] : []
|
|
792770
793728
|
};
|
|
792771
793729
|
break;
|
|
792772
793730
|
}
|
|
792773
793731
|
}
|
|
792774
|
-
for (const [schemaId, schema2] of Object.entries(((_d = document4.components) == null ? void 0 : _d.schemas) ?? {})) {
|
|
792775
|
-
const convertedSchema = convertSchema(schema2, false, context, [schemaId]);
|
|
792776
|
-
schemas[schemaId] = convertedSchema;
|
|
792777
|
-
}
|
|
792778
793732
|
return {
|
|
792779
|
-
schemas,
|
|
793733
|
+
schemas: Object.fromEntries(Object.entries(schemas).map(([id, schema2]) => [id, convertSchemaWithExampleToSchema(schema2)])),
|
|
792780
793734
|
channel: parsedChannel
|
|
792781
793735
|
};
|
|
792782
793736
|
}
|
|
@@ -794106,755 +795060,6 @@ function convertToError({ statusCode, errorBodyCollector, context }) {
|
|
|
794106
795060
|
};
|
|
794107
795061
|
}
|
|
794108
795062
|
|
|
794109
|
-
// pnp:/home/circleci/project/packages/cli/openapi-parser/lib/schema/utils/isSchemaRequired.js
|
|
794110
|
-
function isSchemaRequired3(schema2) {
|
|
794111
|
-
return schema2.type !== "optional" && schema2.type !== "nullable";
|
|
794112
|
-
}
|
|
794113
|
-
|
|
794114
|
-
// pnp:/home/circleci/project/packages/cli/openapi-parser/lib/openapi/v3/converters/example/convertToFullExample.js
|
|
794115
|
-
function convertToFullExample(value) {
|
|
794116
|
-
if (typeof value === "string") {
|
|
794117
|
-
return FullExample.primitive(PrimitiveExample.string(value));
|
|
794118
|
-
} else if (typeof value === "number") {
|
|
794119
|
-
if (Number.isInteger(value)) {
|
|
794120
|
-
return FullExample.primitive(PrimitiveExample.int(value));
|
|
794121
|
-
}
|
|
794122
|
-
return FullExample.primitive(PrimitiveExample.double(value));
|
|
794123
|
-
} else if (typeof value === "boolean") {
|
|
794124
|
-
return FullExample.primitive(PrimitiveExample.boolean(value));
|
|
794125
|
-
} else if (value != null && typeof value === "object" && Object.keys(value).every((key2) => typeof key2 === "string")) {
|
|
794126
|
-
const kvs = [];
|
|
794127
|
-
for (const [property4, propertyValue] of Object.entries(value)) {
|
|
794128
|
-
const propertyExample = convertToFullExample(propertyValue);
|
|
794129
|
-
if (propertyExample != null) {
|
|
794130
|
-
kvs.push({
|
|
794131
|
-
key: PrimitiveExample.string(property4),
|
|
794132
|
-
value: propertyExample
|
|
794133
|
-
});
|
|
794134
|
-
}
|
|
794135
|
-
}
|
|
794136
|
-
return FullExample.map(kvs);
|
|
794137
|
-
}
|
|
794138
|
-
return void 0;
|
|
794139
|
-
}
|
|
794140
|
-
|
|
794141
|
-
// pnp:/home/circleci/project/packages/cli/openapi-parser/lib/openapi/v3/converters/example/getFullExample.js
|
|
794142
|
-
function getFullExampleAsObject(value) {
|
|
794143
|
-
if (value != null && typeof value === "object" && Object.keys(value).every((key2) => typeof key2 === "string")) {
|
|
794144
|
-
return value;
|
|
794145
|
-
}
|
|
794146
|
-
return void 0;
|
|
794147
|
-
}
|
|
794148
|
-
function getFullExampleAsArray(value) {
|
|
794149
|
-
if (value != null && Array.isArray(value)) {
|
|
794150
|
-
return value;
|
|
794151
|
-
}
|
|
794152
|
-
return void 0;
|
|
794153
|
-
}
|
|
794154
|
-
|
|
794155
|
-
// pnp:/home/circleci/project/packages/cli/openapi-parser/lib/openapi/v3/converters/example/ExampleTypeFactory.js
|
|
794156
|
-
var ExampleTypeFactory = class {
|
|
794157
|
-
schemas;
|
|
794158
|
-
constructor(schemas) {
|
|
794159
|
-
this.schemas = schemas;
|
|
794160
|
-
}
|
|
794161
|
-
buildExample({ schema: schema2, example, options }) {
|
|
794162
|
-
return this.buildExampleHelper({ schema: schema2, visitedSchemaIds: /* @__PURE__ */ new Set(), example, options, depth: 0 });
|
|
794163
|
-
}
|
|
794164
|
-
buildExampleHelper({ example, schema: schema2, depth, visitedSchemaIds, options }) {
|
|
794165
|
-
var _a2, _b2;
|
|
794166
|
-
switch (schema2.type) {
|
|
794167
|
-
case "enum":
|
|
794168
|
-
if (typeof example === "string" && enumContainsValue({ schema: schema2, value: example })) {
|
|
794169
|
-
return FullExample.enum(example);
|
|
794170
|
-
}
|
|
794171
|
-
return schema2.values[0] != null ? FullExample.enum((_a2 = schema2.values[0]) == null ? void 0 : _a2.value) : void 0;
|
|
794172
|
-
case "literal":
|
|
794173
|
-
return FullExample.literal(schema2.value);
|
|
794174
|
-
case "nullable": {
|
|
794175
|
-
if (example == null && !this.hasExample(schema2.value) && (options.ignoreOptionals || this.exceedsMaxDepth(depth, options))) {
|
|
794176
|
-
return void 0;
|
|
794177
|
-
}
|
|
794178
|
-
const result2 = this.buildExampleHelper({
|
|
794179
|
-
schema: schema2.value,
|
|
794180
|
-
visitedSchemaIds,
|
|
794181
|
-
example,
|
|
794182
|
-
depth,
|
|
794183
|
-
options
|
|
794184
|
-
});
|
|
794185
|
-
if (result2 != null && result2.type === "array" && result2.value.length === 0) {
|
|
794186
|
-
return void 0;
|
|
794187
|
-
}
|
|
794188
|
-
if (result2 != null && result2.type === "map" && result2.value.length === 0) {
|
|
794189
|
-
return void 0;
|
|
794190
|
-
}
|
|
794191
|
-
if (result2 != null && result2.type === "object" && Object.keys(result2.properties).length === 0) {
|
|
794192
|
-
return void 0;
|
|
794193
|
-
}
|
|
794194
|
-
return result2;
|
|
794195
|
-
}
|
|
794196
|
-
case "optional": {
|
|
794197
|
-
if (example == null && !this.hasExample(schema2.value) && (options.ignoreOptionals || this.exceedsMaxDepth(depth, options))) {
|
|
794198
|
-
return void 0;
|
|
794199
|
-
}
|
|
794200
|
-
const result2 = this.buildExampleHelper({
|
|
794201
|
-
schema: schema2.value,
|
|
794202
|
-
visitedSchemaIds,
|
|
794203
|
-
example,
|
|
794204
|
-
depth,
|
|
794205
|
-
options
|
|
794206
|
-
});
|
|
794207
|
-
if (result2 != null && result2.type === "array" && result2.value.length === 0) {
|
|
794208
|
-
return void 0;
|
|
794209
|
-
}
|
|
794210
|
-
if (result2 != null && result2.type === "map" && result2.value.length === 0) {
|
|
794211
|
-
return void 0;
|
|
794212
|
-
}
|
|
794213
|
-
if (result2 != null && result2.type === "object" && Object.keys(result2.properties).length === 0) {
|
|
794214
|
-
return void 0;
|
|
794215
|
-
}
|
|
794216
|
-
return result2;
|
|
794217
|
-
}
|
|
794218
|
-
case "primitive": {
|
|
794219
|
-
const primitiveExample = this.buildExampleFromPrimitive({ schema: schema2.schema, example, options });
|
|
794220
|
-
return FullExample.primitive(primitiveExample);
|
|
794221
|
-
}
|
|
794222
|
-
case "reference": {
|
|
794223
|
-
const referencedSchemaWithExample = this.schemas[schema2.schema];
|
|
794224
|
-
if (referencedSchemaWithExample != null && !visitedSchemaIds.has(schema2.schema)) {
|
|
794225
|
-
visitedSchemaIds.add(schema2.schema);
|
|
794226
|
-
const referencedExample = this.buildExampleHelper({
|
|
794227
|
-
example,
|
|
794228
|
-
schema: referencedSchemaWithExample,
|
|
794229
|
-
visitedSchemaIds,
|
|
794230
|
-
depth,
|
|
794231
|
-
options
|
|
794232
|
-
});
|
|
794233
|
-
visitedSchemaIds.delete(schema2.schema);
|
|
794234
|
-
return referencedExample;
|
|
794235
|
-
}
|
|
794236
|
-
return void 0;
|
|
794237
|
-
}
|
|
794238
|
-
case "oneOf":
|
|
794239
|
-
switch (schema2.value.type) {
|
|
794240
|
-
case "discriminated": {
|
|
794241
|
-
const result2 = {};
|
|
794242
|
-
let allProperties = {};
|
|
794243
|
-
let requiredProperties = {};
|
|
794244
|
-
const fullExample = getFullExampleAsObject(example);
|
|
794245
|
-
const exampleDiscriminant = fullExample == null ? void 0 : fullExample[schema2.value.discriminantProperty];
|
|
794246
|
-
const exampleUnionVariantSchema = schema2.value.schemas[exampleDiscriminant];
|
|
794247
|
-
const firstUnionVariant = Object.entries(schema2.value.schemas)[0];
|
|
794248
|
-
if (exampleDiscriminant != null && exampleUnionVariantSchema != null && exampleUnionVariantSchema.type === "object") {
|
|
794249
|
-
allProperties = this.getAllProperties(exampleUnionVariantSchema);
|
|
794250
|
-
requiredProperties = this.getAllRequiredProperties(exampleUnionVariantSchema);
|
|
794251
|
-
result2[schema2.value.discriminantProperty] = FullExample.primitive(PrimitiveExample.string(exampleDiscriminant));
|
|
794252
|
-
} else if (firstUnionVariant != null && firstUnionVariant[1].type === "object") {
|
|
794253
|
-
allProperties = this.getAllProperties(firstUnionVariant[1]);
|
|
794254
|
-
requiredProperties = this.getAllRequiredProperties(firstUnionVariant[1]);
|
|
794255
|
-
result2[schema2.value.discriminantProperty] = FullExample.primitive(PrimitiveExample.string(firstUnionVariant[0]));
|
|
794256
|
-
} else {
|
|
794257
|
-
return void 0;
|
|
794258
|
-
}
|
|
794259
|
-
for (const commonProperty of schema2.value.commonProperties) {
|
|
794260
|
-
allProperties[commonProperty.key] = commonProperty.schema;
|
|
794261
|
-
const resolvedSchema = this.getResolvedSchema(commonProperty.schema);
|
|
794262
|
-
if (resolvedSchema.type !== "optional" && resolvedSchema.type !== "nullable") {
|
|
794263
|
-
requiredProperties[commonProperty.key] = commonProperty.schema;
|
|
794264
|
-
}
|
|
794265
|
-
}
|
|
794266
|
-
for (const [property4, schema3] of Object.entries(allProperties)) {
|
|
794267
|
-
const required = property4 in requiredProperties;
|
|
794268
|
-
if (required && (fullExample == null ? void 0 : fullExample[property4]) != null) {
|
|
794269
|
-
const propertyExample = this.buildExampleHelper({
|
|
794270
|
-
schema: schema3,
|
|
794271
|
-
example: fullExample[property4],
|
|
794272
|
-
visitedSchemaIds,
|
|
794273
|
-
depth: depth + 1,
|
|
794274
|
-
options
|
|
794275
|
-
});
|
|
794276
|
-
if (propertyExample != null) {
|
|
794277
|
-
result2[property4] = propertyExample;
|
|
794278
|
-
} else {
|
|
794279
|
-
return void 0;
|
|
794280
|
-
}
|
|
794281
|
-
} else {
|
|
794282
|
-
const propertyExample = this.buildExampleHelper({
|
|
794283
|
-
schema: schema3,
|
|
794284
|
-
example: fullExample == null ? void 0 : fullExample[property4],
|
|
794285
|
-
visitedSchemaIds,
|
|
794286
|
-
depth: depth + 1,
|
|
794287
|
-
options
|
|
794288
|
-
});
|
|
794289
|
-
if (propertyExample != null) {
|
|
794290
|
-
result2[property4] = propertyExample;
|
|
794291
|
-
} else if (required) {
|
|
794292
|
-
return void 0;
|
|
794293
|
-
}
|
|
794294
|
-
}
|
|
794295
|
-
}
|
|
794296
|
-
return FullExample.oneOf(FullOneOfExample.discriminated(result2));
|
|
794297
|
-
}
|
|
794298
|
-
case "undisciminated": {
|
|
794299
|
-
if (schema2.value.schemas[0] != null) {
|
|
794300
|
-
return this.buildExampleHelper({
|
|
794301
|
-
example,
|
|
794302
|
-
schema: schema2.value.schemas[0],
|
|
794303
|
-
visitedSchemaIds,
|
|
794304
|
-
depth,
|
|
794305
|
-
options
|
|
794306
|
-
});
|
|
794307
|
-
}
|
|
794308
|
-
break;
|
|
794309
|
-
}
|
|
794310
|
-
}
|
|
794311
|
-
return void 0;
|
|
794312
|
-
case "unknown":
|
|
794313
|
-
if (example != null) {
|
|
794314
|
-
const fullExample = convertToFullExample(example);
|
|
794315
|
-
if (fullExample != null) {
|
|
794316
|
-
return FullExample.unknown(fullExample);
|
|
794317
|
-
}
|
|
794318
|
-
}
|
|
794319
|
-
if (options.ignoreOptionals || this.exceedsMaxDepth(depth, options)) {
|
|
794320
|
-
return void 0;
|
|
794321
|
-
}
|
|
794322
|
-
if (options.isParameter) {
|
|
794323
|
-
return FullExample.primitive(PrimitiveExample.string(options.name ?? "string"));
|
|
794324
|
-
}
|
|
794325
|
-
return FullExample.map([
|
|
794326
|
-
{
|
|
794327
|
-
key: PrimitiveExample.string("key"),
|
|
794328
|
-
value: FullExample.primitive(PrimitiveExample.string("value"))
|
|
794329
|
-
}
|
|
794330
|
-
]);
|
|
794331
|
-
case "array": {
|
|
794332
|
-
const fullExample = getFullExampleAsArray(example);
|
|
794333
|
-
const itemExamples = [];
|
|
794334
|
-
if (fullExample != null && fullExample.length > 0) {
|
|
794335
|
-
for (const item of fullExample) {
|
|
794336
|
-
const itemExample2 = this.buildExampleHelper({
|
|
794337
|
-
example: item,
|
|
794338
|
-
schema: schema2.value,
|
|
794339
|
-
depth: depth + 1,
|
|
794340
|
-
visitedSchemaIds,
|
|
794341
|
-
options
|
|
794342
|
-
});
|
|
794343
|
-
if (itemExample2 != null) {
|
|
794344
|
-
itemExamples.push(itemExample2);
|
|
794345
|
-
}
|
|
794346
|
-
}
|
|
794347
|
-
}
|
|
794348
|
-
const itemExample = this.buildExampleHelper({
|
|
794349
|
-
example: void 0,
|
|
794350
|
-
schema: schema2.value,
|
|
794351
|
-
depth: depth + 1,
|
|
794352
|
-
visitedSchemaIds,
|
|
794353
|
-
options
|
|
794354
|
-
});
|
|
794355
|
-
if (itemExample != null) {
|
|
794356
|
-
itemExamples.push(itemExample);
|
|
794357
|
-
}
|
|
794358
|
-
return FullExample.array(itemExamples);
|
|
794359
|
-
}
|
|
794360
|
-
case "map": {
|
|
794361
|
-
const objectExample = getFullExampleAsObject(example);
|
|
794362
|
-
if (objectExample != null && Object.entries(objectExample).length > 0) {
|
|
794363
|
-
const kvs = [];
|
|
794364
|
-
for (const [key2, value] of Object.entries(objectExample)) {
|
|
794365
|
-
const keyExample2 = this.buildExampleFromPrimitive({
|
|
794366
|
-
schema: schema2.key.schema,
|
|
794367
|
-
example: key2,
|
|
794368
|
-
options
|
|
794369
|
-
});
|
|
794370
|
-
const valueExample2 = this.buildExampleHelper({
|
|
794371
|
-
example: value,
|
|
794372
|
-
schema: schema2.value,
|
|
794373
|
-
visitedSchemaIds,
|
|
794374
|
-
depth: depth + 1,
|
|
794375
|
-
options
|
|
794376
|
-
});
|
|
794377
|
-
if (valueExample2 != null) {
|
|
794378
|
-
kvs.push({
|
|
794379
|
-
key: keyExample2,
|
|
794380
|
-
value: valueExample2
|
|
794381
|
-
});
|
|
794382
|
-
}
|
|
794383
|
-
}
|
|
794384
|
-
return FullExample.map(kvs);
|
|
794385
|
-
}
|
|
794386
|
-
const keyExample = this.buildExampleFromPrimitive({
|
|
794387
|
-
schema: schema2.key.schema,
|
|
794388
|
-
example: void 0,
|
|
794389
|
-
options
|
|
794390
|
-
});
|
|
794391
|
-
const valueExample = this.buildExampleHelper({
|
|
794392
|
-
example: void 0,
|
|
794393
|
-
schema: schema2.value,
|
|
794394
|
-
visitedSchemaIds,
|
|
794395
|
-
depth: depth + 1,
|
|
794396
|
-
options
|
|
794397
|
-
});
|
|
794398
|
-
if (valueExample != null) {
|
|
794399
|
-
return FullExample.map([
|
|
794400
|
-
{
|
|
794401
|
-
key: keyExample,
|
|
794402
|
-
value: valueExample
|
|
794403
|
-
}
|
|
794404
|
-
]);
|
|
794405
|
-
}
|
|
794406
|
-
return FullExample.map([]);
|
|
794407
|
-
}
|
|
794408
|
-
case "object": {
|
|
794409
|
-
const result2 = {};
|
|
794410
|
-
const fullExample = getFullExampleAsObject(example) ?? (((_b2 = schema2.fullExamples) == null ? void 0 : _b2[0]) != null ? getFullExampleAsObject(schema2.fullExamples[0].value) : {}) ?? {};
|
|
794411
|
-
const allProperties = this.getAllProperties(schema2);
|
|
794412
|
-
const requiredProperties = this.getAllRequiredProperties(schema2);
|
|
794413
|
-
for (const [property4, schema3] of Object.entries(allProperties)) {
|
|
794414
|
-
const required = property4 in requiredProperties;
|
|
794415
|
-
const propertyExample = this.buildExampleHelper({
|
|
794416
|
-
schema: schema3,
|
|
794417
|
-
example: fullExample[property4],
|
|
794418
|
-
visitedSchemaIds,
|
|
794419
|
-
depth: depth + 1,
|
|
794420
|
-
options: {
|
|
794421
|
-
...options,
|
|
794422
|
-
name: property4
|
|
794423
|
-
}
|
|
794424
|
-
});
|
|
794425
|
-
if (propertyExample != null) {
|
|
794426
|
-
result2[property4] = propertyExample;
|
|
794427
|
-
} else if (required) {
|
|
794428
|
-
const generatedExample = this.buildExampleHelper({
|
|
794429
|
-
schema: schema3,
|
|
794430
|
-
example: fullExample[property4],
|
|
794431
|
-
visitedSchemaIds,
|
|
794432
|
-
depth: depth + 1,
|
|
794433
|
-
options: {
|
|
794434
|
-
...options,
|
|
794435
|
-
name: property4
|
|
794436
|
-
}
|
|
794437
|
-
});
|
|
794438
|
-
if (generatedExample == null) {
|
|
794439
|
-
return void 0;
|
|
794440
|
-
}
|
|
794441
|
-
result2[property4] = generatedExample;
|
|
794442
|
-
}
|
|
794443
|
-
}
|
|
794444
|
-
return FullExample.object({
|
|
794445
|
-
properties: result2
|
|
794446
|
-
});
|
|
794447
|
-
}
|
|
794448
|
-
default:
|
|
794449
|
-
assertNever(schema2);
|
|
794450
|
-
}
|
|
794451
|
-
}
|
|
794452
|
-
hasExample(schema2) {
|
|
794453
|
-
switch (schema2.type) {
|
|
794454
|
-
case "array":
|
|
794455
|
-
return this.hasExample(schema2.value);
|
|
794456
|
-
case "enum":
|
|
794457
|
-
return schema2.example != null;
|
|
794458
|
-
case "literal":
|
|
794459
|
-
return false;
|
|
794460
|
-
case "map":
|
|
794461
|
-
return schema2.key.schema.example != null && this.hasExample(schema2.value);
|
|
794462
|
-
case "object": {
|
|
794463
|
-
const objectExample = schema2.fullExamples != null && schema2.fullExamples.length > 0;
|
|
794464
|
-
if (objectExample) {
|
|
794465
|
-
return true;
|
|
794466
|
-
}
|
|
794467
|
-
for (const property4 of schema2.properties) {
|
|
794468
|
-
if (this.hasExample(property4.schema)) {
|
|
794469
|
-
return true;
|
|
794470
|
-
}
|
|
794471
|
-
}
|
|
794472
|
-
return false;
|
|
794473
|
-
}
|
|
794474
|
-
case "primitive":
|
|
794475
|
-
return schema2.schema.example != null;
|
|
794476
|
-
case "reference": {
|
|
794477
|
-
const resolvedSchema = this.schemas[schema2.schema];
|
|
794478
|
-
if (resolvedSchema != null) {
|
|
794479
|
-
return this.hasExample(resolvedSchema);
|
|
794480
|
-
}
|
|
794481
|
-
return false;
|
|
794482
|
-
}
|
|
794483
|
-
case "unknown":
|
|
794484
|
-
return schema2.example != null;
|
|
794485
|
-
case "oneOf":
|
|
794486
|
-
return Object.values(schema2.value.schemas).some((schema3) => this.hasExample(schema3));
|
|
794487
|
-
default:
|
|
794488
|
-
return false;
|
|
794489
|
-
}
|
|
794490
|
-
}
|
|
794491
|
-
exceedsMaxDepth(depth, options) {
|
|
794492
|
-
return depth > (options.maxDepth ?? 0);
|
|
794493
|
-
}
|
|
794494
|
-
getAllProperties(object3) {
|
|
794495
|
-
let properties = {};
|
|
794496
|
-
for (const property4 of object3.properties) {
|
|
794497
|
-
properties[property4.key] = property4.schema;
|
|
794498
|
-
}
|
|
794499
|
-
for (const allOf of object3.allOf) {
|
|
794500
|
-
const allOfSchema = this.schemas[allOf.schema];
|
|
794501
|
-
if (allOfSchema == null) {
|
|
794502
|
-
continue;
|
|
794503
|
-
}
|
|
794504
|
-
const resolvedAllOfSchema = this.getResolvedSchema(allOfSchema);
|
|
794505
|
-
if (resolvedAllOfSchema.type !== "object") {
|
|
794506
|
-
continue;
|
|
794507
|
-
}
|
|
794508
|
-
properties = {
|
|
794509
|
-
...this.getAllProperties(resolvedAllOfSchema),
|
|
794510
|
-
...properties
|
|
794511
|
-
};
|
|
794512
|
-
}
|
|
794513
|
-
return properties;
|
|
794514
|
-
}
|
|
794515
|
-
getAllRequiredProperties(object3) {
|
|
794516
|
-
let requiredProperties = {};
|
|
794517
|
-
for (const property4 of object3.properties) {
|
|
794518
|
-
const resolvedSchema = this.getResolvedSchema(property4.schema);
|
|
794519
|
-
if (resolvedSchema.type !== "optional" && resolvedSchema.type !== "nullable") {
|
|
794520
|
-
requiredProperties[property4.key] = property4.schema;
|
|
794521
|
-
}
|
|
794522
|
-
}
|
|
794523
|
-
for (const allOf of object3.allOf) {
|
|
794524
|
-
const allOfSchema = this.schemas[allOf.schema];
|
|
794525
|
-
if (allOfSchema == null) {
|
|
794526
|
-
continue;
|
|
794527
|
-
}
|
|
794528
|
-
const resolvedAllOfSchema = this.getResolvedSchema(allOfSchema);
|
|
794529
|
-
if (resolvedAllOfSchema.type !== "object") {
|
|
794530
|
-
continue;
|
|
794531
|
-
}
|
|
794532
|
-
requiredProperties = {
|
|
794533
|
-
...this.getAllRequiredProperties(resolvedAllOfSchema),
|
|
794534
|
-
...requiredProperties
|
|
794535
|
-
};
|
|
794536
|
-
}
|
|
794537
|
-
return requiredProperties;
|
|
794538
|
-
}
|
|
794539
|
-
getResolvedSchema(schema2) {
|
|
794540
|
-
while (schema2.type === "reference") {
|
|
794541
|
-
const resolvedSchema = this.schemas[schema2.schema];
|
|
794542
|
-
if (resolvedSchema == null) {
|
|
794543
|
-
throw new Error(`Unexpected error: Failed to resolve schema reference: ${schema2.schema}`);
|
|
794544
|
-
}
|
|
794545
|
-
schema2 = resolvedSchema;
|
|
794546
|
-
}
|
|
794547
|
-
return schema2;
|
|
794548
|
-
}
|
|
794549
|
-
buildExampleFromPrimitive({ example, schema: schema2, options }) {
|
|
794550
|
-
switch (schema2.type) {
|
|
794551
|
-
case "string":
|
|
794552
|
-
if (example != null && typeof example === "string") {
|
|
794553
|
-
return PrimitiveExample.string(example);
|
|
794554
|
-
} else if (schema2.example != null) {
|
|
794555
|
-
return PrimitiveExample.string(schema2.example);
|
|
794556
|
-
} else {
|
|
794557
|
-
return PrimitiveExample.string(options.name ?? "string");
|
|
794558
|
-
}
|
|
794559
|
-
case "base64":
|
|
794560
|
-
if (example != null && typeof example === "string") {
|
|
794561
|
-
return PrimitiveExample.base64(example);
|
|
794562
|
-
} else if (schema2.example != null) {
|
|
794563
|
-
return PrimitiveExample.base64(schema2.example);
|
|
794564
|
-
} else {
|
|
794565
|
-
return PrimitiveExample.base64("SGVsbG8gd29ybGQh");
|
|
794566
|
-
}
|
|
794567
|
-
case "boolean":
|
|
794568
|
-
if (example != null && typeof example === "boolean") {
|
|
794569
|
-
return PrimitiveExample.boolean(example);
|
|
794570
|
-
} else if (schema2.example != null) {
|
|
794571
|
-
return PrimitiveExample.boolean(schema2.example);
|
|
794572
|
-
} else {
|
|
794573
|
-
return PrimitiveExample.boolean(true);
|
|
794574
|
-
}
|
|
794575
|
-
case "date":
|
|
794576
|
-
if (example != null && typeof example === "string") {
|
|
794577
|
-
return PrimitiveExample.date(example);
|
|
794578
|
-
} else if (schema2.example != null) {
|
|
794579
|
-
return PrimitiveExample.date(schema2.example);
|
|
794580
|
-
} else {
|
|
794581
|
-
return PrimitiveExample.date("2023-01-15");
|
|
794582
|
-
}
|
|
794583
|
-
case "datetime":
|
|
794584
|
-
if (example != null && typeof example === "string") {
|
|
794585
|
-
return PrimitiveExample.datetime(new Date(example));
|
|
794586
|
-
} else if (schema2.example != null) {
|
|
794587
|
-
return PrimitiveExample.datetime(new Date(schema2.example));
|
|
794588
|
-
} else {
|
|
794589
|
-
return PrimitiveExample.datetime(new Date("2024-01-15T09:30:00Z"));
|
|
794590
|
-
}
|
|
794591
|
-
case "double":
|
|
794592
|
-
if (example != null && typeof example === "number") {
|
|
794593
|
-
return PrimitiveExample.double(example);
|
|
794594
|
-
} else if (schema2.example != null) {
|
|
794595
|
-
return PrimitiveExample.double(schema2.example);
|
|
794596
|
-
} else {
|
|
794597
|
-
return PrimitiveExample.double(1.1);
|
|
794598
|
-
}
|
|
794599
|
-
case "float":
|
|
794600
|
-
if (example != null && typeof example === "number") {
|
|
794601
|
-
return PrimitiveExample.float(example);
|
|
794602
|
-
} else if (schema2.example != null) {
|
|
794603
|
-
return PrimitiveExample.float(schema2.example);
|
|
794604
|
-
} else {
|
|
794605
|
-
return PrimitiveExample.float(1.1);
|
|
794606
|
-
}
|
|
794607
|
-
case "int":
|
|
794608
|
-
if (example != null && typeof example === "number") {
|
|
794609
|
-
return PrimitiveExample.int(example);
|
|
794610
|
-
} else if (schema2.example != null) {
|
|
794611
|
-
return PrimitiveExample.int(schema2.example);
|
|
794612
|
-
} else {
|
|
794613
|
-
return PrimitiveExample.int(1);
|
|
794614
|
-
}
|
|
794615
|
-
case "int64":
|
|
794616
|
-
if (example != null && typeof example === "number") {
|
|
794617
|
-
return PrimitiveExample.int64(example);
|
|
794618
|
-
} else if (schema2.example != null) {
|
|
794619
|
-
return PrimitiveExample.int64(schema2.example);
|
|
794620
|
-
} else {
|
|
794621
|
-
return PrimitiveExample.int64(1e6);
|
|
794622
|
-
}
|
|
794623
|
-
default:
|
|
794624
|
-
assertNever(schema2);
|
|
794625
|
-
}
|
|
794626
|
-
}
|
|
794627
|
-
};
|
|
794628
|
-
function enumContainsValue({ schema: schema2, value }) {
|
|
794629
|
-
return schema2.values.map((enumValue) => {
|
|
794630
|
-
return enumValue.value;
|
|
794631
|
-
}).includes(value);
|
|
794632
|
-
}
|
|
794633
|
-
|
|
794634
|
-
// pnp:/home/circleci/project/packages/cli/openapi-parser/lib/openapi/v3/converters/example/ExampleEndpointFactory.js
|
|
794635
|
-
var ExampleEndpointFactory = class {
|
|
794636
|
-
exampleTypeFactory;
|
|
794637
|
-
logger;
|
|
794638
|
-
schemas;
|
|
794639
|
-
constructor(schemas, logger) {
|
|
794640
|
-
this.schemas = schemas;
|
|
794641
|
-
this.exampleTypeFactory = new ExampleTypeFactory(schemas);
|
|
794642
|
-
this.logger = logger;
|
|
794643
|
-
}
|
|
794644
|
-
buildEndpointExample(endpoint) {
|
|
794645
|
-
var _a2, _b2, _c2;
|
|
794646
|
-
this.logger.debug(`Building endpoint example for ${endpoint.method.toUpperCase()} ${endpoint.path}`);
|
|
794647
|
-
const requestSchemaIdResponse = getRequestSchema(endpoint.request);
|
|
794648
|
-
const responseSchemaIdResponse = getResponseSchema(endpoint.response);
|
|
794649
|
-
if ((requestSchemaIdResponse == null ? void 0 : requestSchemaIdResponse.type) === "unsupported" || (responseSchemaIdResponse == null ? void 0 : responseSchemaIdResponse.type) === "unsupported") {
|
|
794650
|
-
return void 0;
|
|
794651
|
-
}
|
|
794652
|
-
let requestExample = void 0;
|
|
794653
|
-
if (requestSchemaIdResponse != null) {
|
|
794654
|
-
const required = this.isSchemaRequired(requestSchemaIdResponse.schema);
|
|
794655
|
-
requestExample = this.exampleTypeFactory.buildExample({
|
|
794656
|
-
schema: requestSchemaIdResponse.schema,
|
|
794657
|
-
example: (_a2 = requestSchemaIdResponse.example) == null ? void 0 : _a2.value,
|
|
794658
|
-
options: {
|
|
794659
|
-
isParameter: false,
|
|
794660
|
-
ignoreOptionals: true
|
|
794661
|
-
}
|
|
794662
|
-
});
|
|
794663
|
-
if (required && requestExample == null) {
|
|
794664
|
-
return void 0;
|
|
794665
|
-
}
|
|
794666
|
-
}
|
|
794667
|
-
let responseExample = void 0;
|
|
794668
|
-
if (responseSchemaIdResponse != null) {
|
|
794669
|
-
const required = this.isSchemaRequired(responseSchemaIdResponse.schema);
|
|
794670
|
-
responseExample = this.exampleTypeFactory.buildExample({
|
|
794671
|
-
schema: responseSchemaIdResponse.schema,
|
|
794672
|
-
example: (_b2 = responseSchemaIdResponse.example) == null ? void 0 : _b2.value,
|
|
794673
|
-
options: {
|
|
794674
|
-
isParameter: false,
|
|
794675
|
-
ignoreOptionals: false,
|
|
794676
|
-
maxDepth: 3
|
|
794677
|
-
}
|
|
794678
|
-
});
|
|
794679
|
-
if (required && responseExample == null) {
|
|
794680
|
-
return void 0;
|
|
794681
|
-
}
|
|
794682
|
-
}
|
|
794683
|
-
const pathParameters = [];
|
|
794684
|
-
for (const pathParameter of endpoint.pathParameters) {
|
|
794685
|
-
const required = this.isSchemaRequired(pathParameter.schema);
|
|
794686
|
-
let example = this.exampleTypeFactory.buildExample({
|
|
794687
|
-
schema: pathParameter.schema,
|
|
794688
|
-
example: void 0,
|
|
794689
|
-
options: {
|
|
794690
|
-
name: pathParameter.name,
|
|
794691
|
-
isParameter: true,
|
|
794692
|
-
ignoreOptionals: true
|
|
794693
|
-
}
|
|
794694
|
-
});
|
|
794695
|
-
if (example != null && !isExamplePrimitive(example)) {
|
|
794696
|
-
example = void 0;
|
|
794697
|
-
}
|
|
794698
|
-
if (required && example == null) {
|
|
794699
|
-
return void 0;
|
|
794700
|
-
} else if (example != null) {
|
|
794701
|
-
pathParameters.push({
|
|
794702
|
-
name: pathParameter.name,
|
|
794703
|
-
value: example
|
|
794704
|
-
});
|
|
794705
|
-
}
|
|
794706
|
-
}
|
|
794707
|
-
const queryParameters = [];
|
|
794708
|
-
for (const queryParameter of endpoint.queryParameters) {
|
|
794709
|
-
const required = this.isSchemaRequired(queryParameter.schema);
|
|
794710
|
-
let example = this.exampleTypeFactory.buildExample({
|
|
794711
|
-
schema: queryParameter.schema,
|
|
794712
|
-
example: void 0,
|
|
794713
|
-
options: {
|
|
794714
|
-
name: queryParameter.name,
|
|
794715
|
-
isParameter: true,
|
|
794716
|
-
ignoreOptionals: true
|
|
794717
|
-
}
|
|
794718
|
-
});
|
|
794719
|
-
if (example != null && !isExamplePrimitive(example)) {
|
|
794720
|
-
example = void 0;
|
|
794721
|
-
}
|
|
794722
|
-
if (required && example == null) {
|
|
794723
|
-
return void 0;
|
|
794724
|
-
} else if (example != null) {
|
|
794725
|
-
queryParameters.push({
|
|
794726
|
-
name: queryParameter.name,
|
|
794727
|
-
value: example
|
|
794728
|
-
});
|
|
794729
|
-
}
|
|
794730
|
-
}
|
|
794731
|
-
const headers = [];
|
|
794732
|
-
for (const header of endpoint.headers) {
|
|
794733
|
-
const required = this.isSchemaRequired(header.schema);
|
|
794734
|
-
let example = this.exampleTypeFactory.buildExample({
|
|
794735
|
-
schema: header.schema,
|
|
794736
|
-
example: void 0,
|
|
794737
|
-
options: {
|
|
794738
|
-
name: header.name,
|
|
794739
|
-
isParameter: true,
|
|
794740
|
-
ignoreOptionals: true
|
|
794741
|
-
}
|
|
794742
|
-
});
|
|
794743
|
-
if (example != null && !isExamplePrimitive(example)) {
|
|
794744
|
-
example = void 0;
|
|
794745
|
-
}
|
|
794746
|
-
if (required && example == null) {
|
|
794747
|
-
return void 0;
|
|
794748
|
-
} else if (example != null) {
|
|
794749
|
-
headers.push({
|
|
794750
|
-
name: header.name,
|
|
794751
|
-
value: example
|
|
794752
|
-
});
|
|
794753
|
-
}
|
|
794754
|
-
}
|
|
794755
|
-
let exampleName = (_c2 = requestSchemaIdResponse == null ? void 0 : requestSchemaIdResponse.example) == null ? void 0 : _c2.name;
|
|
794756
|
-
if (exampleName == null && (requestSchemaIdResponse == null ? void 0 : requestSchemaIdResponse.schema) != null) {
|
|
794757
|
-
exampleName = getNameFromSchemaWithExample(requestSchemaIdResponse.schema);
|
|
794758
|
-
}
|
|
794759
|
-
return {
|
|
794760
|
-
name: exampleName,
|
|
794761
|
-
description: void 0,
|
|
794762
|
-
pathParameters,
|
|
794763
|
-
queryParameters,
|
|
794764
|
-
headers,
|
|
794765
|
-
request: requestExample,
|
|
794766
|
-
response: responseExample,
|
|
794767
|
-
codeSamples: []
|
|
794768
|
-
};
|
|
794769
|
-
}
|
|
794770
|
-
isSchemaRequired(schema2) {
|
|
794771
|
-
return isSchemaRequired3(this.getResolvedSchema(schema2));
|
|
794772
|
-
}
|
|
794773
|
-
getResolvedSchema(schema2) {
|
|
794774
|
-
while (schema2.type === "reference") {
|
|
794775
|
-
const resolvedSchema = this.schemas[schema2.schema];
|
|
794776
|
-
if (resolvedSchema == null) {
|
|
794777
|
-
throw new Error(`Unexpected error: Failed to resolve schema reference: ${schema2.schema}`);
|
|
794778
|
-
}
|
|
794779
|
-
schema2 = resolvedSchema;
|
|
794780
|
-
}
|
|
794781
|
-
return schema2;
|
|
794782
|
-
}
|
|
794783
|
-
};
|
|
794784
|
-
function getRequestSchema(request) {
|
|
794785
|
-
var _a2;
|
|
794786
|
-
if (request == null) {
|
|
794787
|
-
return void 0;
|
|
794788
|
-
}
|
|
794789
|
-
if (request.type !== "json") {
|
|
794790
|
-
return { type: "unsupported" };
|
|
794791
|
-
}
|
|
794792
|
-
return { type: "present", schema: request.schema, example: ((_a2 = request.fullExamples) == null ? void 0 : _a2[0]) ?? void 0 };
|
|
794793
|
-
}
|
|
794794
|
-
function getResponseSchema(response) {
|
|
794795
|
-
var _a2;
|
|
794796
|
-
if (response == null) {
|
|
794797
|
-
return void 0;
|
|
794798
|
-
}
|
|
794799
|
-
if (response.type !== "json") {
|
|
794800
|
-
return { type: "unsupported" };
|
|
794801
|
-
}
|
|
794802
|
-
return { type: "present", schema: response.schema, example: ((_a2 = response.fullExamples) == null ? void 0 : _a2[0]) ?? void 0 };
|
|
794803
|
-
}
|
|
794804
|
-
function isExamplePrimitive(example) {
|
|
794805
|
-
switch (example.type) {
|
|
794806
|
-
case "primitive":
|
|
794807
|
-
case "enum":
|
|
794808
|
-
case "literal":
|
|
794809
|
-
return true;
|
|
794810
|
-
case "unknown":
|
|
794811
|
-
return isExamplePrimitive(example);
|
|
794812
|
-
case "array":
|
|
794813
|
-
case "object":
|
|
794814
|
-
case "map":
|
|
794815
|
-
return false;
|
|
794816
|
-
case "oneOf":
|
|
794817
|
-
switch (example.value.type) {
|
|
794818
|
-
case "discriminated":
|
|
794819
|
-
return false;
|
|
794820
|
-
case "undisciminated":
|
|
794821
|
-
return isExamplePrimitive(example.value.value);
|
|
794822
|
-
default:
|
|
794823
|
-
return false;
|
|
794824
|
-
}
|
|
794825
|
-
default:
|
|
794826
|
-
assertNever(example);
|
|
794827
|
-
}
|
|
794828
|
-
}
|
|
794829
|
-
function getNameFromSchemaWithExample(schema2) {
|
|
794830
|
-
var _a2, _b2;
|
|
794831
|
-
switch (schema2.type) {
|
|
794832
|
-
case "primitive":
|
|
794833
|
-
case "enum":
|
|
794834
|
-
case "literal":
|
|
794835
|
-
case "unknown":
|
|
794836
|
-
case "array":
|
|
794837
|
-
case "map":
|
|
794838
|
-
case "optional":
|
|
794839
|
-
case "nullable":
|
|
794840
|
-
case "reference":
|
|
794841
|
-
return void 0;
|
|
794842
|
-
case "object":
|
|
794843
|
-
return ((_b2 = (_a2 = schema2.fullExamples) == null ? void 0 : _a2[0]) == null ? void 0 : _b2.name) ?? void 0;
|
|
794844
|
-
case "oneOf":
|
|
794845
|
-
switch (schema2.value.type) {
|
|
794846
|
-
case "discriminated":
|
|
794847
|
-
return void 0;
|
|
794848
|
-
case "undisciminated":
|
|
794849
|
-
return void 0;
|
|
794850
|
-
default:
|
|
794851
|
-
return void 0;
|
|
794852
|
-
}
|
|
794853
|
-
default:
|
|
794854
|
-
assertNever(schema2);
|
|
794855
|
-
}
|
|
794856
|
-
}
|
|
794857
|
-
|
|
794858
795063
|
// pnp:/home/circleci/project/packages/cli/openapi-parser/lib/openapi/v3/extensions/getGlobalHeaders.js
|
|
794859
795064
|
function getGlobalHeaders(document4) {
|
|
794860
795065
|
return getExtension(document4, FernOpenAPIExtension.FERN_GLOBAL_HEADERS);
|
|
@@ -795533,273 +795738,34 @@ function getQueryParameterTypeReference({ schema: schema2, context, fileContaini
|
|
|
795533
795738
|
}
|
|
795534
795739
|
}
|
|
795535
795740
|
|
|
795536
|
-
// pnp:/home/circleci/project/packages/cli/openapi-ir-to-fern/lib/
|
|
795537
|
-
function
|
|
795538
|
-
const
|
|
795539
|
-
|
|
795540
|
-
auth: false
|
|
795741
|
+
// pnp:/home/circleci/project/packages/cli/openapi-ir-to-fern/lib/buildWebsocketSessionExample.js
|
|
795742
|
+
function buildWebsocketSessionExample({ websocketExample, context }) {
|
|
795743
|
+
const example = {
|
|
795744
|
+
messages: []
|
|
795541
795745
|
};
|
|
795542
|
-
|
|
795543
|
-
|
|
795544
|
-
for (const queryParameter of channel.handshake.queryParameters) {
|
|
795545
|
-
const convertedQueryParameter = buildQueryParameter({
|
|
795546
|
-
queryParameter,
|
|
795547
|
-
context,
|
|
795548
|
-
fileContainingReference: declarationFile
|
|
795549
|
-
});
|
|
795550
|
-
if (convertedQueryParameter == null) {
|
|
795551
|
-
continue;
|
|
795552
|
-
}
|
|
795553
|
-
queryParameters[queryParameter.name] = convertedQueryParameter;
|
|
795554
|
-
}
|
|
795555
|
-
}
|
|
795556
|
-
if (Object.keys(queryParameters).length > 0) {
|
|
795557
|
-
convertedChannel["query-parameters"] = queryParameters;
|
|
795558
|
-
}
|
|
795559
|
-
const headers = {};
|
|
795560
|
-
if (channel.handshake != null && channel.handshake.headers.length > 0) {
|
|
795561
|
-
for (const header of channel.handshake.headers) {
|
|
795562
|
-
const headerSchema = buildHeader({ header, context, fileContainingReference: declarationFile });
|
|
795563
|
-
headers[header.name] = headerSchema;
|
|
795564
|
-
}
|
|
795565
|
-
}
|
|
795566
|
-
if (Object.keys(headers).length > 0) {
|
|
795567
|
-
convertedChannel.headers = headers;
|
|
795568
|
-
}
|
|
795569
|
-
context.builder.addChannel(declarationFile, {
|
|
795570
|
-
channel: convertedChannel
|
|
795571
|
-
});
|
|
795572
|
-
if (channel.subscribe != null) {
|
|
795573
|
-
context.builder.addChannelMessage(declarationFile, {
|
|
795574
|
-
messageId: "subscribe",
|
|
795575
|
-
message: {
|
|
795576
|
-
origin: "server",
|
|
795577
|
-
body: buildTypeReference({
|
|
795578
|
-
schema: channel.subscribe,
|
|
795579
|
-
context,
|
|
795580
|
-
fileContainingReference: declarationFile
|
|
795581
|
-
})
|
|
795582
|
-
}
|
|
795583
|
-
});
|
|
795584
|
-
}
|
|
795585
|
-
if (channel.publish != null) {
|
|
795586
|
-
context.builder.addChannelMessage(declarationFile, {
|
|
795587
|
-
messageId: "publish",
|
|
795588
|
-
message: {
|
|
795589
|
-
origin: "client",
|
|
795590
|
-
body: buildTypeReference({
|
|
795591
|
-
schema: channel.publish,
|
|
795592
|
-
context,
|
|
795593
|
-
fileContainingReference: declarationFile
|
|
795594
|
-
})
|
|
795595
|
-
}
|
|
795596
|
-
});
|
|
795597
|
-
}
|
|
795598
|
-
}
|
|
795599
|
-
|
|
795600
|
-
// pnp:/home/circleci/project/packages/cli/openapi-ir-to-fern/lib/buildEnvironments.js
|
|
795601
|
-
var PRODUCTION_ENVNIRONMENT_NAME = "Production";
|
|
795602
|
-
var DEFAULT_ENVIRONMENT_NAME = "Default";
|
|
795603
|
-
function buildEnvironments(context) {
|
|
795604
|
-
var _a2;
|
|
795605
|
-
const topLevelServerURLsWithName = {};
|
|
795606
|
-
const topLevelSkippedServerURLs = [];
|
|
795607
|
-
for (const server of context.ir.servers) {
|
|
795608
|
-
if (server.name == null) {
|
|
795609
|
-
topLevelSkippedServerURLs.push(server.url);
|
|
795610
|
-
continue;
|
|
795611
|
-
}
|
|
795612
|
-
topLevelServerURLsWithName[server.name] = server.url;
|
|
795613
|
-
}
|
|
795614
|
-
const endpointLevelServerURLsWithName = {};
|
|
795615
|
-
const endpointLevelSkippedServerURLs = [];
|
|
795616
|
-
for (const endpoint of context.ir.endpoints) {
|
|
795617
|
-
for (const server of endpoint.server) {
|
|
795618
|
-
if (server.name == null) {
|
|
795619
|
-
endpointLevelSkippedServerURLs.push(server.url);
|
|
795620
|
-
continue;
|
|
795621
|
-
}
|
|
795622
|
-
endpointLevelServerURLsWithName[server.name] = server.url;
|
|
795623
|
-
}
|
|
795624
|
-
}
|
|
795625
|
-
const numTopLevelURLs = Object.keys(topLevelServerURLsWithName).length;
|
|
795626
|
-
const numEndpointLevelURLs = Object.keys(endpointLevelServerURLsWithName).length;
|
|
795627
|
-
if (numTopLevelURLs === 0 && numEndpointLevelURLs === 0) {
|
|
795628
|
-
const singleURL = (_a2 = context.ir.servers[0]) == null ? void 0 : _a2.url;
|
|
795629
|
-
if (singleURL != null) {
|
|
795630
|
-
context.builder.addEnvironment({
|
|
795631
|
-
name: DEFAULT_ENVIRONMENT_NAME,
|
|
795632
|
-
schema: singleURL
|
|
795633
|
-
});
|
|
795634
|
-
context.builder.setDefaultEnvironment(DEFAULT_ENVIRONMENT_NAME);
|
|
795635
|
-
}
|
|
795636
|
-
} else if (numTopLevelURLs > 0 && numEndpointLevelURLs === 0) {
|
|
795637
|
-
let count = 0;
|
|
795638
|
-
if (topLevelSkippedServerURLs.length > 0) {
|
|
795639
|
-
context.logger.error(`Skipping servers ${topLevelSkippedServerURLs.join(", ")} because x-fern-server-name was not provided.`);
|
|
795640
|
-
}
|
|
795641
|
-
for (const [name2, url] of Object.entries(topLevelServerURLsWithName)) {
|
|
795642
|
-
if (count === 0) {
|
|
795643
|
-
context.builder.setDefaultEnvironment(name2);
|
|
795644
|
-
}
|
|
795645
|
-
context.builder.addEnvironment({
|
|
795646
|
-
name: name2,
|
|
795647
|
-
schema: url
|
|
795648
|
-
});
|
|
795649
|
-
count += 1;
|
|
795650
|
-
}
|
|
795651
|
-
} else if (numEndpointLevelURLs > 0) {
|
|
795652
|
-
if (topLevelSkippedServerURLs.length > 0 || endpointLevelSkippedServerURLs.length > 0) {
|
|
795653
|
-
context.logger.error(`Skipping servers ${[...topLevelSkippedServerURLs, ...endpointLevelSkippedServerURLs].join(", ")} because x-fern-server-name was not provided.`);
|
|
795654
|
-
}
|
|
795655
|
-
const toplevelServerURLEntries = Object.entries(topLevelServerURLsWithName)[0];
|
|
795656
|
-
if (toplevelServerURLEntries != null) {
|
|
795657
|
-
const [name2, _4] = toplevelServerURLEntries;
|
|
795658
|
-
context.setDefaultServerName(name2);
|
|
795659
|
-
}
|
|
795660
|
-
context.builder.addEnvironment({
|
|
795661
|
-
name: PRODUCTION_ENVNIRONMENT_NAME,
|
|
795662
|
-
schema: {
|
|
795663
|
-
urls: {
|
|
795664
|
-
...topLevelServerURLsWithName,
|
|
795665
|
-
...endpointLevelServerURLsWithName
|
|
795666
|
-
}
|
|
795667
|
-
}
|
|
795668
|
-
});
|
|
795669
|
-
context.builder.setDefaultEnvironment(PRODUCTION_ENVNIRONMENT_NAME);
|
|
795746
|
+
if (websocketExample.name != null) {
|
|
795747
|
+
example.name = websocketExample.name;
|
|
795670
795748
|
}
|
|
795671
|
-
|
|
795672
|
-
|
|
795673
|
-
// pnp:/home/circleci/project/packages/cli/openapi-ir-to-fern/lib/utils/wrapTypeReferenceAsOptional.js
|
|
795674
|
-
function wrapTypeReferenceAsOptional(typeReference) {
|
|
795675
|
-
const type2 = getTypeFromTypeReference(typeReference);
|
|
795676
|
-
if (type2.startsWith("optional")) {
|
|
795677
|
-
return typeReference;
|
|
795678
|
-
} else if (typeof typeReference === "string") {
|
|
795679
|
-
return `optional<${typeReference}>`;
|
|
795680
|
-
} else {
|
|
795681
|
-
return { ...typeReference, type: `optional<${typeReference.type}>` };
|
|
795749
|
+
if (websocketExample.description != null) {
|
|
795750
|
+
example.docs = websocketExample.description;
|
|
795682
795751
|
}
|
|
795683
|
-
|
|
795684
|
-
|
|
795685
|
-
// pnp:/home/circleci/project/packages/cli/openapi-ir-to-fern/lib/buildGlobalHeaders.js
|
|
795686
|
-
var HeaderWithCount = class {
|
|
795687
|
-
schema;
|
|
795688
|
-
count = 0;
|
|
795689
|
-
constructor(schema2) {
|
|
795690
|
-
this.schema = schema2;
|
|
795752
|
+
if (websocketExample.queryParameters != null && websocketExample.queryParameters.length > 0) {
|
|
795753
|
+
example["query-parameters"] = convertQueryParameterExample(websocketExample.queryParameters);
|
|
795691
795754
|
}
|
|
795692
|
-
|
|
795693
|
-
|
|
795755
|
+
if (websocketExample.headers != null && websocketExample.headers.length > 0) {
|
|
795756
|
+
example.headers = convertHeaderExamples({ context, namedFullExamples: websocketExample.headers });
|
|
795694
795757
|
}
|
|
795695
|
-
|
|
795696
|
-
|
|
795697
|
-
|
|
795698
|
-
|
|
795699
|
-
|
|
795700
|
-
|
|
795701
|
-
for (const endpoint of context.ir.endpoints) {
|
|
795702
|
-
for (const header of endpoint.headers) {
|
|
795703
|
-
if (HEADERS_TO_IGNORE.has(header.name)) {
|
|
795704
|
-
continue;
|
|
795705
|
-
}
|
|
795706
|
-
let headerWithCount = globalHeaders[header.name];
|
|
795707
|
-
if (headerWithCount == null) {
|
|
795708
|
-
const convertedHeader = buildHeader({
|
|
795709
|
-
header,
|
|
795710
|
-
fileContainingReference: RelativeFilePath.of(FERN_PACKAGE_MARKER_FILENAME),
|
|
795711
|
-
context
|
|
795712
|
-
});
|
|
795713
|
-
headerWithCount = new HeaderWithCount(convertedHeader);
|
|
795714
|
-
globalHeaders[header.name] = headerWithCount;
|
|
795715
|
-
}
|
|
795716
|
-
headerWithCount.increment();
|
|
795717
|
-
}
|
|
795718
|
-
}
|
|
795719
|
-
const globalHeaderThreshold = context.ir.endpoints.length * GLOBAL_HEADER_PERCENTAGE_THRESHOLD;
|
|
795720
|
-
const predefinedGlobalHeaders = new Map((_a2 = context.ir.globalHeaders) == null ? void 0 : _a2.map((header) => [header.header, header]));
|
|
795721
|
-
for (const [headerName, header] of Object.entries(globalHeaders)) {
|
|
795722
|
-
const predefinedHeader = predefinedGlobalHeaders.get(headerName);
|
|
795723
|
-
let isRequired = header.count === context.ir.endpoints.length;
|
|
795724
|
-
const isOptional = header.count >= globalHeaderThreshold;
|
|
795725
|
-
if (predefinedHeader !== void 0) {
|
|
795726
|
-
isRequired = isRequired && predefinedHeader.optional !== true || predefinedHeader.optional === false;
|
|
795727
|
-
const convertedHeaderSchema = typeof header.schema === "string" ? header.schema : {
|
|
795728
|
-
...header.schema,
|
|
795729
|
-
name: predefinedHeader.name ?? header.schema.name
|
|
795730
|
-
};
|
|
795731
|
-
context.builder.addGlobalHeader({
|
|
795732
|
-
name: headerName,
|
|
795733
|
-
schema: isRequired ? convertedHeaderSchema : wrapTypeReferenceAsOptional(convertedHeaderSchema)
|
|
795734
|
-
});
|
|
795735
|
-
} else if (isRequired) {
|
|
795736
|
-
context.builder.addGlobalHeader({
|
|
795737
|
-
name: headerName,
|
|
795738
|
-
schema: header.schema
|
|
795739
|
-
});
|
|
795740
|
-
} else if (isOptional) {
|
|
795741
|
-
context.builder.addGlobalHeader({
|
|
795742
|
-
name: headerName,
|
|
795743
|
-
schema: wrapTypeReferenceAsOptional(header.schema)
|
|
795758
|
+
for (const message of websocketExample.messages) {
|
|
795759
|
+
const convertedMessage = convertFullExample(message.payload);
|
|
795760
|
+
if (convertedMessage != null) {
|
|
795761
|
+
example.messages.push({
|
|
795762
|
+
type: message.messageType,
|
|
795763
|
+
body: convertedMessage
|
|
795744
795764
|
});
|
|
795745
795765
|
}
|
|
795746
795766
|
}
|
|
795747
|
-
}
|
|
795748
|
-
|
|
795749
|
-
// pnp:/home/circleci/project/packages/cli/openapi-ir-to-fern/lib/buildEndpointExample.js
|
|
795750
|
-
function buildEndpointExample({ endpointExample, context }) {
|
|
795751
|
-
const example = {};
|
|
795752
|
-
if (endpointExample.name != null) {
|
|
795753
|
-
example.name = endpointExample.name;
|
|
795754
|
-
}
|
|
795755
|
-
if (endpointExample.description != null) {
|
|
795756
|
-
example.docs = endpointExample.description;
|
|
795757
|
-
}
|
|
795758
|
-
if (endpointExample.pathParameters != null && endpointExample.pathParameters.length > 0) {
|
|
795759
|
-
example["path-parameters"] = convertNamedFullExamples(endpointExample.pathParameters);
|
|
795760
|
-
}
|
|
795761
|
-
if (endpointExample.queryParameters != null && endpointExample.queryParameters.length > 0) {
|
|
795762
|
-
example["query-parameters"] = convertQueryParameterExample(endpointExample.queryParameters);
|
|
795763
|
-
}
|
|
795764
|
-
if (endpointExample.headers != null && endpointExample.headers.length > 0) {
|
|
795765
|
-
example.headers = convertHeaderExamples({ context, namedFullExamples: endpointExample.headers });
|
|
795766
|
-
}
|
|
795767
|
-
if (endpointExample.request != null) {
|
|
795768
|
-
example.request = convertFullExample(endpointExample.request);
|
|
795769
|
-
}
|
|
795770
|
-
if (endpointExample.response != null) {
|
|
795771
|
-
example.response = { body: convertFullExample(endpointExample.response) };
|
|
795772
|
-
}
|
|
795773
|
-
if (endpointExample.response != null) {
|
|
795774
|
-
example.response = { body: convertFullExample(endpointExample.response) };
|
|
795775
|
-
}
|
|
795776
|
-
if (endpointExample.codeSamples.length > 0) {
|
|
795777
|
-
example["code-samples"] = endpointExample.codeSamples.map((codeSample) => {
|
|
795778
|
-
if (codeSample.type === "language") {
|
|
795779
|
-
return {
|
|
795780
|
-
name: codeSample.name ?? void 0,
|
|
795781
|
-
docs: codeSample.description ?? void 0,
|
|
795782
|
-
language: codeSample.language,
|
|
795783
|
-
code: codeSample.code,
|
|
795784
|
-
install: codeSample.install ?? void 0
|
|
795785
|
-
};
|
|
795786
|
-
} else {
|
|
795787
|
-
return {
|
|
795788
|
-
name: codeSample.name ?? void 0,
|
|
795789
|
-
docs: codeSample.description ?? void 0,
|
|
795790
|
-
sdk: codeSample.sdk,
|
|
795791
|
-
code: codeSample.code
|
|
795792
|
-
};
|
|
795793
|
-
}
|
|
795794
|
-
}).filter(isNonNullish);
|
|
795795
|
-
}
|
|
795796
795767
|
return example;
|
|
795797
795768
|
}
|
|
795798
|
-
function convertNamedFullExamples(namedFullExamples) {
|
|
795799
|
-
const result2 = {};
|
|
795800
|
-
namedFullExamples.map((namedFullExample) => result2[namedFullExample.name] = convertFullExample(namedFullExample.value));
|
|
795801
|
-
return result2;
|
|
795802
|
-
}
|
|
795803
795769
|
function convertQueryParameterExample(namedFullExamples) {
|
|
795804
795770
|
const result2 = {};
|
|
795805
795771
|
namedFullExamples.forEach((namedFullExample) => {
|
|
@@ -795910,6 +795876,389 @@ function convertLiteralExample(literal2) {
|
|
|
795910
795876
|
}
|
|
795911
795877
|
}
|
|
795912
795878
|
|
|
795879
|
+
// pnp:/home/circleci/project/packages/cli/openapi-ir-to-fern/lib/buildChannel.js
|
|
795880
|
+
function buildChannel({ channel, context, declarationFile }) {
|
|
795881
|
+
const convertedChannel = {
|
|
795882
|
+
path: channel.path,
|
|
795883
|
+
auth: false
|
|
795884
|
+
};
|
|
795885
|
+
const queryParameters = {};
|
|
795886
|
+
if (channel.handshake.queryParameters.length > 0) {
|
|
795887
|
+
for (const queryParameter of channel.handshake.queryParameters) {
|
|
795888
|
+
const convertedQueryParameter = buildQueryParameter({
|
|
795889
|
+
queryParameter,
|
|
795890
|
+
context,
|
|
795891
|
+
fileContainingReference: declarationFile
|
|
795892
|
+
});
|
|
795893
|
+
if (convertedQueryParameter == null) {
|
|
795894
|
+
continue;
|
|
795895
|
+
}
|
|
795896
|
+
queryParameters[queryParameter.name] = convertedQueryParameter;
|
|
795897
|
+
}
|
|
795898
|
+
}
|
|
795899
|
+
if (Object.keys(queryParameters).length > 0) {
|
|
795900
|
+
convertedChannel["query-parameters"] = queryParameters;
|
|
795901
|
+
}
|
|
795902
|
+
const headers = {};
|
|
795903
|
+
if (channel.handshake.headers.length > 0) {
|
|
795904
|
+
for (const header of channel.handshake.headers) {
|
|
795905
|
+
const headerSchema = buildHeader({ header, context, fileContainingReference: declarationFile });
|
|
795906
|
+
headers[header.name] = headerSchema;
|
|
795907
|
+
}
|
|
795908
|
+
}
|
|
795909
|
+
if (Object.keys(headers).length > 0) {
|
|
795910
|
+
convertedChannel.headers = headers;
|
|
795911
|
+
}
|
|
795912
|
+
context.builder.addChannel(declarationFile, {
|
|
795913
|
+
channel: convertedChannel
|
|
795914
|
+
});
|
|
795915
|
+
if (channel.subscribe != null) {
|
|
795916
|
+
context.builder.addChannelMessage(declarationFile, {
|
|
795917
|
+
messageId: "subscribe",
|
|
795918
|
+
message: {
|
|
795919
|
+
origin: "server",
|
|
795920
|
+
body: buildTypeReference({
|
|
795921
|
+
schema: channel.subscribe,
|
|
795922
|
+
context,
|
|
795923
|
+
fileContainingReference: declarationFile
|
|
795924
|
+
})
|
|
795925
|
+
}
|
|
795926
|
+
});
|
|
795927
|
+
}
|
|
795928
|
+
if (channel.publish != null) {
|
|
795929
|
+
context.builder.addChannelMessage(declarationFile, {
|
|
795930
|
+
messageId: "publish",
|
|
795931
|
+
message: {
|
|
795932
|
+
origin: "client",
|
|
795933
|
+
body: buildTypeReference({
|
|
795934
|
+
schema: channel.publish,
|
|
795935
|
+
context,
|
|
795936
|
+
fileContainingReference: declarationFile
|
|
795937
|
+
})
|
|
795938
|
+
}
|
|
795939
|
+
});
|
|
795940
|
+
}
|
|
795941
|
+
for (const example of channel.examples) {
|
|
795942
|
+
const websocketExample = buildWebsocketSessionExample({ context, websocketExample: example });
|
|
795943
|
+
context.builder.addChannelExample(declarationFile, {
|
|
795944
|
+
example: websocketExample
|
|
795945
|
+
});
|
|
795946
|
+
}
|
|
795947
|
+
}
|
|
795948
|
+
|
|
795949
|
+
// pnp:/home/circleci/project/packages/cli/openapi-ir-to-fern/lib/buildEnvironments.js
|
|
795950
|
+
var PRODUCTION_ENVNIRONMENT_NAME = "Production";
|
|
795951
|
+
var DEFAULT_ENVIRONMENT_NAME = "Default";
|
|
795952
|
+
function buildEnvironments(context) {
|
|
795953
|
+
var _a2;
|
|
795954
|
+
const topLevelServerURLsWithName = {};
|
|
795955
|
+
const topLevelSkippedServerURLs = [];
|
|
795956
|
+
for (const server of context.ir.servers) {
|
|
795957
|
+
if (server.name == null) {
|
|
795958
|
+
topLevelSkippedServerURLs.push(server.url);
|
|
795959
|
+
continue;
|
|
795960
|
+
}
|
|
795961
|
+
topLevelServerURLsWithName[server.name] = server.url;
|
|
795962
|
+
}
|
|
795963
|
+
const endpointLevelServerURLsWithName = {};
|
|
795964
|
+
const endpointLevelSkippedServerURLs = [];
|
|
795965
|
+
for (const endpoint of context.ir.endpoints) {
|
|
795966
|
+
for (const server of endpoint.server) {
|
|
795967
|
+
if (server.name == null) {
|
|
795968
|
+
endpointLevelSkippedServerURLs.push(server.url);
|
|
795969
|
+
continue;
|
|
795970
|
+
}
|
|
795971
|
+
endpointLevelServerURLsWithName[server.name] = server.url;
|
|
795972
|
+
}
|
|
795973
|
+
}
|
|
795974
|
+
const numTopLevelURLs = Object.keys(topLevelServerURLsWithName).length;
|
|
795975
|
+
const numEndpointLevelURLs = Object.keys(endpointLevelServerURLsWithName).length;
|
|
795976
|
+
if (numTopLevelURLs === 0 && numEndpointLevelURLs === 0) {
|
|
795977
|
+
const singleURL = (_a2 = context.ir.servers[0]) == null ? void 0 : _a2.url;
|
|
795978
|
+
if (singleURL != null) {
|
|
795979
|
+
context.builder.addEnvironment({
|
|
795980
|
+
name: DEFAULT_ENVIRONMENT_NAME,
|
|
795981
|
+
schema: singleURL
|
|
795982
|
+
});
|
|
795983
|
+
context.builder.setDefaultEnvironment(DEFAULT_ENVIRONMENT_NAME);
|
|
795984
|
+
}
|
|
795985
|
+
} else if (numTopLevelURLs > 0 && numEndpointLevelURLs === 0) {
|
|
795986
|
+
let count = 0;
|
|
795987
|
+
if (topLevelSkippedServerURLs.length > 0) {
|
|
795988
|
+
context.logger.error(`Skipping servers ${topLevelSkippedServerURLs.join(", ")} because x-fern-server-name was not provided.`);
|
|
795989
|
+
}
|
|
795990
|
+
for (const [name2, url] of Object.entries(topLevelServerURLsWithName)) {
|
|
795991
|
+
if (count === 0) {
|
|
795992
|
+
context.builder.setDefaultEnvironment(name2);
|
|
795993
|
+
}
|
|
795994
|
+
context.builder.addEnvironment({
|
|
795995
|
+
name: name2,
|
|
795996
|
+
schema: url
|
|
795997
|
+
});
|
|
795998
|
+
count += 1;
|
|
795999
|
+
}
|
|
796000
|
+
} else if (numEndpointLevelURLs > 0) {
|
|
796001
|
+
if (topLevelSkippedServerURLs.length > 0 || endpointLevelSkippedServerURLs.length > 0) {
|
|
796002
|
+
context.logger.error(`Skipping servers ${[...topLevelSkippedServerURLs, ...endpointLevelSkippedServerURLs].join(", ")} because x-fern-server-name was not provided.`);
|
|
796003
|
+
}
|
|
796004
|
+
const toplevelServerURLEntries = Object.entries(topLevelServerURLsWithName)[0];
|
|
796005
|
+
if (toplevelServerURLEntries != null) {
|
|
796006
|
+
const [name2, _4] = toplevelServerURLEntries;
|
|
796007
|
+
context.setDefaultServerName(name2);
|
|
796008
|
+
}
|
|
796009
|
+
context.builder.addEnvironment({
|
|
796010
|
+
name: PRODUCTION_ENVNIRONMENT_NAME,
|
|
796011
|
+
schema: {
|
|
796012
|
+
urls: {
|
|
796013
|
+
...topLevelServerURLsWithName,
|
|
796014
|
+
...endpointLevelServerURLsWithName
|
|
796015
|
+
}
|
|
796016
|
+
}
|
|
796017
|
+
});
|
|
796018
|
+
context.builder.setDefaultEnvironment(PRODUCTION_ENVNIRONMENT_NAME);
|
|
796019
|
+
}
|
|
796020
|
+
}
|
|
796021
|
+
|
|
796022
|
+
// pnp:/home/circleci/project/packages/cli/openapi-ir-to-fern/lib/utils/wrapTypeReferenceAsOptional.js
|
|
796023
|
+
function wrapTypeReferenceAsOptional(typeReference) {
|
|
796024
|
+
const type2 = getTypeFromTypeReference(typeReference);
|
|
796025
|
+
if (type2.startsWith("optional")) {
|
|
796026
|
+
return typeReference;
|
|
796027
|
+
} else if (typeof typeReference === "string") {
|
|
796028
|
+
return `optional<${typeReference}>`;
|
|
796029
|
+
} else {
|
|
796030
|
+
return { ...typeReference, type: `optional<${typeReference.type}>` };
|
|
796031
|
+
}
|
|
796032
|
+
}
|
|
796033
|
+
|
|
796034
|
+
// pnp:/home/circleci/project/packages/cli/openapi-ir-to-fern/lib/buildGlobalHeaders.js
|
|
796035
|
+
var HeaderWithCount = class {
|
|
796036
|
+
schema;
|
|
796037
|
+
count = 0;
|
|
796038
|
+
constructor(schema2) {
|
|
796039
|
+
this.schema = schema2;
|
|
796040
|
+
}
|
|
796041
|
+
increment() {
|
|
796042
|
+
this.count += 1;
|
|
796043
|
+
}
|
|
796044
|
+
};
|
|
796045
|
+
var GLOBAL_HEADER_PERCENTAGE_THRESHOLD = 0.75;
|
|
796046
|
+
var HEADERS_TO_IGNORE = new Set(...["Authorization"]);
|
|
796047
|
+
function buildGlobalHeaders(context) {
|
|
796048
|
+
var _a2;
|
|
796049
|
+
const globalHeaders = {};
|
|
796050
|
+
for (const endpoint of context.ir.endpoints) {
|
|
796051
|
+
for (const header of endpoint.headers) {
|
|
796052
|
+
if (HEADERS_TO_IGNORE.has(header.name)) {
|
|
796053
|
+
continue;
|
|
796054
|
+
}
|
|
796055
|
+
let headerWithCount = globalHeaders[header.name];
|
|
796056
|
+
if (headerWithCount == null) {
|
|
796057
|
+
const convertedHeader = buildHeader({
|
|
796058
|
+
header,
|
|
796059
|
+
fileContainingReference: RelativeFilePath.of(FERN_PACKAGE_MARKER_FILENAME),
|
|
796060
|
+
context
|
|
796061
|
+
});
|
|
796062
|
+
headerWithCount = new HeaderWithCount(convertedHeader);
|
|
796063
|
+
globalHeaders[header.name] = headerWithCount;
|
|
796064
|
+
}
|
|
796065
|
+
headerWithCount.increment();
|
|
796066
|
+
}
|
|
796067
|
+
}
|
|
796068
|
+
const globalHeaderThreshold = context.ir.endpoints.length * GLOBAL_HEADER_PERCENTAGE_THRESHOLD;
|
|
796069
|
+
const predefinedGlobalHeaders = new Map((_a2 = context.ir.globalHeaders) == null ? void 0 : _a2.map((header) => [header.header, header]));
|
|
796070
|
+
for (const [headerName, header] of Object.entries(globalHeaders)) {
|
|
796071
|
+
const predefinedHeader = predefinedGlobalHeaders.get(headerName);
|
|
796072
|
+
let isRequired = header.count === context.ir.endpoints.length;
|
|
796073
|
+
const isOptional = header.count >= globalHeaderThreshold;
|
|
796074
|
+
if (predefinedHeader !== void 0) {
|
|
796075
|
+
isRequired = isRequired && predefinedHeader.optional !== true || predefinedHeader.optional === false;
|
|
796076
|
+
const convertedHeaderSchema = typeof header.schema === "string" ? header.schema : {
|
|
796077
|
+
...header.schema,
|
|
796078
|
+
name: predefinedHeader.name ?? header.schema.name
|
|
796079
|
+
};
|
|
796080
|
+
context.builder.addGlobalHeader({
|
|
796081
|
+
name: headerName,
|
|
796082
|
+
schema: isRequired ? convertedHeaderSchema : wrapTypeReferenceAsOptional(convertedHeaderSchema)
|
|
796083
|
+
});
|
|
796084
|
+
} else if (isRequired) {
|
|
796085
|
+
context.builder.addGlobalHeader({
|
|
796086
|
+
name: headerName,
|
|
796087
|
+
schema: header.schema
|
|
796088
|
+
});
|
|
796089
|
+
} else if (isOptional) {
|
|
796090
|
+
context.builder.addGlobalHeader({
|
|
796091
|
+
name: headerName,
|
|
796092
|
+
schema: wrapTypeReferenceAsOptional(header.schema)
|
|
796093
|
+
});
|
|
796094
|
+
}
|
|
796095
|
+
}
|
|
796096
|
+
}
|
|
796097
|
+
|
|
796098
|
+
// pnp:/home/circleci/project/packages/cli/openapi-ir-to-fern/lib/buildEndpointExample.js
|
|
796099
|
+
function buildEndpointExample({ endpointExample, context }) {
|
|
796100
|
+
const example = {};
|
|
796101
|
+
if (endpointExample.name != null) {
|
|
796102
|
+
example.name = endpointExample.name;
|
|
796103
|
+
}
|
|
796104
|
+
if (endpointExample.description != null) {
|
|
796105
|
+
example.docs = endpointExample.description;
|
|
796106
|
+
}
|
|
796107
|
+
if (endpointExample.pathParameters != null && endpointExample.pathParameters.length > 0) {
|
|
796108
|
+
example["path-parameters"] = convertNamedFullExamples(endpointExample.pathParameters);
|
|
796109
|
+
}
|
|
796110
|
+
if (endpointExample.queryParameters != null && endpointExample.queryParameters.length > 0) {
|
|
796111
|
+
example["query-parameters"] = convertQueryParameterExample2(endpointExample.queryParameters);
|
|
796112
|
+
}
|
|
796113
|
+
if (endpointExample.headers != null && endpointExample.headers.length > 0) {
|
|
796114
|
+
example.headers = convertHeaderExamples2({ context, namedFullExamples: endpointExample.headers });
|
|
796115
|
+
}
|
|
796116
|
+
if (endpointExample.request != null) {
|
|
796117
|
+
example.request = convertFullExample2(endpointExample.request);
|
|
796118
|
+
}
|
|
796119
|
+
if (endpointExample.response != null) {
|
|
796120
|
+
example.response = { body: convertFullExample2(endpointExample.response) };
|
|
796121
|
+
}
|
|
796122
|
+
if (endpointExample.response != null) {
|
|
796123
|
+
example.response = { body: convertFullExample2(endpointExample.response) };
|
|
796124
|
+
}
|
|
796125
|
+
if (endpointExample.codeSamples.length > 0) {
|
|
796126
|
+
example["code-samples"] = endpointExample.codeSamples.map((codeSample) => {
|
|
796127
|
+
if (codeSample.type === "language") {
|
|
796128
|
+
return {
|
|
796129
|
+
name: codeSample.name ?? void 0,
|
|
796130
|
+
docs: codeSample.description ?? void 0,
|
|
796131
|
+
language: codeSample.language,
|
|
796132
|
+
code: codeSample.code,
|
|
796133
|
+
install: codeSample.install ?? void 0
|
|
796134
|
+
};
|
|
796135
|
+
} else {
|
|
796136
|
+
return {
|
|
796137
|
+
name: codeSample.name ?? void 0,
|
|
796138
|
+
docs: codeSample.description ?? void 0,
|
|
796139
|
+
sdk: codeSample.sdk,
|
|
796140
|
+
code: codeSample.code
|
|
796141
|
+
};
|
|
796142
|
+
}
|
|
796143
|
+
}).filter(isNonNullish);
|
|
796144
|
+
}
|
|
796145
|
+
return example;
|
|
796146
|
+
}
|
|
796147
|
+
function convertNamedFullExamples(namedFullExamples) {
|
|
796148
|
+
const result2 = {};
|
|
796149
|
+
namedFullExamples.map((namedFullExample) => result2[namedFullExample.name] = convertFullExample2(namedFullExample.value));
|
|
796150
|
+
return result2;
|
|
796151
|
+
}
|
|
796152
|
+
function convertQueryParameterExample2(namedFullExamples) {
|
|
796153
|
+
const result2 = {};
|
|
796154
|
+
namedFullExamples.forEach((namedFullExample) => {
|
|
796155
|
+
const convertedExample = convertFullExample2(namedFullExample.value);
|
|
796156
|
+
if (Array.isArray(convertedExample)) {
|
|
796157
|
+
result2[namedFullExample.name] = convertedExample[0];
|
|
796158
|
+
} else if (convertedExample != null) {
|
|
796159
|
+
result2[namedFullExample.name] = convertedExample;
|
|
796160
|
+
}
|
|
796161
|
+
});
|
|
796162
|
+
return result2;
|
|
796163
|
+
}
|
|
796164
|
+
function convertHeaderExamples2({ context, namedFullExamples }) {
|
|
796165
|
+
const globalHeaderNames = context.builder.getGlobalHeaderNames();
|
|
796166
|
+
const result2 = {};
|
|
796167
|
+
namedFullExamples.forEach((namedFullExample) => {
|
|
796168
|
+
const convertedExample = convertFullExample2(namedFullExample.value);
|
|
796169
|
+
if (globalHeaderNames.has(namedFullExample.name)) {
|
|
796170
|
+
return;
|
|
796171
|
+
} else if (convertedExample != null) {
|
|
796172
|
+
result2[namedFullExample.name] = convertedExample;
|
|
796173
|
+
}
|
|
796174
|
+
});
|
|
796175
|
+
return result2;
|
|
796176
|
+
}
|
|
796177
|
+
function convertFullExample2(fullExample) {
|
|
796178
|
+
switch (fullExample.type) {
|
|
796179
|
+
case "primitive":
|
|
796180
|
+
return convertPrimitive2(fullExample.value);
|
|
796181
|
+
case "object":
|
|
796182
|
+
return convertObject3(fullExample.properties);
|
|
796183
|
+
case "array":
|
|
796184
|
+
return convertArrayExample2(fullExample.value);
|
|
796185
|
+
case "map":
|
|
796186
|
+
return convertMapExample2(fullExample.value);
|
|
796187
|
+
case "oneOf":
|
|
796188
|
+
return convertOneOfExample2(fullExample.value);
|
|
796189
|
+
case "enum":
|
|
796190
|
+
return fullExample.value;
|
|
796191
|
+
case "literal":
|
|
796192
|
+
return convertLiteralExample2(fullExample.value);
|
|
796193
|
+
case "unknown":
|
|
796194
|
+
return convertFullExample2(fullExample.value);
|
|
796195
|
+
default:
|
|
796196
|
+
assertNever(fullExample);
|
|
796197
|
+
}
|
|
796198
|
+
}
|
|
796199
|
+
function convertPrimitive2(primitiveExample) {
|
|
796200
|
+
switch (primitiveExample.type) {
|
|
796201
|
+
case "int":
|
|
796202
|
+
return primitiveExample.value;
|
|
796203
|
+
case "int64":
|
|
796204
|
+
return primitiveExample.value;
|
|
796205
|
+
case "float":
|
|
796206
|
+
return primitiveExample.value;
|
|
796207
|
+
case "double":
|
|
796208
|
+
return primitiveExample.value;
|
|
796209
|
+
case "string": {
|
|
796210
|
+
if (primitiveExample.value.startsWith("$")) {
|
|
796211
|
+
return `${primitiveExample.value.slice(1)}`;
|
|
796212
|
+
}
|
|
796213
|
+
return primitiveExample.value;
|
|
796214
|
+
}
|
|
796215
|
+
case "datetime":
|
|
796216
|
+
try {
|
|
796217
|
+
return primitiveExample.value.toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
796218
|
+
} catch (e) {
|
|
796219
|
+
return "2024-01-15T09:30:00Z";
|
|
796220
|
+
}
|
|
796221
|
+
case "date":
|
|
796222
|
+
return primitiveExample.value;
|
|
796223
|
+
case "base64":
|
|
796224
|
+
case "boolean":
|
|
796225
|
+
return primitiveExample.value;
|
|
796226
|
+
default:
|
|
796227
|
+
assertNever(primitiveExample);
|
|
796228
|
+
}
|
|
796229
|
+
}
|
|
796230
|
+
function convertObject3(object3) {
|
|
796231
|
+
return Object.fromEntries(Object.entries(object3).map(([propertyKey, fullExample]) => {
|
|
796232
|
+
return [propertyKey, convertFullExample2(fullExample)];
|
|
796233
|
+
}));
|
|
796234
|
+
}
|
|
796235
|
+
function convertArrayExample2(fullExamples) {
|
|
796236
|
+
return fullExamples.map((fullExample) => {
|
|
796237
|
+
return convertFullExample2(fullExample);
|
|
796238
|
+
});
|
|
796239
|
+
}
|
|
796240
|
+
function convertMapExample2(pairs2) {
|
|
796241
|
+
return Object.fromEntries(pairs2.map((pair) => {
|
|
796242
|
+
return [convertPrimitive2(pair.key), convertFullExample2(pair.value)];
|
|
796243
|
+
}));
|
|
796244
|
+
}
|
|
796245
|
+
function convertOneOfExample2(oneOf) {
|
|
796246
|
+
if (oneOf.type === "discriminated") {
|
|
796247
|
+
return convertObject3(oneOf.value);
|
|
796248
|
+
}
|
|
796249
|
+
return convertFullExample2(oneOf.value);
|
|
796250
|
+
}
|
|
796251
|
+
function convertLiteralExample2(literal2) {
|
|
796252
|
+
switch (literal2.type) {
|
|
796253
|
+
case "string":
|
|
796254
|
+
return literal2.value;
|
|
796255
|
+
case "boolean":
|
|
796256
|
+
return literal2.value;
|
|
796257
|
+
default:
|
|
796258
|
+
assertNever(literal2);
|
|
796259
|
+
}
|
|
796260
|
+
}
|
|
796261
|
+
|
|
795913
796262
|
// pnp:/home/circleci/project/packages/cli/openapi-ir-to-fern/lib/buildPathParameter.js
|
|
795914
796263
|
function buildPathParameter({ pathParameter, context, fileContainingReference }) {
|
|
795915
796264
|
const typeReference = buildTypeReference({
|
|
@@ -796702,6 +797051,22 @@ var FernDefinitionBuilderImpl = class {
|
|
|
796702
797051
|
const fernFile = this.getOrCreateFile(file);
|
|
796703
797052
|
fernFile.channel = channel;
|
|
796704
797053
|
}
|
|
797054
|
+
addChannelExample(file, { example }) {
|
|
797055
|
+
const fernFile = this.getOrCreateFile(file);
|
|
797056
|
+
if (fernFile.channel == null) {
|
|
797057
|
+
fernFile.channel = {
|
|
797058
|
+
path: "",
|
|
797059
|
+
auth: false
|
|
797060
|
+
};
|
|
797061
|
+
}
|
|
797062
|
+
if (fernFile.channel.messages == null) {
|
|
797063
|
+
fernFile.channel.messages = {};
|
|
797064
|
+
}
|
|
797065
|
+
if (fernFile.channel.examples == null) {
|
|
797066
|
+
fernFile.channel.examples = [];
|
|
797067
|
+
}
|
|
797068
|
+
fernFile.channel.examples.push(example);
|
|
797069
|
+
}
|
|
796705
797070
|
addChannelMessage(file, { messageId, message }) {
|
|
796706
797071
|
const fernFile = this.getOrCreateFile(file);
|
|
796707
797072
|
if (fernFile.channel == null) {
|
|
@@ -804127,10 +804492,10 @@ var CliContext = class {
|
|
|
804127
804492
|
return "fern-api";
|
|
804128
804493
|
}
|
|
804129
804494
|
getPackageVersion() {
|
|
804130
|
-
if ("0.18.
|
|
804495
|
+
if ("0.18.3-rc0" == null) {
|
|
804131
804496
|
this.logger.error("CLI_VERSION is not defined");
|
|
804132
804497
|
}
|
|
804133
|
-
return "0.18.
|
|
804498
|
+
return "0.18.3-rc0";
|
|
804134
804499
|
}
|
|
804135
804500
|
getCliName() {
|
|
804136
804501
|
if ("fern" == null) {
|
|
@@ -806987,7 +807352,7 @@ function convertTypeExample({ typeName, typeDeclaration, example, typeResolver,
|
|
|
806987
807352
|
});
|
|
806988
807353
|
},
|
|
806989
807354
|
object: (rawObject) => {
|
|
806990
|
-
return
|
|
807355
|
+
return convertObject4({
|
|
806991
807356
|
typeName,
|
|
806992
807357
|
rawObject,
|
|
806993
807358
|
example,
|
|
@@ -807268,7 +807633,7 @@ function convertPrimitiveExample({ example, typeBeingExemplified }) {
|
|
|
807268
807633
|
}
|
|
807269
807634
|
});
|
|
807270
807635
|
}
|
|
807271
|
-
function
|
|
807636
|
+
function convertObject4({ typeName, rawObject, example, fileContainingType, fileContainingExample, typeResolver, exampleResolver, workspace }) {
|
|
807272
807637
|
if (!isPlainObject(example)) {
|
|
807273
807638
|
throw new Error("Example is not an object");
|
|
807274
807639
|
}
|
|
@@ -807404,7 +807769,7 @@ function convertSingleUnionType({ rawValueType, rawSingleUnionType, fileContaini
|
|
|
807404
807769
|
wireDiscriminantValue,
|
|
807405
807770
|
shape: ExampleSingleUnionTypeProperties.samePropertiesAsObject({
|
|
807406
807771
|
typeId: IdGenerator.generateTypeId(typeName),
|
|
807407
|
-
object:
|
|
807772
|
+
object: convertObject4({
|
|
807408
807773
|
rawObject: rawDeclaration.declaration,
|
|
807409
807774
|
example: nonDiscriminantPropertiesFromExample,
|
|
807410
807775
|
fileContainingType: rawDeclaration.file,
|