Skip to content

Commit

Permalink
Merge branch 'master' of github.com:anymaniax/orval
Browse files Browse the repository at this point in the history
  • Loading branch information
anymaniax committed Mar 5, 2023
2 parents eb0ed3b + b384ff4 commit 6aac5bf
Show file tree
Hide file tree
Showing 5 changed files with 989 additions and 1,330 deletions.
4 changes: 2 additions & 2 deletions docs/src/pages/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ You can install Orval with <a href="https://npmjs.com" target="_blank">NPM</a> o
Using NPM:

```bash
$ npm i -g orval
$ npm i orval -D
```

Using Yarn:

```
$ yarn global add orval
$ yarn add orval -D
```
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"esutils": "2.0.3",
"fs-extra": "^10.1.0",
"globby": "11.1.0",
"ibm-openapi-validator": "^0.88.0",
"ibm-openapi-validator": "^0.97.3",
"lodash.get": "^4.4.2",
"lodash.isempty": "^4.4.0",
"lodash.omit": "^4.5.0",
Expand Down
32 changes: 30 additions & 2 deletions packages/core/src/getters/query-params.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,38 @@ describe('getQueryParams getter', () => {
});

expect(result?.schema.model.trim()).toBe(
`export type Params = { ${parameter.name}${
`export type Params = {\n${parameter.name}${
optional ? '?' : ''
}: string };`,
}: string;\n};`,
);
});
});

it('queryParamWithDescription should be documented', () => {
const result = getQueryParams({
queryParams: [
{
parameter: {
name: 'queryParamWithDescription',
in: 'query',
description: 'Parameter description.',
schema: {
type: 'string',
},
},
imports: [],
},
],
operationName: '',
context,
});
expect(result?.schema.model.trim()).toBe([
'export type Params = {',
'/**',
' * Parameter description.',
' */',
'queryParamWithDescription?: string;',
'};',
].join('\n'));
});
});
21 changes: 11 additions & 10 deletions packages/core/src/getters/query-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
GetterParameters,
GetterQueryParam,
} from '../types';
import { pascal, sanitize } from '../utils';
import { jsDoc, pascal, sanitize } from '../utils';
import { getEnum } from './enum';
import { getKey } from './keys';

Expand Down Expand Up @@ -52,12 +52,13 @@ const getQueryParamsTypes = (
});

const key = getKey(name);
const doc = jsDoc(parameter);

if (parameterImports.length) {
return {
definition: `${key}${!required || schema.default ? '?' : ''}: ${
definition: `${doc}${key}${!required || schema.default ? '?' : ''}: ${
parameterImports[0].name
}`,
};`,
imports: parameterImports,
schemas: [],
};
Expand All @@ -73,9 +74,9 @@ const getQueryParamsTypes = (
);

return {
definition: `${key}${
definition: `${doc}${key}${
!required || schema.default ? '?' : ''
}: ${enumName}`,
}: ${enumName};`,
imports: [{ name: enumName }],
schemas: [
...resolvedeValue.schemas,
Expand All @@ -84,9 +85,9 @@ const getQueryParamsTypes = (
};
}

const definition = `${key}${!required || schema.default ? '?' : ''}: ${
resolvedeValue.value
}`;
const definition = `${doc}${key}${
!required || schema.default ? '?' : ''
}: ${resolvedeValue.value};`;

return {
definition,
Expand Down Expand Up @@ -115,12 +116,12 @@ export const getQueryParams = ({
const schemas = types.flatMap(({ schemas }) => schemas);
const name = `${pascal(operationName)}${pascal(suffix)}`;

const type = types.map(({ definition }) => definition).join('; ');
const type = types.map(({ definition }) => definition).join('\n');
const allOptional = queryParams.every(({ parameter }) => !parameter.required);

const schema = {
name,
model: `export type ${name} = { ${type} };\n`,
model: `export type ${name} = {\n${type}\n};\n`,
imports,
};

Expand Down
Loading

1 comment on commit 6aac5bf

@vercel
Copy link

@vercel vercel bot commented on 6aac5bf Mar 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.