Skip to content

Commit 5568964

Browse files
Fix some more const
1 parent e3bc08c commit 5568964

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openapi-typescript-codegen",
3-
"version": "0.26.1",
3+
"version": "0.26.2",
44
"description": "Library that generates Typescript clients based on the OpenAPI specification.",
55
"author": "Ferdi Koomen",
66
"homepage": "https://github.com/ferdikoomen/openapi-typescript-codegen",

src/openApi/v3/parser/getModel.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,15 @@ export const getModel = (
179179
}
180180
}
181181

182+
if (definition.const !== undefined) {
183+
model.export = 'const';
184+
const definitionConst = definition.const;
185+
const modelConst = typeof definitionConst === 'string' ? `"${definitionConst}"` : `${definitionConst}`;
186+
model.type = modelConst;
187+
model.base = modelConst;
188+
return model;
189+
}
190+
182191
// If the schema has a type than it can be a basic or generic type.
183192
if (definition.type) {
184193
const definitionType = getType(definition.type, definition.format);
@@ -192,14 +201,5 @@ export const getModel = (
192201
return model;
193202
}
194203

195-
if (definition.const !== undefined) {
196-
model.export = 'const';
197-
const definitionConst = definition.const;
198-
const modelConst = typeof definitionConst === 'string' ? `"${definitionConst}"` : `${definitionConst}`;
199-
model.type = modelConst;
200-
model.base = modelConst;
201-
return model;
202-
}
203-
204204
return model;
205205
};

test/__snapshots__/index.spec.ts.snap

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4567,10 +4567,10 @@ exports[`v3 should generate: test/generated/v3/models/ModelWithConst.ts 1`] = `
45674567
/* tslint:disable */
45684568
/* eslint-disable */
45694569
export type ModelWithConst = {
4570-
string?: "string";
4570+
String?: "String";
45714571
number?: 0;
4572-
boolean?: false;
45734572
null?: null;
4573+
withType?: "Some string";
45744574
};
45754575

45764576
"
@@ -5894,18 +5894,18 @@ exports[`v3 should generate: test/generated/v3/schemas/$ModelWithConst.ts 1`] =
58945894
/* eslint-disable */
58955895
export const $ModelWithConst = {
58965896
properties: {
5897-
string: {
5898-
type: '"string"',
5897+
String: {
5898+
type: '"String"',
58995899
},
59005900
number: {
59015901
type: '0',
59025902
},
5903-
boolean: {
5904-
type: 'false',
5905-
},
59065903
null: {
59075904
type: 'null',
59085905
},
5906+
withType: {
5907+
type: '"Some string"',
5908+
},
59095909
},
59105910
} as const;
59115911
"

test/spec/v3.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2557,17 +2557,18 @@
25572557
"ModelWithConst": {
25582558
"type": "object",
25592559
"properties": {
2560-
"string": {
2561-
"const": "string"
2560+
"String": {
2561+
"const": "String"
25622562
},
25632563
"number": {
25642564
"const": 0
25652565
},
2566-
"boolean": {
2567-
"const": false
2568-
},
25692566
"null": {
25702567
"const": null
2568+
},
2569+
"withType": {
2570+
"type": "string",
2571+
"const": "Some string"
25712572
}
25722573
}
25732574
}

0 commit comments

Comments
 (0)