orval is able to generate client with appropriate type-signatures (TypeScript) from any valid OpenAPI v3 or Swagger v2 specification, either in yaml or json formats. 🍺
Create an OpenAPI 3.1 schema with const: false in a property
Generate Orval code
Example schema:
openapi: 3.1.0
info:
version: 1.0.0
title: Example
license:
name: MIT
identifier: MIT
servers:
- url: http://api.example.xyz/v1
paths:
/somePath:
get:
operationId: getSomePath
responses:
'200':
description: OK
content:
application/json:
schema: {}
components:
schemas:
BooleanConstFalse:
type: object
required:
- value
properties:
value:
type: boolean
const: false
What happens?
The generated code will produce the field with type: boolean instead of type: false.
Generated code from above sample:
export type BooleanConstFalse = {
value: boolean;
};
What were you expecting to happen?
The type should be generated with type: false.
Expected code from above sample:
export type BooleanConstFalse = {
value: false;
};
Any other comments?
Problem is here, if const is false, then this if statement will evaluate to false and thus not set the value. We just need to change the check to if (itemWithConst.const !== undefined). The same probably happens for integers with const: 0.
What are the steps to reproduce this issue?
const: false
in a propertyExample schema:
What happens?
The generated code will produce the field with
type: boolean
instead oftype: false
.Generated code from above sample:
What were you expecting to happen?
The type should be generated with
type: false
.Expected code from above sample:
Any other comments?
Problem is here, if
const
isfalse
, then thisif
statement will evaluate tofalse
and thus not set thevalue
. We just need to change the check toif (itemWithConst.const !== undefined)
. The same probably happens for integers withconst: 0
.What versions are you using?