poe-code 3.0.186 → 3.0.187

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "poe-code",
3
- "version": "3.0.186",
3
+ "version": "3.0.187",
4
4
  "description": "CLI tool to configure Poe API for developer workflows.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -311,7 +311,7 @@ function assertSupportedSuccessResponses(document, operation, operationId) {
311
311
  }
312
312
  }
313
313
  function assertSupportedSuccessResponseSchema(document, schema, operationId, context) {
314
- const resolvedSchema = expectSchema(document, schema, operationId, context);
314
+ const resolvedSchema = expectSupportedSuccessResponseSchema(document, schema, operationId, context);
315
315
  if (resolvedSchema.additionalProperties !== undefined &&
316
316
  resolvedSchema.additionalProperties !== false) {
317
317
  throw new UserError(`Operation ${JSON.stringify(operationId)} uses unsupported ${context}. Object response schemas with additionalProperties are not supported in v1.`);
@@ -323,6 +323,20 @@ function assertSupportedSuccessResponseSchema(document, schema, operationId, con
323
323
  assertSupportedSuccessResponseSchema(document, resolvedSchema.items, operationId, `${context} items`);
324
324
  }
325
325
  }
326
+ function expectSupportedSuccessResponseSchema(document, schema, operationId, context) {
327
+ const resolvedSchema = resolveSchema(document, schema, operationId, context);
328
+ const compositionKeyword = getCompositionKeyword(resolvedSchema);
329
+ if (compositionKeyword === undefined) {
330
+ return resolvedSchema;
331
+ }
332
+ const nullableAnyOfSchema = compositionKeyword === "anyOf"
333
+ ? resolveNullableAnyOfSchema(document, resolvedSchema, operationId, context)
334
+ : undefined;
335
+ if (nullableAnyOfSchema !== undefined) {
336
+ return nullableAnyOfSchema;
337
+ }
338
+ throw new UserError(`Operation ${JSON.stringify(operationId)} uses unsupported ${context}. JSON Schema composition keyword ${JSON.stringify(compositionKeyword)} is not supported in v1.`);
339
+ }
326
340
  function createGeneratedParameter(document, parameter, operationId) {
327
341
  const schema = expectSchema(document, parameter.schema, operationId, `parameter ${JSON.stringify(parameter.name)}`);
328
342
  if (parameter.in === "path") {
@@ -749,16 +763,20 @@ function expectResponse(document, response, operationId, statusCode, refChain =
749
763
  return expectResponse(document, resolveLocalReference(document, response.$ref, operationId, context), operationId, statusCode, [...refChain, response.$ref]);
750
764
  }
751
765
  function expectSchema(document, schema, operationId, context, refChain = []) {
766
+ const resolvedSchema = resolveSchema(document, schema, operationId, context, refChain);
767
+ const compositionKeyword = getCompositionKeyword(resolvedSchema);
768
+ if (compositionKeyword !== undefined) {
769
+ throw new UserError(`Operation ${JSON.stringify(operationId)} uses unsupported ${context}. JSON Schema composition keyword ${JSON.stringify(compositionKeyword)} is not supported in v1.`);
770
+ }
771
+ return resolvedSchema;
772
+ }
773
+ function resolveSchema(document, schema, operationId, context, refChain = []) {
752
774
  if (schema === undefined) {
753
775
  throw new UserError(`Operation ${JSON.stringify(operationId)} is missing a schema for ${context}.`);
754
776
  }
755
777
  if (isReferenceObject(schema)) {
756
778
  assertAcyclicRef(schema.$ref, refChain, operationId, context);
757
- return expectSchema(document, resolveLocalReference(document, schema.$ref, operationId, context), operationId, context, [...refChain, schema.$ref]);
758
- }
759
- const compositionKeyword = getCompositionKeyword(schema);
760
- if (compositionKeyword !== undefined) {
761
- throw new UserError(`Operation ${JSON.stringify(operationId)} uses unsupported ${context}. JSON Schema composition keyword ${JSON.stringify(compositionKeyword)} is not supported in v1.`);
779
+ return resolveSchema(document, resolveLocalReference(document, schema.$ref, operationId, context), operationId, context, [...refChain, schema.$ref]);
762
780
  }
763
781
  return schema;
764
782
  }
@@ -770,6 +788,28 @@ function getCompositionKeyword(schema) {
770
788
  }
771
789
  return undefined;
772
790
  }
791
+ function resolveNullableAnyOfSchema(document, schema, operationId, context) {
792
+ const variants = schema.anyOf;
793
+ if (variants === undefined || variants.length !== 2) {
794
+ return undefined;
795
+ }
796
+ const resolvedVariants = variants.map((variant, index) => resolveSchema(document, variant, operationId, `${context} anyOf variant ${index}`));
797
+ const nullVariantIndex = resolvedVariants.findIndex(isExplicitNullSchema);
798
+ if (nullVariantIndex === -1) {
799
+ return undefined;
800
+ }
801
+ const nonNullVariant = resolvedVariants[Number(!nullVariantIndex)];
802
+ if (nonNullVariant === undefined || getCompositionKeyword(nonNullVariant) !== undefined) {
803
+ return undefined;
804
+ }
805
+ return {
806
+ ...nonNullVariant,
807
+ nullable: true
808
+ };
809
+ }
810
+ function isExplicitNullSchema(schema) {
811
+ return schema.type === "null";
812
+ }
773
813
  function assertAcyclicRef(ref, refChain, operationId, context) {
774
814
  if (!refChain.includes(ref)) {
775
815
  return;