@tahminator/sapling 2.0.5-beta.66bccb38 → 2.0.5-beta.75e5e346

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/dist/index.cjs CHANGED
@@ -548,25 +548,26 @@ var OpenAPIGenerator = class {
548
548
  const schemas = _getValidatorSchema(controllerClass, route.fnName);
549
549
  const routeSchema = _getRouteSchema(controllerClass, route.fnName);
550
550
  if (route.path instanceof RegExp) throw new Error(`You have a route with a regex path of ${route.path.source}. This is not compatible with OpenAPI.`);
551
- const openApiPath = prefix + route.path;
551
+ const openApiPath = (prefix + route.path).replace(/:([A-Za-z0-9_]+)/g, "{$1}");
552
552
  if (!paths[openApiPath]) paths[openApiPath] = {};
553
553
  const responses = {};
554
554
  if (schemas?.responseBody) {
555
- const responseSchema = this.toJsonSchema(schemas.responseBody, "input");
555
+ const responseSchema = this.toJsonSchema(schemas.responseBody, "output");
556
556
  responses["200"] = {
557
557
  description: responseSchema.description ?? "Successful response",
558
558
  content: { "application/json": { schema: responseSchema } }
559
559
  };
560
560
  } else responses["200"] = { description: "Successful response" };
561
561
  if (routeSchema?.responses) for (const resp of routeSchema.responses) {
562
- const responseSchema = this.toJsonSchema(resp.schema, "input");
562
+ const responseSchema = resp.schema ? this.toJsonSchema(resp.schema, "output") : void 0;
563
563
  responses[String(resp.statusCode)] = {
564
- description: responseSchema.description ?? `Response ${resp.statusCode}`,
565
- content: { "application/json": { schema: responseSchema } }
564
+ description: resp.description ?? responseSchema?.description ?? `Response ${resp.statusCode}`,
565
+ ...responseSchema ? { content: { "application/json": { schema: responseSchema } } } : {}
566
566
  };
567
567
  }
568
568
  const operation = {
569
569
  responses,
570
+ summary: routeSchema?.summary,
570
571
  description: routeSchema?.description,
571
572
  tags: controllerSchema?.title ? [controllerSchema.title] : void 0
572
573
  };
@@ -817,7 +818,7 @@ function _getOrCreateSchemaDefinition(ctor, fnName) {
817
818
  async function _parseOrThrow(schema, input, kind) {
818
819
  const result = await schema["~standard"].validate(input);
819
820
  if (result.issues) {
820
- console.debug(`Failed to parse a schema`);
821
+ console.debug(`Failed to parse ${schema["~standard"].vendor} schema\nissues: ${result.issues}`);
821
822
  throw new ParserError(kind, result.issues, schema["~standard"].vendor);
822
823
  }
823
824
  return result.value;
package/dist/index.d.cts CHANGED
@@ -892,9 +892,11 @@ declare function _setOnce(def: ValidatorSchema, key: keyof ValidatorSchema, sche
892
892
  //#region src/annotation/schema.d.ts
893
893
  type ResponseSchema = {
894
894
  statusCode: HttpStatus;
895
- schema: StandardSchemaV1 & StandardJSONSchemaV1;
895
+ description?: string;
896
+ schema?: StandardSchemaV1 & StandardJSONSchemaV1;
896
897
  };
897
898
  type RouteSchemaDefinition = {
899
+ summary?: string;
898
900
  description?: string;
899
901
  responses?: ResponseSchema[];
900
902
  };
@@ -907,6 +909,7 @@ declare function ControllerSchema(options: {
907
909
  description?: string;
908
910
  }): ClassDecorator;
909
911
  declare function RouteSchema(options: {
912
+ summary?: string;
910
913
  description?: string;
911
914
  responses?: ResponseSchema[];
912
915
  }): MethodDecorator;
package/dist/index.d.mts CHANGED
@@ -892,9 +892,11 @@ declare function _setOnce(def: ValidatorSchema, key: keyof ValidatorSchema, sche
892
892
  //#region src/annotation/schema.d.ts
893
893
  type ResponseSchema = {
894
894
  statusCode: HttpStatus;
895
- schema: StandardSchemaV1 & StandardJSONSchemaV1;
895
+ description?: string;
896
+ schema?: StandardSchemaV1 & StandardJSONSchemaV1;
896
897
  };
897
898
  type RouteSchemaDefinition = {
899
+ summary?: string;
898
900
  description?: string;
899
901
  responses?: ResponseSchema[];
900
902
  };
@@ -907,6 +909,7 @@ declare function ControllerSchema(options: {
907
909
  description?: string;
908
910
  }): ClassDecorator;
909
911
  declare function RouteSchema(options: {
912
+ summary?: string;
910
913
  description?: string;
911
914
  responses?: ResponseSchema[];
912
915
  }): MethodDecorator;
package/dist/index.mjs CHANGED
@@ -523,25 +523,26 @@ var OpenAPIGenerator = class {
523
523
  const schemas = _getValidatorSchema(controllerClass, route.fnName);
524
524
  const routeSchema = _getRouteSchema(controllerClass, route.fnName);
525
525
  if (route.path instanceof RegExp) throw new Error(`You have a route with a regex path of ${route.path.source}. This is not compatible with OpenAPI.`);
526
- const openApiPath = prefix + route.path;
526
+ const openApiPath = (prefix + route.path).replace(/:([A-Za-z0-9_]+)/g, "{$1}");
527
527
  if (!paths[openApiPath]) paths[openApiPath] = {};
528
528
  const responses = {};
529
529
  if (schemas?.responseBody) {
530
- const responseSchema = this.toJsonSchema(schemas.responseBody, "input");
530
+ const responseSchema = this.toJsonSchema(schemas.responseBody, "output");
531
531
  responses["200"] = {
532
532
  description: responseSchema.description ?? "Successful response",
533
533
  content: { "application/json": { schema: responseSchema } }
534
534
  };
535
535
  } else responses["200"] = { description: "Successful response" };
536
536
  if (routeSchema?.responses) for (const resp of routeSchema.responses) {
537
- const responseSchema = this.toJsonSchema(resp.schema, "input");
537
+ const responseSchema = resp.schema ? this.toJsonSchema(resp.schema, "output") : void 0;
538
538
  responses[String(resp.statusCode)] = {
539
- description: responseSchema.description ?? `Response ${resp.statusCode}`,
540
- content: { "application/json": { schema: responseSchema } }
539
+ description: resp.description ?? responseSchema?.description ?? `Response ${resp.statusCode}`,
540
+ ...responseSchema ? { content: { "application/json": { schema: responseSchema } } } : {}
541
541
  };
542
542
  }
543
543
  const operation = {
544
544
  responses,
545
+ summary: routeSchema?.summary,
545
546
  description: routeSchema?.description,
546
547
  tags: controllerSchema?.title ? [controllerSchema.title] : void 0
547
548
  };
@@ -792,7 +793,7 @@ function _getOrCreateSchemaDefinition(ctor, fnName) {
792
793
  async function _parseOrThrow(schema, input, kind) {
793
794
  const result = await schema["~standard"].validate(input);
794
795
  if (result.issues) {
795
- console.debug(`Failed to parse a schema`);
796
+ console.debug(`Failed to parse ${schema["~standard"].vendor} schema\nissues: ${result.issues}`);
796
797
  throw new ParserError(kind, result.issues, schema["~standard"].vendor);
797
798
  }
798
799
  return result.value;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tahminator/sapling",
3
- "version": "2.0.5-beta.66bccb38",
3
+ "version": "2.0.5-beta.75e5e346",
4
4
  "author": "Tahmid Ahmed",
5
5
  "description": "A library to help you write cleaner Express.js code",
6
6
  "repository": {