You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Generating typescript types from parameters with default defined results in a type marked as optional with ?, while it should be generated without marking it as optional.
For example given such parameter:
parameters:
- name: statusin: querydescription: Status values that need to be considered for filterexplode: trueschema:
type: stringdefault: availableenum:
- available
- pending
- sold
We get such type
parameters: {query?: {/** @description Status values that need to be considered for filter */status?: 'available'|'pending'|'sold';};
...
};
Notice status? while it should've been status since it will always contain at least the default 'available'.
Including --default-non-nullable flag doesn't fix it.
!options.path?.includes("requestBodies"))// can’t be required, even with defaults
? undefined
: QUESTION_TOKEN;
Reproduction
Full YAML example
openapi: 3.0.4info:
title: Swagger Petstore - OpenAPI 3.0description: |- This is a sample Pet Store Server based on the OpenAPI 3.0 specification. You can find out more about Swagger at [https://swagger.io](https://swagger.io). In the third iteration of the pet store, we've switched to the design first approach! You can now help us improve the API whether it's by making changes to the definition itself or to the code. That way, with time, we can improve the API in general, and expose some of the new features in OAS3. Some useful links: - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore) - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)termsOfService: https://swagger.io/terms/contact:
email: [email protected]license:
name: Apache 2.0url: https://www.apache.org/licenses/LICENSE-2.0.htmlversion: 1.0.12servers:
- url: https://petstore3.swagger.io/api/v3tags:
- name: petdescription: Everything about your PetsexternalDocs:
description: Find out moreurl: https://swagger.io
- name: storedescription: Access to Petstore ordersexternalDocs:
description: Find out more about our storeurl: https://swagger.io
- name: userdescription: Operations about userexternalDocs:
description: Find out more about Swaggerurl: https://swagger.iopaths:
/pet/findByStatus:
get:
tags:
- petsummary: Finds Pets by status.description: Multiple status values can be provided with comma separated strings.operationId: findPetsByStatusparameters:
- name: statusin: querydescription: Status values that need to be considered for filterexplode: trueschema:
type: stringdefault: availableenum:
- available
- pending
- soldresponses:
'200':
description: successful operationcontent:
application/json:
schema:
type: arrayitems:
$ref: '#/components/schemas/Pet'application/xml:
schema:
type: arrayitems:
$ref: '#/components/schemas/Pet''400':
description: Invalid status valuedefault:
description: Unexpected errorcontent:
application/json:
schema:
$ref: '#/components/schemas/Error'security:
- petstore_auth:
- write:pets
- read:petscomponents:
schemas:
Category:
type: objectproperties:
id:
type: integerformat: int64example: 1name:
type: stringexample: Dogsxml:
name: categoryTag:
type: objectproperties:
id:
type: integerformat: int64name:
type: stringxml:
name: tagPet:
required:
- name
- photoUrlstype: objectproperties:
id:
type: integerformat: int64example: 10name:
type: stringexample: doggiecategory:
$ref: '#/components/schemas/Category'photoUrls:
type: arrayxml:
wrapped: trueitems:
type: stringxml:
name: photoUrltags:
type: arrayxml:
wrapped: trueitems:
$ref: '#/components/schemas/Tag'status:
type: stringdescription: pet status in the storeenum:
- available
- pending
- soldxml:
name: petError:
type: objectproperties:
code:
type: stringmessage:
type: stringrequired:
- code
- messagesecuritySchemes:
petstore_auth:
type: oauth2flows:
implicit:
authorizationUrl: https://petstore3.swagger.io/oauth/authorizescopes:
write:pets: modify pets in your accountread:pets: read your petsapi_key:
type: apiKeyname: api_keyin: header
Expected result
parameters: {query?: {/** @description Status values that need to be considered for filter */status: 'available'|'pending'|'sold';};
...
};
Required
My OpenAPI schema is valid and passes the Redocly validator (npx @redocly/cli@latest lint)
openapi-typescript version
7.8.0
Node.js version
22.14.0
OS + version
macOS 15.4.1
Description
Generating typescript types from parameters with
default
defined results in a type marked as optional with?
, while it should be generated without marking it as optional.For example given such parameter:
We get such type
Notice
status?
while it should've beenstatus
since it will always contain at least the default'available'
.Including
--default-non-nullable
flag doesn't fix it.openapi-typescript/packages/openapi-typescript/src/transform/schema-object.ts
Lines 478 to 484 in d309753
Reproduction
Full YAML example
Expected result
Required
npx @redocly/cli@latest lint
)Extra
The text was updated successfully, but these errors were encountered: