Skip to content

Commit be775ce

Browse files
committed
Add additionalProperties tests
1 parent 0aeefa0 commit be775ce

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

tests/swagger-2.test.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Swagger2 } from '../src/swagger-2';
88
// Let Prettier handle formatting, not the test expectations
99
function format(spec: string, namespaced?: boolean) {
1010
const wrapped = namespaced === false ? spec : `namespace OpenAPI2 { ${spec} }`;
11-
return prettier.format(wrapped, { parser: 'typescript' });
11+
return prettier.format(wrapped, { parser: 'typescript', singleQuote: true });
1212
}
1313

1414
describe('Swagger 2 spec', () => {
@@ -249,6 +249,44 @@ describe('Swagger 2 spec', () => {
249249
});
250250
});
251251

252+
it('can deal with additionalProperties: true', () => {
253+
const swagger: Swagger2 = {
254+
definitions: {
255+
FeatureMap: {
256+
type: 'object',
257+
additionalProperties: true,
258+
},
259+
},
260+
};
261+
262+
const ts = format(`
263+
export interface FeatureMap {
264+
[name: string]: any;
265+
}`);
266+
267+
expect(swaggerToTS(swagger)).toBe(ts);
268+
});
269+
270+
it('can deal with additionalProperties of type', () => {
271+
const swagger: Swagger2 = {
272+
definitions: {
273+
Credentials: {
274+
type: 'object',
275+
additionalProperties: {
276+
type: 'string',
277+
},
278+
},
279+
},
280+
};
281+
282+
const ts = format(`
283+
export interface Credentials {
284+
[name: string]: string;
285+
}`);
286+
287+
expect(swaggerToTS(swagger)).toBe(ts);
288+
});
289+
252290
describe('other output', () => {
253291
it('generates the example output correctly', () => {
254292
const input = yaml.safeLoad(

0 commit comments

Comments
 (0)