validation
Type: { response?: boolean } | undefined
| Default: undefined
When setting the response
property to true
, it enables runtime validation of API responses against the OpenAPI schema using a validation library of your choice (e.g., zod
, valibot
, ajv
, etc.). This is particularly useful for ensuring that the data received from the server conforms to the expected structure, enhancing type safety and reducing runtime errors.
Usage
typescript
// openapi.config.ts
import { GeneratorConfig } from 'ng-openapi';
const config: GeneratorConfig = {
options: {
validation: {
response: true
}
},
... // other configurations
};
export default config;
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
After generation, you can use your preferred validation library in the parse
option of the generated service methods to validate responses.