Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: schema type casing #221

Merged
merged 3 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions test/transforms/components/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -647,13 +647,29 @@ describe('parseComponents method', () => {
});

it('Should parse an album schema with an array of Songs schemas.', () => {
const jsodInput = [`
/**
* Album
* @typedef {object} Album
* @property {array<Song>} Songs
*/
`];
const jsodInput = [
[`
/**
* Album
* @typedef {object} Album
* @property {array<Song>} Songs
*/
`],
[`
/**
* Album
* @typedef {object} Album
* @property {Array<Song>} Songs
*/
`],
[`
/**
* Album
* @typedef {object} Album
* @property {Song[]} Songs
*/
`],
];
const expected = {
components: {
schemas: {
Expand All @@ -673,9 +689,11 @@ describe('parseComponents method', () => {
},
},
};
const parsedJSDocs = jsdocInfo()(jsodInput);
const result = parseComponents({}, parsedJSDocs);
expect(result).toEqual(expected);
jsodInput.forEach(jsod => {
const parsedJSDocs = jsdocInfo()(jsod);
const result = parseComponents({}, parsedJSDocs);
expect(result).toEqual(expected);
});
});

it('Should parse a SingleAlbum schema with allOf reference of Song.', () => {
Expand Down
34 changes: 25 additions & 9 deletions test/transforms/paths/parameters.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,26 @@ describe('params tests', () => {
});

it('should parse jsdoc path params with array of references', () => {
const jsodInput = [`
/**
* GET /api/v1
* @param {array<Song>} name.query.required.deprecated - name param description
*/
`];
const jsodInput = [
[`
/**
* GET /api/v1
* @param {array<Song>} name.query.required.deprecated - name param description
*/
`],
[`
/**
* GET /api/v1
* @param {Array<Song>} name.query.required.deprecated - name param description
*/
`],
[`
/**
* GET /api/v1
* @param {Song[]} name.query.required.deprecated - name param description
*/
`],
];
const expected = {
paths: {
'/api/v1': {
Expand Down Expand Up @@ -225,9 +239,11 @@ describe('params tests', () => {
},
},
};
const parsedJSDocs = jsdocInfo()(jsodInput);
const result = setPaths({}, parsedJSDocs);
expect(result).toEqual(expected);
jsodInput.forEach(jsod => {
const parsedJSDocs = jsdocInfo()(jsod);
const result = setPaths({}, parsedJSDocs);
expect(result).toEqual(expected);
});
});

it('should parse jsdoc path params with enum values', () => {
Expand Down
2 changes: 1 addition & 1 deletion transforms/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const getPropertyName = ({ name: propertyName }) => {
const addTypeApplication = (applications, expression) => {
if (!applications && !expression) return {};
return {
type: expression.name,
type: expression.name.toLowerCase(),
items: {
type: applications[0].name,
},
Expand Down
2 changes: 1 addition & 1 deletion transforms/paths/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const getSchema = (entity, message) => (type, enumValues = [], jsonOptions = {})
const parseItems = formatRefSchema(type.applications);
schema = {
...schema,
type: type.expression.name,
type: type.expression.name.toLowerCase(),
items: parseItems.items ? parseItems.items : parseItems,
};
}
Expand Down