Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 36362e6

Browse files
committed
Move helpers below plugin.
1 parent 3d5597f commit 36362e6

File tree

3 files changed

+62
-62
lines changed

3 files changed

+62
-62
lines changed

conformance/src/fastify/conformanceApiPlugin.ts

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,6 @@
44
import { FastifyPluginAsync, RegisterOptions } from 'fastify';
55
import { IServiceResult, IServiceError } from 'facility-core';
66

7-
const standardErrorCodes: { [code: string]: number } = {
8-
'NotModified': 304,
9-
'InvalidRequest': 400,
10-
'NotAuthenticated': 401,
11-
'NotAuthorized': 403,
12-
'NotFound': 404,
13-
'Conflict': 409,
14-
'RequestTooLarge': 413,
15-
'TooManyRequests': 429,
16-
'InternalError': 500,
17-
'ServiceUnavailable': 503,
18-
'NotAdmin': 403,
19-
'TooHappy': 500,
20-
};
21-
22-
function parseBoolean(value: string | undefined) {
23-
if (typeof value === 'string') {
24-
const lowerValue = value.toLowerCase();
25-
if (lowerValue === 'true') {
26-
return true;
27-
}
28-
if (lowerValue === 'false') {
29-
return false;
30-
}
31-
}
32-
return undefined;
33-
}
34-
357
export type ConformanceApiPluginOptions = RegisterOptions & {
368
api: IConformanceApi;
379
caseInsenstiveQueryStringKeys?: boolean;
@@ -829,6 +801,34 @@ const jsonSchemas = [
829801
} as const,
830802
] as const;
831803

804+
const standardErrorCodes: { [code: string]: number } = {
805+
'NotModified': 304,
806+
'InvalidRequest': 400,
807+
'NotAuthenticated': 401,
808+
'NotAuthorized': 403,
809+
'NotFound': 404,
810+
'Conflict': 409,
811+
'RequestTooLarge': 413,
812+
'TooManyRequests': 429,
813+
'InternalError': 500,
814+
'ServiceUnavailable': 503,
815+
'NotAdmin': 403,
816+
'TooHappy': 500,
817+
};
818+
819+
function parseBoolean(value: string | undefined) {
820+
if (typeof value === 'string') {
821+
const lowerValue = value.toLowerCase();
822+
if (lowerValue === 'true') {
823+
return true;
824+
}
825+
if (lowerValue === 'false') {
826+
return false;
827+
}
828+
}
829+
return undefined;
830+
}
831+
832832
/** API for a Facility test server. */
833833
export interface IConformanceApi {
834834
/** Gets API information. */

conformance/src/fastify/jsConformanceApiPlugin.js

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,6 @@
33
'use strict';
44

55

6-
const standardErrorCodes = {
7-
'NotModified': 304,
8-
'InvalidRequest': 400,
9-
'NotAuthenticated': 401,
10-
'NotAuthorized': 403,
11-
'NotFound': 404,
12-
'Conflict': 409,
13-
'RequestTooLarge': 413,
14-
'TooManyRequests': 429,
15-
'InternalError': 500,
16-
'ServiceUnavailable': 503,
17-
'NotAdmin': 403,
18-
'TooHappy': 500,
19-
};
20-
21-
function parseBoolean(value) {
22-
if (typeof value === 'string') {
23-
const lowerValue = value.toLowerCase();
24-
if (lowerValue === 'true') {
25-
return true;
26-
}
27-
if (lowerValue === 'false') {
28-
return false;
29-
}
30-
}
31-
return undefined;
32-
}
33-
346
export const jsConformanceApiPlugin = async (fastify, opts) => {
357
const { api, caseInsenstiveQueryStringKeys, includeErrorDetails } = opts;
368

@@ -821,3 +793,31 @@ const jsonSchemas = [
821793
enum: [ 'yes', 'no', 'maybe' ],
822794
},
823795
];
796+
797+
const standardErrorCodes = {
798+
'NotModified': 304,
799+
'InvalidRequest': 400,
800+
'NotAuthenticated': 401,
801+
'NotAuthorized': 403,
802+
'NotFound': 404,
803+
'Conflict': 409,
804+
'RequestTooLarge': 413,
805+
'TooManyRequests': 429,
806+
'InternalError': 500,
807+
'ServiceUnavailable': 503,
808+
'NotAdmin': 403,
809+
'TooHappy': 500,
810+
};
811+
812+
function parseBoolean(value) {
813+
if (typeof value === 'string') {
814+
const lowerValue = value.toLowerCase();
815+
if (lowerValue === 'true') {
816+
return true;
817+
}
818+
if (lowerValue === 'false') {
819+
return false;
820+
}
821+
}
822+
return undefined;
823+
}

src/Facility.CodeGen.JavaScript/JavaScriptGenerator.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -589,12 +589,6 @@ private CodeGenOutput GenerateFastifyPluginOutput(ServiceInfo service)
589589
}
590590
WriteImports(code, facilityImports, "facility-core");
591591

592-
code.WriteLine();
593-
WriteStandardErrorCodesVariable("standardErrorCodes", code, httpServiceInfo.ErrorSets);
594-
595-
code.WriteLine();
596-
WriteParseBooleanFunction("parseBoolean", code);
597-
598592
if (TypeScript)
599593
{
600594
code.WriteLine();
@@ -832,6 +826,12 @@ private CodeGenOutput GenerateFastifyPluginOutput(ServiceInfo service)
832826

833827
WriteJsonSchemaDtos(code, service);
834828

829+
code.WriteLine();
830+
WriteStandardErrorCodesVariable("standardErrorCodes", code, httpServiceInfo.ErrorSets);
831+
832+
code.WriteLine();
833+
WriteParseBooleanFunction("parseBoolean", code);
834+
835835
if (TypeScript)
836836
WriteTypes(code, httpServiceInfo);
837837
});

0 commit comments

Comments
 (0)