Skip to content

Commit 3ddaf19

Browse files
authored
fix: const parameter types not working as expected (#273)
1 parent 84d0b48 commit 3ddaf19

File tree

13 files changed

+278
-60
lines changed

13 files changed

+278
-60
lines changed

package-lock.json

Lines changed: 35 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"bugs": "https://github.com/the-codegen-project/cli/issues",
99
"dependencies": {
1010
"@asyncapi/avro-schema-parser": "^3.0.24",
11-
"@asyncapi/modelina": "^5.7.2",
11+
"@asyncapi/modelina": "^6.0.0-next.3",
1212
"@asyncapi/openapi-schema-parser": "^3.0.24",
1313
"@asyncapi/parser": "^3.4.0",
1414
"@asyncapi/protobuf-schema-parser": "^3.5.1",

src/codegen/inputs/asyncapi/generators/parameters.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,14 @@ export function unwrap(channelParameters: ConstrainedObjectModel) {
7575
if(${variableName} && ${variableName} !== '') {
7676
parameters.${parameter.propertyName} = ${variableName} as any
7777
} else {
78-
throw new Error(\`Parameter: '${parameter.propertyName}' is not valid. Abort! \`)
78+
throw new Error(\`Parameter: '${parameter.propertyName}' is not valid in ${channelParameters.name}. Aborting parameter extracting! \`)
7979
}`;
8080
}
8181
);
8282

83-
const parameterInitializer = Object.values(channelParameters.properties).map(
84-
(parameter) => {
83+
const parameterInitializer = Object.values(channelParameters.properties)
84+
.filter(parameter => parameter.property.options.const?.value === undefined)
85+
.map((parameter) => {
8586
if (parameter.property.options.isNullable) {
8687
return `${parameter.propertyName}: null`;
8788
}

src/codegen/inputs/asyncapi/generators/payloads.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ export interface ProcessedPayloadSchemaData {
1515
operationPayloads: Record<string, {schema: any; schemaId: string}>;
1616
otherPayloads: {schema: any; schemaId: string}[];
1717
}
18-
const processor = new AsyncAPIInputProcessor();
19-
// AsyncAPI input processor
18+
2019
// eslint-disable-next-line sonarjs/cognitive-complexity
2120
export async function processAsyncAPIPayloads(
2221
asyncapiDocument: AsyncAPIDocumentInterface

src/codegen/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export interface LoadArgument {
6868
export type SupportedLanguages = 'typescript';
6969
export interface GenericCodegenContext {
7070
dependencyOutputs: Record<string, any>;
71-
config: TheCodegenConfiguration;
71+
config?: TheCodegenConfiguration;
7272
}
7373

7474
export const zodAsyncAPITypeScriptGenerators = z.discriminatedUnion('preset', [

test/codegen/generators/typescript/__snapshots__/channels.spec.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

33
exports[`channels typescript should work with basic AsyncAPI inputs 1`] = `
44
"import * as TestPayloadModelModule from './../../../../TestPayloadModel';

test/codegen/generators/typescript/__snapshots__/headers.spec.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

33
exports[`headers typescript should work with OpenAPI 2.0 inputs 1`] = `
44
"import {Ajv, Options as AjvOptions, ErrorObject, ValidateFunction} from 'ajv';

0 commit comments

Comments
 (0)